X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FContact.php;h=18e041ab9849c1f18611f925b81e0e534deef8f1;hb=ea6f7aba40e4a99661d6fb4d4367e2762a27306e;hp=9b5d816046b303e57dd35a0e53cdac19600d8b5a;hpb=a2f5190bdb082246578694a5e907848e6fdd43b6;p=friendica.git diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 9b5d816046..18e041ab98 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -830,17 +830,17 @@ class Contact * Sends an unfriend message. Removes the contact for two-way unfriending or sharing only protocols (feed an mail) * * @param array $user User unfriending - * @param array $contact Contact unfriended + * @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 action was performed * @throws HTTPException\InternalServerErrorException * @throws \ImagickException */ - public static function terminateFriendship(array $user, array $contact, bool $two_way = false): bool + public static function terminateFriendship(array $user, array $contact): bool { - $result = Protocol::terminateFriendship($user, $contact, $two_way); + $result = Protocol::terminateFriendship($user, $contact); - if ($two_way || in_array($contact['network'], [Protocol::FEED, Protocol::MAIL])) { + 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']]); @@ -849,6 +849,40 @@ class Contact 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'])) { + throw new \InvalidArgumentException('Empty network in contact array'); + } + + if (empty($contact['uid'])) { + throw new \InvalidArgumentException('Unexpected public contact record'); + } + + $result = Protocol::revokeFollow($contact); + + // 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']); + } + } + + return $result; + } + + /** * Marks a contact for archival after a communication issue delay * @@ -964,7 +998,6 @@ class Contact $pm_url = ''; $status_link = ''; $photos_link = ''; - $contact_drop_link = ''; $poke_link = ''; if ($uid == 0) { @@ -1016,13 +1049,9 @@ class Contact $posts_link = DI::baseUrl() . '/contact/' . $contact['id'] . '/conversations'; - if (!$contact['self']) { - $contact_drop_link = DI::baseUrl() . '/contact/' . $contact['id'] . '/drop?confirm=1'; - } - $follow_link = ''; $unfollow_link = ''; - if (!$contact['self'] && in_array($contact['network'], Protocol::NATIVE_SUPPORT)) { + if (!$contact['self'] && Protocol::supportsFollow($contact['network'])) { if ($contact['uid'] && in_array($contact['rel'], [self::SHARING, self::FRIEND])) { $unfollow_link = 'unfollow?url=' . urlencode($contact['url']) . '&auto=1'; } elseif(!$contact['pending']) { @@ -1030,10 +1059,6 @@ class Contact } } - if (!empty($follow_link) || !empty($unfollow_link)) { - $contact_drop_link = ''; - } - /** * Menu array: * "name" => [ "Label", "link", (bool)Should the link opened in a new tab? ] @@ -1053,7 +1078,6 @@ class Contact 'photos' => [DI::l10n()->t('View Photos') , $photos_link , true], 'network' => [DI::l10n()->t('Network Posts') , $posts_link , false], 'edit' => [DI::l10n()->t('View Contact') , $contact_url , false], - 'drop' => [DI::l10n()->t('Drop Contact') , $contact_drop_link, false], 'pm' => [DI::l10n()->t('Send PM') , $pm_url , false], 'poke' => [DI::l10n()->t('Poke') , $poke_link , false], 'follow' => [DI::l10n()->t('Connect/Follow'), $follow_link , true], @@ -2681,7 +2705,7 @@ class Contact // Ensure to always have the correct network type, independent from the connection request method self::updateFromProbe($contact['id']); - Post\UserNotification::insertNotication($contact['id'], Verb::getID(Activity::FOLLOW), $importer['uid']); + Post\UserNotification::insertNotification($contact['id'], Verb::getID(Activity::FOLLOW), $importer['uid']); return true; } else { @@ -2712,7 +2736,7 @@ class Contact self::updateAvatar($contact_id, $photo, true); - Post\UserNotification::insertNotication($contact_id, Verb::getID(Activity::FOLLOW), $importer['uid']); + Post\UserNotification::insertNotification($contact_id, Verb::getID(Activity::FOLLOW), $importer['uid']); $contact_record = DBA::selectFirst('contact', ['id', 'network', 'name', 'url', 'photo'], ['id' => $contact_id]);