]> git.mxchange.org Git - friendica.git/commitdiff
Remove the obsolete parameter $two_way from terminateFriendship methods
authorHypolite Petovan <hypolite@mrpetovan.com>
Sat, 2 Oct 2021 19:48:20 +0000 (15:48 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Sat, 2 Oct 2021 20:14:22 +0000 (16:14 -0400)
- Follow revokation is now done independently

doc/Addons.md
include/api.php
mod/unfollow.php
src/Core/Protocol.php
src/Model/Contact.php
src/Module/Contact.php

index 89c3c3d99ac65ecdece6221a0af514a73817ac4f..ec82452d54b65d14c80c22786403277d3da756ec 100644 (file)
@@ -510,7 +510,6 @@ Called when unfollowing a remote contact on a non-native network (like Twitter)
 
 Hook data:
 - **contact** (input): the remote contact (uid = local unfollowing user id) array.
-- **two_way** (input): wether to stop sharing with the remote contact as well.
 - **result** (output): wether the unfollowing is successful or not.
 
 ### revoke_follow
index fe87799cc8ac18a89090511f8ad100783abbe7a5..af9fe7736b180471e7e04244f2d343774506a655 100644 (file)
@@ -3826,10 +3826,8 @@ function api_friendships_destroy($type)
                throw new HTTPException\NotFoundException('Not following Contact');
        }
 
-       $dissolve = ($contact['rel'] == Contact::SHARING);
-
        try {
-               $result = Contact::terminateFriendship($owner, $contact, $dissolve);
+               $result = Contact::terminateFriendship($owner, $contact);
 
                if ($result === null) {
                        Logger::notice(API_LOG_PREFIX . 'Not supported for {network}', ['module' => 'api', 'action' => 'friendships_destroy', 'network' => $contact['network']]);
@@ -3840,7 +3838,7 @@ function api_friendships_destroy($type)
                        throw new HTTPException\ServiceUnavailableException('Unable to unfollow this contact, please retry in a few minutes or contact your administrator.');
                }
        } catch (Exception $e) {
-               Logger::error(API_LOG_PREFIX . $e->getMessage(), ['owner' => $owner, 'contact' => $contact, 'dissolve' => $dissolve]);
+               Logger::error(API_LOG_PREFIX . $e->getMessage(), ['owner' => $owner, 'contact' => $contact]);
                throw new HTTPException\InternalServerErrorException('Unable to unfollow this contact, please contact your administrator');
        }
 
index a307c4d6e683594d3fd61ec4a97502816276bd1a..2dc9180dc940084ec7f558d90e1bbf8b24d32205 100644 (file)
@@ -137,13 +137,11 @@ function unfollow_process(string $url)
                // NOTREACHED
        }
 
-       $dissolve = ($contact['rel'] == Contact::SHARING);
-
        $notice_message = '';
        $return_path = $base_return_path . '/' . $contact['id'];
 
        try {
-               $result = Contact::terminateFriendship($owner, $contact, $dissolve);
+               $result = Contact::terminateFriendship($owner, $contact);
 
                if ($result === null) {
                        $notice_message = DI::l10n()->t('Unfollowing is currently not supported by this contact\'s network.');
@@ -157,7 +155,7 @@ function unfollow_process(string $url)
                        $notice_message = DI::l10n()->t('Contact was successfully unfollowed');
                }
        } catch (Exception $e) {
-               DI::logger()->error($e->getMessage(), ['owner' => $owner, 'contact' => $contact, 'dissolve' => $dissolve]);
+               DI::logger()->error($e->getMessage(), ['owner' => $owner, 'contact' => $contact]);
                $notice_message = DI::l10n()->t('Unable to unfollow this contact, please contact your administrator');
        }
 
index bce6bc699cc8cd31b9966f99faed31e7798736c8..66c74ccc9195d6e71e0e7e2f09a38f0b07c6051f 100644 (file)
@@ -207,12 +207,11 @@ class Protocol
         *
         * @param array   $user    User unfriending
         * @param array   $contact Contact 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
        {
                if (empty($contact['network'])) {
                        throw new \InvalidArgumentException('Missing network key in contact array');
@@ -243,17 +242,12 @@ class Protocol
                } elseif ($protocol == Protocol::DIASPORA) {
                        return Diaspora::sendUnshare($user, $contact) > 0;
                } elseif ($protocol == Protocol::ACTIVITYPUB) {
-                       if ($two_way) {
-                               ActivityPub\Transmitter::sendContactReject($contact['url'], $contact['hub-verify'], $user['uid']);
-                       }
-
                        return ActivityPub\Transmitter::sendContactUndo($contact['url'], $contact['id'], $user['uid']);
                }
 
                // Catch-all hook for connector addons
                $hook_data = [
                        'contact' => $contact,
-                       'two_way' => $two_way,
                        'result' => null
                ];
                Hook::callAll('unfollow', $hook_data);
@@ -265,6 +259,7 @@ class Protocol
         * Revoke an incoming follow from the provided contact
         *
         * @param array $contact Private contact (uid != 0) array
+        * @return bool|null true if successful, false if not, null if no action was performed
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
index bc8a6cbe7bce8fdab50bbcdd7949ac845e1fb552..bfbeb90024474132fa60320ef9955fc19eb0f274 100644 (file)
@@ -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']]);
index 3b253b85c158f451c825d8a2148cb3161e6e5906..4aebc4c93acf9d84435ed11be9d2dfbbd3d141f4 100644 (file)
@@ -69,7 +69,8 @@ class Contact extends BaseModule
                $count_actions = 0;
                foreach ($orig_records as $orig_record) {
                        $cdata = Model\Contact::getPublicAndUserContactID($orig_record['id'], local_user());
-                       if (empty($cdata)) {
+                       if (empty($cdata) || public_contact() === $cdata['public']) {
+                               // No action available on your own contact
                                continue;
                        }
 
@@ -79,7 +80,7 @@ class Contact extends BaseModule
                        }
 
                        if (!empty($_POST['contacts_batch_block'])) {
-                               self::toggleBlockContact($cdata['public']);
+                               self::toggleBlockContact($cdata['public'], local_user());
                                $count_actions++;
                        }
 
@@ -204,12 +205,13 @@ class Contact extends BaseModule
         * Toggles the blocked status of a contact identified by id.
         *
         * @param int $contact_id Id of the contact with uid = 0
+        * @param int $owner_id   Id of the user we want to block the contact for
         * @throws \Exception
         */
-       private static function toggleBlockContact(int $contact_id)
+       private static function toggleBlockContact(int $contact_id, int $owner_id)
        {
-               $blocked = !Model\Contact\User::isBlocked($contact_id, local_user());
-               Model\Contact\User::setBlocked($contact_id, local_user(), $blocked);
+               $blocked = !Model\Contact\User::isBlocked($contact_id, $owner_id);
+               Model\Contact\User::setBlocked($contact_id, $owner_id, $blocked);
        }
 
        /**
@@ -373,7 +375,7 @@ class Contact extends BaseModule
                                        throw new BadRequestException(DI::l10n()->t('You can\'t block yourself'));
                                }
 
-                               self::toggleBlockContact($cdata['public']);
+                               self::toggleBlockContact($cdata['public'], local_user());
 
                                $blocked = Model\Contact\User::isBlocked($contact_id, local_user());
                                info(($blocked ? DI::l10n()->t('Contact has been blocked') : DI::l10n()->t('Contact has been unblocked')));