]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/ActivityPub/Processor.php
Merge remote-tracking branch 'upstream/develop' into more-q
[friendica.git] / src / Protocol / ActivityPub / Processor.php
index 790a933bb03925c32db92ad14aecd57eafbf8618..47ea6a1bde5db78b8626a3852012010de092ec3b 100644 (file)
@@ -90,7 +90,7 @@ class Processor
         *
         * @return string with replaced emojis
         */
-       private static function replaceEmojis($body, array $emojis)
+       private static function replaceEmojis(int $uri_id, $body, array $emojis)
        {
                $body = strtr($body,
                        array_combine(
@@ -101,6 +101,10 @@ class Processor
                        )
                );
 
+               // We store the emoji here to be able to avoid storing it in the media
+               foreach ($emojis as $emoji) {
+                       Post\Link::getByLink($uri_id, $emoji['href']);
+               }
                return $body;
        }
 
@@ -392,7 +396,7 @@ class Processor
         *
         * @param array $activity Activity array
         * @param array $item
-        * 
+        *
         * @return int event id
         * @throws \Exception
         */
@@ -456,7 +460,7 @@ class Processor
                }
 
                if (!empty($activity['emojis'])) {
-                       $content = self::replaceEmojis($content, $activity['emojis']);
+                       $content = self::replaceEmojis($item['uri-id'], $content, $activity['emojis']);
                }
 
                $content = self::addMentionLinks($content, $activity['tags']);
@@ -912,7 +916,7 @@ class Processor
                $cid = Contact::getIdForURL($activity['actor'], $uid);
                if (!empty($cid)) {
                        self::switchContact($cid);
-                       DBA::update('contact', ['hub-verify' => $activity['id'], 'protocol' => Protocol::ACTIVITYPUB], ['id' => $cid]);
+                       Contact::update(['hub-verify' => $activity['id'], 'protocol' => Protocol::ACTIVITYPUB], ['id' => $cid]);
                }
 
                $item = ['author-id' => Contact::getIdForURL($activity['actor']),
@@ -932,7 +936,7 @@ class Processor
                }
 
                if (empty($contact)) {
-                       DBA::update('contact', ['hub-verify' => $activity['id'], 'protocol' => Protocol::ACTIVITYPUB], ['id' => $cid]);
+                       Contact::update(['hub-verify' => $activity['id'], 'protocol' => Protocol::ACTIVITYPUB], ['id' => $cid]);
                }
 
                Logger::notice('Follow user ' . $uid . ' from contact ' . $cid . ' with id ' . $activity['id']);
@@ -1011,7 +1015,7 @@ class Processor
                }
 
                $condition = ['id' => $cid];
-               DBA::update('contact', $fields, $condition);
+               Contact::update($fields, $condition);
                Logger::info('Accept contact request', ['contact' => $cid, 'user' => $uid]);
        }
 
@@ -1037,9 +1041,12 @@ class Processor
 
                self::switchContact($cid);
 
-               if (DBA::exists('contact', ['id' => $cid, 'rel' => Contact::SHARING])) {
+               $contact = Contact::getById($cid, ['rel']);
+               if ($contact['rel'] == Contact::SHARING) {
                        Contact::remove($cid);
                        Logger::info('Rejected contact request - contact removed', ['contact' => $cid, 'user' => $uid]);
+               } elseif ($contact['rel'] == Contact::FRIEND) {
+                       Contact::update(['rel' => Contact::FOLLOWER], ['id' => $cid]);
                } else {
                        Logger::info('Rejected contact request', ['contact' => $cid, 'user' => $uid]);
                }
@@ -1102,7 +1109,7 @@ class Processor
                        return;
                }
 
-               Contact::removeFollower($owner, $contact);
+               Contact::removeFollower($contact);
                Logger::info('Undo following request', ['contact' => $cid, 'user' => $uid]);
        }
 
@@ -1207,20 +1214,24 @@ class Processor
                // This prevents links to be added again to Pleroma-style mention links
                $body = self::normalizeMentionLinks($body);
 
-               foreach ($tags as $tag) {
-                       if (empty($tag['name']) || empty($tag['type']) || empty($tag['href']) || !in_array($tag['type'], ['Mention', 'Hashtag'])) {
-                               continue;
-                       }
+               $body = BBCode::performWithEscapedTags($body, ['url'], function ($body) use ($tags) {
+                       foreach ($tags as $tag) {
+                               if (empty($tag['name']) || empty($tag['type']) || empty($tag['href']) || !in_array($tag['type'], ['Mention', 'Hashtag'])) {
+                                       continue;
+                               }
 
-                       $hash = substr($tag['name'], 0, 1);
-                       $name = substr($tag['name'], 1);
-                       if (!in_array($hash, Tag::TAG_CHARACTER)) {
-                               $hash = '';
-                               $name = $tag['name'];
+                               $hash = substr($tag['name'], 0, 1);
+                               $name = substr($tag['name'], 1);
+                               if (!in_array($hash, Tag::TAG_CHARACTER)) {
+                                       $hash = '';
+                                       $name = $tag['name'];
+                               }
+
+                               $body = str_replace($tag['name'], $hash . '[url=' . $tag['href'] . ']' . $name . '[/url]', $body);
                        }
 
-                       $body = str_replace($tag['name'], $hash . '[url=' . $tag['href'] . ']' . $name . '[/url]', $body);
-               }
+                       return $body;
+               });
 
                return $body;
        }