]> git.mxchange.org Git - friendica.git/commitdiff
Fixes duplicated transmissions and not working undo of like/dislike
authorMichael <heluecht@pirati.ca>
Sat, 27 Oct 2018 11:09:23 +0000 (11:09 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 27 Oct 2018 11:09:23 +0000 (11:09 +0000)
mod/item.php
mod/photos.php
mod/poke.php
src/Model/Item.php
src/Protocol/ActivityPub/Transmitter.php
src/Protocol/Diaspora.php
src/Worker/Notifier.php

index dcccf5d75c096202935953dc86903a88ed962e08..a4f8d7c6679709e05b0c09ad68dc520ddd112435 100644 (file)
@@ -830,9 +830,6 @@ function item_post(App $a) {
        // We don't fork a new process since this is done anyway with the following command
        Worker::add(['priority' => PRIORITY_HIGH, 'dont_fork' => true], "CreateShadowEntry", $post_id);
 
-       // Call the background process that is delivering the item to the receivers
-       Worker::add(PRIORITY_HIGH, "Notifier", $notify_type, $post_id);
-
        logger('post_complete');
 
        if ($api_source) {
index b80350221bf4cdc93336714fc66b47661ef8d3e5..f5b1bf91901fc0b80da8f06ff3b67ee8946627a4 100644 (file)
@@ -691,9 +691,6 @@ function photos_post(App $a)
                                        $arr['target'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '" />' . "\n" . '<link rel="preview" type="'.$p[0]['type'].'" href="' . System::baseUrl() . "/photo/" . $p[0]['resource-id'] . '-' . $best . '.' . $ext . '" />') . '</link></target>';
 
                                        $item_id = Item::insert($arr);
-                                       if ($item_id) {
-                                               Worker::add(PRIORITY_HIGH, "Notifier", "tag", $item_id);
-                                       }
                                }
                        }
                }
@@ -919,10 +916,6 @@ function photos_post(App $a)
        // Update the photo albums cache
        Photo::clearAlbumCache($page_owner_uid);
 
-       if ($visible) {
-               Worker::add(PRIORITY_HIGH, "Notifier", 'wall-new', $item_id);
-       }
-
        Addon::callHooks('photo_post_end', $item_id);
 
        // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
index 80d476005c06aa526350f48ac81d6a5173f2831d..3318b0fcde9b9cd9a9ff82e8e32128d74e857110 100644 (file)
@@ -128,9 +128,6 @@ function poke_init(App $a)
        $arr['object'] .= '</link></object>' . "\n";
 
        $item_id = Item::insert($arr);
-       if ($item_id) {
-               Worker::add(PRIORITY_HIGH, "Notifier", "tag", $item_id);
-       }
 
        Addon::callHooks('post_local_end', $arr);
 
index e7358a776e8412b0a9f2be4c712e43ddb136ae0c..298a8be0018872068cbba511662ffe27615b3d5e 100644 (file)
@@ -1827,9 +1827,17 @@ class Item extends BaseObject
                check_user_notification($current_post);
 
                if ($notify) {
-                       Worker::add(['priority' => $priority, 'dont_fork' => true], "Notifier", $notify_type, $current_post);
-               } elseif (!empty($parent) && $parent['origin']) {
-                       Worker::add(['priority' => PRIORITY_HIGH, 'dont_fork' => true], "Notifier", "comment-import", $current_post);
+                       Worker::add(['priority' => $priority, 'dont_fork' => true], 'Notifier', $notify_type, $current_post);
+               } elseif ($item['visible'] && ((!empty($parent) && $parent['origin']) || $item['origin'])) {
+                       if ($item['gravity'] == GRAVITY_ACTIVITY) {
+                               $cmd = $item['origin'] ? 'activity-new' : 'activity-import';
+                       } elseif ($item['gravity'] == GRAVITY_COMMENT) {
+                               $cmd = $item['origin'] ? 'comment-new' : 'comment-import';
+                       } else {
+                               $cmd = 'wall-new';
+                       }
+
+                       Worker::add(['priority' => PRIORITY_HIGH, 'dont_fork' => true], 'Notifier', $cmd, $current_post);
                }
 
                return $current_post;
