Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Talk-Widget direct mentions #11929

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
17 changes: 17 additions & 0 deletions lib/Service/ParticipantService.php
Original file line number Diff line number Diff line change
Expand Up @@ -1947,4 +1947,21 @@
$this->cacheParticipant($room, $participant);
return $participant;
}

/**
* @param int $mentionId
* @return string
*/
public function getLastUnreadMentionMessage(int $mentionId)
nickvergessen marked this conversation as resolved.
Show resolved Hide resolved
{
$query = $this->connection->getQueryBuilder();
$query->select('c.message')
->from('comments', 'c')
->where('c.id = :mentionId')
->setParameter('mentionId', $mentionId)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this works in the doctrine query builder, we never use this pattern. You will always find code like the following when looking around:

Suggested change
->where('c.id = :mentionId')
->setParameter('mentionId', $mentionId)
->where($query->expr()->eq('c.id', $query->createNamedParameter($mentionId)))

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These statements are removed with the removal of the function getLastUnreadMentionMessage() in ParticipantService.php. Also noticed the common way of building queries in this project.

->setMaxResults(1);

$result = $query->executeQuery();
return $result->fetchOne();

Check failure on line 1965 in lib/Service/ParticipantService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

FalsableReturnStatement

lib/Service/ParticipantService.php:1965:10: FalsableReturnStatement: The declared return type 'string' for OCA\Talk\Service\ParticipantService::getLastUnreadMentionMessage does not allow false, but the function returns 'false|mixed' (see https://psalm.dev/137)
}
}
2 changes: 2 additions & 0 deletions lib/Service/RoomFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
'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();
Expand All @@ -177,7 +178,7 @@
|| ($isListingBreakoutRooms && !$currentParticipant instanceof Participant)
|| ($room->getListable() !== Room::LISTABLE_NONE && !$currentParticipant instanceof Participant)
) {
return array_merge($roomData, [

Check failure on line 181 in lib/Service/RoomFormatter.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

InvalidReturnStatement

lib/Service/RoomFormatter.php:181:11: InvalidReturnStatement: The inferred type 'array{actorId: '', actorType: '', attendeeId: 0, attendeePermissions: 1, attendeePin: '', avatarVersion: string, breakoutRoomMode: int, breakoutRoomStatus: int, callFlag: int, callPermissions: 1, callRecording: int, callStartTime: int, canDeleteConversation: false, canEnableSIP: false, canLeaveConversation: false, canStartCall: false, defaultPermissions: 1, description: '', displayName: string, hasCall: bool, hasPassword: bool, id: int, isCustomAvatar: bool, isFavorite: false, lastActivity: int, lastCommonReadMessage: 0, lastMessage: array<never, never>, lastPing: 0, lastReadMessage: 0, lastUnreadMentionMessage: '', listable: int, lobbyState: int, lobbyTimer: int, messageExpiration: 0, name: string, notificationCalls: 0, notificationLevel: 3, objectId: string, objectType: string, participantFlags: 0, participantType: 4, permissions: 1, readOnly: int, recordingConsent: 0|1|2, sessionId: '0', sipEnabled: int, token: string, type: -1|1|2|3|4|5|6, unreadMention: false, unreadMentionDirect: false, unreadMessages: 0}' does not match the declared return type 'array{actorId: string, actorType: string, attendeeId: int, attendeePermissions: int, attendeePin: null|string, avatarVersion: string, breakoutRoomMode: int, breakoutRoomStatus: int, callFlag: int, callPermissions: int, callRecording: int, callStartTime: int, canDeleteConversation: bool, canEnableSIP: bool, canLeaveConversation: bool, canStartCall: bool, defaultPermissions: int, description: string, displayName: string, hasCall: bool, hasPassword: bool, id: int, isCustomAvatar: bool, isFavorite: bool, lastActivity: int, lastCommonReadMessage: int, lastMessage: array{actorDisplayName?: string, actorId?: string, actorType?: string, deleted?: true, expirationTimestamp?: int, id?: int, isReplyable?: bool, lastEditActorDisplayName?: string, lastEditActorId?: string, lastEditActorType?: string, lastEditTimestamp?: int, markdown?: bool, message?: string, messageParameters?: array<string, array{'call-type'?: 'group'|'one2one'|'public', 'icon-url'?: string, 'message-id'?: string, 'preview-available'?: 'no'|'yes', assignable?: '0'|'1', boardname?: string, conversation?: string, description?: string, id: string, latitude?: string, link?: string, longitude?: string, mimetype?: string, mtime?: string, name: string, path?: string, server?: string, size?: string, stackname?: string, thumb?: string, type: string, visibility?: '0'|'1', website?: string}>, messageType?: string, reactions?: array<string, int>|stdClass, referenceId?: string, silent?: bool, systemMessage?: string, timestamp?: int, token?: string}, lastPing: int, lastReadMessage: int, listable: int, lobbyState: int, lobbyTimer: int, messageExpiration: int, name: string, notificationCalls: int, notificationLevel: int, objectId: string, objectType: string, participantFlags: int, participantType: int, permissions: int, readOnly: int, recordingConsent: int, sessionId: string, sipEnabled: int, status?: string, statusClearAt?: int|null, statusIcon?: null|string, statusMessage?: null|string, token: string, type: int, unreadMention: bool, unreadMentionDirect: bool, unreadMessages: int}' for OCA\Talk\Service\RoomFormatter::formatRoomV4 due to additional array shape fields (lastUnreadMentionMessage) (see https://psalm.dev/128)
'name' => $room->getName(),
'displayName' => $room->getDisplayName($isListingBreakoutRooms || $isSIPBridgeRequest || $this->userId === null ? '' : $this->userId, $isListingBreakoutRooms || $isSIPBridgeRequest),
'objectType' => $room->getObjectType(),
Expand All @@ -198,7 +199,7 @@
}

if (!$currentParticipant instanceof Participant) {
return $roomData;

Check failure on line 202 in lib/Service/RoomFormatter.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

InvalidReturnStatement

lib/Service/RoomFormatter.php:202:11: InvalidReturnStatement: The inferred type 'array{actorId: '', actorType: '', attendeeId: 0, attendeePermissions: 1, attendeePin: '', avatarVersion: string, breakoutRoomMode: 0, breakoutRoomStatus: 0, callFlag: 0, callPermissions: 1, callRecording: 0, callStartTime: 0, canDeleteConversation: false, canEnableSIP: false, canLeaveConversation: false, canStartCall: false, defaultPermissions: 1, description: '', displayName: '', hasCall: false, hasPassword: bool, id: int, isCustomAvatar: bool, isFavorite: false, lastActivity: 0, lastCommonReadMessage: 0, lastMessage: array<never, never>, lastPing: 0, lastReadMessage: 0, lastUnreadMentionMessage: '', listable: 0, lobbyState: 0, lobbyTimer: 0, messageExpiration: 0, name: '', notificationCalls: 0, notificationLevel: 3, objectId: '', objectType: '', participantFlags: 0, participantType: 4, permissions: 1, readOnly: 0, recordingConsent: 0|1|2, sessionId: '0', sipEnabled: 0, token: string, type: -1|1|2|3|4|5|6, unreadMention: false, unreadMentionDirect: false, unreadMessages: 0}' does not match the declared return type 'array{actorId: string, actorType: string, attendeeId: int, attendeePermissions: int, attendeePin: null|string, avatarVersion: string, breakoutRoomMode: int, breakoutRoomStatus: int, callFlag: int, callPermissions: int, callRecording: int, callStartTime: int, canDeleteConversation: bool, canEnableSIP: bool, canLeaveConversation: bool, canStartCall: bool, defaultPermissions: int, description: string, displayName: string, hasCall: bool, hasPassword: bool, id: int, isCustomAvatar: bool, isFavorite: bool, lastActivity: int, lastCommonReadMessage: int, lastMessage: array{actorDisplayName?: string, actorId?: string, actorType?: string, deleted?: true, expirationTimestamp?: int, id?: int, isReplyable?: bool, lastEditActorDisplayName?: string, lastEditActorId?: string, lastEditActorType?: string, lastEditTimestamp?: int, markdown?: bool, message?: string, messageParameters?: array<string, array{'call-type'?: 'group'|'one2one'|'public', 'icon-url'?: string, 'message-id'?: string, 'preview-available'?: 'no'|'yes', assignable?: '0'|'1', boardname?: string, conversation?: string, description?: string, id: string, latitude?: string, link?: string, longitude?: string, mimetype?: string, mtime?: string, name: string, path?: string, server?: string, size?: string, stackname?: string, thumb?: string, type: string, visibility?: '0'|'1', website?: string}>, messageType?: string, reactions?: array<string, int>|stdClass, referenceId?: string, silent?: bool, systemMessage?: string, timestamp?: int, token?: string}, lastPing: int, lastReadMessage: int, listable: int, lobbyState: int, lobbyTimer: int, messageExpiration: int, name: string, notificationCalls: int, notificationLevel: int, objectId: string, objectType: string, participantFlags: int, participantType: int, permissions: int, readOnly: int, recordingConsent: int, sessionId: string, sipEnabled: int, status?: string, statusClearAt?: int|null, statusIcon?: null|string, statusMessage?: null|string, token: string, type: int, unreadMention: bool, unreadMentionDirect: bool, unreadMessages: int}' for OCA\Talk\Service\RoomFormatter::formatRoomV4 due to additional array shape fields (lastUnreadMentionMessage) (see https://psalm.dev/128)
}

$attendee = $currentParticipant->getAttendee();
Expand Down Expand Up @@ -284,7 +285,7 @@
// No participants and chat messages for users in the lobby.
$roomData['hasCall'] = false;
$roomData['canLeaveConversation'] = true;
return $roomData;

Check failure on line 288 in lib/Service/RoomFormatter.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

InvalidReturnStatement

lib/Service/RoomFormatter.php:288:11: InvalidReturnStatement: The inferred type 'array{actorId: string, actorType: string, attendeeId: int, attendeePermissions: int, attendeePin: null|string, avatarVersion: string, breakoutRoomMode: int, breakoutRoomStatus: int, callFlag: int, callPermissions: int, callRecording: int, callStartTime: int, canDeleteConversation: false, canEnableSIP: false, canLeaveConversation: true, canStartCall: false, defaultPermissions: int, description: string, displayName: string, hasCall: false, hasPassword: bool, id: int, isCustomAvatar: bool, isFavorite: bool, lastActivity: int, lastCommonReadMessage: int, lastMessage: array<never, never>, lastPing: int, lastReadMessage: 0, lastUnreadMentionMessage: '', listable: int, lobbyState: int, lobbyTimer: int, messageExpiration: int, name: string, notificationCalls: int, notificationLevel: int, objectId: string, objectType: string, participantFlags: int, participantType: int, permissions: int, readOnly: int, recordingConsent: 0|1|2, sessionId: string, sipEnabled: int, token: string, type: -1|1|2|3|4|5|6, unreadMention: false, unreadMentionDirect: false, unreadMessages: 0}' does not match the declared return type 'array{actorId: string, actorType: string, attendeeId: int, attendeePermissions: int, attendeePin: null|string, avatarVersion: string, breakoutRoomMode: int, breakoutRoomStatus: int, callFlag: int, callPermissions: int, callRecording: int, callStartTime: int, canDeleteConversation: bool, canEnableSIP: bool, canLeaveConversation: bool, canStartCall: bool, defaultPermissions: int, description: string, displayName: string, hasCall: bool, hasPassword: bool, id: int, isCustomAvatar: bool, isFavorite: bool, lastActivity: int, lastCommonReadMessage: int, lastMessage: array{actorDisplayName?: string, actorId?: string, actorType?: string, deleted?: true, expirationTimestamp?: int, id?: int, isReplyable?: bool, lastEditActorDisplayName?: string, lastEditActorId?: string, lastEditActorType?: string, lastEditTimestamp?: int, markdown?: bool, message?: string, messageParameters?: array<string, array{'call-type'?: 'group'|'one2one'|'public', 'icon-url'?: string, 'message-id'?: string, 'preview-available'?: 'no'|'yes', assignable?: '0'|'1', boardname?: string, conversation?: string, description?: string, id: string, latitude?: string, link?: string, longitude?: string, mimetype?: string, mtime?: string, name: string, path?: string, server?: string, size?: string, stackname?: string, thumb?: string, type: string, visibility?: '0'|'1', website?: string}>, messageType?: string, reactions?: array<string, int>|stdClass, referenceId?: string, silent?: bool, systemMessage?: string, timestamp?: int, token?: string}, lastPing: int, lastReadMessage: int, listable: int, lobbyState: int, lobbyTimer: int, messageExpiration: int, name: string, notificationCalls: int, notificationLevel: int, objectId: string, objectType: string, participantFlags: int, participantType: int, permissions: int, readOnly: int, recordingConsent: int, sessionId: string, sipEnabled: int, status?: string, statusClearAt?: int|null, statusIcon?: null|string, statusMessage?: null|string, token: string, type: int, unreadMention: bool, unreadMentionDirect: bool, unreadMessages: int}' for OCA\Talk\Service\RoomFormatter::formatRoomV4 due to additional array shape fields (lastUnreadMentionMessage) (see https://psalm.dev/128)
}

$roomData['canStartCall'] = $currentParticipant->canStartCall($this->serverConfig);
Expand Down Expand Up @@ -319,6 +320,7 @@
$lastMentionDirect = $attendee->getLastMentionDirect();
$roomData['unreadMention'] = $lastMention !== 0 && $lastReadMessage < $lastMention;
$roomData['unreadMentionDirect'] = $lastMentionDirect !== 0 && $lastReadMessage < $lastMentionDirect;
$roomData['lastUnreadMentionMessage'] = ($lastMentionDirect !== 0 or $lastMentionDirect !== null) ? $this->participantService->getLastUnreadMentionMessage($lastMentionDirect) : '';
nickvergessen marked this conversation as resolved.
Show resolved Hide resolved
$roomData['lastReadMessage'] = $lastReadMessage;

$roomData['canDeleteConversation'] = $room->getType() !== Room::TYPE_ONE_TO_ONE
Expand Down
6 changes: 3 additions & 3 deletions src/views/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 t('spreed', conversation.lastUnreadMentionMessage)
}

return this.simpleLastChatMessage(conversation.lastMessage)
Expand Down Expand Up @@ -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))
})

Expand Down
Loading