From bbcf97de468ef48594ab55771df2778a6465871e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 28 Nov 2024 13:43:38 +0100 Subject: [PATCH] fix(frontend): Make frontend compatible with absence of lastMessage Signed-off-by: Joas Schilling --- .../LeftSidebar/ConversationsList/Conversation.spec.js | 2 +- .../LeftSidebar/ConversationsList/Conversation.vue | 1 - .../ConversationsList/ConversationSearchResult.vue | 1 - src/components/LeftSidebar/LeftSidebar.spec.js | 5 ----- src/composables/useConversationInfo.js | 2 +- src/store/conversationsStore.js | 4 ++-- src/store/messagesStore.js | 8 ++++---- src/utils/getMessageIcon.ts | 4 ++-- 8 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/components/LeftSidebar/ConversationsList/Conversation.spec.js b/src/components/LeftSidebar/ConversationsList/Conversation.spec.js index 4ba6b58c529..ce09fa78a88 100644 --- a/src/components/LeftSidebar/ConversationsList/Conversation.spec.js +++ b/src/components/LeftSidebar/ConversationsList/Conversation.spec.js @@ -137,7 +137,7 @@ describe('Conversation.vue', () => { }) test('displays nothing when there is no last chat message', () => { - item.lastMessage = {} + delete item.lastMessage testConversationLabel(item, 'No messages') }) diff --git a/src/components/LeftSidebar/ConversationsList/Conversation.vue b/src/components/LeftSidebar/ConversationsList/Conversation.vue index 67b1a95a5d0..2c5ecb2f3d9 100644 --- a/src/components/LeftSidebar/ConversationsList/Conversation.vue +++ b/src/components/LeftSidebar/ConversationsList/Conversation.vue @@ -284,7 +284,6 @@ export default { type: 0, displayName: '', isFavorite: false, - lastMessage: {}, notificationLevel: PARTICIPANT.NOTIFY.DEFAULT, notificationCalls: PARTICIPANT.NOTIFY_CALLS.ON, canDeleteConversation: false, diff --git a/src/components/LeftSidebar/ConversationsList/ConversationSearchResult.vue b/src/components/LeftSidebar/ConversationsList/ConversationSearchResult.vue index 788c6c70286..41aee3fd9d3 100644 --- a/src/components/LeftSidebar/ConversationsList/ConversationSearchResult.vue +++ b/src/components/LeftSidebar/ConversationsList/ConversationSearchResult.vue @@ -54,7 +54,6 @@ export default { displayName: '', isFavorite: false, notificationLevel: 0, - lastMessage: {}, } }, }, diff --git a/src/components/LeftSidebar/LeftSidebar.spec.js b/src/components/LeftSidebar/LeftSidebar.spec.js index 4f28d1b59ca..4c5dfacf264 100644 --- a/src/components/LeftSidebar/LeftSidebar.spec.js +++ b/src/components/LeftSidebar/LeftSidebar.spec.js @@ -225,7 +225,6 @@ describe('LeftSidebar.vue', () => { isFavorite: false, name: 'one', displayName: 'the searched one by display name', - lastMessage: {}, }, { id: 200, token: 't200', @@ -233,7 +232,6 @@ describe('LeftSidebar.vue', () => { isFavorite: false, name: 'searched by name', displayName: 'another one', - lastMessage: {}, }, { id: 300, token: 't300', @@ -241,20 +239,17 @@ describe('LeftSidebar.vue', () => { isFavorite: true, name: 'excluded', displayName: 'excluded from results', - lastMessage: {}, }] listedResults = [{ id: 1000, name: 'listed one searched', displayName: 'listed one searched', - lastMessage: {}, token: 'listed-token-1', }, { id: 1001, name: 'listed two searched', displayName: 'listed two searched', - lastMessage: {}, token: 'listed-token-2', }] usersResults = [{ diff --git a/src/composables/useConversationInfo.js b/src/composables/useConversationInfo.js index 8e6404e8363..f94280ce429 100644 --- a/src/composables/useConversationInfo.js +++ b/src/composables/useConversationInfo.js @@ -43,7 +43,7 @@ export function useConversationInfo({ }) const hasLastMessage = computed(() => { - return !!Object.keys(Object(item.value?.lastMessage)).length + return !!item.value?.lastMessage && !!Object.keys(Object(item.value?.lastMessage)).length }) /** diff --git a/src/store/conversationsStore.js b/src/store/conversationsStore.js index 2a16c8465d5..78a014f2e56 100644 --- a/src/store/conversationsStore.js +++ b/src/store/conversationsStore.js @@ -760,8 +760,8 @@ const actions = { } const conversation = Object.assign({}, getters.conversations[token]) - if (conversation.lastMessage.id === parseInt(messageId, 10) - || conversation.lastMessage.timestamp >= Date.parse(notification.datetime) / 1000) { + if (conversation.lastMessage?.id === parseInt(messageId, 10) + || conversation.lastMessage?.timestamp >= Date.parse(notification.datetime) / 1000) { // Already updated from other source, skipping return } diff --git a/src/store/messagesStore.js b/src/store/messagesStore.js index 9eb625a6276..cab1ff5b18b 100644 --- a/src/store/messagesStore.js +++ b/src/store/messagesStore.js @@ -552,7 +552,7 @@ const actions = { if (message.systemMessage === 'message_edited' || message.systemMessage === 'message_deleted') { // update conversation lastMessage, if it was edited or deleted - if (message.parent.id === context.getters.conversation(token).lastMessage.id) { + if (message.parent.id === context.getters.conversation(token).lastMessage?.id) { context.dispatch('updateConversationLastMessage', { token, lastMessage: message.parent }) } // Check existing messages for having a deleted / edited message as parent, and update them @@ -1118,7 +1118,7 @@ const actions = { // Overwrite the conversation.hasCall property so people can join // after seeing the message in the chat. - if (conversation && conversation.lastMessage && message.id > conversation.lastMessage.id) { + if (conversation?.lastMessage && message.id > conversation.lastMessage.id) { if (['call_started', 'call_ended', 'call_ended_everyone', 'call_missed'].includes(message.systemMessage)) { context.dispatch('overwriteHasCallByChat', { token, @@ -1150,7 +1150,7 @@ const actions = { id: parseInt(response.headers['x-chat-last-given'], 10), }) - if (conversation && conversation.lastMessage && lastMessage.id > conversation.lastMessage.id) { + if (conversation?.lastMessage && lastMessage.id > conversation.lastMessage.id) { context.dispatch('updateConversationLastMessage', { token, lastMessage, @@ -1237,7 +1237,7 @@ const actions = { // update lastMessage and lastReadMessage // do it conditionally because there could have been more messages appearing concurrently - if (conversation && conversation.lastMessage && message.id > conversation.lastMessage.id) { + if (conversation?.lastMessage && message.id > conversation.lastMessage.id) { context.dispatch('updateConversationLastMessage', { token, lastMessage: message, diff --git a/src/utils/getMessageIcon.ts b/src/utils/getMessageIcon.ts index dcee379afb0..80112093388 100644 --- a/src/utils/getMessageIcon.ts +++ b/src/utils/getMessageIcon.ts @@ -22,10 +22,10 @@ const iconSvgTemplate = (path: string) => { } export const getMessageIcon = (lastMessage: Conversation['lastMessage']): string => { - if (Array.isArray(lastMessage)) { + if (!lastMessage || Array.isArray(lastMessage)) { return '' } - const file = lastMessage?.messageParameters?.file + const file = lastMessage.messageParameters?.file if (file) { if (file.mimetype?.startsWith('video')) { return iconSvgTemplate(mdiMovie) // Media - Videos