]> git.mxchange.org Git - friendica.git/commitdiff
Added the option to only receive top level posts from people you follow
authorMichael <heluecht@pirati.ca>
Wed, 17 Jul 2019 21:37:13 +0000 (21:37 +0000)
committerMichael <heluecht@pirati.ca>
Wed, 17 Jul 2019 21:37:13 +0000 (21:37 +0000)
mod/settings.php
src/Model/Contact.php
src/Module/Admin/Site.php
src/Protocol/ActivityPub/Processor.php
view/templates/settings/connectors.tpl
view/theme/frio/templates/settings/connectors.tpl

index d744dbff17f6bc1d89f5c5dfad990005327de17d..2f61a6e079fa8b304113a743b2b42febb44d5374 100644 (file)
@@ -234,6 +234,7 @@ function settings_post(App $a)
                BaseModule::checkFormSecurityTokenRedirectOnError('/settings/connectors', 'settings_connectors');
 
                if (!empty($_POST['general-submit'])) {
+                       PConfig::set(local_user(), 'system', 'accept_only_sharer', intval($_POST['accept_only_sharer']));
                        PConfig::set(local_user(), 'system', 'disable_cw', intval($_POST['disable_cw']));
                        PConfig::set(local_user(), 'system', 'no_intelligent_shortening', intval($_POST['no_intelligent_shortening']));
                        PConfig::set(local_user(), 'system', 'ostatus_autofriend', intval($_POST['snautofollow']));
@@ -786,6 +787,7 @@ function settings_content(App $a)
        }
 
        if (($a->argc > 1) && ($a->argv[1] === 'connectors')) {
+               $accept_only_sharer        = intval(PConfig::get(local_user(), 'system', 'accept_only_sharer'));
                $disable_cw                = intval(PConfig::get(local_user(), 'system', 'disable_cw'));
                $no_intelligent_shortening = intval(PConfig::get(local_user(), 'system', 'no_intelligent_shortening'));
                $ostatus_autofriend        = intval(PConfig::get(local_user(), 'system', 'ostatus_autofriend'));
@@ -844,6 +846,7 @@ function settings_content(App $a)
                        '$ostat_enabled' => $ostat_enabled,
 
                        '$general_settings' => L10n::t('General Social Media Settings'),
+                       '$accept_only_sharer' => ['accept_only_sharer', L10n::t('Accept only top level posts by contacts you follow'), $accept_only_sharer, L10n::t('The system does an auto completion of threads when a comment arrives. This has got the side effect that can you receive posts that had been started by a non-follower but had been commented by someone you follow. This setting deactivates this behaviour. When activated, you strictly only will receive posts from people you really do follow.')],
                        '$disable_cw' => ['disable_cw', L10n::t('Disable Content Warning'), $disable_cw, L10n::t('Users on networks like Mastodon or Pleroma are able to set a content warning field which collapse their post by default. This disables the automatic collapsing and sets the content warning as the post title. Doesn\'t affect any other content filtering you eventually set up.')],
                        '$no_intelligent_shortening' => ['no_intelligent_shortening', L10n::t('Disable intelligent shortening'), $no_intelligent_shortening, L10n::t('Normally the system tries to find the best link to add to shortened posts. If this option is enabled then every shortened post will always point to the original friendica post.')],
                        '$ostatus_autofriend' => ['snautofollow', L10n::t("Automatically follow any GNU Social \x28OStatus\x29 followers/mentioners"), $ostatus_autofriend, L10n::t('If you receive a message from an unknown OStatus user, this option decides what to do. If it is checked, a new contact will be created for every unknown user.')],
index 9f6fa6264b3736272b421455aa3346f671643e4a..559236001eee0da25d74a62875b4c38fff0c1128 100644 (file)
@@ -174,6 +174,73 @@ class Contact extends BaseObject
                return DBA::exists('contact', $condition);
        }
 
