Merge pull request #11270 from MrPetovan/task/10862-move-unfollow-worker

Move unfollow/revoke follow protocol to worker tasks
This commit is contained in:
Michael Vogel 2022-02-24 21:24:39 +01:00 committed by GitHub
commit 67eb9ae360
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 298 additions and 184 deletions

View File

@ -626,7 +626,8 @@ Hook data:
Called when unfollowing a remote contact on a non-native network (like Twitter) Called when unfollowing a remote contact on a non-native network (like Twitter)
Hook data: Hook data:
- **contact** (input): the remote contact (uid = local unfollowing user id) array. - **contact** (input): the target public contact (uid = 0) array.
- **uid** (input): the id of the source local user.
- **result** (output): wether the unfollowing is successful or not. - **result** (output): wether the unfollowing is successful or not.
### revoke_follow ### revoke_follow
@ -634,7 +635,8 @@ Hook data:
Called when making a remote contact on a non-native network (like Twitter) unfollow you. Called when making a remote contact on a non-native network (like Twitter) unfollow you.
Hook data: Hook data:
- **contact** (input): the remote contact (uid = local revoking user id) array. - **contact** (input): the target public contact (uid = 0) array.
- **uid** (input): the id of the source local user.
- **result** (output): a boolean value indicating wether the operation was successful or not. - **result** (output): a boolean value indicating wether the operation was successful or not.
### block ### block

View File

@ -122,8 +122,7 @@ function unfollow_process(string $url)
$owner = User::getOwnerDataById($uid); $owner = User::getOwnerDataById($uid);
if (!$owner) { if (!$owner) {
(new \Friendica\Module\Security\Logout())->init(); throw new \Friendica\Network\HTTPException\NotFoundException();
// NOTREACHED
} }
$condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?)", $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?)",
@ -140,15 +139,10 @@ function unfollow_process(string $url)
$return_path = $base_return_path . '/' . $contact['id']; $return_path = $base_return_path . '/' . $contact['id'];
try { try {
$result = Contact::terminateFriendship($owner, $contact); Contact::unfollow($contact);
if ($result === false) {
$notice_message = DI::l10n()->t('Unable to unfollow this contact, please retry in a few minutes or contact your administrator.');
} else {
$notice_message = DI::l10n()->t('Contact was successfully unfollowed'); $notice_message = DI::l10n()->t('Contact was successfully unfollowed');
}
} catch (Exception $e) { } catch (Exception $e) {
DI::logger()->error($e->getMessage(), ['owner' => $owner, 'contact' => $contact]); DI::logger()->error($e->getMessage(), ['contact' => $contact]);
$notice_message = DI::l10n()->t('Unable to unfollow this contact, please contact your administrator'); $notice_message = DI::l10n()->t('Unable to unfollow this contact, please contact your administrator');
} }

View File

@ -199,19 +199,18 @@ HELP;
throw new RuntimeException('Contact not found'); throw new RuntimeException('Contact not found');
} }
$user = UserModel::getById($contact['uid']); if (empty($contact['uid'])) {
throw new RuntimeException('Contact must be user-specific (uid != 0)');
}
try { try {
$result = ContactModel::terminateFriendship($user, $contact); ContactModel::unfollow($contact);
if ($result === false) {
throw new RuntimeException('Unable to unfollow this contact, please retry in a few minutes or check the logs.');
}
$this->out('Contact was successfully unfollowed'); $this->out('Contact was successfully unfollowed');
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
DI::logger()->error($e->getMessage(), ['owner' => $user, 'contact' => $contact]); DI::logger()->error($e->getMessage(), ['contact' => $contact]);
throw new RuntimeException('Unable to unfollow this contact, please check the log'); throw new RuntimeException('Unable to unfollow this contact, please check the log');
} }
} }

View File

