diff --git a/lib/BackgroundJob/SendScheduledMessages.php b/lib/BackgroundJob/SendScheduledMessages.php index 0e019537562..1af323f8f2b 100644 --- a/lib/BackgroundJob/SendScheduledMessages.php +++ b/lib/BackgroundJob/SendScheduledMessages.php @@ -158,7 +158,8 @@ protected function run($argument): void { $metaData = $message->getDecodedMetaData(); $threadId = $message->getThreadId(); $threadTitle = $metaData[ScheduledMessage::METADATA_THREAD_TITLE] ?? null; - $comment = $this->chatManager->sendMessage($room, + $comment = $this->chatManager->sendMessage( + $room, $participant, $message->getActorType(), $message->getActorId(), @@ -167,7 +168,9 @@ protected function run($argument): void { $parent, '', $metaData[ScheduledMessage::METADATA_SILENT] ?? false, - threadId: $threadId + threadId: $threadId, + threadTitle: $threadTitle, + fromScheduledMessage: true, ); $this->logger->debug('Sent scheduled message ' . $message->getId() . ' to room ' . $message->getRoomId() . ' for ' . $message->getActorType() . ' ' . $message->getActorId()); if ($threadId === Thread::THREAD_CREATE && $threadTitle !== '') { @@ -185,7 +188,7 @@ protected function run($argument): void { null, $comment, true, - true + true, ); $this->logger->debug('Created thread ' . $thread->getId() . ' in room ' . $message->getRoomId() . ' for scheduled message ' . $message->getId() . ' for ' . $message->getActorType() . ' ' . $message->getActorId()); } diff --git a/lib/Chat/ChatManager.php b/lib/Chat/ChatManager.php index 92780b7f812..f26bcbb66a3 100644 --- a/lib/Chat/ChatManager.php +++ b/lib/Chat/ChatManager.php @@ -392,6 +392,7 @@ public function sendMessage( bool $rateLimitGuestMentions = true, int $threadId = 0, string $threadTitle = '', + bool $fromScheduledMessage = false, ): IComment { if ($chat->isFederatedConversation()) { $e = new MessagingNotAllowedException(); @@ -466,7 +467,7 @@ public function sendMessage( } } - if ($participant instanceof Participant) { + if (!$fromScheduledMessage && $participant instanceof Participant) { $this->participantService->updateLastReadMessage($participant, $messageId); } diff --git a/tests/integration/features/chat-4/scheduled-messages.feature b/tests/integration/features/chat-4/scheduled-messages.feature index c295631ca71..0174476f484 100644 --- a/tests/integration/features/chat-4/scheduled-messages.feature +++ b/tests/integration/features/chat-4/scheduled-messages.feature @@ -7,9 +7,10 @@ Feature: chat-4/scheduling | roomName | room | And user "participant1" adds user "participant2" to room "room" with 200 (v4) And user "participant2" sends message "Message" to room "room" with 201 + Then user "participant1" reads message "Message" in room "room" with 200 Then user "participant1" is participant of the following rooms (v4) - | id | type | hasScheduledMessages | - | room | 2 |0 | + | id | type | hasScheduledMessages | unreadMessages | lastReadMessage | + | room | 2 | 0 | 0 | Message | Scenario: Schedule a message When user "participant1" schedules a message to room "room" with 201 @@ -19,14 +20,14 @@ Feature: chat-4/scheduling | id | actorType | actorId | threadId | parent | message | messageType | sendAt | silent | | Message 1 | users | participant1 | 0 | null | Message 1 | comment | {NOW} | false | And user "participant1" is participant of the following rooms (v4) - | id | type | hasScheduledMessages | - | room | 2 | 1 | + | id | type | hasScheduledMessages | unreadMessages | lastReadMessage | + | room | 2 | 1 | 0 | Message | When wait for 4 seconds And force run "OCA\Talk\BackgroundJob\SendScheduledMessages" background jobs Then user "participant1" sees the following scheduled messages in room "room" with 200 And user "participant1" is participant of the following rooms (v4) - | id | type | hasScheduledMessages | - | room | 2 | 0 | + | id | type | hasScheduledMessages | unreadMessages | lastReadMessage | + | room | 2 | 0 | 1 | Message | Then user "participant2" sees the following messages in room "room" with 200 | room | actorType | actorId | actorDisplayName | messageType | message | messageParameters | | room | users | participant1 | participant1-displayname | comment | Message 1 | [] |