diff options
author | Joas Schilling <coding@schilljs.com> | 2022-09-23 16:13:42 +0300 |
---|---|---|
committer | backportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com> | 2022-09-29 19:27:59 +0300 |
commit | fa5b7f0c8455dabe59f6a6260cb2bbf00f5ede2f (patch) | |
tree | b933e72a1d817716c040e52de137efb390bb2d9a /lib | |
parent | 1e4d03225516f9e241fe90668a56d15d80238268 (diff) |
Invalidate cache on relevant changes
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AppInfo/Application.php | 2 | ||||
-rw-r--r-- | lib/Chat/ChatManager.php | 11 | ||||
-rw-r--r-- | lib/Collaboration/Reference/ReferenceInvalidationListener.php | 52 | ||||
-rw-r--r-- | lib/Collaboration/Reference/TalkReferenceProvider.php | 9 |
4 files changed, 68 insertions, 6 deletions
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 965abbf85..d50322263 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace OCA\Talk\AppInfo; +use OCA\Talk\Collaboration\Reference\ReferenceInvalidationListener; use OCA\Talk\Collaboration\Reference\TalkReferenceProvider; use OCP\Util; use OCA\Circles\Events\AddingCircleMemberEvent; @@ -175,6 +176,7 @@ class Application extends App implements IBootstrap { CommandListener::register($dispatcher); CollaboratorsListener::register($dispatcher); ResourceListener::register($dispatcher); + ReferenceInvalidationListener::register($dispatcher); // Register only when Talk Updates are not disabled if ($server->getConfig()->getAppValue('spreed', 'changelog', 'yes') === 'yes') { ChangelogListener::register($dispatcher); diff --git a/lib/Chat/ChatManager.php b/lib/Chat/ChatManager.php index d26cbeb40..e62e44b62 100644 --- a/lib/Chat/ChatManager.php +++ b/lib/Chat/ChatManager.php @@ -38,6 +38,7 @@ use OCA\Talk\Service\ParticipantService; use OCA\Talk\Service\PollService; use OCA\Talk\Share\RoomShareProvider; use OCP\AppFramework\Utility\ITimeFactory; +use OCP\Collaboration\Reference\IReferenceManager; use OCP\Comments\IComment; use OCP\Comments\ICommentsManager; use OCP\Comments\NotFoundException; @@ -86,7 +87,6 @@ class ChatManager { private IDBConnection $connection; private INotificationManager $notificationManager; private IManager $shareManager; - private Manager $manager; private RoomShareProvider $shareProvider; private ParticipantService $participantService; private PollService $pollService; @@ -95,26 +95,26 @@ class ChatManager { protected ICache $cache; protected ICache $unreadCountCache; protected AttachmentService $attachmentService; + protected IReferenceManager $referenceManager; public function __construct(CommentsManager $commentsManager, IEventDispatcher $dispatcher, IDBConnection $connection, INotificationManager $notificationManager, IManager $shareManager, - Manager $manager, RoomShareProvider $shareProvider, ParticipantService $participantService, PollService $pollService, Notifier $notifier, ICacheFactory $cacheFactory, ITimeFactory $timeFactory, - AttachmentService $attachmentService) { + AttachmentService $attachmentService, + IReferenceManager $referenceManager) { $this->commentsManager = $commentsManager; $this->dispatcher = $dispatcher; $this->connection = $connection; $this->notificationManager = $notificationManager; $this->shareManager = $shareManager; - $this->manager = $manager; $this->shareProvider = $shareProvider; $this->participantService = $participantService; $this->pollService = $pollService; @@ -123,6 +123,7 @@ class ChatManager { $this->unreadCountCache = $cacheFactory->createDistributed('talk/unreadcount'); $this->timeFactory = $timeFactory; $this->attachmentService = $attachmentService; + $this->referenceManager = $referenceManager; } /** @@ -378,6 +379,8 @@ class ChatManager { $this->attachmentService->deleteAttachmentByMessageId((int) $comment->getId()); + $this->referenceManager->invalidateCache($chat->getToken()); + return $this->addSystemMessage( $chat, $participant->getAttendee()->getActorType(), diff --git a/lib/Collaboration/Reference/ReferenceInvalidationListener.php b/lib/Collaboration/Reference/ReferenceInvalidationListener.php new file mode 100644 index 000000000..2db37c824 --- /dev/null +++ b/lib/Collaboration/Reference/ReferenceInvalidationListener.php @@ -0,0 +1,52 @@ +<?php + +declare(strict_types=1); +/** + * @copyright Copyright (c) 2022 Joas Schilling <coding@schilljs.com> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCA\Talk\Collaboration\Reference; + +use OCA\Talk\Events\RoomEvent; +use OCA\Talk\Room; +use OCP\Collaboration\Reference\IReferenceManager; +use OCP\EventDispatcher\IEventDispatcher; +use OCP\Server; + +class ReferenceInvalidationListener { + public static function register(IEventDispatcher $dispatcher): void { + $listener = static function (RoomEvent $event): void { + $room = $event->getRoom(); + $referenceManager = Server::get(IReferenceManager::class); + + $referenceManager->invalidateCache($room->getToken()); + }; + + $dispatcher->addListener(Room::EVENT_AFTER_ROOM_DELETE, $listener); + $dispatcher->addListener(Room::EVENT_AFTER_USERS_ADD, $listener); + $dispatcher->addListener(Room::EVENT_AFTER_USER_REMOVE, $listener); + $dispatcher->addListener(Room::EVENT_AFTER_DESCRIPTION_SET, $listener); + $dispatcher->addListener(Room::EVENT_AFTER_LISTABLE_SET, $listener); + $dispatcher->addListener(Room::EVENT_AFTER_LOBBY_STATE_SET, $listener); + $dispatcher->addListener(Room::EVENT_AFTER_NAME_SET, $listener); + $dispatcher->addListener(Room::EVENT_AFTER_PARTICIPANT_REMOVE, $listener); + $dispatcher->addListener(Room::EVENT_AFTER_PASSWORD_SET, $listener); + $dispatcher->addListener(Room::EVENT_AFTER_SET_MESSAGE_EXPIRATION, $listener); + } +} diff --git a/lib/Collaboration/Reference/TalkReferenceProvider.php b/lib/Collaboration/Reference/TalkReferenceProvider.php index 821366780..e3aa1d2e2 100644 --- a/lib/Collaboration/Reference/TalkReferenceProvider.php +++ b/lib/Collaboration/Reference/TalkReferenceProvider.php @@ -234,14 +234,19 @@ class TalkReferenceProvider implements IReferenceProvider { return ''; } - return $referenceMatch['token'] . '#' . ($referenceMatch['message'] ?? 0); + return $referenceMatch['token']; } /** * @inheritDoc */ public function getCacheKey(string $referenceId): ?string { - return $this->userId ?? ''; + $referenceMatch = $this->getTalkAppLinkToken($referenceId); + if ($referenceMatch === null) { + return ''; + } + + return ($this->userId ?? '') . '#' . ($referenceMatch['message'] ?? 0); } protected function getRoomIconUrl(Room $room, string $userId): string { |