From: Michael Date: Mon, 28 Jan 2019 06:23:06 +0000 (+0000) Subject: Another preparation for forum posts via AP X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=030c0b5dc661bacc7d66db56263ec1dc227e29e6;p=friendica.git Another preparation for forum posts via AP --- diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index 05ce138794..41239b3afd 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -28,6 +28,7 @@ use Friendica\Util\Map; use Friendica\Util\Network; require_once 'include/api.php'; +require_once 'mod/share.php'; /** * @brief ActivityPub Transmitter Protocol class @@ -635,16 +636,29 @@ class Transmitter return false; } - $condition = ['item-uri' => $item['uri'], 'protocol' => Conversation::PARCEL_ACTIVITYPUB]; - $conversation = DBA::selectFirst('conversation', ['source'], $condition); - if (DBA::isResult($conversation)) { - $data = json_decode($conversation['source']); - if (!empty($data)) { - return $data; + if ($item['wall']) { + $owner = User::getOwnerDataById($item['uid']); + if (($owner['account-type'] == User::ACCOUNT_TYPE_COMMUNITY) && ($item['author-link'] != $owner['url'])) { + $type = 'Announce'; + + // Disguise forum posts as reshares. Will later be converted to a real announce + $item['body'] = share_header($item['author-name'], $item['author-link'], $item['author-avatar'], + $item['guid'], $item['created'], $item['plink']) . $item['body'] . '[/share]'; } } - $type = self::getTypeOfItem($item); + if (empty($type)) { + $condition = ['item-uri' => $item['uri'], 'protocol' => Conversation::PARCEL_ACTIVITYPUB]; + $conversation = DBA::selectFirst('conversation', ['source'], $condition); + if (DBA::isResult($conversation)) { + $data = json_decode($conversation['source']); + if (!empty($data)) { + return $data; + } + } + + $type = self::getTypeOfItem($item); + } if (!$object_mode) { $data = ['@context' => ActivityPub::CONTEXT]; @@ -671,7 +685,7 @@ class Transmitter if (in_array($data['type'], ['Create', 'Update', 'Delete'])) { $data['object'] = self::createNote($item); } elseif ($data['type'] == 'Announce') { - $data['object'] = self::createAnnounce($item); + $data = self::createAnnounce($item, $data); } elseif ($data['type'] == 'Undo') { $data['object'] = self::createActivityFromItem($item_id, true); } else { @@ -1045,11 +1059,13 @@ class Transmitter * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \ImagickException */ - public static function createAnnounce($item) + private static function createAnnounce($item, $data) { $announce = api_share_as_retweet($item); if (empty($announce['plink'])) { - return self::createNote($item); + $data['type'] = 'Create'; + $data['object'] = self::createNote($item); + return $data; } // Fetch the original id of the object @@ -1058,11 +1074,14 @@ class Transmitter $ldactivity = JsonLD::compact($activity); $id = JsonLD::fetchElement($ldactivity, '@id'); if (!empty($id)) { - return $id; + $data['object'] = $id; + return $data; } } - return self::createNote($item); + $data['type'] = 'Create'; + $data['object'] = self::createNote($item); + return $data; } /** diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index 512fbe8844..4d63d436fe 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -603,15 +603,20 @@ class Notifier return false; } + return self::isForum($item['contact-id']); + } + + private static function isForum($contactid) + { $fields = ['forum', 'prv']; - $condition = ['id' => $item['contact-id']]; + $condition = ['id' => $contactid]; $contact = DBA::selectFirst('contact', $fields, $condition); if (!DBA::isResult($contact)) { // Should never happen return false; } - // Is the post from a forum? + // Is it a forum? return ($contact['forum'] || $contact['prv']); } }