Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Combine last_activity and last_message update where possible
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Feb 26, 2022
commit 3925520f0da25350d3bf90e15f0ebda583f33540
19 changes: 0 additions & 19 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
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;
Expand Down Expand Up @@ -82,7 +81,6 @@
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;
Expand Down Expand Up @@ -172,7 +170,6 @@ public function boot(IBootContext $context): void {
ShareListener::register($dispatcher);
StatusListener::register($dispatcher);

$this->registerRoomActivityHooks($dispatcher);
$this->registerChatHooks($dispatcher);
$context->injectFn(\Closure::fromCallable([$this, 'registerCloudFederationProviderManager']));
}
Expand Down Expand Up @@ -215,22 +212,6 @@ protected function registerNavigationLink(IServerContainer $server): void {
});
}

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 */
Expand Down
2 changes: 2 additions & 0 deletions lib/Chat/ChatManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ public function sendMessage(Room $chat, Participant $participant, string $actorT
if ($comment->getActorType() !== 'bots' || $comment->getActorId() === 'changelog') {
$chat->setLastMessage($comment);
$this->unreadCountCache->clear($chat->getId() . '-');
} else {
$chat->setLastActivity($comment->getCreationDateTime());
}

$alreadyNotifiedUsers = [];
Expand Down
3 changes: 2 additions & 1 deletion lib/Room.php
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,6 @@ public function setPassword(string $password): bool {
* @return bool
*/
public function setLastActivity(\DateTime $now): bool {
// FIXME combine with setLastMessage and delay in case of multiple system messages
$update = $this->db->getQueryBuilder();
$update->update('talk_rooms')
->set('last_activity', $update->createNamedParameter($now, 'datetime'))
Expand Down Expand Up @@ -830,11 +829,13 @@ public function setLastMessage(IComment $message): void {
$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 {
Expand Down
1 change: 0 additions & 1 deletion lib/Service/ParticipantService.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,6 @@ public function addUsers(Room $room, array $participants, ?IUser $addedBy = null

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');
Expand Down