]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #8224 from nupplaphil/task/force_avatar_contact
authorHypolite Petovan <hypolite@mrpetovan.com>
Sun, 2 Feb 2020 20:33:48 +0000 (15:33 -0500)
committerGitHub <noreply@github.com>
Sun, 2 Feb 2020 20:33:48 +0000 (15:33 -0500)
Force avatar update for Contact Advanced page

src/Model/Item.php
src/Protocol/ActivityPub/Processor.php
src/Protocol/ActivityPub/Receiver.php

index 47af3d5a69b9e2afdf9a004c9b40fc9638a6dd42..badf9281bb50ff84df1115ef24a9c95426e1b3d4 100644 (file)
@@ -3744,6 +3744,36 @@ class Item
                return 0;
        }
 
+       /**
+        * Return the URI for a link to the post 
+        * 
+        * @param string $uri URI or link to post
+        *
+        * @return string URI
+        */
+       public static function getURIByLink(string $uri)
+       {
+               $ssl_uri = str_replace('http://', 'https://', $uri);
+               $uris = [$uri, $ssl_uri, Strings::normaliseLink($uri)];
+
+               $item = DBA::selectFirst('item', ['uri'], ['uri' => $uris]);
+               if (DBA::isResult($item)) {
+                       return $item['uri'];
+               }
+
+               $itemcontent = DBA::selectFirst('item-content', ['uri-id'], ['plink' => $uris]);
+               if (!DBA::isResult($itemcontent)) {
+                       return '';
+               }
+
+               $itemuri = DBA::selectFirst('item-uri', ['uri'], ['id' => $itemcontent['uri-id']]);
+               if (DBA::isResult($itemuri)) {
+                       return $itemuri['uri'];
+               }
+
+               return '';
+       }
+
        /**
         * Fetches item for given URI or plink
         *
index 9267943d5eb8c9218c4f96509854a844570d8e88..3bc7ff4a73a8df4993bd56f9a6c2c08e511bfb67 100644 (file)
@@ -181,7 +181,7 @@ class Processor
                }
 
                if (empty($activity['directmessage']) && ($activity['id'] != $activity['reply-to-id']) && !Item::exists(['uri' => $activity['reply-to-id']])) {
-                       Logger::log('Parent ' . $activity['reply-to-id'] . ' not found. Try to refetch it.');
+                       Logger::notice('Parent not found. Try to refetch it.', ['parent' => $activity['reply-to-id']]);
                        self::fetchMissingActivity($activity['reply-to-id'], $activity);
                }
 
index b15ce2bc1331f91861bc3fcbb42575593cad7caf..0ef1791413b50ecd02b5f77bcbfbd769cfc9ba3e 100644 (file)
@@ -503,6 +503,10 @@ class Receiver
                // When it is an answer, we inherite the receivers from the parent
                $replyto = JsonLD::fetchElement($activity, 'as:inReplyTo', '@id');
                if (!empty($replyto)) {
+                       // Fix possibly wrong item URI (could be an answer to a plink uri)
+                       $fixedReplyTo = Item::getURIByLink($replyto);
+                       $replyto = $fixedReplyTo ?: $replyto;
+
                        $parents = Item::select(['uid'], ['uri' => $replyto]);
                        while ($parent = Item::fetch($parents)) {
                                $receivers['uid:' . $parent['uid']] = $parent['uid'];
@@ -723,6 +727,15 @@ class Receiver
                $object_data['service'] = JsonLD::fetchElement($activity, 'as:instrument', 'as:name', '@type', 'as:Service');
                $object_data['service'] = JsonLD::fetchElement($object_data, 'service', '@value');
 
+               if (!empty($object_data['object_id'])) {
+                       // Some systems (e.g. GNU Social) don't reply to the "id" field but the "uri" field.
+                       $objectId = Item::getURIByLink($object_data['object_id']);
+                       if (!empty($objectId) && ($object_data['object_id'] != $objectId)) {
+                               Logger::notice('Fix wrong object-id', ['received' => $object_data['object_id'], 'correct' => $objectId]);
+                               $object_data['object_id'] = $objectId;
+                       }
+               }
+
                return $object_data;
        }
 
@@ -932,6 +945,13 @@ class Receiver
                // An empty "id" field is translated to "./" by the compactor, so we have to check for this content
                if (empty($object_data['reply-to-id']) || ($object_data['reply-to-id'] == './')) {
                        $object_data['reply-to-id'] = $object_data['id'];
+               } else {
+                       // Some systems (e.g. GNU Social) don't reply to the "id" field but the "uri" field.
+                       $replyToId = Item::getURIByLink($object_data['reply-to-id']);
+                       if (!empty($replyToId) && ($object_data['reply-to-id'] != $replyToId)) {
+                               Logger::notice('Fix wrong reply-to', ['received' => $object_data['reply-to-id'], 'correct' => $replyToId]);
+                               $object_data['reply-to-id'] = $replyToId;
+                       }
                }
 
                $object_data['published'] = JsonLD::fetchElement($object, 'as:published', '@value');