]> git.mxchange.org Git - friendica.git/commitdiff
Fixing processing forum posts
authorMichael <heluecht@pirati.ca>
Sun, 9 Aug 2020 22:46:18 +0000 (22:46 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 9 Aug 2020 22:46:18 +0000 (22:46 +0000)
src/Model/Item.php
src/Protocol/ActivityPub/Receiver.php
src/Protocol/DFRN.php

index d8a9f631c117d285b3643e6b157489364ed7200a..b486ee53a3572c768f8611794a7a4cdeeca3cf0e 100644 (file)
@@ -1800,6 +1800,7 @@ class Item
                // It is mainly used in the "post_local" hook.
                unset($item['api_source']);
 
+               self::transformToForumPost($item);
 
                // Check for hashtags in the body and repair or add hashtag links
                $item['body'] = self::setHashtags($item['body']);
@@ -1990,6 +1991,31 @@ class Item
                return $current_post;
        }
 
+       /**
+        * Convert items to forum posts
+        *
+        * @param array $item
+        * @return void
+        */
+       private static function transformToForumPost(array $item)
+       {
+               if ($item["verb"] != Activity::ANNOUNCE) {
+                       return;
+               }
+
+               $pcontact = Contact::selectFirst(['nurl'], ['id' => $item['author-id'], 'contact-type' => Contact::TYPE_COMMUNITY]);
+               if (empty($pcontact['nurl'])) {
+                       return;
+               }
+
+               $contact = Contact::selectFirst(['id'], ['nurl' => $pcontact['nurl'], 'uid' => $item['uid']]);
+               if (!empty($contact['id'])) {
+                       Item::update(['owner-id' => $item['author-id'], 'contact-id' => $contact['id']],
+                               ['uri-id' => $item['parent-uri-id'], 'uid' => $item['uid']]);
+                       LOgger::info('Convert message into a forum message', ['uri-id' => $item['uri-id'], 'parent-uri-id' => $item['parent-uri-id'], 'uid' => $item['uid'], 'owner-id' => $item['author-id'], 'contact-id' => $contact['id']]);
+               }
+       }
+
        /**
         * Distribute the given item to users who subscribed to their tags
         *
index 88c23f2be63623989f6b782caae210faed72c5d8..d59a5da0ea8517564347b87eb0f9dcaab8e6ac4f 100644 (file)
@@ -387,29 +387,23 @@ class Receiver
 
                        case 'as:Announce':
                                if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
-                                       $profile = APContact::getByURL($object_data['actor']);
-                                       // Reshared posts from persons appear as summary at the bottom
-                                       // If this isn't set, then a single reshare appears on top. This is used for groups.
-                                       $object_data['thread-completion'] = ($profile['type'] != 'Group');
+                                       $object_data['thread-completion'] = true;
 
                                        $item = ActivityPub\Processor::createItem($object_data);
                                        ActivityPub\Processor::postItem($object_data, $item);
 
-                                       // Add the bottom reshare information only for persons
-                                       if ($profile['type'] != 'Group') {
-                                               $announce_object_data = self::processObject($activity);
-                                               $announce_object_data['name'] = $type;
-                                               $announce_object_data['author'] = JsonLD::fetchElement($activity, 'as:actor', '@id');
-                                               $announce_object_data['object_id'] = $object_data['object_id'];
-                                               $announce_object_data['object_type'] = $object_data['object_type'];
-                                               $announce_object_data['push'] = $push;
-
-                                               if (!empty($body)) {
-                                                       $announce_object_data['raw'] = $body;
-                                               }
+                                       $announce_object_data = self::processObject($activity);
+                                       $announce_object_data['name'] = $type;
+                                       $announce_object_data['author'] = JsonLD::fetchElement($activity, 'as:actor', '@id');
+                                       $announce_object_data['object_id'] = $object_data['object_id'];
+                                       $announce_object_data['object_type'] = $object_data['object_type'];
+                                       $announce_object_data['push'] = $push;
 
-                                               ActivityPub\Processor::createActivity($announce_object_data, Activity::ANNOUNCE);
+                                       if (!empty($body)) {
+                                               $announce_object_data['raw'] = $body;
                                        }
+
+                                       ActivityPub\Processor::createActivity($announce_object_data, Activity::ANNOUNCE);
                                }
                                break;
 
index 2956e7bfc8b3acc9d649c5d106173aaaed9eea77..064f1f3aca6027972c20cdc09cc8fb43fe824c46 100644 (file)
@@ -2162,6 +2162,7 @@ class DFRN
                                || ($item["verb"] == Activity::ATTEND)
                                || ($item["verb"] == Activity::ATTENDNO)
                                || ($item["verb"] == Activity::ATTENDMAYBE)
+                               || ($item["verb"] == Activity::ANNOUNCE)
                        ) {
                                $is_like = true;
                                $item["gravity"] = GRAVITY_ACTIVITY;