+       /**
+        * @brief Tests if the given contact url is a follower
+        *
+        * @param string $url Contact URL
+        * @param int    $uid User ID
+        *
+        * @return boolean is the contact id a follower?
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        * @throws \ImagickException
+        */
+       public static function isFollowerByURL($url, $uid)
+       {
+               $cid = self::getIdForURL($url, $uid, true);
+
+               if (empty($cid)) {
+                       return false;
+               }
+
+               return self::isFollower($cid, $uid);
+       }
+
+       /**
+        * @brief Tests if the given user follow the given contact
+        *
+        * @param int $cid Either public contact id or user's contact id
+        * @param int $uid User ID
+        *
+        * @return boolean is the contact url being followed?
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        * @throws \ImagickException
+        */
+       public static function isSharing($cid, $uid)
+       {
+               if (self::isBlockedByUser($cid, $uid)) {
+                       return false;
+               }
+
+               $cdata = self::getPublicAndUserContacID($cid, $uid);
+               if (empty($cdata['user'])) {
+                       return false;
+               }
+
+               $condition = ['id' => $cdata['user'], 'rel' => [self::SHARING, self::FRIEND]];
+               return DBA::exists('contact', $condition);
+       }
+
+       /**
+        * @brief Tests if the given user follow the given contact url
+        *
+        * @param string $url Contact URL
+        * @param int    $uid User ID
+        *
+        * @return boolean is the contact url being followed?
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        * @throws \ImagickException
+        */
+       public static function isSharingByURL($url, $uid)
+       {
+               $cid = self::getIdForURL($url, $uid, true);
+
+               if (empty($cid)) {
+                       return false;
+               }
+
+               return self::isSharing($cid, $uid);
+       }
+
        /**
         * @brief Get the basepath for a given contact link
         *
index 78576efe3bce0f710a926fc9074a729f8f6616b8..8e36d865056e6539a30999a7a8930a234b5e8ef7 100644 (file)
@@ -627,7 +627,7 @@ class Site extends BaseAdminModule
                        '$community_page_style'   => ['community_page_style', L10n::t('Community pages for visitors'), Config::get('system', 'community_page_style'), L10n::t('Which community pages should be available for visitors. Local users always see both pages.'), $community_page_style_choices],
                        '$max_author_posts_community_page' => ['max_author_posts_community_page', L10n::t('Posts per user on community page'), Config::get('system', 'max_author_posts_community_page'), L10n::t('The maximum number of posts per user on the community page. (Not valid for "Global Community")')],
                        '$ostatus_disabled'       => ['ostatus_disabled', L10n::t('Disable OStatus support'), Config::get('system', 'ostatus_disabled'), L10n::t('Disable built-in OStatus (StatusNet, GNU Social etc.) compatibility. All communications in OStatus are public, so privacy warnings will be occasionally displayed.')],
-                       '$ostatus_full_threads'   => ['ostatus_full_threads', L10n::t('Only import OStatus/ActivityPub threads from our contacts'), Config::get('system', 'ostatus_full_threads'), L10n::t('Normally we import every content from our OStatus and ActivityPub contacts. With this option we only store threads that are started by a contact that is known on our system.')],
+                       '$ostatus_full_threads'   => ['ostatus_full_threads', L10n::t('Only import OStatus threads from our contacts'), Config::get('system', 'ostatus_full_threads'), L10n::t('Normally we import every content from our OStatus contacts. With this option we only store threads that are started by a contact that is known on our system.')],
                        '$ostatus_not_able'       => L10n::t('OStatus support can only be enabled if threading is enabled.'),
                        '$diaspora_able'          => $diaspora_able,
                        '$diaspora_not_able'      => L10n::t('Diaspora support can\'t be enabled because Friendica was installed into a sub directory.'),
index bdf2e63f2e9b1c729a7a49af4daa6ae5cc61d667..aaf5a251858d2a2eb3035e9c1c5cb47bd1e9a8c9 100644 (file)
@@ -425,6 +425,21 @@ class Processor
                                continue;
                        }
 
+                       if (PConfig::get($receiver, 'system', 'accept_only_sharer', false) && ($receiver != 0) && ($item['gravity'] == GRAVITY_PARENT)) {
+                               $skip = !Contact::isSharingByURL($activity['author'], $receiver);
+
+                               if ($skip && (($activity['type'] == 'as:Announce') || $isForum)) {
+                                       $skip = !Contact::isSharingByURL($activity['actor'], $receiver);
+                               }
+
+                               if ($skip) {
+                                       Logger::info('Skipping post', ['uid' => $receiver, 'url' => $item['uri']]);
+                                       continue;
+                               }
+
+                               Logger::info('Accepting post', ['uid' => $receiver, 'url' => $item['uri']]);
+                       }
+
                        if ($activity['object_type'] == 'as:Event') {
                                self::createEvent($activity, $item);
                        }
@@ -524,10 +539,6 @@ class Processor
         */
        public static function fetchMissingActivity($url, $child = [])
        {
-               if (Config::get('system', 'ostatus_full_threads')) {
-                       return;
-               }
-
                if (!empty($child['receiver'])) {
                        $uid = ActivityPub\Receiver::getFirstUserFromReceivers($child['receiver']);
                } else {
index e275e68ce362358bd95a20efbce3557e32329b2f..28f9ffab198c80701fee3264768d527c4099876b 100644 (file)
@@ -11,6 +11,7 @@
 
 <div id="settings_general_expanded" class="settings-block" style="display: none;">
 
+       {{include file="field_checkbox.tpl" field=$accept_only_sharer}}
        {{include file="field_checkbox.tpl" field=$disable_cw}}
        {{include file="field_checkbox.tpl" field=$no_intelligent_shortening}}
        {{include file="field_checkbox.tpl" field=$ostatus_autofriend}}
index bf8de450c46a703a279671b74a95c86b1db1fb6e..30c2ca6b4af360b80805315c89a29b28af222476 100644 (file)
@@ -20,6 +20,8 @@
                                <div id="content-settings-content" class="panel-collapse collapse" role="tabpanel" aria-labelledby="content-settings">
                                        <div class="section-content-wrapper">
 
+                                               {{include file="field_checkbox.tpl" field=$accept_only_sharer}}
+
                                                {{include file="field_checkbox.tpl" field=$disable_cw}}
 
                                                {{include file="field_checkbox.tpl" field=$no_intelligent_shortening}}