// 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']);
return $current_post;
}
+ /**
+ * Convert items to forum posts
+ *
+ * (public) forum posts in the new format consist of the regular post by the author
+ * followed by an announce message sent from the forum account.
+ * This means we have to look out for an announce message send by a forum account.
+ *
+ * @param array $item
+ * @return void
+ */
+ private static function transformToForumPost(array $item)
+ {
+ if ($item["verb"] != Activity::ANNOUNCE) {
+ // No announce message, so don't do anything
+ return;
+ }
+
+ $pcontact = Contact::selectFirst(['nurl'], ['id' => $item['author-id'], 'contact-type' => Contact::TYPE_COMMUNITY]);
+ if (empty($pcontact['nurl'])) {
+ // The announce message wasn't created by a forum account, so we don't need to continue
+ return;
+ }
+
+ $contact = Contact::selectFirst(['id'], ['nurl' => $pcontact['nurl'], 'uid' => $item['uid']]);
+ if (!empty($contact['id'])) {
+ $condition = ['uri-id' => $item['parent-uri-id'], 'uid' => $item['uid']];
+ Item::update(['owner-id' => $item['author-id'], 'contact-id' => $contact['id']], $condition);
+ 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
*
Worker::add(['priority' => PRIORITY_HIGH, 'dont_fork' => true], 'Notifier', Delivery::POST, $item_id);
- Item::performActivity($item_id, 'announce', $uid);
+ /// @todo This code should be activated by the end of the year 2020
+ // See also "createActivityFromItem"
+ //Item::performActivity($item_id, 'announce', $uid);
return false;
}