@ -22,7 +22,6 @@
namespace Friendica\Core; namespace Friendica\Core;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
use Friendica\Protocol\Activity; use Friendica\Protocol\Activity;
@ -171,15 +170,15 @@ class Protocol
} }
/** /**
* Sends an unfriend message. Does not remove the contact * Sends an unfollow message. Does not remove the contact
* *
* @param array $user User unfriending * @param array $contact Target public contact (uid = 0) array
* @param array $contact Contact unfriended * @param array $user Source local user array
* @return bool|null true if successful, false if not, null if no remote action was performed * @return bool|null true if successful, false if not, null if no remote action was performed
* @throws HTTPException\InternalServerErrorException * @throws HTTPException\InternalServerErrorException
* @throws \ImagickException * @throws \ImagickException
*/ */
public static function terminateFriendship(array $user, array $contact): ?bool public static function unfollow(array $contact, array $user): ?bool
{ {
if (empty($contact['network'])) { if (empty($contact['network'])) {
throw new \InvalidArgumentException('Missing network key in contact array'); throw new \InvalidArgumentException('Missing network key in contact array');
@ -216,7 +215,8 @@ class Protocol
// Catch-all hook for connector addons // Catch-all hook for connector addons
$hook_data = [ $hook_data = [
'contact' => $contact, 'contact' => $contact,
'result' => null 'uid' => $user['uid'],
'result' => null,
]; ];
Hook::callAll('unfollow', $hook_data); Hook::callAll('unfollow', $hook_data);
@ -226,12 +226,13 @@ class Protocol
/** /**
* Revoke an incoming follow from the provided contact * Revoke an incoming follow from the provided contact
* *
* @param array $contact Private contact (uid != 0) array * @param array $contact Target public contact (uid == 0) array
* @param int $uid Source local user id
* @return bool|null true if successful, false if not, null if no action was performed * @return bool|null true if successful, false if not, null if no action was performed
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException * @throws \ImagickException
*/ */
public static function revokeFollow(array $contact): ?bool public static function revokeFollow(array $contact, int $uid): ?bool
{ {
if (empty($contact['network'])) { if (empty($contact['network'])) {
throw new \InvalidArgumentException('Missing network key in contact array'); throw new \InvalidArgumentException('Missing network key in contact array');
@ -243,12 +244,13 @@ class Protocol
} }
if ($protocol == Protocol::ACTIVITYPUB) { if ($protocol == Protocol::ACTIVITYPUB) {
return ActivityPub\Transmitter::sendContactReject($contact['url'], $contact['hub-verify'], $contact['uid']); return ActivityPub\Transmitter::sendContactReject($contact['url'], $contact['hub-verify'], $uid);
} }
// Catch-all hook for connector addons // Catch-all hook for connector addons
$hook_data = [ $hook_data = [
'contact' => $contact, 'contact' => $contact,
'uid' => $uid,
'result' => null, 'result' => null,
]; ];
Hook::callAll('revoke_follow', $hook_data); Hook::callAll('revoke_follow', $hook_data);

View File

@ -1378,8 +1378,9 @@ class Worker
* Defers the current worker entry * Defers the current worker entry
* *
* @return boolean had the entry been deferred? * @return boolean had the entry been deferred?
* @throws \Exception
*/ */
public static function defer() public static function defer(): bool
{ {
$queue = DI::app()->getQueue(); $queue = DI::app()->getQueue();
@ -1387,7 +1388,6 @@ class Worker
return false; return false;
} }
$retrial = $queue['retrial'];
$id = $queue['id']; $id = $queue['id'];
$priority = $queue['priority']; $priority = $queue['priority'];

View File

@ -813,37 +813,13 @@ class Contact
} }
/** /**
* Sends an unfriend message. Removes the contact for two-way unfriending or sharing only protocols (feed an mail) * Unfollow the remote contact
* *
* @param array $user User unfriending * @param array $contact Target user-specific contact (uid != 0) array
* @param array $contact Contact (uid != 0) unfriended
* @param boolean $two_way Revoke eventual inbound follow as well
* @return bool|null true if successful, false if not, null if no remote action was performed
* @throws HTTPException\InternalServerErrorException * @throws HTTPException\InternalServerErrorException
* @throws \ImagickException * @throws \ImagickException
*/ */
public static function terminateFriendship(array $user, array $contact): ?bool public static function unfollow(array $contact): void
{
$result = Protocol::terminateFriendship($user, $contact);
if ($contact['rel'] == Contact::SHARING || in_array($contact['network'], [Protocol::FEED, Protocol::MAIL])) {
self::remove($contact['id']);
} else {
self::update(['rel' => Contact::FOLLOWER], ['id' => $contact['id']]);
}
return $result;
}
/**
* Revoke follow privileges of the remote user contact
*
* @param array $contact Contact unfriended
* @return bool|null Whether the remote operation is successful or null if no remote operation was performed
* @throws HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
public static function revokeFollow(array $contact): ?bool
{ {
if (empty($contact['network'])) { if (empty($contact['network'])) {
throw new \InvalidArgumentException('Empty network in contact array'); throw new \InvalidArgumentException('Empty network in contact array');
@ -853,20 +829,70 @@ class Contact
throw new \InvalidArgumentException('Unexpected public contact record'); throw new \InvalidArgumentException('Unexpected public contact record');
} }
$result = Protocol::revokeFollow($contact); if (in_array($contact['rel'], [self::SHARING, self::FRIEND])) {
$cdata = Contact::getPublicAndUserContactID($contact['id'], $contact['uid']);
Worker::add(PRIORITY_HIGH, 'Contact\Unfollow', $cdata['public'], $contact['uid']);
}
self::removeSharer($contact);
}
/**
* Revoke follow privileges of the remote user contact
*
* The local relationship is updated immediately, the eventual remote server is messaged in the background.
*
* @param array $contact User-specific contact array (uid != 0) to revoke the follow from
* @throws HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
public static function revokeFollow(array $contact): void
{
if (empty($contact['network'])) {
throw new \InvalidArgumentException('Empty network in contact array');
}
if (empty($contact['uid'])) {
throw new \InvalidArgumentException('Unexpected public contact record');
}
if (in_array($contact['rel'], [self::FOLLOWER, self::FRIEND])) {
$cdata = Contact::getPublicAndUserContactID($contact['id'], $contact['uid']);
Worker::add(PRIORITY_HIGH, 'Contact\RevokeFollow', $cdata['public'], $contact['uid']);
}
self::removeFollower($contact);
}
/**
* Completely severs a relationship with a contact
*
* @param array $contact User-specific contact (uid != 0) array
* @throws HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
public static function terminateFriendship(array $contact)
{
if (empty($contact['network'])) {
throw new \InvalidArgumentException('Empty network in contact array');
}
if (empty($contact['uid'])) {
throw new \InvalidArgumentException('Unexpected public contact record');
}
$cdata = Contact::getPublicAndUserContactID($contact['id'], $contact['uid']);
if (in_array($contact['rel'], [self::SHARING, self::FRIEND])) {
Worker::add(PRIORITY_HIGH, 'Contact\Unfollow', $cdata['public'], $contact['uid']);
}
if (in_array($contact['rel'], [self::FOLLOWER, self::FRIEND])) {
Worker::add(PRIORITY_HIGH, 'Contact\RevokeFollow', $cdata['public'], $contact['uid']);
}
// A null value here means the remote network doesn't support explicit follow revocation, we can still
// break the locally recorded relationship
if ($result !== false) {
if ($contact['rel'] == self::FRIEND) {
self::update(['rel' => self::SHARING], ['id' => $contact['id']]);
} else {
self::remove($contact['id']); self::remove($contact['id']);
} }
}
return $result;
}
/** /**
@ -2574,28 +2600,6 @@ class Contact
return $result; return $result;
} }
/**
* Unfollow a contact
*
* @param int $cid Public contact id
* @param int $uid User ID
*
* @return bool "true" if unfollowing had been successful
*/
public static function unfollow(int $cid, int $uid)
{
$cdata = self::getPublicAndUserContactID($cid, $uid);
if (empty($cdata['user'])) {
return false;
}
$contact = self::getById($cdata['user']);
self::removeSharer([], $contact);
return true;
}
/** /**
* @param array $importer Owner (local user) data * @param array $importer Owner (local user) data
* @param array $contact Existing owner-specific contact data we want to expand the relationship with. Optional. * @param array $contact Existing owner-specific contact data we want to expand the relationship with. Optional.
@ -2744,10 +2748,17 @@ class Contact
return null; return null;
} }
/**
* Update the local relationship when a local user loses a follower
*
* @param array $contact User-specific contact (uid != 0) array
* @throws HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
public static function removeFollower(array $contact) public static function removeFollower(array $contact)
{ {
if (in_array($contact['rel'] ?? [], [self::FRIEND, self::SHARING])) { if (in_array($contact['rel'] ?? [], [self::FRIEND, self::SHARING])) {
DBA::update('contact', ['rel' => self::SHARING], ['id' => $contact['id']]); self::update(['rel' => self::SHARING], ['id' => $contact['id']]);
} elseif (!empty($contact['id'])) { } elseif (!empty($contact['id'])) {
self::remove($contact['id']); self::remove($contact['id']);
} else { } else {
@ -2755,12 +2766,19 @@ class Contact
} }
} }
public static function removeSharer($importer, $contact) /**
* Update the local relationship when a local user unfollow a contact.
* Removes the contact for sharing-only protocols (feed and mail).
*
* @param array $contact User-specific contact (uid != 0) array
* @throws HTTPException\InternalServerErrorException
*/
public static function removeSharer(array $contact)
{ {
if (($contact['rel'] == self::FRIEND) || ($contact['rel'] == self::FOLLOWER)) { if ($contact['rel'] == self::SHARING || in_array($contact['network'], [Protocol::FEED, Protocol::MAIL])) {
self::update(['rel' => self::FOLLOWER], ['id' => $contact['id']]);
} else {
self::remove($contact['id']); self::remove($contact['id']);
} else {
self::update(['rel' => self::FOLLOWER], ['id' => $contact['id']]);
} }
} }

View File

@ -59,8 +59,7 @@ class Block extends BaseApi
Contact\User::setBlocked($cdata['user'], $uid, true); Contact\User::setBlocked($cdata['user'], $uid, true);
// Mastodon-expected behavior: relationship is severed on block // Mastodon-expected behavior: relationship is severed on block
Contact::terminateFriendship($owner, $contact); Contact::terminateFriendship($contact);
Contact::revokeFollow($contact);
System::jsonExit(DI::mstdnRelationship()->createFromContactId($this->parameters['id'], $uid)->toArray()); System::jsonExit(DI::mstdnRelationship()->createFromContactId($this->parameters['id'], $uid)->toArray());
} }

View File

@ -40,7 +40,14 @@ class Unfollow extends BaseApi
DI::mstdnError()->UnprocessableEntity(); DI::mstdnError()->UnprocessableEntity();
} }
Contact::unfollow($this->parameters['id'], $uid); $cdata = Contact::getPublicAndUserContactID($this->parameters['id'], $uid);
if (empty($cdata['user'])) {
DI::mstdnError()->RecordNotFound();
}
$contact = Contact::getById($cdata['user']);
Contact::unfollow($contact);
System::jsonExit(DI::mstdnRelationship()->createFromContactId($this->parameters['id'], $uid)->toArray()); System::jsonExit(DI::mstdnRelationship()->createFromContactId($this->parameters['id'], $uid)->toArray());
} }

