diff --git a/src/components/MessagesList/MessagesGroup/Message/Message.vue b/src/components/MessagesList/MessagesGroup/Message/Message.vue index 4da5892f01a..5db073c0695 100644 --- a/src/components/MessagesList/MessagesGroup/Message/Message.vue +++ b/src/components/MessagesList/MessagesGroup/Message/Message.vue @@ -303,8 +303,6 @@ export default { } }, - expose: ['highlightMessage'], - data() { return { isHovered: false, @@ -450,6 +448,14 @@ export default { }, }, + mounted() { + EventBus.$on('highlight-message', this.highlightMessage) + }, + + beforeDestroy() { + EventBus.$off('highlight-message', this.highlightMessage) + }, + methods: { lastReadMessageVisibilityChanged(isVisible) { if (isVisible) { @@ -457,8 +463,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 46d23ac6100..f46b4af0361 100644 --- a/src/components/MessagesList/MessagesGroup/MessagesSystemGroup.vue +++ b/src/components/MessagesList/MessagesGroup/MessagesSystemGroup.vue @@ -89,8 +89,6 @@ export default { }, }, - expose: ['highlightMessage'], - setup() { const { createCombinedSystemMessage } = useCombinedSystemMessage() @@ -235,15 +233,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 d6d8c92f2b2..027d1a08e28 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) => {