]> git.mxchange.org Git - friendica.git/commitdiff
Diaspora signatures are now stored and transmitted correctly
authorMichael <heluecht@pirati.ca>
Sat, 27 Oct 2018 14:35:22 +0000 (14:35 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 27 Oct 2018 14:35:22 +0000 (14:35 +0000)
mod/item.php
src/Model/Item.php
src/Protocol/ActivityPub/Processor.php
src/Protocol/ActivityPub/Receiver.php
src/Protocol/ActivityPub/Transmitter.php
src/Protocol/Diaspora.php

index a4f8d7c6679709e05b0c09ad68dc520ddd112435..032cd511ad4b03dfd57d5394614b18702e6a68fc 100644 (file)
@@ -727,6 +727,11 @@ function item_post(App $a) {
        unset($datarray['self']);
        unset($datarray['api_source']);
 
+       $signed = Diaspora::createCommentSignature($author, $datarray);
+       if (!empty($signed)) {
+               $datarray['diaspora_signed_text'] = json_encode($signed);
+       }
+
        $post_id = Item::insert($datarray);
 
        if (!$post_id) {
@@ -765,9 +770,6 @@ function item_post(App $a) {
                                'parent_uri'   => $parent_item['uri']
                        ]);
                }
-
-               // Store the comment signature information in case we need to relay to Diaspora
-               Diaspora::storeCommentSignature($datarray, $author, ($self ? $user['prvkey'] : false), $post_id);
        } else {
                if (($contact_record != $author) && !count($forum_contact)) {
                        notification([
index 298a8be0018872068cbba511662ffe27615b3d5e..c4985aa835ec8d77ac937fdb556cc670f0799471 100644 (file)
@@ -3113,7 +3113,7 @@ class Item extends BaseObject
 
                $signed = Diaspora::createLikeSignature($item_contact, $new_item);
                if (!empty($signed)) {
-                       $new_item['diaspora_signed_text'] = $signed;
+                       $new_item['diaspora_signed_text'] = json_encode($signed);
                }
 
                $new_item_id = self::insert($new_item);
index dee70f152c08d10aeeb0cfcd7668fba92244a087..964499af1d41904d42ced55872d3b95e92559377 100644 (file)
@@ -144,6 +144,8 @@ class Processor
                        self::fetchMissingActivity($activity['reply-to-id'], $activity);
                }
 
+               $item['diaspora_signed_text'] = defaults($activity, 'diaspora:comment', '');
+
                self::postItem($activity, $item);
        }
 
@@ -174,6 +176,8 @@ class Processor
                $item['gravity'] = GRAVITY_ACTIVITY;
                $item['object-type'] = ACTIVITY_OBJ_NOTE;
 
+               $item['diaspora_signed_text'] = defaults($activity, 'diaspora:like', '');
+
                self::postItem($activity, $item);
        }
 
@@ -260,7 +264,6 @@ class Processor
                $item['tag'] = self::constructTagList($activity['tags'], $activity['sensitive']);
                $item['app'] = $activity['generator'];
                $item['plink'] = defaults($activity, 'alternate-url', $item['uri']);
-               $item['diaspora_signed_text'] = defaults($activity, 'diaspora:comment', '');
 
                $item = self::constructAttachList($activity['attachments'], $item);
 
index e94940a39e3174cafc9417ca0493d2b1be6c39b2..8bc9d76463397ee7b190bff92ae8d6ed333f8dc5 100644 (file)
@@ -705,6 +705,7 @@ class Receiver
 
                $object_data['diaspora:guid'] = JsonLD::fetchElement($object, 'diaspora:guid');
                $object_data['diaspora:comment'] = JsonLD::fetchElement($object, 'diaspora:comment');
+               $object_data['diaspora:like'] = JsonLD::fetchElement($object, 'diaspora:like');
                $object_data['actor'] = $object_data['author'] = $actor;
                $object_data['context'] = JsonLD::fetchElement($object, 'as:context');
                $object_data['conversation'] = JsonLD::fetchElement($object, 'ostatus:conversation');
index 8f01a53611299383b8e98479b81810ba5c24a6ad..ed2a84e7103da3753ea8adff52dc0ddcd276b9df 100644 (file)
@@ -627,6 +627,9 @@ class Transmitter
                        $data['object'] = self::createActivityFromItem($item_id, true);
                } else {
                        $data['diaspora:guid'] = $item['guid'];
+                       if (!empty($item['signed_text'])) {
+                               $data['diaspora:like'] = $item['signed_text'];
+                       }
                        $data['object'] = $item['thr-parent'];
                }
 
index f04eaa2a4049de2d186006663fd167cdd2d38043..9c48c1bf24225779a200043c45d457e9f8421bf2 100644 (file)
@@ -4150,23 +4150,27 @@ class Diaspora
        }
 
        /**
-        * @brief Stores the signature for comments that are created on our system
+        * @brief Creates the signature for Comments that are created on our system
         *
-        * @param array  $item       The item array of the comment
-        * @param array  $contact    The contact array of the item owner
-        * @param string $uprvkey    The private key of the sender
-        * @param int    $message_id The message id of the comment
+        * @param array $contact The contact array of the comment
+        * @param array $item Item array
         *
-        * @return bool Success
+        * @return array Signed content
         */
-       public static function storeCommentSignature(array $item, array $contact, $uprvkey, $message_id)
+       public static function createCommentSignature(array $contact, array $item)
        {
-               if ($uprvkey == "") {
-                       logger('No private key, so not storing comment signature', LOGGER_DEBUG);
+               // Is the contact the owner? Then fetch the private key
+               if (!$contact['self'] || ($contact['uid'] == 0)) {
+                       logger("No owner post, so not storing signature", LOGGER_DEBUG);
                        return false;
                }
 
-               $contact["uprvkey"] = $uprvkey;
+               $user = DBA::selectFirst('user', ['prvkey'], ['uid' => $contact["uid"]]);
+               if (!DBA::isResult($user)) {
+                       return false;
+               }
+
+               $contact["uprvkey"] = $user['prvkey'];
 
                $message = self::constructComment($item, $contact);
                if ($message === false) {
@@ -4175,13 +4179,6 @@ 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' => $message_id, 'signed_text' => json_encode($message)]);
-
-               logger('Stored diaspora comment signature');
-               return true;
+               return $message;
        }
 }