Merge pull request #9322 from annando/issue-9305
authorTobias Diekershoff <tobias.diekershoff@gmx.net>
Wed, 30 Sep 2020 05:21:59 +0000 (07:21 +0200)
committerGitHub <noreply@github.com>
Wed, 30 Sep 2020 05:21:59 +0000 (07:21 +0200)
Issue 9305: Relay deny tags are added

src/Console/Relay.php
src/Model/Contact.php
src/Module/Admin/Federation.php
src/Protocol/ActivityPub/Receiver.php
src/Protocol/ActivityPub/Transmitter.php
src/Worker/Notifier.php

index ab994dc..206726f 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 6fde812..1ec1424 100644 (file)
@@ -23,9 +23,11 @@ namespace Friendica\Model;
 
 use Friendica\App\BaseURL;
 use Friendica\Content\Pager;
+use Friendica\Content\Text\HTML;
 use Friendica\Core\Hook;
 use Friendica\Core\Logger;
 use Friendica\Core\Protocol;
+use Friendica\Core\Renderer;
 use Friendica\Core\Session;
 use Friendica\Core\System;
 use Friendica\Core\Worker;
@@ -126,6 +128,7 @@ class Contact
         * Relationship types
         * @{
         */
+       const NOTHING  = 0;
        const FOLLOWER = 1;
        const SHARING  = 2;
        const FRIEND   = 3;
@@ -1283,6 +1286,11 @@ class Contact
                if ($thread_mode) {
                        $condition = ["(`$contact_field` = ? OR (`causer-id` = ? AND `post-type` = ?)) AND `gravity` = ? AND " . $sql,
                                $cid, $cid, Item::PT_ANNOUNCEMENT, GRAVITY_PARENT, local_user()];
+
+                       $last_received = isset($_GET['last_received']) ? DateTimeFormat::utc($_GET['last_received']) : '';
+                       if (!empty($last_received)) {
+                               $condition = DBA::mergeConditions($condition, ["`received` < ?", $last_received]);
+                       }
                } else {
                        $condition = ["`$contact_field` = ? AND `gravity` IN (?, ?) AND " . $sql,
                                $cid, GRAVITY_PARENT, GRAVITY_COMMENT, local_user()];
@@ -1302,6 +1310,13 @@ class Contact
                        'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
 
                if ($thread_mode) {
+                       if (DI::pConfig()->get(local_user(), 'system', 'infinite_scroll')) {
+                               $tpl = Renderer::getMarkupTemplate('infinite_scroll_head.tpl');
+                               $o = Renderer::replaceMacros($tpl, ['$reload_uri' => DI::args()->getQueryString()]);
+                       } else {
+                               $o = '';
+                       }
+               
                        $r = Item::selectForUser(local_user(), ['uri', 'gravity', 'parent-uri'], $condition, $params);
                        $items = [];
                        while ($item = DBA::fetch($r)) {
@@ -1315,7 +1330,7 @@ class Contact
                        }
                        DBA::close($r);
 
-                       $o = conversation($a, $items, 'contacts', $update, false, 'commented', local_user());
+                       $o .= conversation($a, $items, 'contacts', $update, false, 'commented', local_user());
                } else {
                        $r = Item::selectForUser(local_user(), [], $condition, $params);
 
@@ -1325,7 +1340,11 @@ class Contact
                }
 
                if (!$update) {
-                       $o .= $pager->renderMinimal(count($items));
+                       if ($thread_mode && DI::pConfig()->get(local_user(), 'system', 'infinite_scroll')) {
+                               $o .= HTML::scrollLoader();
+                       } else {
+                               $o .= $pager->renderMinimal(count($items));
+                       }
                }
 
                return $o;
index 1fdd7a5..f5d7cb0 100644 (file)
@@ -161,8 +161,9 @@ class Federation extends BaseAdmin
                        $newVC = $vv['total'];
                        $newVV = $vv['version'];
                        $lastDot = strrpos($newVV, '.');
+                       $firstDash = strpos($newVV, '-');
                        $len = strlen($newVV) - 1;
-                       if (($lastDot == $len - 4) && (!strrpos($newVV, '-rc') == $len - 3)) {
+                       if (($lastDot == $len - 4) && (!strrpos($newVV, '-rc') == $len - 3) && (!$firstDash == $len - 1)) {
                                $newVV = substr($newVV, 0, $lastDot);
                        }
                        if (isset($newV[$newVV])) {
index 67e38fc..69d24a7 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 b232c8c..54df8e0 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;
index 7e14894..d6cf0c2 100644 (file)
@@ -629,12 +629,12 @@ class Notifier
                }
 
                // Skip the delivery to Diaspora if the item is from an ActivityPub author
-               if ($item['author-network'] == Protocol::ACTIVITYPUB) {
+               if (!empty($item['author-network']) && ($item['author-network'] == Protocol::ACTIVITYPUB)) {
                        return true;
                }
 
                // Skip the delivery to Diaspora if the thread parent is from an ActivityPub author
-               if ($thr_parent['author-network'] == Protocol::ACTIVITYPUB) {
+               if (!empty($thr_parent['author-network']) && ($thr_parent['author-network'] == Protocol::ACTIVITYPUB)) {
                        return true;
                }