diff --git a/src/components/MessagesList/MessagesList.vue b/src/components/MessagesList/MessagesList.vue index 2797002c4b7..1ca0603af13 100644 --- a/src/components/MessagesList/MessagesList.vue +++ b/src/components/MessagesList/MessagesList.vue @@ -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' @@ -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 diff --git a/src/constants.js b/src/constants.js index 384bb111fd8..70bc1e9db4e 100644 --- a/src/constants.js +++ b/src/constants.js @@ -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, diff --git a/src/store/messagesStore.js b/src/store/messagesStore.js index 885d7627edf..9eb625a6276 100644 --- a/src/store/messagesStore.js +++ b/src/store/messagesStore.js @@ -12,6 +12,7 @@ import { ATTENDEE, CHAT, CONVERSATION, + MESSAGE, } from '../constants.js' import { hasTalkFeature } from '../services/CapabilitiesManager.ts' import { fetchNoteToSelfConversation } from '../services/conversationsService.js' @@ -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' @@ -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,