From 62ce87dfe6923aaf142939d98bef1c95e2745f78 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 9 Aug 2020 22:46:18 +0000 Subject: [PATCH] Fixing processing forum posts --- src/Model/Item.php | 26 +++++++++++++++++++++++++ src/Protocol/ActivityPub/Receiver.php | 28 +++++++++++---------------- src/Protocol/DFRN.php | 1 + 3 files changed, 38 insertions(+), 17 deletions(-) diff --git a/src/Model/Item.php b/src/Model/Item.php index d8a9f631c1..b486ee53a3 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -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 * diff --git a/src/Protocol/ActivityPub/Receiver.php b/src/Protocol/ActivityPub/Receiver.php index 88c23f2be6..d59a5da0ea 100644 --- a/src/Protocol/ActivityPub/Receiver.php +++ b/src/Protocol/ActivityPub/Receiver.php @@ -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; + $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; - } - - 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; diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index 2956e7bfc8..064f1f3aca 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -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;