From b269a2da8704c0500f8bc93db690a3d49a418489 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 6 Jun 2021 09:19:29 +0000 Subject: [PATCH 1/5] Respect the "unlisted" setting for forum posts --- src/Model/Item.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Model/Item.php b/src/Model/Item.php index f85bce5e8f..0d7df891e2 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -1918,8 +1918,13 @@ class Item $owner_id = Contact::getIdForURL($self['url']); // also reset all the privacy bits to the forum default permissions - - $private = ($user['allow_cid'] || $user['allow_gid'] || $user['deny_cid'] || $user['deny_gid']) ? self::PRIVATE : self::UNLISTED; + if ($user['allow_cid'] || $user['allow_gid'] || $user['deny_cid'] || $user['deny_gid']) { + $private = self::PRIVATE; + } elseif (DI::pConfig()->get($user['uid'], 'system', 'unlisted')) { + $private = Item::UNLISTED; + } else { + $private = Item::PUBLIC; + } $psid = PermissionSet::getIdFromACL( $user['uid'], From 73b0af52fb36db4869f5fb4010cc6bb8e4998c19 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 6 Jun 2021 09:24:12 +0000 Subject: [PATCH 2/5] Use "self" --- src/Model/Item.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Model/Item.php b/src/Model/Item.php index 0d7df891e2..7956494675 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -1921,9 +1921,9 @@ class Item if ($user['allow_cid'] || $user['allow_gid'] || $user['deny_cid'] || $user['deny_gid']) { $private = self::PRIVATE; } elseif (DI::pConfig()->get($user['uid'], 'system', 'unlisted')) { - $private = Item::UNLISTED; + $private = self::UNLISTED; } else { - $private = Item::PUBLIC; + $private = self::PUBLIC; } $psid = PermissionSet::getIdFromACL( From 56f07d412be75a5354e55bc743f0d1675b9bf916 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 6 Jun 2021 10:07:21 +0000 Subject: [PATCH 3/5] Addec comments on forum delivery --- src/Model/Item.php | 11 +++++++++-- src/Protocol/ActivityPub/Transmitter.php | 4 +++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Model/Item.php b/src/Model/Item.php index 7956494675..769a2898aa 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -1909,6 +1909,15 @@ class Item return false; } + self::performActivity($item['id'], 'announce', $uid); + + /** + * All the following lines are only needed for private forums and compatibility to older systems without AP support. + * A possible way would be that the followers list of a forum would always be readable by all followers. + * So this would mean that the comment distribution could be done exactly for the intended audience. + * Or possibly we could store the receivers that had been in the "announce" message above and use this. + */ + // now change this copy of the post to a forum head message and deliver to all the tgroup members $self = DBA::selectFirst('contact', ['id', 'name', 'url', 'thumb'], ['uid' => $uid, 'self' => true]); if (!DBA::isResult($self)) { @@ -1942,8 +1951,6 @@ class Item Worker::add(['priority' => PRIORITY_HIGH, 'dont_fork' => true], 'Notifier', Delivery::POST, (int)$item['uri-id'], (int)$item['uid']); - self::performActivity($item['id'], 'announce', $uid); - return false; } diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index 76bc295d1c..018fdc7b0f 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -618,7 +618,9 @@ class Transmitter } } } elseif (!$exclusive) { - // Public thread parent post always are directed to the followers + // Public thread parent post always are directed to the followers. + // This mustn't be done by posts that are directed to forum servers via the exclusive mention. + // But possibly in that case we could add the "followers" collection of the forum to the message. if (($item['private'] != Item::PRIVATE) && !$forum_mode) { $data['cc'][] = $actor_profile['followers']; } From 3fd5c79025ad30d23793ab2f6246d15f4b44c73c Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 6 Jun 2021 13:25:42 +0000 Subject: [PATCH 4/5] Add the forum followers to forum posts --- src/Protocol/ActivityPub/Transmitter.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index 018fdc7b0f..f6fd1ad132 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -561,6 +561,9 @@ class Transmitter if (!empty($profile)) { if ($term['type'] == Tag::EXCLUSIVE_MENTION) { $exclusive = true; + if (!empty($profile['followers']) && ($profile['type'] == 'Group')) { + $data['cc'][] = $profile['followers']; + } } $data['to'][] = $profile['url']; } From 038e505ca3c833fc3531ccd8ca2c98dbb8027554 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 6 Jun 2021 19:28:47 +0000 Subject: [PATCH 5/5] Improve forum delivery, avoid false distribution --- src/Protocol/ActivityPub/Receiver.php | 9 +++++---- src/Worker/Notifier.php | 21 ++++++++++++++++++--- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/Protocol/ActivityPub/Receiver.php b/src/Protocol/ActivityPub/Receiver.php index 34d45d5ab8..8e1f3853a5 100644 --- a/src/Protocol/ActivityPub/Receiver.php +++ b/src/Protocol/ActivityPub/Receiver.php @@ -663,13 +663,14 @@ class Receiver } if (!empty($actor)) { - $profile = APContact::getByURL($actor); + $profile = APContact::getByURL($actor); $followers = $profile['followers'] ?? ''; - - Logger::log('Actor: ' . $actor . ' - Followers: ' . $followers, Logger::DEBUG); + $is_forum = $actor['type'] == 'Group'; + Logger::info('Got actor and followers', ['actor' => $actor, 'followers' => $followers]); } else { Logger::info('Empty actor', ['activity' => $activity]); $followers = ''; + $is_forum = false; } // We have to prevent false follower assumptions upon thread completions @@ -692,7 +693,7 @@ class Receiver } // Fetch the receivers for the public and the followers collection - if (in_array($receiver, [$followers, self::PUBLIC_COLLECTION]) && !empty($actor)) { + if ((($receiver == $followers) || (($receiver == self::PUBLIC_COLLECTION) && !$is_forum)) && !empty($actor)) { $receivers = self::getReceiverForActor($actor, $tags, $receivers, $follower_target); continue; } diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index 4af1bc9148..550b3a4739 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -42,6 +42,7 @@ use Friendica\Protocol\OStatus; use Friendica\Protocol\Relay; use Friendica\Protocol\Salmon; use Friendica\Util\Network; +use Friendica\Util\Strings; /* * The notifier is typically called with: @@ -249,6 +250,20 @@ class Notifier $direct_forum_delivery = true; } + $exclusive_delivery = false; + + $exclusive_targets = Tag::getByURIId($parent['uri-id'], [Tag::EXCLUSIVE_MENTION]); + if (!empty($exclusive_targets)) { + $exclusive_delivery = true; + Logger::info('Possible Exclusively delivering', ['uid' => $target_item['uid'], 'guid' => $target_item['guid'], 'uri-id' => $target_item['uri-id']]); + foreach ($exclusive_targets as $target) { + if (Strings::compareLink($owner['url'], $target['url'])) { + $exclusive_delivery = false; + Logger::info('False Exclusively delivering', ['uid' => $target_item['uid'], 'guid' => $target_item['guid'], 'uri-id' => $target_item['uri-id'], 'url' => $target['url']]); + } + } + } + if ($relay_to_owner) { // local followup to remote post $followup = true; @@ -283,14 +298,14 @@ class Notifier } Logger::log('Notify ' . $target_item["guid"] .' via PuSH: ' . ($push_notify ? "Yes":"No"), Logger::DEBUG); - } elseif ($targets = Tag::getByURIId($target_item['uri-id'], [Tag::EXCLUSIVE_MENTION])) { + } elseif ($exclusive_delivery) { $followup = true; - foreach ($targets as $target) { + foreach ($exclusive_targets as $target) { $cid = Contact::getIdForURL($target['url'], $uid, false); if ($cid) { $recipients_followup[] = $cid; - Logger::info('Exclusively delivering', ['guid' => $target_item['guid'], 'uri-id' => $target_item['uri-id'], 'url' => $target['url']]); + Logger::info('Exclusively delivering', ['uid' => $target_item['uid'], 'guid' => $target_item['guid'], 'uri-id' => $target_item['uri-id'], 'url' => $target['url']]); } } } else {