]> git.mxchange.org Git - friendica.git/commitdiff
Don't transmit content to already archived contacts
authorMichael Vogel <icarus@dabo.de>
Tue, 27 Aug 2019 19:01:11 +0000 (21:01 +0200)
committerMichael Vogel <icarus@dabo.de>
Tue, 27 Aug 2019 19:01:11 +0000 (21:01 +0200)
src/Core/Worker.php
src/Model/Contact.php
src/Protocol/Diaspora.php
src/Worker/Delivery.php
src/Worker/Notifier.php

index 1fd5378abbc1dd79b07d49e0b8c3db05883e25a5..f24df5252d4479bf9c4105039b706c2d0bd061f5 100644 (file)
@@ -1243,7 +1243,7 @@ class Worker
                $new_retrial = self::getNextRetrial($queue, $max_level);
 
                if ($new_retrial > $max_level) {
-                       Logger::info('The task exceeded the maximum retry count', ['id' => $id, 'max_level' => $max_level, 'retrial' => $new_retrial]);
+                       Logger::info('The task exceeded the maximum retry count', ['id' => $id, 'created' => $queue['created'], 'old_prio' => $queue['priority'], 'old_retrial' => $queue['retrial'], 'max_level' => $max_level, 'retrial' => $new_retrial]);
                        return false;
                }
 
@@ -1259,7 +1259,7 @@ class Worker
                        $priority = PRIORITY_NEGLIGIBLE;
                }
 
-               Logger::info('Deferred task', ['id' => $id, 'retrial' => $new_retrial, 'next_execution' => $next, 'old_prio' => $queue['priority'], 'new_prio' => $priority]);
+               Logger::info('Deferred task', ['id' => $id, 'retrial' => $new_retrial, 'created' => $queue['created'], 'next_execution' => $next, 'old_prio' => $queue['priority'], 'new_prio' => $priority]);
 
                $stamp = (float)microtime(true);
                $fields = ['retrial' => $new_retrial, 'next_try' => $next, 'executed' => DBA::NULL_DATETIME, 'pid' => 0, 'priority' => $priority];
index 6f9ee4cdb6d9f4aa2bf508d83af596d2581f7311..75d820517fc08dd5709f12f7365f9af3d2b29c3c 100644 (file)
@@ -860,8 +860,8 @@ class Contact extends BaseObject
                                 * delete, though if the owner tries to unarchive them we'll start
                                 * the whole process over again.
                                 */
-                               DBA::update('contact', ['archive' => 1], ['id' => $contact['id']]);
-                               DBA::update('contact', ['archive' => 1], ['nurl' => Strings::normaliseLink($contact['url']), 'self' => false]);
+                               DBA::update('contact', ['archive' => true], ['id' => $contact['id']]);
+                               DBA::update('contact', ['archive' => true], ['nurl' => Strings::normaliseLink($contact['url']), 'self' => false]);
                                GContact::updateFromPublicContactURL($contact['url']);
                        }
                }
@@ -899,7 +899,7 @@ class Contact extends BaseObject
                // It's a miracle. Our dead contact has inexplicably come back to life.
                $fields = ['term-date' => DBA::NULL_DATETIME, 'archive' => false];
                DBA::update('contact', $fields, ['id' => $contact['id']]);
-               DBA::update('contact', $fields, ['nurl' => Strings::normaliseLink($contact['url'])]);
+               DBA::update('contact', $fields, ['nurl' => Strings::normaliseLink($contact['url']), 'self' => false]);
                GContact::updateFromPublicContactURL($contact['url']);
 
                if (!empty($contact['batch'])) {
@@ -1556,6 +1556,45 @@ class Contact extends BaseObject
                return $contact_id;
        }
 
