diff --git a/mod/ostatus_subscribe.php b/mod/ostatus_subscribe.php index 9e817eda93..9ff5c20521 100644 --- a/mod/ostatus_subscribe.php +++ b/mod/ostatus_subscribe.php @@ -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 = '

' . DI::l10n()->t('Subscribing to OStatus contacts') . '

'; + $o = '

' . DI::l10n()->t('Subscribing to contacts') . '

'; $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/'; + if ($contact['network'] == Protocol::OSTATUS) { + $api = $contact['baseurl'] . '/api/'; - // Fetching friends - $curlResult = DI::httpRequest()->get($api . 'statuses/friends.json?screen_name=' . $contact['nick']); + // Fetching friends + $curlResult = DI::httpRequest()->get($api . 'statuses/friends.json?screen_name=' . $contact['nick']); - if (!$curlResult->isSuccess()) { + 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 .= '

' . $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 { diff --git a/mod/salmon.php b/mod/salmon.php index 1e92980f1c..52fce80739 100644 --- a/mod/salmon.php +++ b/mod/salmon.php @@ -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(); diff --git a/mod/settings.php b/mod/settings.php index c9350e68e8..317f09201c 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -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'] = ''; } - + $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'), diff --git a/src/Model/User.php b/src/Model/User.php index 5d349ce69e..3d76b08003 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -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; diff --git a/view/templates/settings/connectors.tpl b/view/templates/settings/connectors.tpl index ef9cc2b95b..adb4b249dc 100644 --- a/view/templates/settings/connectors.tpl +++ b/view/templates/settings/connectors.tpl @@ -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}}

{{$repair_ostatus_text}}

diff --git a/view/theme/frio/templates/settings/connectors.tpl b/view/theme/frio/templates/settings/connectors.tpl index 88e4977e14..81d5219e8a 100644 --- a/view/theme/frio/templates/settings/connectors.tpl +++ b/view/theme/frio/templates/settings/connectors.tpl @@ -28,10 +28,6 @@ {{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}}

{{$repair_ostatus_text}}