Skip to content

Commit

Permalink
fix(frontend): Make frontend compatible with absence of lastMessage
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Nov 28, 2024
1 parent d8acd47 commit bbcf97d
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ export default {
type: 0,
displayName: '',
isFavorite: false,
lastMessage: {},
notificationLevel: PARTICIPANT.NOTIFY.DEFAULT,
notificationCalls: PARTICIPANT.NOTIFY_CALLS.ON,
canDeleteConversation: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export default {
displayName: '',
isFavorite: false,
notificationLevel: 0,
lastMessage: {},
}
},
},
Expand Down
5 changes: 0 additions & 5 deletions src/components/LeftSidebar/LeftSidebar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,36 +225,31 @@ describe('LeftSidebar.vue', () => {
isFavorite: false,
name: 'one',
displayName: 'the searched one by display name',
lastMessage: {},
}, {
id: 200,
token: 't200',
lastActivity: 80,
isFavorite: false,
name: 'searched by name',
displayName: 'another one',
lastMessage: {},
}, {
id: 300,
token: 't300',
lastActivity: 120,
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 = [{
Expand Down
2 changes: 1 addition & 1 deletion src/composables/useConversationInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})

/**
Expand Down
4 changes: 2 additions & 2 deletions src/store/conversationsStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions src/store/messagesStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/utils/getMessageIcon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bbcf97d

Please sign in to comment.