diff --git a/src/components/MessagesList/MessagesGroup/Message/Message.vue b/src/components/MessagesList/MessagesGroup/Message/Message.vue index c8bbae118da..f69fc346726 100644 --- a/src/components/MessagesList/MessagesGroup/Message/Message.vue +++ b/src/components/MessagesList/MessagesGroup/Message/Message.vue @@ -314,8 +314,6 @@ export default { } }, - expose: ['highlightMessage'], - data() { return { isHovered: false, @@ -470,6 +468,14 @@ export default { }, }, + mounted() { + EventBus.$on('highlight-message', this.highlightMessage) + }, + + beforeDestroy() { + EventBus.$off('highlight-message', this.highlightMessage) + }, + methods: { lastReadMessageVisibilityChanged(isVisible) { if (isVisible) { @@ -477,8 +483,10 @@ export default { } }, - highlightMessage() { - this.isHighlighted = true + highlightMessage(messageId) { + if (this.id === messageId) { + this.isHighlighted = true + } }, handleMouseover() { diff --git a/src/components/MessagesList/MessagesGroup/MessagesGroup.vue b/src/components/MessagesList/MessagesGroup/MessagesGroup.vue index c899c02358d..53d68f60493 100644 --- a/src/components/MessagesList/MessagesGroup/MessagesGroup.vue +++ b/src/components/MessagesList/MessagesGroup/MessagesGroup.vue @@ -38,7 +38,6 @@ diff --git a/src/components/MessagesList/MessagesGroup/MessagesSystemGroup.vue b/src/components/MessagesList/MessagesGroup/MessagesSystemGroup.vue index 01dbd38b20a..ad424e560a3 100644 --- a/src/components/MessagesList/MessagesGroup/MessagesSystemGroup.vue +++ b/src/components/MessagesList/MessagesGroup/MessagesSystemGroup.vue @@ -92,8 +92,6 @@ export default { }, }, - expose: ['highlightMessage'], - setup() { const { createCombinedSystemMessage } = useCombinedSystemMessage() @@ -246,15 +244,6 @@ export default { const prevMessage = this.messages[this.messages.findIndex(searchedMessage => searchedMessage.id === message.id) - 1] return prevMessage?.id || this.previousMessageId }, - - highlightMessage(messageId) { - for (const message of this.$refs.message) { - if (message.id === messageId) { - message.highlightMessage() - break - } - } - }, }, } diff --git a/src/components/MessagesList/MessagesList.spec.js b/src/components/MessagesList/MessagesList.spec.js index ac5211064ae..b8f198a3565 100644 --- a/src/components/MessagesList/MessagesList.spec.js +++ b/src/components/MessagesList/MessagesList.spec.js @@ -141,9 +141,6 @@ describe('MessagesList.vue', () => { expect(group.props('nextMessageId')).toBe(0) expect(messagesListMock).toHaveBeenCalledWith(TOKEN) - - const placeholder = wrapper.findAllComponents({ name: 'LoadingPlaceholder' }) - expect(placeholder.exists()).toBe(false) }) test('displays a date separator between days', () => { @@ -254,7 +251,7 @@ describe('MessagesList.vue', () => { }, }) - const groups = wrapper.findAllComponents({ ref: 'messagesGroup' }) + const groups = wrapper.findAll('.messages-group') expect(groups.exists()).toBe(true) @@ -279,7 +276,7 @@ describe('MessagesList.vue', () => { }, }) - const groups = wrapper.findAllComponents({ ref: 'messagesGroup' }) + const groups = wrapper.findAll('.messages-group') expect(groups.exists()).toBeTruthy() diff --git a/src/components/MessagesList/MessagesList.vue b/src/components/MessagesList/MessagesList.vue index b81af52a6b3..bac4b007b4d 100644 --- a/src/components/MessagesList/MessagesList.vue +++ b/src/components/MessagesList/MessagesList.vue @@ -48,7 +48,6 @@ { - this.scrollToFocusedMessage() + this.scrollToFocusedMessage(focusMessageId) }) } } @@ -726,11 +710,11 @@ export default { // get new messages await this.lookForNewMessages() - if (this.loadChatInLegacyMode || focusMessageId === null) { + if (focusMessageId === null) { // don't scroll if lookForNewMessages was polling as we don't want // to scroll back to the read marker after receiving new messages later if (!hasScrolled) { - this.scrollToFocusedMessage() + this.scrollToFocusedMessage(focusMessageId) } } } else { @@ -905,16 +889,14 @@ export default { return } - if (!this.loadChatInLegacyMode) { - if (this.isInitialisingMessages) { - console.debug('Ignore handleScroll as we are initialising the message history') - return - } + if (this.isInitialisingMessages) { + console.debug('Ignore handleScroll as we are initialising the message history') + return + } - if (this.isFocusingMessage) { - console.debug('Ignore handleScroll as we are programmatically scrolling to focus a message') - return - } + if (this.isFocusingMessage) { + console.debug('Ignore handleScroll as we are programmatically scrolling to focus a message') + return } const { scrollHeight, scrollTop, clientHeight } = this.$refs.scroller @@ -1152,7 +1134,7 @@ export default { this.$nextTick(async () => { // FIXME: this doesn't wait for the smooth scroll to end - await element.scrollIntoView({ + element.scrollIntoView({ behavior: smooth ? 'smooth' : 'auto', block: 'center', inline: 'nearest', @@ -1162,12 +1144,7 @@ export default { this.$refs.scroller.scrollTop += this.$refs.scroller.offsetHeight / 4 } if (highlightAnimation) { - for (const group of this.$refs.messagesGroup) { - if (group.messages.some(message => message.id === messageId)) { - group.highlightMessage(messageId) - break - } - } + EventBus.$emit('highlight-message', messageId) } this.isFocusingMessage = false await this.handleScroll() @@ -1290,9 +1267,16 @@ export default { } .messages-list { - &__empty-content { - height: 100%; - } + &__placeholder { + display: flex; + flex-direction: column-reverse; + overflow: hidden; + height: 100%; + } + + &__empty-content { + height: 100%; + } } .messages-group { diff --git a/src/store/messagesStore.js b/src/store/messagesStore.js index b9d8b3895ee..906090771f5 100644 --- a/src/store/messagesStore.js +++ b/src/store/messagesStore.js @@ -224,16 +224,16 @@ const getters = { return null } - const displayableMessages = getters.messagesList(token).filter(message => { + return getters.messagesList(token).find(message => { return message.id >= readMessageId - && !('' + message.id).startsWith('temp-') - }) - - if (displayableMessages.length) { - return displayableMessages.shift().id - } - - return null + && !String(message.id).startsWith('temp-') + && message.systemMessage !== 'reaction' + && message.systemMessage !== 'reaction_deleted' + && message.systemMessage !== 'reaction_revoked' + && message.systemMessage !== 'poll_voted' + && message.systemMessage !== 'message_deleted' + && message.systemMessage !== 'message_edited' + })?.id }, getFirstDisplayableMessageIdBeforeReadMarker: (state, getters) => (token, readMessageId) => { @@ -241,16 +241,16 @@ const getters = { return null } - const displayableMessages = getters.messagesList(token).filter(message => { + return getters.messagesList(token).findLast(message => { return message.id < readMessageId - && !('' + message.id).startsWith('temp-') - }) - - if (displayableMessages.length) { - return displayableMessages.pop().id - } - - return null + && !String(message.id).startsWith('temp-') + && message.systemMessage !== 'reaction' + && message.systemMessage !== 'reaction_deleted' + && message.systemMessage !== 'reaction_revoked' + && message.systemMessage !== 'poll_voted' + && message.systemMessage !== 'message_deleted' + && message.systemMessage !== 'message_edited' + })?.id }, isSendingMessages: (state) => {