diff options
author | Joas Schilling <coding@schilljs.com> | 2022-02-26 02:20:48 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2022-03-08 14:11:06 +0300 |
commit | dcc6291e0948140ff232b1b3c8b864ec6fec75e8 (patch) | |
tree | 7a5442feffbcabfde018ced2223d5ea089f29b65 /lib | |
parent | 4348f61fdea704916273822f9603532e2ba56abe (diff) |
Combine last_activity and last_message update where possible
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AppInfo/Application.php | 19 | ||||
-rw-r--r-- | lib/Chat/ChatManager.php | 2 | ||||
-rw-r--r-- | lib/Room.php | 2 | ||||
-rw-r--r-- | lib/Service/ParticipantService.php | 1 |
4 files changed, 4 insertions, 20 deletions
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index a91636635..3cffc1723 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -42,7 +42,6 @@ use OCA\Talk\Dashboard\TalkWidget; use OCA\Talk\Deck\DeckPluginLoader; use OCA\Talk\Events\AttendeesAddedEvent; use OCA\Talk\Events\AttendeesRemovedEvent; -use OCA\Talk\Events\ChatEvent; use OCA\Talk\Events\RoomEvent; use OCA\Talk\Federation\CloudFederationProviderTalk; use OCA\Talk\Files\Listener as FilesListener; @@ -82,7 +81,6 @@ use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\AppFramework\IAppContainer; -use OCP\AppFramework\Utility\ITimeFactory; use OCP\Collaboration\Resources\IProviderManager; use OCP\EventDispatcher\IEventDispatcher; use OCP\Federation\ICloudFederationProvider; @@ -172,7 +170,6 @@ class Application extends App implements IBootstrap { ShareListener::register($dispatcher); StatusListener::register($dispatcher); - $this->registerRoomActivityHooks($dispatcher); $this->registerChatHooks($dispatcher); $context->injectFn(\Closure::fromCallable([$this, 'registerCloudFederationProviderManager'])); } @@ -215,22 +212,6 @@ class Application extends App implements IBootstrap { }); } - protected function registerRoomActivityHooks(IEventDispatcher $dispatcher): void { - $listener = function (ChatEvent $event): void { - if ($event->shouldSkipLastActivityUpdate()) { - return; - } - - $room = $event->getRoom(); - /** @var ITimeFactory $timeFactory */ - $timeFactory = $this->getContainer()->query(ITimeFactory::class); - $room->setLastActivity($timeFactory->getDateTime()); - }; - - $dispatcher->addListener(ChatManager::EVENT_AFTER_MESSAGE_SEND, $listener); - $dispatcher->addListener(ChatManager::EVENT_AFTER_SYSTEM_MESSAGE_SEND, $listener); - } - protected function registerChatHooks(IEventDispatcher $dispatcher): void { $listener = function (RoomEvent $event): void { /** @var ChatManager $chatManager */ diff --git a/lib/Chat/ChatManager.php b/lib/Chat/ChatManager.php index c50cf7005..a2d5416f7 100644 --- a/lib/Chat/ChatManager.php +++ b/lib/Chat/ChatManager.php @@ -253,6 +253,8 @@ class ChatManager { if ($comment->getActorType() !== 'bots' || $comment->getActorId() === 'changelog') { $chat->setLastMessage($comment); $this->unreadCountCache->clear($chat->getId() . '-'); + } else { + $chat->setLastActivity($comment->getCreationDateTime()); } $alreadyNotifiedUsers = []; diff --git a/lib/Room.php b/lib/Room.php index d8520258d..f9cdc1c19 100644 --- a/lib/Room.php +++ b/lib/Room.php @@ -829,11 +829,13 @@ class Room { $update = $this->db->getQueryBuilder(); $update->update('talk_rooms') ->set('last_message', $update->createNamedParameter((int) $message->getId())) + ->set('last_activity', $update->createNamedParameter($message->getCreationDateTime(), 'datetime')) ->where($update->expr()->eq('id', $update->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT))); $update->executeStatement(); $this->lastMessage = $message; $this->lastMessageId = (int) $message->getId(); + $this->lastActivity = $message->getCreationDateTime(); } public function resetActiveSince(): bool { diff --git a/lib/Service/ParticipantService.php b/lib/Service/ParticipantService.php index c02a4910a..3e3cd8d74 100644 --- a/lib/Service/ParticipantService.php +++ b/lib/Service/ParticipantService.php @@ -441,7 +441,6 @@ class ParticipantService { protected function updateRoomLastMessage(Room $room, IComment $message): void { $room->setLastMessage($message); - $room->setLastActivity($message->getCreationDateTime()); $lastMessageCache = $this->cacheFactory->createDistributed('talk/lastmsgid'); $lastMessageCache->remove($room->getToken()); $unreadCountCache = $this->cacheFactory->createDistributed('talk/unreadcount'); |