@@ -3103,6 +3111,11 @@ class Item extends BaseObject
                        'unseen'        => 1,
                ];
 
+               $signed = Diaspora::createLikeSignature($item_contact, $new_item);
+               if (!empty($signed)) {
+                       $new_item['diaspora_signed_text'] = $signed;
+               }
+
                $new_item_id = self::insert($new_item);
 
                // If the parent item isn't visible then set it to visible
@@ -3110,15 +3123,10 @@ class Item extends BaseObject
                        self::update(['visible' => true], ['id' => $item['id']]);
                }
 
-               // Save the author information for the like in case we need to relay to Diaspora
-               Diaspora::storeLikeSignature($item_contact, $new_item_id);
-
                $new_item['id'] = $new_item_id;
 
                Addon::callHooks('post_local_end', $new_item);
 
-               Worker::add(PRIORITY_HIGH, "Notifier", "like", $new_item_id);
-
                return true;
        }
 
index bfc26cd9f138bbc0f2290d7a486253a0a465a24f..8f01a53611299383b8e98479b81810ba5c24a6ad 100644 (file)
@@ -549,15 +549,19 @@ class Transmitter
         * Creates the activity or fetches it from the cache
         *
         * @param integer $item_id
+        * @param boolean $force   Force new cache entry
         *
         * @return array with the activity
         */
-       public static function createCachedActivityFromItem($item_id)
+       public static function createCachedActivityFromItem($item_id, $force = false)
        {
                $cachekey = 'APDelivery:createActivity:' . $item_id;
-               $data = Cache::get($cachekey);
-               if (!is_null($data)) {
-                       return $data;
+
+               if (!$force) {
+                       $data = Cache::get($cachekey);
+                       if (!is_null($data)) {
+                               return $data;
+                       }
                }
 
                $data = ActivityPub\Transmitter::createActivityFromItem($item_id);
index 1a8054aad51757a0103d633a0b79b24c4596f3a4..f04eaa2a4049de2d186006663fd167cdd2d38043 100644 (file)
@@ -4113,14 +4113,14 @@ class Diaspora
        }
 
        /**
-        * @brief Stores the signature for likes that are created on our system
+        * @brief Creates the signature for likes that are created on our system
         *
         * @param array $contact The contact array of the "like"
-        * @param int   $post_id The post id of the "like"
+        * @param array $item Item array
         *
-        * @return bool Success
+        * @return array Signed content
         */
-       public static function storeLikeSignature(array $contact, $post_id)
+       public static function createLikeSignature(array $contact, array $item)
        {
                // Is the contact the owner? Then fetch the private key
                if (!$contact['self'] || ($contact['uid'] == 0)) {
@@ -4135,11 +4135,6 @@ class Diaspora
 
                $contact["uprvkey"] = $user['prvkey'];
 
-               $item = Item::selectFirst([], ['id' => $post_id]);
-               if (!DBA::isResult($item)) {
-                       return false;
-               }
-
                if (!in_array($item["verb"], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) {
                        return false;
                }
@@ -4151,14 +4146,7 @@ class Diaspora
 
                $message["author_signature"] = self::signature($contact, $message);
 
-               /*
-                * Now store the signature more flexible to dynamically support new fields.
-                * This will break Diaspora compatibility with Friendica versions prior to 3.5.
-                */
-               DBA::insert('sign', ['iid' => $post_id, 'signed_text' => json_encode($message)]);
-
-               logger('Stored diaspora like signature');
-               return true;
+               return $message;
        }
 
        /**
index 31000a26f29e3eb88d737e160032e1b365181ee6..480938ec534577a787856099c1c0271ea04c4352 100644 (file)
@@ -539,7 +539,7 @@ class Notifier
                }
 
                // Fill the item cache
-               ActivityPub\Transmitter::createCachedActivityFromItem($item_id);
+               ActivityPub\Transmitter::createCachedActivityFromItem($item_id, true);
 
                foreach ($inboxes as $inbox) {
                        logger('Deliver ' . $item_id .' to ' . $inbox .' via ActivityPub', LOGGER_DEBUG);