]> git.mxchange.org Git - friendica.git/commitdiff
Fix delivery only for comments to native networks
authorMichael <heluecht@pirati.ca>
Wed, 26 Sep 2018 13:00:48 +0000 (13:00 +0000)
committerMichael <heluecht@pirati.ca>
Wed, 26 Sep 2018 13:00:48 +0000 (13:00 +0000)
src/Protocol/ActivityPub.php
src/Worker/APDelivery.php

index 9463c783d1fed223ee760b1e9108d487baf57b61..f0717b0f0994eb852251f5dbd5359379c2d0949f 100644 (file)
@@ -66,6 +66,8 @@ use Friendica\Core\Config;
  * - Event
  *
  * General:
+ * - Attachments
+ * - nsfw (sensitive)
  * - Queueing unsucessful deliveries
  * - Polling the outboxes for missing content?
  * - Possibly using the LD-JSON parser
@@ -465,7 +467,7 @@ class ActivityPub
 
        public static function createActivityFromItem($item_id, $object_mode = false)
        {
-               $item = Item::selectFirst([], ['id' => $item_id]);
+               $item = Item::selectFirst([], ['id' => $item_id, 'parent-network' => Protocol::NATIVE_SUPPORT]);
 
                if (!DBA::isResult($item)) {
                        return false;
@@ -504,7 +506,7 @@ class ActivityPub
                        $data['updated'] = DateTimeFormat::utc($item["edited"]."+00:00", DateTimeFormat::ATOM);
                }
 
-               $data['context'] = self::createConversationURLFromItem($item);
+               $data['context'] = self::fetchContextURLForItem($item);
 
                $data = array_merge($data, ActivityPub::createPermissionBlockForItem($item));
 
@@ -527,7 +529,7 @@ class ActivityPub
 
        public static function createObjectFromItemID($item_id)
        {
-               $item = Item::selectFirst([], ['id' => $item_id]);
+               $item = Item::selectFirst([], ['id' => $item_id, 'parent-network' => Protocol::NATIVE_SUPPORT]);
 
                if (!DBA::isResult($item)) {
                        return false;
@@ -559,17 +561,32 @@ class ActivityPub
                return $tags;
        }
 
-       private static function createConversationURLFromItem($item)
+       private static function fetchConversationURLForItem($item)
        {
-               $conversation = DBA::selectFirst('conversation', ['conversation-uri'], ['item-uri' => $item['parent-uri']]);
+               $conversation = DBA::selectFirst('conversation', ['conversation-href', 'conversation-uri'], ['item-uri' => $item['parent-uri']]);
                if (DBA::isResult($conversation) && !empty($conversation['conversation-uri'])) {
                        $conversation_uri = $conversation['conversation-uri'];
+               } elseif (DBA::isResult($conversation) && !empty($conversation['conversation-href'])) {
+                       $conversation_uri = $conversation['conversation-href'];
                } else {
                        $conversation_uri = str_replace('/object/', '/context/', $item['parent-uri']);
                }
                return $conversation_uri;
        }
 
+       private static function fetchContextURLForItem($item)
+       {
+               $conversation = DBA::selectFirst('conversation', ['conversation-href', 'conversation-uri'], ['item-uri' => $item['parent-uri']]);
+               if (DBA::isResult($conversation) && !empty($conversation['conversation-href'])) {
+                       $context_uri = $conversation['conversation-href'];
+               } elseif (DBA::isResult($conversation) && !empty($conversation['conversation-uri'])) {
+                       $context_uri = $conversation['conversation-uri'];
+               } else {
+                       $context_uri = str_replace('/object/', '/context/', $item['parent-uri']);
+               }
+               return $context_uri;
+       }
+
        private static function CreateNote($item)
        {
                if (!empty($item['title'])) {
@@ -609,7 +626,8 @@ class ActivityPub
                $data['attributedTo'] = $item['author-link'];
                $data['actor'] = $item['author-link'];
                $data['sensitive'] = false; // - Query NSFW
-               $data['conversation'] = $data['context'] = self::createConversationURLFromItem($item);
+               $data['conversation'] = self::fetchConversationURLForItem($item);
+               $data['context'] = self::fetchContextURLForItem($item);
 
                if (!empty($item['title'])) {
                        $data['name'] = BBCode::convert($item['title'], false, 7);
@@ -621,7 +639,6 @@ class ActivityPub
                $data['tag'] = self::createTagList($item);
                $data = array_merge($data, ActivityPub::createPermissionBlockForItem($item));
 
-               //$data['emoji'] = []; // Ignore by now
                return $data;
        }
 
@@ -1524,6 +1541,7 @@ class ActivityPub
 
                $item['protocol'] = Conversation::PARCEL_ACTIVITYPUB;
                $item['source'] = $body;
+               $item['conversation-href'] = $activity['context'];
                $item['conversation-uri'] = $activity['conversation'];
 
                foreach ($activity['receiver'] as $receiver) {
index 493bb5fac83a993256e77d836808eb45daf0ea12..943238a7b41ecdc90e6328f2e32ae1a40673c3a7 100644 (file)
@@ -20,7 +20,9 @@ class APDelivery extends BaseObject
                } elseif ($cmd == Delivery::RELOCATION) {
                } else {
                        $data = ActivityPub::createActivityFromItem($item_id);
-                       HTTPSignature::transmit($data, $inbox, $uid);
+                       if (!empty($data)) {
+                               HTTPSignature::transmit($data, $inbox, $uid);
+                       }
                }
 
                return;