+       /**
+        * @brief Checks if the contact is archived
+        *
+        * @param int $cid contact id
+        *
+        * @return boolean Is the contact archived?
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        */
+       public static function isArchived($cid)
+       {
+               if ($cid == 0) {
+                       return false;
+               }
+
+               $archived = DBA::selectFirst('contact', ['archive', 'url'], ['id' => $cid]);
+               if (!DBA::isResult($archived)) {
+                       return false;
+               }
+
+               if ($archived['archive']) {
+                       return true;
+               }
+
+               $apcontact = APContact::getByURL($archived['url'], false);
+               if (empty($apcontact)) {
+                       return false;
+               }
+
+               if (!empty($apcontact['inbox']) && DBA::exists('inbox-status', ['archive' => true, 'url' => $apcontact['inbox']])) {
+                       return true;
+               }
+
+               if (!empty($apcontact['sharedinbox']) && DBA::exists('inbox-status', ['archive' => true, 'url' => $apcontact['sharedinbox']])) {
+                       return true;
+               }
+
+               return false;
+       }
+
        /**
         * @brief Checks if the contact is blocked
         *
index 325debe7bc97d65f84d2e7e4d7cdd7ba4898ecfe..d578ba4545264085a265dd6ac3f574d721547707 100644 (file)
@@ -223,7 +223,7 @@ class Diaspora
                                `fcontact`.`batch` AS `fbatch`, `fcontact`.`network` AS `fnetwork` FROM `participation`
                                INNER JOIN `contact` ON `contact`.`id` = `participation`.`cid`
                                INNER JOIN `fcontact` ON `fcontact`.`id` = `participation`.`fid`
-                               WHERE `participation`.`iid` = ?", $thread);
+                               WHERE `participation`.`iid` = ? AND NOT `contact`.`archive`", $thread);
 
                while ($contact = DBA::fetch($r)) {
                        if (!empty($contact['fnetwork'])) {
index 7733d3f575364407af538302beb90275f0a42ded..eb86f910dd9dcb03eca57b66c2a21ae7a7cf234d 100644 (file)
@@ -33,7 +33,7 @@ class Delivery extends BaseObject
 
        public static function execute($cmd, $target_id, $contact_id)
        {
-               Logger::log('Invoked: ' . $cmd . ': ' . $target_id . ' to ' . $contact_id, Logger::DEBUG);
+               Logger::info('Invoked', ['cmd' => $cmd, 'target' => $target_id, 'contact' => $contact_id]);
 
                $top_level = false;
                $followup = false;
@@ -96,6 +96,14 @@ class Delivery extends BaseObject
                                return;
                        }
 
+                       if (!empty($contact_id) && Model\Contact::isArchived($contact_id)) {
+                               Logger::info('Contact is archived', ['id' => $contact_id, 'cmd' => $cmd, 'item' => $target_item['id']]);
+                               if (in_array($cmd, [Delivery::POST, Delivery::POKE])) {
+                                       Model\ItemDeliveryData::incrementQueueFailed($target_item['id']);
+                               }
+                               return;
+                       }
+
                        // avoid race condition with deleting entries
                        if ($items[0]['deleted']) {
                                foreach ($items as $item) {
index 4efd3e912622fd4e590afc0ebca29ee8af54af4d..20023792d51925ca550b1b3685a7f49f284ab535 100644 (file)
@@ -429,6 +429,11 @@ class Notifier
 
                        if (DBA::isResult($r)) {
                                foreach ($r as $rr) {
+                                       if (!empty($rr['id']) && Contact::isArchived($rr['id'])) {
+                                               Logger::info('Contact is archived', $rr);
+                                               continue;
+                                       }
+
                                        if (self::isRemovalActivity($cmd, $owner, $rr['network'])) {
                                                Logger::log('Skipping dropping for ' . $rr['url'] . ' since the network supports account removal commands.', Logger::DEBUG);
                                                continue;
@@ -463,6 +468,11 @@ class Notifier
 
                // delivery loop
                while ($contact = DBA::fetch($delivery_contacts_stmt)) {
+                       if (!empty($contact['id']) && Contact::isArchived($contact['id'])) {
+                               Logger::info('Contact is archived', $contact);
+                               continue;
+                       }
+
                        if (self::isRemovalActivity($cmd, $owner, $contact['network'])) {
                                Logger::log('Skipping dropping for ' . $contact['url'] . ' since the network supports account removal commands.', Logger::DEBUG);
                                continue;