]> git.mxchange.org Git - friendica.git/commitdiff
Force removal from relay list
authorMichael <heluecht@pirati.ca>
Tue, 29 Sep 2020 05:06:37 +0000 (05:06 +0000)
committerMichael <heluecht@pirati.ca>
Tue, 29 Sep 2020 05:06:37 +0000 (05:06 +0000)
src/Console/Relay.php
src/Model/Contact.php
src/Protocol/ActivityPub/Receiver.php
src/Protocol/ActivityPub/Transmitter.php

index ab994dc62c1af0e2b030e8279c7fd6152ea2731f..206726f6bca6862dd261fc8a8b843d5faf778b68 100644 (file)
@@ -49,7 +49,7 @@ console relay - Manage ActivityPub relay configuration
 Synopsis
        bin/console relay list [-h|--help|-?] [-v]
        bin/console relay add <actor> [-h|--help|-?] [-v]
-       bin/console relay remove <actor> [-h|--help|-?] [-v]
+       bin/console relay remove <actor> [-f|--force] [-h|--help|-?] [-v]
 
 Description
        bin/console relay list
@@ -62,6 +62,7 @@ Description
                Remove a relay actor in the format https://relayserver.tld/actor
 
 Options
+    -f|--force   Change the relay status in the system even if the unsubscribe message failed
     -h|--help|-? Show help information
     -v           Show more debug information.
 HELP;
@@ -119,10 +120,14 @@ HELP;
                                        $this->out($actor . " couldn't be added");
                                }
                        } elseif ($mode == 'remove') {
-                               if (Transmitter::sendRelayUndoFollow($actor)) {
+                               $force = $this->getOption(['f', 'force'], false);
+
+                               if (Transmitter::sendRelayUndoFollow($actor, $force)) {
                                        $this->out('Successfully removed ' . $actor);
-                               } else {
+                               } elseif (!$force) {
                                        $this->out($actor . " couldn't be removed");
+                               } else {
+                                       $this->out($actor . " is forcefully removed");
                                }
                        } else {
                                throw new CommandArgsException($mode . ' is no valid command');
index 6fde8123a1b21c049d336851718e82506de655a2..6e74241b6fa57e90838081625fa2fcbc410f23f4 100644 (file)
@@ -126,6 +126,7 @@ class Contact
         * Relationship types
         * @{
         */
+       const NOTHING  = 0;
        const FOLLOWER = 1;
        const SHARING  = 2;
        const FRIEND   = 3;
index 67e38fcfef2b587f2e1e3555db449a7deaa96440..69d24a7abbc2f5019e1bf8b7df5788f3b06d2df3 100644 (file)
@@ -173,6 +173,17 @@ class Receiver
                        return;
                }
 
+               $contact = Contact::getByURL($actor);
+               if (empty($contact)) {
+                       Logger::info('Relay contact not found', ['actor' => $actor]);
+                       return;
+               }
+
+               if (!in_array($contact['rel'], [Contact::SHARING, Contact::FRIEND])) {
+                       Logger::notice('Relay is no sharer', ['actor' => $actor]);
+                       return;
+               }
+
                Logger::info('Got relayed message id', ['id' => $object_id]);
 
                $item_id = Item::searchByLink($object_id);
index b232c8c7f3b72e30985cc385b22e403391bfa71f..54df8e059e07592d87ebba648f5c18326111457c 100644 (file)
@@ -88,15 +88,16 @@ class Transmitter
         */
        public static function sendRelayFollow(string $url)
        {
-               $contact_id = Contact::getIdForURL($url);
-               if (!$contact_id) {
+               $contact = Contact::getByURL($url);
+               if (empty($contact)) {
                        return false;
                }
 
-               $activity_id = ActivityPub\Transmitter::activityIDFromContact($contact_id);
+               $activity_id = ActivityPub\Transmitter::activityIDFromContact($contact['id']);
                $success = ActivityPub\Transmitter::sendActivity('Follow', $url, 0, $activity_id);
                if ($success) {
-                       DBA::update('contact', ['rel' => Contact::FRIEND], ['id' => $contact_id]);
+                       $rel = $contact['rel'] == Contact::SHARING ? Contact::FRIEND : Contact::FOLLOWER;
+                       DBA::update('contact', ['rel' => $rel], ['id' => $contact['id']]);
                }
 
                return $success;
@@ -105,19 +106,21 @@ class Transmitter
        /**
         * Unsubscribe from a relay
         *
-        * @param string $url Subscribe actor url
+        * @param string $url   Subscribe actor url
+        * @param bool   $force Set the relay status as non follower even if unsubscribe hadn't worked
         * @return bool success
         */
-       public static function sendRelayUndoFollow(string $url)
+       public static function sendRelayUndoFollow(string $url, bool $force = false)
        {
-               $contact_id = Contact::getIdForURL($url);
-               if (!$contact_id) {
+               $contact = Contact::getByURL($url);
+               if (empty($contact)) {
                        return false;
                }
 
-               $success = self::sendContactUndo($url, $contact_id, 0);
-               if ($success) {
-                       DBA::update('contact', ['rel' => Contact::SHARING], ['id' => $contact_id]);
+               $success = self::sendContactUndo($url, $contact['id'], 0);
+               if ($success || $force) {
+                       $rel = $contact['rel'] == Contact::FRIEND ? Contact::SHARING : Contact::NOTHING;
+                       DBA::update('contact', ['rel' => $rel], ['id' => $contact['id']]);
                }
 
                return $success;