Skip to content

Commit c08c7aa

Browse files
committed
fix(conversations): this fixes the behavior described in #11882: system messages like user added or removed, moderator promoted or demoted trigger an activity bump of the conversation in the list and move it to the top. This fix keeps activity bumps for real chat messages but won't bump the activity anymore for the aforementioned system messages. This fix also incorporates use of the new lastMetadataActivity field to update this information instead of lastActivity accordingly and can be expanded later on to handle other kind of messages differently. No changes client side are needed.
Signed-off-by: Christian Lorang <madcatcl2@gmx.de>
1 parent 739857c commit c08c7aa

3 files changed

Lines changed: 47 additions & 4 deletions

File tree

lib/Migration/Version24000Date20260510193300.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,30 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
4242
$table->addColumn('last_metadata_activity', Types::DATETIME, [
4343
'notnull' => false,
4444
]);
45+
<<<<<<< HEAD
46+
<<<<<<< HEAD
4547
$table->addIndex(['last_metadata_activity'], 'talkroom_lastmetadataactive');
4648

4749
}
4850

4951
$table = $schema->getTable('talk_threads');
5052

53+
if (!$table->hasColumn('last_metadata_activity')) {
54+
$table->addColumn('last_metadata_activity', Types::DATETIME, [
55+
'notnull' => false,
56+
]);
57+
$table->addIndex(['last_metadata_activity'], 'talkthread_lastmetadataactive');
58+
=======
59+
$table->addIndex(['last_metadata_activity'], 'talkthread_lastmetadataactive');
60+
=======
61+
$table->addIndex(['last_metadata_activity'], 'talkroom_lastmetadataactive');
62+
>>>>>>> a798ce9366 (change(conversations): change behavior in all necessary places for Rooms and Threads to use / set lastMetadataActivity instaed of lastActivity where appropriate, i.e. where system messages are signalled and not real chat messages.)
63+
64+
>>>>>>> 2ed52550f0 (feature(api): Add a new field and corresponding functionality for lastMetadaActivity for Rooms and Threads, similar to lastActivity. This also adds a database migration for the oc_talk_rooms and oc_talk_threads tables as well. Functions are introduced and prepared for later use. The use of the field lastActivity to signal when the last real message in a conversation appeared remains unchanged to keep the API stable. The intended use of this feature is to better distinguish between real messages (lastActivity) to notify and bump conversations in the thread list to the top, and other status / metadata related messages (lastMetadataActivity) like room state and participant list changes that shall get synced and be updated in the clients, but not trigger an activity bump of its conversations in the thread list.)
65+
}
66+
67+
$table = $schema->getTable('talk_threads');
68+
5169
if (!$table->hasColumn('last_metadata_activity')) {
5270
$table->addColumn('last_metadata_activity', Types::DATETIME, [
5371
'notnull' => false,
@@ -65,6 +83,10 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
6583
*/
6684
#[Override]
6785
public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) : void {
86+
<<<<<<< HEAD
87+
<<<<<<< HEAD
88+
=======
89+
>>>>>>> a798ce9366 (change(conversations): change behavior in all necessary places for Rooms and Threads to use / set lastMetadataActivity instaed of lastActivity where appropriate, i.e. where system messages are signalled and not real chat messages.)
6890
$update = $this->connection->getQueryBuilder();
6991
$update->update('talk_rooms')
7092
->set('last_metadata_activity', 'last_activity');
@@ -73,6 +95,15 @@ public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array
7395
$update->update('talk_threads')
7496
->set('last_metadata_activity', 'last_activity');
7597
$update->executeStatement();
98+
<<<<<<< HEAD
99+
=======
100+
$update = $this->connection->getQueryBuilder();
101+
$update->update('talk_rooms')
102+
->set('last_metadata_activity', 'last_activity');
103+
$update->executeStatement();
104+
>>>>>>> 2ed52550f0 (feature(api): Add a new field and corresponding functionality for lastMetadaActivity for Rooms and Threads, similar to lastActivity. This also adds a database migration for the oc_talk_rooms and oc_talk_threads tables as well. Functions are introduced and prepared for later use. The use of the field lastActivity to signal when the last real message in a conversation appeared remains unchanged to keep the API stable. The intended use of this feature is to better distinguish between real messages (lastActivity) to notify and bump conversations in the thread list to the top, and other status / metadata related messages (lastMetadataActivity) like room state and participant list changes that shall get synced and be updated in the clients, but not trigger an activity bump of its conversations in the thread list.)
105+
=======
106+
>>>>>>> a798ce9366 (change(conversations): change behavior in all necessary places for Rooms and Threads to use / set lastMetadataActivity instaed of lastActivity where appropriate, i.e. where system messages are signalled and not real chat messages.)
76107
}
77108

78109
}

lib/Service/ParticipantService.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -738,24 +738,33 @@ public function addUsers(Room $room, array $participants, ?IUser $addedBy = null
738738
$this->dispatcher->dispatchTyped($event);
739739

740740
$lastMessage = $event->getLastMessage();
741-
if ($lastMessage instanceof IComment) {
741+
// TODO: is there any better getter / way to access message type?
742+
$lastMessageType = json_decode($lastMessage->getMessage(), true)['message'] ?? '';
743+
if ($lastMessage instanceof IComment || !in_array($lastMessageType, ['user_added', 'user_removed', 'moderator_promoted', 'moderator_demoted'], true)) {
744+
// do not update the room message to the status message, so the conversion / thread will not be bumped by activity to the top
745+
// left to do is to update the last message in the preview in the room list, without bumping it up.
746+
} elseif ($lastMessage instanceof IComment) {
742747
$this->updateRoomLastMessage($room, $lastMessage);
743748
}
749+
$now = $this->timeFactory->getDateTime();
750+
$room->setLastMetadataActivity($now);
744751

745752
return $attendees;
746753
}
747754

748755
protected function updateRoomLastMessage(Room $room, IComment $message): void {
749756
/** @var RoomService $roomService */
750757
$roomService = Server::get(RoomService::class);
751-
$roomService->setLastMessage($room, $message);
758+
$roomService->setLastMessageInfo($room, (int)$message->getId(), $message->getCreationDateTime());
759+
$now = $this->timeFactory->getDateTime();
760+
$room->setLastMetadataActivity($now);
752761

753762
$lastMessageCache = $this->cacheFactory->createDistributed(CachePrefix::CHAT_LAST_MESSAGE_ID);
754763
$lastMessageCache->remove($room->getToken());
755764
$unreadCountCache = $this->cacheFactory->createDistributed(CachePrefix::CHAT_UNREAD_COUNT);
756765
$unreadCountCache->clear($room->getId() . '-');
757766

758-
$event = new SystemMessagesMultipleSentEvent($room, $message);
767+
$event = new SystemMessagesMultipleSentEvent($room, $message, skipLastActivityUpdate: true);
759768
$this->dispatcher->dispatchTyped($event);
760769
}
761770

@@ -1255,6 +1264,9 @@ public function removeUser(Room $room, IUser $user, string $reason): void {
12551264
return;
12561265
}
12571266

1267+
$now = $this->timeFactory->getDateTime();
1268+
$room->setLastMetadataActivity($now);
1269+
12581270
$attendee = $participant->getAttendee();
12591271
$sessions = $this->sessionService->getAllSessionsForAttendee($attendee);
12601272

lib/Signaling/Listener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ protected function notifySystemMessageSent(ASystemMessageSentEvent $event): void
557557
$messageType = $messageDecoded['message'] ?? '';
558558

559559
if ($event->shouldSkipLastActivityUpdate() === true
560-
&& !in_array($messageType, ['message_deleted', 'message_edited', 'thread_created', 'thread_renamed'], true)
560+
&& !in_array($messageType, ['message_deleted', 'message_edited', 'thread_created', 'thread_renamed', 'user_added', 'user_removed', 'moderator_promoted', 'moderator_demoted'], true)
561561
) {
562562
return;
563563
}

0 commit comments

Comments
 (0)