From 26429961716e579489711eeb9ca457af953e5c79 Mon Sep 17 00:00:00 2001
From: Michael <heluecht@pirati.ca>
Date: Sun, 13 Mar 2022 19:31:21 +0000
Subject: [PATCH] Send community posts only to the community

---
 src/Protocol/ActivityPub/Transmitter.php | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php
index d17e269edf..55b863488b 100644
--- a/src/Protocol/ActivityPub/Transmitter.php
+++ b/src/Protocol/ActivityPub/Transmitter.php
@@ -618,10 +618,17 @@ class Transmitter
 			}
 		}
 
+		$is_forum_thread = false;
+
 		if (!empty($item['parent'])) {
-			$parents = Post::select(['id', 'author-link', 'owner-link', 'gravity', 'uri'], ['parent' => $item['parent']]);
+			$parents = Post::select(['id', 'author-link', 'owner-link', 'causer-link', 'gravity', 'uri', 'post-reason'], ['parent' => $item['parent']], ['order' => ['id']]);
 			while ($parent = Post::fetch($parents)) {
 				if ($parent['gravity'] == GRAVITY_PARENT) {
+					if (($parent['post-reason'] == Item::PR_ANNOUNCEMENT) && !empty($parent['causer-link'])) {
+						$profile = APContact::getByURL($parent['causer-link'], false);
+						$is_forum_thread = ($profile['type'] == 'Group');
+					}
+
 					$profile = APContact::getByURL($parent['owner-link'], false);
 					if (!empty($profile)) {
 						if ($item['gravity'] != GRAVITY_PARENT) {
@@ -633,11 +640,11 @@ class Transmitter
 								$data['to'][] = $profile['url'];
 							} else {
 								$data['cc'][] = $profile['url'];
-								if (($item['private'] != Item::PRIVATE) && !empty($actor_profile['followers'])) {
+								if (($item['private'] != Item::PRIVATE) && !empty($actor_profile['followers'])&& !$is_forum_thread) {
 									$data['cc'][] = $actor_profile['followers'];
 								}
 							}
-						} elseif (!$exclusive) {
+						} elseif (!$exclusive && !$is_forum_thread) {
 							// Public thread parent post always are directed to the followers.
 							if ($item['private'] != Item::PRIVATE) {
 								$data['cc'][] = $actor_profile['followers'];
-- 
2.39.5