View File

@ -22,13 +22,18 @@
namespace Friendica\Module\Api\Twitter\Friendships; namespace Friendica\Module\Api\Twitter\Friendships;
use Exception; use Exception;
use Friendica\App;
use Friendica\Core\L10n;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\DI; use Friendica\Factory\Api\Twitter\User as TwitterUser;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Module\Api\ApiResponse;
use Friendica\Module\Api\Twitter\ContactEndpoint; use Friendica\Module\Api\Twitter\ContactEndpoint;
use Friendica\Module\BaseApi; use Friendica\Module\BaseApi;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
use Friendica\Util\Profiler;
use Psr\Log\LoggerInterface;
/** /**
* Unfollow Contact * Unfollow Contact
@ -37,6 +42,16 @@ use Friendica\Network\HTTPException;
*/ */
class Destroy extends ContactEndpoint class Destroy extends ContactEndpoint
{ {
/** @var TwitterUser */
private $twitterUser;
public function __construct(App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, TwitterUser $twitterUser, array $server, array $parameters = [])
{
parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->twitterUser = $twitterUser;
}
protected function post(array $request = []) protected function post(array $request = [])
{ {
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE); BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
@ -66,18 +81,9 @@ class Destroy extends ContactEndpoint
$user = $this->twitterUser->createFromContactId($contact_id, $uid, true)->toArray(); $user = $this->twitterUser->createFromContactId($contact_id, $uid, true)->toArray();
try { try {
$result = Contact::terminateFriendship($owner, $contact); Contact::unfollow($contact);
if ($result === null) {
Logger::notice(BaseApi::LOG_PREFIX . 'Not supported for {network}', ['module' => 'api', 'action' => 'friendships_destroy', 'network' => $contact['network']]);
throw new HTTPException\ExpectationFailedException('Unfollowing is currently not supported by this contact\'s network.');
}
if ($result === false) {
throw new HTTPException\ServiceUnavailableException('Unable to unfollow this contact, please retry in a few minutes or contact your administrator.');
}
} catch (Exception $e) { } catch (Exception $e) {
Logger::error(BaseApi::LOG_PREFIX . $e->getMessage(), ['owner' => $owner, 'contact' => $contact]); Logger::error(BaseApi::LOG_PREFIX . $e->getMessage(), ['contact' => $contact]);
throw new HTTPException\InternalServerErrorException('Unable to unfollow this contact, please contact your administrator'); throw new HTTPException\InternalServerErrorException('Unable to unfollow this contact, please contact your administrator');
} }

View File

@ -38,7 +38,10 @@ use Psr\Log\LoggerInterface;
class Revoke extends BaseModule class Revoke extends BaseModule
{ {
/** @var array */ /**
* User-specific contact (uid != 0) array
* @var array
*/
protected $contact; protected $contact;
/** @var Database */ /** @var Database */
@ -82,14 +85,9 @@ class Revoke extends BaseModule
self::checkFormSecurityTokenRedirectOnError('contact/' . $this->parameters['id'], 'contact_revoke'); self::checkFormSecurityTokenRedirectOnError('contact/' . $this->parameters['id'], 'contact_revoke');
$result = Model\Contact::revokeFollow($this->contact); Model\Contact::revokeFollow($this->contact);
if ($result === true) {
notice($this->t('Follow was successfully revoked.')); notice($this->t('Follow was successfully revoked.'));
} elseif ($result === null) {
notice($this->t('Follow was successfully revoked, however the remote contact won\'t be aware of this revokation.'));
} else {
notice($this->t('Unable to revoke follow, please try again later or contact the administrator.'));
}
$this->baseUrl->redirect('contact/' . $this->parameters['id']); $this->baseUrl->redirect('contact/' . $this->parameters['id']);
} }

View File

@ -1668,7 +1668,7 @@ class DFRN
} }
if ($activity->match($item["verb"], Activity::UNFRIEND)) { if ($activity->match($item["verb"], Activity::UNFRIEND)) {
Logger::notice("Lost sharer"); Logger::notice("Lost sharer");
Contact::removeSharer($importer, $contact, $item); Contact::removeSharer($contact);
return false; return false;
} }
} else { } else {

View File

@ -837,8 +837,7 @@ class Diaspora
// It is deactivated by now, due to side effects. See issue https://github.com/friendica/friendica/pull/4033 // It is deactivated by now, due to side effects. See issue https://github.com/friendica/friendica/pull/4033
// It is not removed by now. Possibly the code is needed? // It is not removed by now. Possibly the code is needed?
//if (!$is_comment && $contact["rel"] == Contact::FOLLOWER && in_array($importer["page-flags"], array(User::PAGE_FLAGS_FREELOVE))) { //if (!$is_comment && $contact["rel"] == Contact::FOLLOWER && in_array($importer["page-flags"], array(User::PAGE_FLAGS_FREELOVE))) {
// DBA::update( // Contact::update(
// 'contact',
// array('rel' => Contact::FRIEND, 'writable' => true), // array('rel' => Contact::FRIEND, 'writable' => true),
// array('id' => $contact["id"], 'uid' => $contact["uid"]) // array('id' => $contact["id"], 'uid' => $contact["uid"])
// ); // );
@ -2123,8 +2122,7 @@ class Diaspora
private static function receiveRequestMakeFriend(array $importer, array $contact) private static function receiveRequestMakeFriend(array $importer, array $contact)
{ {
if ($contact["rel"] == Contact::SHARING) { if ($contact["rel"] == Contact::SHARING) {
DBA::update( Contact::update(
'contact',
['rel' => Contact::FRIEND, 'writable' => true], ['rel' => Contact::FRIEND, 'writable' => true],
['id' => $contact["id"], 'uid' => $importer["uid"]] ['id' => $contact["id"], 'uid' => $importer["uid"]]
); );

View File

@ -0,0 +1,51 @@
<?php
/**
* @copyright Copyright (C) 2010-2022, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
namespace Friendica\Worker\Contact;
use Friendica\Core\Protocol;
use Friendica\Core\Worker;
use Friendica\Model\Contact;
class RevokeFollow
{
/**
* Issue asynchronous follow revokation message to remote servers.
* The local relationship has already been updated, so we can't use the user-specific contact
*
* @param int $cid Target public contact id
* @param int $uid Source local user id
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
public static function execute(int $cid, int $uid)
{
$contact = Contact::getById($cid);
if (empty($contact)) {
return;
}
$result = Protocol::revokeFollow($contact, $uid);
if ($result === false) {
Worker::defer();
}
}
}

View File

@ -0,0 +1,57 @@
<?php
/**
* @copyright Copyright (C) 2010-2022, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
namespace Friendica\Worker\Contact;
use Friendica\Core\Protocol;
use Friendica\Core\Worker;
use Friendica\Model\Contact;
use Friendica\Model\User;
class Unfollow
{
/**
* Issue asynchronous unfollow message to remote servers.
* The local relationship has already been updated, so we can't use the user-specific contact.
*
* @param int $cid Target public contact (uid = 0) id
* @param int $uid Source local user id
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
public static function execute(int $cid, int $uid)
{
$contact = Contact::getById($cid);
if (empty($contact)) {
return;
}
$owner = User::getOwnerDataById($uid, false);
if (empty($owner)) {
return;
}
$result = Protocol::unfollow($contact, $owner);
if ($result === false) {
Worker::defer();
}
}
}

View File

@ -445,7 +445,7 @@ class Notifier
$condition = ['network' => Protocol::DFRN, 'uid' => $owner['uid'], 'blocked' => false, $condition = ['network' => Protocol::DFRN, 'uid' => $owner['uid'], 'blocked' => false,
'pending' => false, 'archive' => false, 'rel' => [Contact::FOLLOWER, Contact::FRIEND]]; 'pending' => false, 'archive' => false, 'rel' => [Contact::FOLLOWER, Contact::FRIEND]];
$contacts = DBA::toArray(DBA::select('contact', ['id', 'url', 'addr', 'name', 'network', 'protocol'], $condition)); $contacts = DBA::selectToArray('contact', ['id', 'url', 'addr', 'name', 'network', 'protocol'], $condition);
$conversants = array_merge($contacts, $participants); $conversants = array_merge($contacts, $participants);
@ -673,7 +673,7 @@ class Notifier
} }
while($contact = DBA::fetch($contacts_stmt)) { while($contact = DBA::fetch($contacts_stmt)) {
Protocol::terminateFriendship($owner, $contact, true); Contact::terminateFriendship($contact);
} }
DBA::close($contacts_stmt); DBA::close($contacts_stmt);

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: 2022.05-dev\n" "Project-Id-Version: 2022.05-dev\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-02-24 07:09+0000\n" "POT-Creation-Date: 2022-02-24 09:39-0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -268,7 +268,7 @@ msgstr ""
#: mod/editpost.php:130 mod/fbrowser.php:117 mod/fbrowser.php:144 #: mod/editpost.php:130 mod/fbrowser.php:117 mod/fbrowser.php:144
#: mod/follow.php:144 mod/photos.php:1010 mod/photos.php:1111 mod/tagrm.php:35 #: mod/follow.php:144 mod/photos.php:1010 mod/photos.php:1111 mod/tagrm.php:35
#: mod/tagrm.php:127 mod/unfollow.php:97 src/Content/Conversation.php:373 #: mod/tagrm.php:127 mod/unfollow.php:97 src/Content/Conversation.php:373
#: src/Module/Contact/Revoke.php:110 src/Module/RemoteFollow.php:127 #: src/Module/Contact/Revoke.php:108 src/Module/RemoteFollow.php:127
msgid "Cancel" msgid "Cancel"
msgstr "" msgstr ""
@ -465,7 +465,7 @@ msgid "OStatus support is disabled. Contact can't be added."
msgstr "" msgstr ""
#: mod/follow.php:138 src/Content/Item.php:452 src/Content/Widget.php:76 #: mod/follow.php:138 src/Content/Item.php:452 src/Content/Widget.php:76
#: src/Model/Contact.php:1057 src/Model/Contact.php:1069 #: src/Model/Contact.php:1083 src/Model/Contact.php:1095
#: view/theme/vier/theme.php:172 #: view/theme/vier/theme.php:172
msgid "Connect/Follow" msgid "Connect/Follow"
msgstr "" msgstr ""
@ -2038,7 +2038,7 @@ msgid ""
"select \"Export account\"" "select \"Export account\""
msgstr "" msgstr ""
#: mod/unfollow.php:65 mod/unfollow.php:135 #: mod/unfollow.php:65 mod/unfollow.php:134
msgid "You aren't following this contact." msgid "You aren't following this contact."
msgstr "" msgstr ""
@ -2050,17 +2050,11 @@ msgstr ""
msgid "Disconnect/Unfollow" msgid "Disconnect/Unfollow"
msgstr "" msgstr ""
#: mod/unfollow.php:146 #: mod/unfollow.php:143
msgid ""
"Unable to unfollow this contact, please retry in a few minutes or contact "
"your administrator."
msgstr ""
#: mod/unfollow.php:148
msgid "Contact was successfully unfollowed" msgid "Contact was successfully unfollowed"
msgstr "" msgstr ""
#: mod/unfollow.php:152 #: mod/unfollow.php:146
msgid "Unable to unfollow this contact, please contact your administrator" msgid "Unable to unfollow this contact, please contact your administrator"
msgstr "" msgstr ""
@ -2729,31 +2723,31 @@ msgstr ""
msgid "Follow Thread" msgid "Follow Thread"
msgstr "" msgstr ""
#: src/Content/Item.php:432 src/Model/Contact.php:1062 #: src/Content/Item.php:432 src/Model/Contact.php:1088
msgid "View Status" msgid "View Status"
msgstr "" msgstr ""
#: src/Content/Item.php:433 src/Content/Item.php:455 src/Model/Contact.php:996 #: src/Content/Item.php:433 src/Content/Item.php:455 src/Model/Contact.php:1022
#: src/Model/Contact.php:1054 src/Model/Contact.php:1063 #: src/Model/Contact.php:1080 src/Model/Contact.php:1089
#: src/Module/Directory.php:157 src/Module/Settings/Profile/Index.php:225 #: src/Module/Directory.php:157 src/Module/Settings/Profile/Index.php:225
msgid "View Profile" msgid "View Profile"
msgstr "" msgstr ""
#: src/Content/Item.php:434 src/Model/Contact.php:1064 #: src/Content/Item.php:434 src/Model/Contact.php:1090
msgid "View Photos" msgid "View Photos"
msgstr "" msgstr ""
#: src/Content/Item.php:435 src/Model/Contact.php:1055 #: src/Content/Item.php:435 src/Model/Contact.php:1081
#: src/Model/Contact.php:1065 #: src/Model/Contact.php:1091
msgid "Network Posts" msgid "Network Posts"
msgstr "" msgstr ""
#: src/Content/Item.php:436 src/Model/Contact.php:1056 #: src/Content/Item.php:436 src/Model/Contact.php:1082
#: src/Model/Contact.php:1066 #: src/Model/Contact.php:1092
msgid "View Contact" msgid "View Contact"
msgstr "" msgstr ""
#: src/Content/Item.php:437 src/Model/Contact.php:1067 #: src/Content/Item.php:437 src/Model/Contact.php:1093
msgid "Send PM" msgid "Send PM"
msgstr "" msgstr ""
@ -2776,7 +2770,7 @@ msgstr ""
msgid "Languages" msgid "Languages"
msgstr "" msgstr ""
#: src/Content/Item.php:447 src/Model/Contact.php:1068 #: src/Content/Item.php:447 src/Model/Contact.php:1094
msgid "Poke" msgid "Poke"
msgstr "" msgstr ""
@ -3228,7 +3222,7 @@ msgstr ""
msgid "Organisations" msgid "Organisations"
msgstr "" msgstr ""
#: src/Content/Widget.php:519 src/Model/Contact.php:1472 #: src/Content/Widget.php:519 src/Model/Contact.php:1498
msgid "News" msgid "News"
msgstr "" msgstr ""
@ -4051,81 +4045,81 @@ msgstr ""
msgid "Legacy module file not found: %s" msgid "Legacy module file not found: %s"
msgstr "" msgstr ""
#: src/Model/Contact.php:1058 src/Model/Contact.php:1070 #: src/Model/Contact.php:1084 src/Model/Contact.php:1096
msgid "UnFollow" msgid "UnFollow"
msgstr "" msgstr ""
#: src/Model/Contact.php:1076 src/Module/Admin/Users/Pending.php:107 #: src/Model/Contact.php:1102 src/Module/Admin/Users/Pending.php:107
#: src/Module/Notifications/Introductions.php:130 #: src/Module/Notifications/Introductions.php:130
#: src/Module/Notifications/Introductions.php:202 #: src/Module/Notifications/Introductions.php:202
msgid "Approve" msgid "Approve"
msgstr "" msgstr ""
#: src/Model/Contact.php:1468 #: src/Model/Contact.php:1494
msgid "Organisation" msgid "Organisation"
msgstr "" msgstr ""
#: src/Model/Contact.php:1476 #: src/Model/Contact.php:1502
msgid "Forum" msgid "Forum"
msgstr "" msgstr ""
#: src/Model/Contact.php:2411 #: src/Model/Contact.php:2437
msgid "Disallowed profile URL." msgid "Disallowed profile URL."
msgstr "" msgstr ""
#: src/Model/Contact.php:2416 src/Module/Friendica.php:81 #: src/Model/Contact.php:2442 src/Module/Friendica.php:81
msgid "Blocked domain" msgid "Blocked domain"
msgstr "" msgstr ""
#: src/Model/Contact.php:2421 #: src/Model/Contact.php:2447
msgid "Connect URL missing." msgid "Connect URL missing."
msgstr "" msgstr ""
#: src/Model/Contact.php:2430 #: src/Model/Contact.php:2456
msgid "" msgid ""
"The contact could not be added. Please check the relevant network " "The contact could not be added. Please check the relevant network "
"credentials in your Settings -> Social Networks page." "credentials in your Settings -> Social Networks page."
msgstr "" msgstr ""
#: src/Model/Contact.php:2467 #: src/Model/Contact.php:2493
msgid "The profile address specified does not provide adequate information." msgid "The profile address specified does not provide adequate information."
msgstr "" msgstr ""
#: src/Model/Contact.php:2469 #: src/Model/Contact.php:2495
msgid "No compatible communication protocols or feeds were discovered." msgid "No compatible communication protocols or feeds were discovered."
msgstr "" msgstr ""
#: src/Model/Contact.php:2472 #: src/Model/Contact.php:2498
msgid "An author or name was not found." msgid "An author or name was not found."
msgstr "" msgstr ""
#: src/Model/Contact.php:2475 #: src/Model/Contact.php:2501
msgid "No browser URL could be matched to this address." msgid "No browser URL could be matched to this address."
msgstr "" msgstr ""
#: src/Model/Contact.php:2478 #: src/Model/Contact.php:2504
msgid "" msgid ""
"Unable to match @-style Identity Address with a known protocol or email " "Unable to match @-style Identity Address with a known protocol or email "
"contact." "contact."
msgstr "" msgstr ""
#: src/Model/Contact.php:2479 #: src/Model/Contact.php:2505
msgid "Use mailto: in front of address to force email check." msgid "Use mailto: in front of address to force email check."
msgstr "" msgstr ""
#: src/Model/Contact.php:2485 #: src/Model/Contact.php:2511
msgid "" msgid ""
"The profile address specified belongs to a network which has been disabled " "The profile address specified belongs to a network which has been disabled "
"on this site." "on this site."
msgstr "" msgstr ""
#: src/Model/Contact.php:2490 #: src/Model/Contact.php:2516
msgid "" msgid ""
"Limited profile. This person will be unable to receive direct/personal " "Limited profile. This person will be unable to receive direct/personal "
"notifications from you." "notifications from you."
msgstr "" msgstr ""
#: src/Model/Contact.php:2549 #: src/Model/Contact.php:2575
msgid "Unable to retrieve contact information." msgid "Unable to retrieve contact information."
msgstr "" msgstr ""
@ -7518,7 +7512,7 @@ msgstr ""
msgid "Toggle Ignored status" msgid "Toggle Ignored status"
msgstr "" msgstr ""
#: src/Module/Contact/Profile.php:466 src/Module/Contact/Revoke.php:107 #: src/Module/Contact/Profile.php:466 src/Module/Contact/Revoke.php:105
msgid "Revoke Follow" msgid "Revoke Follow"
msgstr "" msgstr ""
@ -7526,40 +7520,29 @@ msgstr ""
msgid "Revoke the follow from this contact" msgid "Revoke the follow from this contact"
msgstr "" msgstr ""
#: src/Module/Contact/Revoke.php:59 #: src/Module/Contact/Revoke.php:62
msgid "Unknown contact." msgid "Unknown contact."
msgstr "" msgstr ""
#: src/Module/Contact/Revoke.php:69 src/Module/Group.php:112 #: src/Module/Contact/Revoke.php:72 src/Module/Group.php:112
msgid "Contact is deleted." msgid "Contact is deleted."
msgstr "" msgstr ""
#: src/Module/Contact/Revoke.php:73 #: src/Module/Contact/Revoke.php:76
msgid "Contact is being deleted." msgid "Contact is being deleted."
msgstr "" msgstr ""
#: src/Module/Contact/Revoke.php:87 #: src/Module/Contact/Revoke.php:90
msgid "Follow was successfully revoked." msgid "Follow was successfully revoked."
msgstr "" msgstr ""
#: src/Module/Contact/Revoke.php:89 #: src/Module/Contact/Revoke.php:106
msgid ""
"Follow was successfully revoked, however the remote contact won't be aware "
"of this revokation."
msgstr ""
#: src/Module/Contact/Revoke.php:91
msgid ""
"Unable to revoke follow, please try again later or contact the administrator."
msgstr ""
#: src/Module/Contact/Revoke.php:108
msgid "" msgid ""
"Do you really want to revoke this contact's follow? This cannot be undone " "Do you really want to revoke this contact's follow? This cannot be undone "
"and they will have to manually follow you back again." "and they will have to manually follow you back again."
msgstr "" msgstr ""
#: src/Module/Contact/Revoke.php:109 #: src/Module/Contact/Revoke.php:107
#: src/Module/Notifications/Introductions.php:142 #: src/Module/Notifications/Introductions.php:142
#: src/Module/OAuth/Acknowledge.php:53 src/Module/Register.php:130 #: src/Module/OAuth/Acknowledge.php:53 src/Module/Register.php:130
msgid "Yes" msgid "Yes"