mirror of
https://github.com/friendica/friendica
synced 2025-04-27 18:30:12 +00:00
Move unfollow protocol to worker task
- Add uid parameter to unfollow hook - Rework and unify Contact::unfollow, Contact::removeSharer and Contact::terminateFriendship - Add missing twitterUser property to Twitter\Friendships\Destroy module
This commit is contained in:
parent
48e2963ac7
commit
6a1f9a7fa3
11 changed files with 159 additions and 78 deletions
|
@ -813,26 +813,28 @@ 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 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
|
||||
* @param array $contact Target user-specific contact (uid != 0) array
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @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']]);
|
||||
if (empty($contact['network'])) {
|
||||
throw new \InvalidArgumentException('Empty network in contact array');
|
||||
}
|
||||
|
||||
return $result;
|
||||
if (empty($contact['uid'])) {
|
||||
throw new \InvalidArgumentException('Unexpected public contact record');
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -868,6 +870,36 @@ class Contact
|
|||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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']);
|
||||
}
|
||||
|
||||
self::remove($contact['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Marks a contact for archival after a communication issue delay
|
||||
|
@ -2574,28 +2606,6 @@ class Contact
|
|||
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 $contact Existing owner-specific contact data we want to expand the relationship with. Optional.
|
||||
|
@ -2755,12 +2765,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)) {
|
||||
self::update(['rel' => self::FOLLOWER], ['id' => $contact['id']]);
|
||||
} else {
|
||||
if ($contact['rel'] == self::SHARING || in_array($contact['network'], [Protocol::FEED, Protocol::MAIL])) {
|
||||
self::remove($contact['id']);
|
||||
} else {
|
||||
self::update(['rel' => self::FOLLOWER], ['id' => $contact['id']]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue