]> git.mxchange.org Git - friendica.git/commitdiff
Improve distribution of non public messages
authorMichael <heluecht@pirati.ca>
Tue, 31 Oct 2023 13:08:24 +0000 (13:08 +0000)
committerMichael <heluecht@pirati.ca>
Tue, 31 Oct 2023 13:08:24 +0000 (13:08 +0000)
src/Model/Item.php
src/Protocol/Diaspora.php
src/Worker/Notifier.php

index d498b978f287e22c704db17ea86102343c7b607b..811eab50b41e17532ab9aaa48019a84f3d38ed2f 100644 (file)
@@ -1042,10 +1042,12 @@ class Item
 
                        // Reshares have to keep their permissions to allow groups to work
                        if (!$defined_permissions && (!$item['origin'] || ($item['verb'] != Activity::ANNOUNCE))) {
-                               $item['allow_cid']     = $toplevel_parent['allow_cid'];
-                               $item['allow_gid']     = $toplevel_parent['allow_gid'];
-                               $item['deny_cid']      = $toplevel_parent['deny_cid'];
-                               $item['deny_gid']      = $toplevel_parent['deny_gid'];
+                               // Don't store the permissions on pure AP posts
+                               $store_permissions = ($item['network'] != Protocol::ACTIVITYPUB) || $item['origin'] || !empty($item['diaspora_signed_text']);
+                               $item['allow_cid'] = $store_permissions ? $toplevel_parent['allow_cid'] : '';
+                               $item['allow_gid'] = $store_permissions ? $toplevel_parent['allow_gid'] : '';
+                               $item['deny_cid']  = $store_permissions ? $toplevel_parent['deny_cid'] : '';
+                               $item['deny_gid']  = $store_permissions ? $toplevel_parent['deny_gid'] : '';
                        }
 
                        $parent_origin         = $toplevel_parent['origin'];
