]> git.mxchange.org Git - friendica.git/commitdiff
Prevent sending forum posts via AP
authorMichael <heluecht@pirati.ca>
Mon, 10 Aug 2020 19:44:37 +0000 (19:44 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 10 Aug 2020 19:44:37 +0000 (19:44 +0000)
src/Protocol/ActivityPub/Transmitter.php
src/Worker/Notifier.php

index 5768c4439a60d5a459df7d518ff0e855cb6a8cfe..1ffe034d1664cbbc5f536b59c151d835322b2f7e 100644 (file)
@@ -356,12 +356,14 @@ class Transmitter
                }
 
                $always_bcc = false;
+               $isforum = false;
 
                // Check if we should always deliver our stuff via BCC
                if (!empty($item['uid'])) {
-                       $profile = Profile::getByUID($item['uid']);
+                       $profile = User::getOwnerDataById($item['uid']);
                        if (!empty($profile)) {
                                $always_bcc = $profile['hide-friends'];
+                               $isforum = $profile['account-type'] == User::ACCOUNT_TYPE_COMMUNITY;
                        }
                }
 
@@ -369,7 +371,7 @@ class Transmitter
                        $always_bcc = true;
                }
 
-               if (self::isAnnounce($item) || DI::config()->get('debug', 'total_ap_delivery')) {
+               if ((self::isAnnounce($item) && !$isforum) || DI::config()->get('debug', 'total_ap_delivery')) {
                        // Will be activated in a later step
                        $networks = Protocol::FEDERATED;
                } else {
@@ -423,6 +425,10 @@ class Transmitter
                                                continue;
                                        }
 
+                                       if ($isforum && DBA::isResult($contact) && ($contact['dfrn'] == Protocol::DFRN)) {
+                                               continue;
+                                       }
+
                                        if (!empty($profile = APContact::getByURL($contact['url'], false))) {
                                                $data['to'][] = $profile['url'];
                                        }
@@ -435,6 +441,10 @@ class Transmitter
                                        continue;
                                }
 
+                               if ($isforum && DBA::isResult($contact) && ($contact['dfrn'] == Protocol::DFRN)) {
+                                       continue;
+                               }
+
                                if (!empty($profile = APContact::getByURL($contact['url'], false))) {
                                        if ($contact['hidden'] || $always_bcc) {
                                                $data['bcc'][] = $profile['url'];
@@ -557,6 +567,15 @@ class Transmitter
        {
                $inboxes = [];
 
+               $isforum = false;
+
+               if (!empty($item['uid'])) {
+                       $profile = User::getOwnerDataById($item['uid']);
+                       if (!empty($profile)) {
+                               $isforum = $profile['account-type'] == User::ACCOUNT_TYPE_COMMUNITY;
+                       }
+               }
+
                if (DI::config()->get('debug', 'total_ap_delivery')) {
                        // Will be activated in a later step
                        $networks = Protocol::FEDERATED;
@@ -581,6 +600,10 @@ class Transmitter
                                continue;
                        }
 
+                       if ($isforum && ($contact['dfrn'] == Protocol::DFRN)) {
+                               continue;
+                       }
+
                        if (Network::isUrlBlocked($contact['url'])) {
                                continue;
                        }
index ec038d2313325ed5af55d083e4e59b1498ad95cb..17aaed57238672f939a84ebc08ea30e782a00987 100644 (file)
@@ -475,7 +475,7 @@ class Notifier
                                                continue;
                                        }
 
-                                       if (self::skipDFRN($rr, $target_item, $parent, $thr_parent, $cmd)) {
+                                       if (self::skipDFRN($rr, $target_item, $parent, $thr_parent, $owner, $cmd)) {
                                                Logger::info('Contact can be delivered via AP, so skip delivery via legacy DFRN/Diaspora', ['id' => $target_id, 'url' => $rr['url']]);
                                                continue;
                                        }
@@ -530,7 +530,7 @@ class Notifier
                                continue;
                        }
 
-                       if (self::skipDFRN($contact, $target_item, $parent, $thr_parent, $cmd)) {
+                       if (self::skipDFRN($contact, $target_item, $parent, $thr_parent, $owner, $cmd)) {
                                Logger::info('Contact can be delivered via AP, so skip delivery via legacy DFRN/Diaspora', ['target' => $target_id, 'url' => $contact['url']]);
                                continue;
                        }
@@ -648,12 +648,13 @@ class Notifier
         * @param array  $item       The post
         * @param array  $parent     The parent
         * @param array  $thr_parent The thread parent
+        * @param array  $owner      Owner array
         * @param string $cmd        Notifier command
         * @return bool
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
-       private static function skipDFRN($contact, $item, $parent, $thr_parent, $cmd)
+       private static function skipDFRN($contact, $item, $parent, $thr_parent, $owner, $cmd)
        {
                if (empty($parent['network'])) {
                        return false;
@@ -684,6 +685,12 @@ class Notifier
                        return false;
                }
 
+               // For the time being we always deliver forum post via DFRN if possible
+               // This can be removed possible at the end of 2020 when hopefully most system can process AP forum posts
+               if ($owner['account-type'] == User::ACCOUNT_TYPE_COMMUNITY) {
+                       return false;
+               }
+
                // We deliver reshares via AP whenever possible
                if (ActivityPub\Transmitter::isAnnounce($item)) {
                        return true;