]> git.mxchange.org Git - friendica.git/commitdiff
Automatically subscribe to the followings of a given AP account
authorMichael <heluecht@pirati.ca>
Tue, 13 Jul 2021 06:06:08 +0000 (06:06 +0000)
committerMichael <heluecht@pirati.ca>
Tue, 13 Jul 2021 06:06:08 +0000 (06:06 +0000)
mod/ostatus_subscribe.php
mod/salmon.php
mod/settings.php
src/Model/User.php
view/templates/settings/connectors.tpl
view/theme/frio/templates/settings/connectors.tpl

index 9e817eda930e3633d2306f65766d9ad8437ad96c..9ff5c205212e7e9c4323310f3291e0ee5945737f 100644 (file)
@@ -22,7 +22,9 @@
 use Friendica\App;
 use Friendica\Core\Protocol;
 use Friendica\DI;
+use Friendica\Model\APContact;
 use Friendica\Model\Contact;
+use Friendica\Protocol\ActivityPub;
 
 function ostatus_subscribe_content(App $a)
 {
@@ -32,11 +34,11 @@ function ostatus_subscribe_content(App $a)
                // NOTREACHED
        }
 
-       $o = '<h2>' . DI::l10n()->t('Subscribing to OStatus contacts') . '</h2>';
+       $o = '<h2>' . DI::l10n()->t('Subscribing to contacts') . '</h2>';
 
        $uid = local_user();
 
-       $counter = intval($_REQUEST['counter']);
+       $counter = intval($_REQUEST['counter'] ?? 0);
 
        if (DI::pConfig()->get($uid, 'ostatus', 'legacy_friends') == '') {
 
@@ -51,17 +53,38 @@ function ostatus_subscribe_content(App $a)
                        return $o . DI::l10n()->t('Couldn\'t fetch information for contact.');
                }
 
-               $api = $contact['baseurl'] . '/api/';
-
-               // Fetching friends
-               $curlResult = DI::httpRequest()->get($api . 'statuses/friends.json?screen_name=' . $contact['nick']);
-
-               if (!$curlResult->isSuccess()) {
+               if ($contact['network'] == Protocol::OSTATUS) {
+                       $api = $contact['baseurl'] . '/api/';
+
+                       // Fetching friends
+                       $curlResult = DI::httpRequest()->get($api . 'statuses/friends.json?screen_name=' . $contact['nick']);
+
+                       if (!$curlResult->isSuccess()) {
+                               DI::pConfig()->delete($uid, 'ostatus', 'legacy_contact');
+                               return $o . DI::l10n()->t('Couldn\'t fetch friends for contact.');
+                       }
+
+                       $friends = $curlResult->getBody();
+                       if (empty($friends)) {
+                               DI::pConfig()->delete($uid, 'ostatus', 'legacy_contact');
+                               return $o . DI::l10n()->t('Couldn\'t fetch following contacts.');
+                       }
+                       DI::pConfig()->set($uid, 'ostatus', 'legacy_friends', $friends);
+               } elseif ($apcontact = APContact::getByURL($contact['url'])) {
+                       if (empty($apcontact['following'])) {
+                               DI::pConfig()->delete($uid, 'ostatus', 'legacy_contact');
+                               return $o . DI::l10n()->t('Couldn\'t fetch remote profile.');
+                       }
+                       $followings = ActivityPub::fetchItems($apcontact['following']);
+                       if (empty($followings)) {
+                               DI::pConfig()->delete($uid, 'ostatus', 'legacy_contact');
+                               return $o . DI::l10n()->t('Couldn\'t fetch following contacts.');
+                       }
+                       DI::pConfig()->set($uid, 'ostatus', 'legacy_friends', json_encode($followings));
+               } else {
                        DI::pConfig()->delete($uid, 'ostatus', 'legacy_contact');
-                       return $o . DI::l10n()->t('Couldn\'t fetch friends for contact.');
+                       return $o . DI::l10n()->t('Unsupported network');
                }
-
-               DI::pConfig()->set($uid, 'ostatus', 'legacy_friends', $curlResult->getBody());
        }
 
        $friends = json_decode(DI::pConfig()->get($uid, 'ostatus', 'legacy_friends'));
@@ -82,13 +105,13 @@ function ostatus_subscribe_content(App $a)
 
        $friend = $friends[$counter++];
 
