From 3c48a1f787a6338fc1ce9ba7d7ac2a475f1dd093 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 13 Oct 2018 16:41:29 +0000 Subject: [PATCH] AP: Announce will now work --- index.php | 2 +- src/Protocol/ActivityPub/Transmitter.php | 29 +++++++++++++++++++++--- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/index.php b/index.php index dc3dc80f6..6ab405c63 100644 --- a/index.php +++ b/index.php @@ -46,7 +46,7 @@ if ($a->isMaxProcessesReached() || $a->isMaxLoadReached()) { System::httpExit(503, ['title' => 'Error 503 - Service Temporarily Unavailable', 'description' => 'System is currently overloaded. Please try again later.']); } -if (strstr($a->query_string, '.well-known/host-meta') and ($a->query_string != '.well-known/host-meta')) { +if (strstr($a->query_string, '.well-known/host-meta') && ($a->query_string != '.well-known/host-meta')) { System::httpExit(404); } diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index 96c069e58..3fc5900af 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -22,8 +22,11 @@ use Friendica\Model\Profile; use Friendica\Core\Config; use Friendica\Object\Image; use Friendica\Protocol\ActivityPub; +use Friendica\Protocol\Diaspora; use Friendica\Core\Cache; +require_once 'include/api.php'; + /** * @brief ActivityPub Transmitter Protocol class * @@ -37,7 +40,6 @@ use Friendica\Core\Cache; * - Event * * Complicated object types: - * - Announce * - Undo Announce * * General: @@ -467,7 +469,9 @@ class Transmitter */ private static function getTypeOfItem($item) { - if ($item['verb'] == ACTIVITY_POST) { + if (!empty(Diaspora::isReshare($item['body'], false))) { + $type = 'Announce'; + } elseif ($item['verb'] == ACTIVITY_POST) { if ($item['created'] == $item['edited']) { $type = 'Create'; } else { @@ -558,8 +562,10 @@ class Transmitter $data = array_merge($data, self::createPermissionBlockForItem($item)); - if (in_array($data['type'], ['Create', 'Update', 'Announce', 'Delete'])) { + if (in_array($data['type'], ['Create', 'Update', 'Delete'])) { $data['object'] = self::createNote($item); + } elseif ($data['type'] == 'Announce') { + $data['object'] = self::createAnnounce($item); } elseif ($data['type'] == 'Undo') { $data['object'] = self::createActivityFromItem($item_id, true); } else { @@ -805,6 +811,23 @@ class Transmitter return $data; } + /** + * Creates an announce object entry + * + * @param array $item + * + * @return string with announced object url + */ + public static function createAnnounce($item) + { + $announce = api_share_as_retweet($item); + if (empty($announce['plink'])) { + return self::createNote($item); + } + + return $announce['plink']; + } + /** * Transmits a contact suggestion to a given inbox *