diff --git a/lib/Dashboard/TalkWidget.php b/lib/Dashboard/TalkWidget.php index ccf366e1ffc..aaa318f77bd 100644 --- a/lib/Dashboard/TalkWidget.php +++ b/lib/Dashboard/TalkWidget.php @@ -26,6 +26,7 @@ namespace OCA\Talk\Dashboard; use OCA\Talk\Chat\MessageParser; +use OCA\Talk\Chat\ChatManager; use OCA\Talk\Config; use OCA\Talk\Manager; use OCA\Talk\Model\BreakoutRoom; @@ -60,6 +61,7 @@ public function __construct( protected AvatarService $avatarService, protected ParticipantService $participantService, protected MessageParser $messageParser, + protected ChatManager $chatManager, protected ITimeFactory $timeFactory, ) { } @@ -175,8 +177,15 @@ protected function prepareRoom(Room $room, string $userId): WidgetItem { $subtitle = ''; $lastMessage = $room->getLastMessage(); + + $lastMentionDirect = $participant->getAttendee()->getLastMentionDirect(); + $lastReadMessage = $participant->getAttendee()->getLastReadMessage(); + if ($lastMentionDirect > $lastReadMessage) { + $lastMessage = $this->chatManager->getComment($room, (string)$lastMentionDirect); + } + if ($lastMessage instanceof IComment) { - $message = $this->messageParser->createMessage($room, $participant, $room->getLastMessage(), $this->l10n); + $message = $this->messageParser->createMessage($room, $participant, $lastMessage, $this->l10n); $this->messageParser->parseMessage($message); $now = $this->timeFactory->getDateTime(); @@ -200,8 +209,6 @@ protected function prepareRoom(Room $room, string $userId): WidgetItem { if ($room->getCallFlag() !== Participant::FLAG_DISCONNECTED) { $subtitle = $this->l10n->t('Call in progress'); - } elseif ($participant->getAttendee()->getLastMentionMessage() > $participant->getAttendee()->getLastReadMessage()) { - $subtitle = $this->l10n->t('You were mentioned'); } return new WidgetItem( diff --git a/lib/Service/RoomFormatter.php b/lib/Service/RoomFormatter.php index 90a1c20b16e..1f0fc74e33c 100644 --- a/lib/Service/RoomFormatter.php +++ b/lib/Service/RoomFormatter.php @@ -157,6 +157,7 @@ public function formatRoomV4( 'breakoutRoomMode' => BreakoutRoom::MODE_NOT_CONFIGURED, 'breakoutRoomStatus' => BreakoutRoom::STATUS_STOPPED, 'recordingConsent' => $this->talkConfig->recordingConsentRequired() === RecordingService::CONSENT_REQUIRED_OPTIONAL ? $room->getRecordingConsent() : $this->talkConfig->recordingConsentRequired(), + 'lastUnreadMentionMessage' => '', ]; $lastActivity = $room->getLastActivity(); @@ -319,6 +320,16 @@ public function formatRoomV4( $lastMentionDirect = $attendee->getLastMentionDirect(); $roomData['unreadMention'] = $lastMention !== 0 && $lastReadMessage < $lastMention; $roomData['unreadMentionDirect'] = $lastMentionDirect !== 0 && $lastReadMessage < $lastMentionDirect; + + $lastMentionMessage = $lastMentionDirect ? $this->chatManager->getComment($room, (string)$lastMentionDirect): ''; + if ($lastMentionMessage instanceof IComment) { + $roomData['lastUnreadMentionMessage'] = $this->formatDirectMentionMessage( + $responseFormat, + $room, + $currentParticipant, + $lastMentionMessage, + )['message']; + } $roomData['lastReadMessage'] = $lastReadMessage; $roomData['canDeleteConversation'] = $room->getType() !== Room::TYPE_ONE_TO_ONE @@ -340,6 +351,17 @@ public function formatRoomV4( $roomData['unreadMessages'] = $this->chatManager->getUnreadCount($room, $lastReadMessage); $roomData['unreadMention'] = $lastMention !== 0 && $lastReadMessage < $lastMention; $roomData['unreadMentionDirect'] = $lastMentionDirect !== 0 && $lastReadMessage < $lastMentionDirect; + + $lastMentionMessage = $lastMentionDirect ? $this->chatManager->getComment($room, (string)$lastMentionDirect): ''; + if ($lastMentionMessage instanceof IComment) { + $roomData['lastUnreadMentionMessage'] = $this->formatDirectMentionMessage( + $responseFormat, + $room, + $currentParticipant, + $lastMentionMessage, + )['message']; + } + } else { $roomData['lastReadMessage'] = $attendee->getLastReadMessage(); } @@ -431,4 +453,40 @@ public function formatLastMessage( return $message->toArray($responseFormat); } + + public function formatDirectMentionMessage( + string $responseFormat, + Room $room, + Participant $participant, + IComment $lastMessage, + ) { + $message = $this->messageParser->createMessage($room, $participant, $lastMessage, $this->l10n); + $this->messageParser->parseMessage($message); + + if (!$message->getVisibility()) { + return []; + } + + $now = $this->timeFactory->getDateTime(); + $expireDate = $message->getComment()->getExpireDate(); + if ((!$expireDate instanceof \DateTime || $expireDate >= $now) + && $message->getVisibility()) { + $transformedMessage = []; + $placeholders = $replacements = []; + + foreach ($message->getMessageParameters() as $placeholder => $parameter) { + $placeholders[] = '{' . $placeholder . '}'; + if ($parameter['type'] === 'user' || $parameter['type'] === 'guest') { + $replacements[] = '@' . $parameter['name']; + } else { + $replacements[] = $parameter['name']; + } + } + + $transformedMessage['message'] = str_replace($placeholders, $replacements, $message->getMessage()); + return $transformedMessage; + } + + return $message->toArray($responseFormat); + } } diff --git a/src/views/Dashboard.vue b/src/views/Dashboard.vue index 05a7a8c2698..888ad73172d 100644 --- a/src/views/Dashboard.vue +++ b/src/views/Dashboard.vue @@ -148,8 +148,8 @@ export default { return t('spreed', 'Call in progress') } - if (conversation.unreadMention) { - return t('spreed', 'You were mentioned') + if (conversation.unreadMentionDirect) { + return conversation.lastUnreadMentionMessage } return this.simpleLastChatMessage(conversation.lastMessage) @@ -188,7 +188,7 @@ export default { const rooms = allRooms.filter((conversation) => conversation.objectType !== CONVERSATION.OBJECT_TYPE.BREAKOUT_ROOM) const importantRooms = rooms.filter((conversation) => { return conversation.hasCall - || conversation.unreadMention + || conversation.unreadMentionDirect || (conversation.unreadMessages > 0 && (conversation.type === CONVERSATION.TYPE.ONE_TO_ONE || conversation.type === CONVERSATION.TYPE.ONE_TO_ONE_FORMER)) })