]> git.mxchange.org Git - friendica.git/commitdiff
Remove related notifications when marking an item for deletion
authorHypolite Petovan <hypolite@mrpetovan.com>
Sun, 27 Nov 2022 02:48:26 +0000 (21:48 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Sun, 27 Nov 2022 02:48:26 +0000 (21:48 -0500)
src/Model/Item.php
src/Navigation/Notifications/Repository/Notification.php
src/Navigation/Notifications/Repository/Notify.php

index 0390730fd8c178d9744976924b0c210d1a127afe..cb998c0fdcb4feac35219a8acf10aa78868baa60 100644 (file)
@@ -385,6 +385,9 @@ class Item
                        Post\ThreadUser::update($item['uri-id'], $item['uid'], ['hidden' => true]);
                }
 
+               DI::notify()->deleteForItem($item['uri-id']);
+               DI::notification()->deleteForItem($item['uri-id']);
+
                Logger::info('Item has been marked for deletion.', ['id' => $item_id]);
 
                return true;
index a9630464aa576113a64d987a749f4386baf417e2..6a513c5dc2f3d2c59692c1fe264ee6b1f445b793 100644 (file)
@@ -33,6 +33,7 @@ use Friendica\Navigation\Notifications\Collection;
 use Friendica\Navigation\Notifications\Entity;
 use Friendica\Navigation\Notifications\Factory;
 use Friendica\Network\HTTPException\NotFoundException;
+use Friendica\Protocol\Activity;
 use Friendica\Util\DateTimeFormat;
 use Psr\Log\LoggerInterface;
 
@@ -268,4 +269,23 @@ class Notification extends BaseRepository
 
                return $this->db->delete(self::$table_name, $condition);
        }
+
+       public function deleteForItem(int $itemUriId): bool
+       {
+               $conditionTarget = [
+                       'vid' => Verb::getID(Activity::POST),
+                       'target-uri-id' => $itemUriId,
+               ];
+
+               $conditionParent = [
+                       'vid' => Verb::getID(Activity::POST),
+                       'parent-uri-id' => $itemUriId,
+               ];
+
+               $this->logger->notice('deleteForItem', ['conditionTarget' => $conditionTarget, 'conditionParent' => $conditionParent]);
+
+               return
+                       $this->db->delete(self::$table_name, $conditionTarget)
+                       && $this->db->delete(self::$table_name, $conditionParent);
+       }
 }
index 3891a6e256c3fc6775573d66539514582adbab37..75aff6b8708c5c7e85801c26ed4e4f9600fb4ccc 100644 (file)
@@ -807,4 +807,10 @@ class Notify extends BaseRepository
 
                return $this->storeAndSend($params, $sitelink, $tsitelink, $hsitelink, $title, $subject, $preamble, $epreamble, $item['body'], $itemlink, true);
        }
+
+       public function deleteForItem(int $itemUriId): void
+       {
+               $this->db->delete('notify', ['otype' => 'item', 'uri-id' => $itemUriId]);
+               $this->db->delete('notify', ['otype' => 'item', 'parent-uri-id' => $itemUriId]);
+       }
 }