index 1aff0efb9575ce8676bfe4349d7657c255e5d953..c0bc1a5a072db2e46e1ec0c45e187c36f43a7c3f 100644 (file)
@@ -1192,6 +1192,7 @@ class Diaspora
        {
                $fields = [
                        'id', 'parent', 'body', 'wall', 'uri', 'guid', 'private', 'origin',
+                       'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
                        'author-name', 'author-link', 'author-avatar', 'gravity',
                        'owner-name', 'owner-link', 'owner-avatar'
                ];
@@ -1567,6 +1568,12 @@ class Diaspora
                $datarray['verb'] = Activity::POST;
                $datarray['gravity'] = Item::GRAVITY_COMMENT;
 
+               $datarray['private']   = $toplevel_parent_item['private'];
+               $datarray['allow_cid'] = $toplevel_parent_item['allow_cid'];
+               $datarray['allow_gid'] = $toplevel_parent_item['allow_gid'];
+               $datarray['deny_cid']  = $toplevel_parent_item['deny_cid'];
+               $datarray['deny_gid']  = $toplevel_parent_item['deny_gid'];
+
                $datarray['thr-parent'] = $thr_parent ?: $toplevel_parent_item['uri'];
 
                $datarray['object-type'] = Activity\ObjectType::COMMENT;
@@ -1823,6 +1830,13 @@ class Diaspora
 
                $datarray['verb'] = $verb;
                $datarray['gravity'] = Item::GRAVITY_ACTIVITY;
+
+               $datarray['private']   = $toplevel_parent_item['private'];
+               $datarray['allow_cid'] = $toplevel_parent_item['allow_cid'];
+               $datarray['allow_gid'] = $toplevel_parent_item['allow_gid'];
+               $datarray['deny_cid']  = $toplevel_parent_item['deny_cid'];
+               $datarray['deny_gid']  = $toplevel_parent_item['deny_gid'];
+
                $datarray['thr-parent'] = $toplevel_parent_item['uri'];
 
                $datarray['object-type'] = Activity\ObjectType::NOTE;
index a15eca1bcf6d672842f83b195ce5974f262b24b3..e6ae0e0dadaaaa464694afb0068d96d5e28ddc52 100644 (file)
@@ -102,7 +102,7 @@ class Notifier
                        $uid = $target_id;
 
                        $condition = ['uid' => $target_id, 'self' => false, 'network' => [Protocol::DFRN, Protocol::DIASPORA]];
-                       $delivery_contacts_stmt = DBA::select('contact', ['id', 'url', 'addr', 'network', 'protocol', 'baseurl', 'gsid', 'batch'], $condition);
+                       $delivery_contacts_stmt = DBA::select('contact', ['id', 'uri-id', 'url', 'addr', 'network', 'protocol', 'baseurl', 'gsid', 'batch'], $condition);
                } else {
                        $post = Post::selectFirst(['id'], ['uri-id' => $post_uriid, 'uid' => $sender_uid]);
                        if (!DBA::isResult($post)) {
@@ -191,7 +191,8 @@ class Notifier
                                $apdelivery = self::activityPubDelivery($cmd, $target_item, $parent, $thr_parent, $a->getQueueValue('priority'), $a->getQueueValue('created'), $owner);
                                $ap_contacts = $apdelivery['contacts'];
                                $delivery_queue_count += $apdelivery['count'];
-                               if (($thr_parent['network'] == Protocol::ACTIVITYPUB) && ($thr_parent['private'] == Item::PRIVATE)) {
+                               // Restrict distribution to AP, when there are no permissions.
+                               if (($target_item['private'] == Item::PRIVATE) && empty($target_item['allow_cid']) && empty($target_item['allow_gid']) && empty($target_item['deny_cid']) && empty($target_item['deny_gid'])) {
                                        $only_ap_delivery   = true;
                                        $public_message     = false;
                                        $diaspora_delivery  = false;
@@ -438,7 +439,7 @@ class Notifier
                        if (!empty($networks)) {
                                $condition['network'] = $networks;
                        }
-                       $delivery_contacts_stmt = DBA::select('contact', ['id', 'addr', 'url', 'network', 'protocol', 'baseurl', 'gsid', 'batch'], $condition);
+                       $delivery_contacts_stmt = DBA::select('contact', ['id', 'uri-id', 'addr', 'url', 'network', 'protocol', 'baseurl', 'gsid', 'batch'], $condition);
                }
 
                $conversants = [];
@@ -462,7 +463,7 @@ class Notifier
                        $condition = ['network' => Protocol::DFRN, 'uid' => $owner['uid'], 'blocked' => false,
                                'pending' => false, 'archive' => false, 'rel' => [Contact::FOLLOWER, Contact::FRIEND]];
 
-                       $contacts = DBA::selectToArray('contact', ['id', 'url', 'addr', 'name', 'network', 'protocol', 'baseurl', 'gsid'], $condition);
+                       $contacts = DBA::selectToArray('contact', ['id', 'uri-id', 'url', 'addr', 'name', 'network', 'protocol', 'baseurl', 'gsid'], $condition);
 
                        $conversants = array_merge($contacts, $participants);
 
@@ -593,6 +594,11 @@ class Notifier
                                continue;
                        }
 
+                       if (($contact['network'] == Protocol::ACTIVITYPUB) && !DI::dsprContact()->existsByUriId($contact['uri-id'])) {
+                               Logger::info('The ActivityPub contact does not support Diaspora, so skip delivery via Diaspora', ['id' => $post_uriid, 'uid' => $sender_uid, 'url' => $contact['url']]);
+                               continue;
+                       }
+
                        Logger::info('Delivery', ['batch' => $in_batch, 'target' => $post_uriid, 'uid' => $sender_uid, 'guid' => $target_item['guid'] ?? '', 'to' => $contact]);
 
                        // Ensure that posts with our own protocol arrives before Diaspora posts arrive.