]> git.mxchange.org Git - friendica.git/commitdiff
No notifcations for forum / fetch user for fetching content
authorMichael <heluecht@pirati.ca>
Sun, 13 Feb 2022 05:45:06 +0000 (05:45 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 13 Feb 2022 05:45:06 +0000 (05:45 +0000)
src/Model/Post/UserNotification.php
src/Protocol/ActivityPub/Receiver.php

index ad7b9c4904b4cb616175e9562b3baedfb9d61d1d..79499897dd333a6a7f793d09416d7dd5e8e418b9 100644 (file)
@@ -33,6 +33,7 @@ use Friendica\Model\Contact;
 use Friendica\Model\Post;
 use Friendica\Model\Subscription;
 use Friendica\Model\Tag;
+use Friendica\Model\User;
 use Friendica\Navigation\Notifications;
 use Friendica\Network\HTTPException;
 use Friendica\Protocol\Activity;
@@ -176,6 +177,11 @@ class UserNotification
                        return;
                }
 
+               $user = User::getById($uid, ['account-type']);
+               if (in_array($user['account-type'], [User::ACCOUNT_TYPE_COMMUNITY, User::ACCOUNT_TYPE_RELAY])) {
+                       return;
+               }
+
                $notification_type = self::TYPE_NONE;
 
                if (self::checkShared($item, $uid)) {
index 3da53a033e8b4ef67d0b8eed5fc28801bf907394..3d183aec56a6ed38d2da24c6f0fce482e402c9c0 100644 (file)
@@ -263,7 +263,19 @@ class Receiver
        {
                $id = JsonLD::fetchElement($activity, '@id');
                if (!empty($id) && !$trust_source) {
-                       $fetched_activity = ActivityPub::fetchContent($id, $uid ?? 0);
+                       if (empty($uid)) {
+                               $actor = JsonLD::fetchElement($activity, 'as:actor', '@id');
+                               if (empty($actor)) {
+                                       $actor = '';
+                               }
+       
+                               // Fetch a user out of the receivers of the message.
+                               $fetch_uid = Receiver::getBestUserForActivity($activity, $actor);
+                       } else {
+                               $fetch_uid = $uid;
+                       }
+
+                       $fetched_activity = ActivityPub::fetchContent($id, $fetch_uid);
                        if (!empty($fetched_activity)) {
                                $object = JsonLD::compact($fetched_activity);
                                $fetched_id = JsonLD::fetchElement($object, '@id');
@@ -643,6 +655,29 @@ class Receiver
                }
        }
 
+       /**
+        * Fetch a user id from an activity array
+        *
+        * @param array  $activity
+        * @param string $actor
+        *
+        * @return int   user id
+        */
+       private static function getBestUserForActivity(array $activity, string $actor)
+       {
+               $uid = 0;
+               $receivers = self::getReceivers($activity, $actor);
+               foreach ($receivers as $receiver) {
+                       if ($receiver['type'] == self::TARGET_GLOBAL) {
+                               return 0;
+                       }
+                       if (empty($uid) || ($receiver['type'] == self::TARGET_TO)) {
+                               $uid = $receiver['uid'];
+                       }
+               }
+               return $uid;
+       }
+
        /**
         * Fetch the receiver list from an activity array
         *