#17 「いいね解除」された時に投稿が増えるバグ、及び、付随するバグの修正

Спојено
senooken споји(ла) 1 комит(е) из tak4/main у gnusocialjp/main пре 1 година

+ 1 - 1
plugins/ActivityPub/ActivityPubPlugin.php

@@ -139,7 +139,7 @@ class ActivityPubPlugin extends Plugin
                         // Keep conversation tree
                         return Notice::getByUri($object['id']);
                     } catch (Exception $e) {
-                        // NOOP
+                        common_debug('ActivityPubPlugin Notice Grabber: failed to find object-id: ' . $object['id']);
                     }
                     return Activitypub_notice::create_notice($object, $acclaimed_actor_profile);
                 } else {

+ 3 - 1
plugins/ActivityPub/lib/inbox_handler.php

@@ -391,7 +391,9 @@ class Activitypub_inbox_handler
      */
     private function handle_undo_like()
     {
-        $notice = ActivityPubPlugin::grab_notice_from_url($this->activity['id']);
+        $object = $this->activity['object'];
+        $notice_url = $object['object'];
+        $notice = ActivityPubPlugin::grab_notice_from_url($notice_url);
         Fave::removeEntry($this->actor, $notice);
     }
 

+ 7 - 1
plugins/ActivityPub/lib/models/Activitypub_like.php

@@ -46,12 +46,18 @@ class Activitypub_like
      */
     public static function like_to_array(string $actor, Notice $notice): array
     {
+	if ($notice->hasParent() && Notice::getByID($notice->reply_to)) {
+		$object = Activitypub_notice::getUri($notice->getParent());
+	} else {
+		// When unlike.
+		$object = Activitypub_notice::getUri($notice);
+	}
         $res = [
             '@context' => 'https://www.w3.org/ns/activitystreams',
             'id'       => Activitypub_notice::getUri($notice),
             'type'     => 'Like',
             'actor'    => $actor,
-            'object'   => Activitypub_notice::getUri($notice->getParent()),
+            'object'   => $object,
         ];
         return $res;
     }

+ 6 - 0
plugins/ActivityPub/lib/models/Activitypub_notice.php

@@ -150,6 +150,12 @@ class Activitypub_notice
         $url = isset($object['url']) ? $object['url'] : $id; // string
         $content = $object['content'];                       // string
 
+        // Avoid duplication
+        if (is_numeric($id) && Notice::getByID((int)$id)) {
+            common_debug('create_notice: not found $id' . $id);
+            return null;
+        }
+
         // possible keys: ['inReplyTo', 'latitude', 'longitude']
         $settings = [];
         if (isset($object['inReplyTo'])) {