-       $url = $friend->statusnet_profile_url;
+       $url = $friend->statusnet_profile_url ?? $friend;
 
        $o .= '<p>' . $counter . '/' . $total . ': ' . $url;
 
        $probed = Contact::getByURL($url);
-       if ($probed['network'] == Protocol::OSTATUS) {
-               $result = Contact::createFromProbe($a->user, $probed['url'], true, Protocol::OSTATUS);
+       if (in_array($probed['network'], Protocol::FEDERATED)) {
+               $result = Contact::createFromProbe($a->user, $probed['url']);
                if ($result['success']) {
                        $o .= ' - ' . DI::l10n()->t('success');
                } else {
index 1e92980f1ceb123a2ef362e97581fc780be7e816..52fce807399fa3a13adfbdeb6ba951ea915ae13e 100644 (file)
@@ -169,24 +169,6 @@ function salmon_post(App $a, $xml = '') {
                intval($importer['uid'])
        );
 
-       if (!DBA::isResult($r)) {
-               Logger::log('Author ' . $author_link . ' unknown to user ' . $importer['uid'] . '.');
-
-               if (DI::pConfig()->get($importer['uid'], 'system', 'ostatus_autofriend')) {
-                       $result = Contact::createFromProbe($importer, $author_link);
-
-                       if ($result['success']) {
-                               $r = q("SELECT * FROM `contact` WHERE `network` = '%s' AND ( `url` = '%s' OR `alias` = '%s')
-                                       AND `uid` = %d LIMIT 1",
-                                       DBA::escape(Protocol::OSTATUS),
-                                       DBA::escape($author_link),
-                                       DBA::escape($author_link),
-                                       intval($importer['uid'])
-                               );
-                       }
-               }
-       }
-
        if (!empty($r[0]['gsid'])) {
                GServer::setProtocol($r[0]['gsid'], Post\DeliveryData::OSTATUS);
        }
@@ -194,7 +176,6 @@ function salmon_post(App $a, $xml = '') {
        // Have we ignored the person?
        // If so we can not accept this post.
 
-       //if((DBA::isResult($r)) && (($r[0]['readonly']) || ($r[0]['rel'] == Contact::FOLLOWER) || ($r[0]['blocked']))) {
        if (DBA::isResult($r) && $r[0]['blocked']) {
                Logger::log('Ignoring this author.');
                throw new \Friendica\Network\HTTPException\AcceptedException();
index c9350e68e8b7d8ead6cd654b42828e1f821fee9c..317f09201cff04e16ad9e31dfb4a047776e4454d 100644 (file)
@@ -139,8 +139,6 @@ function settings_post(App $a)
                        DI::pConfig()->set(local_user(), 'system', 'no_intelligent_shortening', intval($_POST['no_intelligent_shortening']));
                        DI::pConfig()->set(local_user(), 'system', 'simple_shortening', intval($_POST['simple_shortening']));
                        DI::pConfig()->set(local_user(), 'system', 'attach_link_title', intval($_POST['attach_link_title']));
-                       DI::pConfig()->set(local_user(), 'system', 'ostatus_autofriend', intval($_POST['snautofollow']));
-                       DI::pConfig()->set(local_user(), 'ostatus', 'default_group', $_POST['group-selection']);
                        DI::pConfig()->set(local_user(), 'ostatus', 'legacy_contact', $_POST['legacy_contact']);
                } elseif (!empty($_POST['imap-submit'])) {
                        $mail_server       =                 $_POST['mail_server']       ?? '';
@@ -549,15 +547,13 @@ function settings_content(App $a)
                $no_intelligent_shortening = intval(DI::pConfig()->get(local_user(), 'system', 'no_intelligent_shortening'));
                $simple_shortening         = intval(DI::pConfig()->get(local_user(), 'system', 'simple_shortening'));
                $attach_link_title         = intval(DI::pConfig()->get(local_user(), 'system', 'attach_link_title'));
-               $ostatus_autofriend        = intval(DI::pConfig()->get(local_user(), 'system', 'ostatus_autofriend'));
-               $default_group             = DI::pConfig()->get(local_user(), 'ostatus', 'default_group');
                $legacy_contact            = DI::pConfig()->get(local_user(), 'ostatus', 'legacy_contact');
 
                if (!empty($legacy_contact)) {
                        /// @todo Isn't it supposed to be a $a->internalRedirect() call?
                        DI::page()['htmlhead'] = '<meta http-equiv="refresh" content="0; URL=' . DI::baseUrl().'/ostatus_subscribe?url=' . urlencode($legacy_contact) . '">';
                }
-
+               
                $settings_connectors = '';
                Hook::callAll('connector_settings', $settings_connectors);
 
@@ -616,9 +612,7 @@ function settings_content(App $a)
                        '$no_intelligent_shortening' => ['no_intelligent_shortening', DI::l10n()->t('Disable intelligent shortening'), $no_intelligent_shortening, DI::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.')],
                        '$simple_shortening' => ['simple_shortening', DI::l10n()->t('Enable simple text shortening'), $simple_shortening, DI::l10n()->t('Normally the system shortens posts at the next line feed. If this option is enabled then the system will shorten the text at the maximum character limit.')],
                        '$attach_link_title' => ['attach_link_title', DI::l10n()->t('Attach the link title'), $attach_link_title, DI::l10n()->t('When activated, the title of the attached link will be added as a title on posts to Diaspora. This is mostly helpful with "remote-self" contacts that share feed content.')],
-                       '$ostatus_autofriend' => ['snautofollow', DI::l10n()->t("Automatically follow any GNU Social \x28OStatus\x29 followers/mentioners"), $ostatus_autofriend, DI::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.')],
-                       '$default_group' => Group::displayGroupSelection(local_user(), $default_group, DI::l10n()->t("Default group for OStatus contacts")),
-                       '$legacy_contact' => ['legacy_contact', DI::l10n()->t('Your legacy GNU Social account'), $legacy_contact, DI::l10n()->t("If you enter your old GNU Social/Statusnet account name here \x28in the format user@domain.tld\x29, your contacts will be added automatically. The field will be emptied when done.")],
+                       '$legacy_contact' => ['legacy_contact', DI::l10n()->t('Your legacy ActivityPub/GNU Social account'), $legacy_contact, DI::l10n()->t("If you enter your old account name from an ActivityPub based system or your GNU Social/Statusnet account name here (in the format user@domain.tld), your contacts will be added automatically. The field will be emptied when done.")],
 
                        '$repair_ostatus_url' => DI::baseUrl() . '/repair_ostatus',
                        '$repair_ostatus_text' => DI::l10n()->t('Repair OStatus subscriptions'),
index 5d349ce69e77a72be5f57a49033cb4d39ee820b3..3d76b080032139a1e14830ca0f1d8215bba69044 100644 (file)
@@ -476,20 +476,11 @@ class User
         */
        public static function getDefaultGroup($uid, $network = '')
        {
-               $default_group = 0;
-
-               if ($network == Protocol::OSTATUS) {
-                       $default_group = DI::pConfig()->get($uid, "ostatus", "default_group");
-               }
-
-               if ($default_group != 0) {
-                       return $default_group;
-               }
-
                $user = DBA::selectFirst('user', ['def_gid'], ['uid' => $uid]);
-
                if (DBA::isResult($user)) {
                        $default_group = $user["def_gid"];
+               } else {
+                       $default_group = 0;
                }
 
                return $default_group;
index ef9cc2b95bb297fefbffae57328053d015fd6239..adb4b249dc59366127d1cd070337c742fe9b9cb5 100644 (file)
@@ -16,8 +16,6 @@
                {{include file="field_checkbox.tpl" field=$no_intelligent_shortening}}
                {{include file="field_checkbox.tpl" field=$simple_shortening}}
                {{include file="field_checkbox.tpl" field=$attach_link_title}}
-               {{include file="field_checkbox.tpl" field=$ostatus_autofriend}}
-               {{$default_group nofilter}}
                {{include file="field_input.tpl" field=$legacy_contact}}
 
                <p><a href="{{$repair_ostatus_url}}">{{$repair_ostatus_text}}</a></p>
index 88e4977e149ecaafee58362da1505c7cbe7ff120..81d5219e8aa783d44f85b6e46c95591b84b82572 100644 (file)
 
                                                {{include file="field_checkbox.tpl" field=$attach_link_title}}
 
-                                               {{include file="field_checkbox.tpl" field=$ostatus_autofriend}}
-
-                                               {{$default_group nofilter}}
-
                                                {{include file="field_input.tpl" field=$legacy_contact}}
 
                                                <p><a href="{{$repair_ostatus_url}}">{{$repair_ostatus_text}}</a></p>