Skip to content

Commit

Permalink
fix(MessagesList): fix fetching messages completion when there is no …
Browse files Browse the repository at this point in the history
…message.

Signed-off-by: DorraJaouad <dorra.jaoued7@gmail.com>
  • Loading branch information
DorraJaouad authored and backportbot[bot] committed Nov 22, 2024
1 parent 6fb9b03 commit 9257360
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/components/MessagesList/MessagesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ import TransitionWrapper from '../UIShared/TransitionWrapper.vue'

import { useDocumentVisibility } from '../../composables/useDocumentVisibility.ts'
import { useIsInCall } from '../../composables/useIsInCall.js'
import { ATTENDEE, CHAT, CONVERSATION } from '../../constants.js'
import { ATTENDEE, CHAT, CONVERSATION, MESSAGE } from '../../constants.js'
import { EventBus } from '../../services/EventBus.ts'
import { useChatExtrasStore } from '../../stores/chatExtras.js'
import { debugTimer } from '../../utils/debugTimer.ts'
Expand Down Expand Up @@ -670,9 +670,10 @@ export default {
}
this.$store.dispatch('setFirstKnownMessageId', { token, id: startingMessageId })
this.$store.dispatch('setLastKnownMessageId', { token, id: startingMessageId })

// If MESSAGE.CHAT_BEGIN_ID we need to get the context from the beginning
// using 0 as the API does not support negative values
// Get chat messages before last read message and after it
await this.getMessageContext(token, startingMessageId)
await this.getMessageContext(token, startingMessageId !== MESSAGE.CHAT_BEGIN_ID ? startingMessageId : 0)
} catch (exception) {
console.debug(exception)
// Request was cancelled, stop getting preconditions and restore initial state
Expand Down
5 changes: 5 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ export const ATTENDEE = {
CHANGELOG_BOT_ID: 'changelog',
}

export const MESSAGE = {
CHAT_BEGIN_ID: -2,
CHAT_MIGRATION_ID: -1,
}

export const PARTICIPANT = {
CALL_FLAG: {
DISCONNECTED: 0,
Expand Down
6 changes: 4 additions & 2 deletions src/store/messagesStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
ATTENDEE,
CHAT,
CONVERSATION,
MESSAGE,
} from '../constants.js'
import { hasTalkFeature } from '../services/CapabilitiesManager.ts'
import { fetchNoteToSelfConversation } from '../services/conversationsService.js'
Expand Down Expand Up @@ -967,7 +968,7 @@ const actions = {
}
context.dispatch('processMessage', { token, message })
newestKnownMessageId = Math.max(newestKnownMessageId, message.id)
oldestKnownMessageId = Math.min(oldestKnownMessageId, message.id)
oldestKnownMessageId = oldestKnownMessageId === 0 ? message.id : Math.min(oldestKnownMessageId, message.id)

if (message.id <= messageId
&& message.systemMessage !== 'reaction'
Expand All @@ -979,7 +980,8 @@ const actions = {
}
})

if (!context.getters.getFirstKnownMessageId(token) || oldestKnownMessageId < context.getters.getFirstKnownMessageId(token)) {
if (!context.getters.getFirstKnownMessageId(token) || oldestKnownMessageId < context.getters.getFirstKnownMessageId(token)
|| context.getters.getFirstKnownMessageId(token) === MESSAGE.CHAT_BEGIN_ID) {
context.dispatch('setFirstKnownMessageId', {
token,
id: oldestKnownMessageId,
Expand Down

0 comments on commit 9257360

Please sign in to comment.