]> git.mxchange.org Git - friendica.git/commitdiff
Prevent post mirroring by blocked users
authorHypolite Petovan <hypolite@mrpetovan.com>
Wed, 26 Jul 2023 05:50:15 +0000 (07:50 +0200)
committerHypolite Petovan <hypolite@mrpetovan.com>
Wed, 2 Aug 2023 19:53:10 +0000 (21:53 +0200)
src/Model/Item.php

index 9028c9f853d13017b6854d0d9f2f5e99365313f4..a2304056d373096b4ae90e393ae355bb39c752b5 100644 (file)
@@ -21,6 +21,7 @@
 
 namespace Friendica\Model;
 
+use Friendica\Contact\LocalRelationship\Entity\LocalRelationship;
 use Friendica\Content\Text\BBCode;
 use Friendica\Content\Text\HTML;
 use Friendica\Core\Hook;
@@ -2333,16 +2334,15 @@ class Item
                        return;
                }
 
-               $cdata = Contact::getPublicAndUserContactID($item['author-id'], $item['uid']);
-               if (empty($cdata['user']) || ($cdata['user'] != $item['contact-id'])) {
+               if (!DBA::exists('contact', ['id' => $cdata['user'], 'remote_self' => LocalRelationship::MIRROR_NATIVE_RESHARE])) {
                        return;
                }
 
-               if (!DBA::exists('contact', ['id' => $cdata['user'], 'remote_self' => Contact::MIRROR_NATIVE_RESHARE])) {
+               if (!in_array($item['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN])) {
                        return;
                }
 
-               if (!in_array($item['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN])) {
+               if (User::getById($item['uid'], ['blocked'])['blocked'] ?? false) {
                        return;
                }
 
@@ -2353,7 +2353,7 @@ class Item
 
        public static function isRemoteSelf(array $contact, array &$datarray): bool
        {
-               if ($contact['remote_self'] != Contact::MIRROR_OWN_POST) {
+               if ($contact['remote_self'] != LocalRelationship::MIRROR_OWN_POST) {
                        return false;
                }
 
@@ -2380,6 +2380,11 @@ class Item
                        return false;
                }
 
+               if (User::getById($contact['uid'], ['blocked'])['blocked'] ?? false) {
+                       Logger::info('User is blocked', ['contact' => $contact]);
+                       return false;
+               }
+
                $datarray2 = $datarray;
                Logger::info('remote-self start', ['contact' => $contact['url'], 'remote_self' => $contact['remote_self'], 'item' => $datarray]);
 
@@ -3222,7 +3227,7 @@ class Item
                        $shared_html = substr($s, $pos + strlen(BBCode::SHARED_ANCHOR));
                        $s = substr($s, 0, $pos);
                }
-       
+
                $s = self::addGallery($s, $attachments, $item['uri-id']);
                $s = self::addVisualAttachments($attachments, $item, $s, false);
                $s = self::addLinkAttachment($item['uri-id'], $attachments, $body, $s, false, $shared_links);
@@ -3628,9 +3633,9 @@ class Item
                        }
 
                        $author = [
-                               'uid'     => 0, 
+                               'uid'     => 0,
                                'id'      => $item['author-id'],
-                               'network' => $item['author-network'], 
+                               'network' => $item['author-network'],
                                'url'     => $item['author-link'],
                                'alias'   => $item['author-alias']
                        ];
@@ -3721,9 +3726,9 @@ class Item
 
                        if (!empty($plink) && ($item['private'] == self::PRIVATE)) {
                                $author = [
-                                       'uid'     => 0, 
+                                       'uid'     => 0,
                                        'id'      => $item['author-id'],
-                                       'network' => $item['author-network'], 
+                                       'network' => $item['author-network'],
                                        'url'     => $item['author-link'],
                                        'alias'   => $item['author-alias'],
                                ];