Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable30] fix: reduce amount of EventBus listeners on messages #13747

Merged
merged 2 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions src/components/MessagesList/MessagesGroup/Message/Message.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
:data-next-message-id="nextMessageId"
:data-previous-message-id="previousMessageId"
class="message"
:class="{'message--highlighted': isHighlighted, 'message--hovered': showMessageButtonsBar}"
:class="{'message--hovered': showMessageButtonsBar}"
tabindex="0"
@animationend="isHighlighted = false"
@animationend="clearHighlightedClass"
@mouseover="handleMouseover"
@mouseleave="handleMouseleave">
<div :class="{'normal-message-body': !isSystemMessage && !isDeletedMessage,
Expand Down Expand Up @@ -191,7 +191,6 @@ export default {
return {
isHovered: false,
isDeleting: false,
isHighlighted: false,
// whether the message was seen, only used if this was marked as last read message
seen: false,
isActionMenuOpen: false,
Expand Down Expand Up @@ -344,14 +343,6 @@ export default {
},
},

mounted() {
EventBus.on('highlight-message', this.highlightMessage)
},

beforeDestroy() {
EventBus.off('highlight-message', this.highlightMessage)
},

methods: {
t,
lastReadMessageVisibilityChanged([{ isIntersecting }]) {
Expand All @@ -360,10 +351,8 @@ export default {
}
},

highlightMessage(messageId) {
if (this.message.id === messageId) {
this.isHighlighted = true
}
clearHighlightedClass() {
this.$refs.message.classList.remove('message--highlighted')
},

handleMouseover() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,21 @@ export default {
},

mounted() {
EventBus.on('editing-message-processing', this.setIsEditing)
if (this.isEditable) {
EventBus.on('editing-message-processing', this.setIsEditing)
}

if (!this.containsCodeBlocks) {
return
}

this.codeBlocks = Array.from(this.$refs.messageMain?.querySelectorAll('pre'))
},

beforeDestroy() {
EventBus.off('editing-message-processing', this.setIsEditing)
},

methods: {
t,
handleMarkdownMouseOver(event) {
Expand Down
14 changes: 8 additions & 6 deletions src/components/MessagesList/MessagesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ export default {
* @return {boolean} true if element was found, false otherwise
*/
focusMessage(messageId, smooth = true, highlightAnimation = true) {
let element = document.getElementById(`message_${messageId}`)
const element = document.getElementById(`message_${messageId}`)
if (!element) {
// Message id doesn't exist
// TODO: in some cases might need to trigger a scroll up if this is an older message
Expand All @@ -1145,17 +1145,18 @@ export default {
return false // element not found
}

if (this.isChatVisible && element.offsetParent === null) {
let scrollElement = element
if (this.isChatVisible && scrollElement.offsetParent === null) {
console.debug('Message to focus is hidden, scrolling to its nearest visible parent', messageId)
element = element.closest('ul[style="display: none;"]').parentElement
scrollElement = scrollElement.closest('ul[style="display: none;"]').parentElement
}

console.debug('Scrolling to a focused message programmatically')
this.isFocusingMessage = true

// TODO: doesn't work if chat is hidden. Need to store
// delayed 'shouldScroll' and call after chat is visible
element.scrollIntoView({
scrollElement.scrollIntoView({
behavior: smooth ? 'smooth' : 'auto',
block: 'center',
inline: 'nearest',
Expand All @@ -1171,8 +1172,9 @@ export default {
this.setChatScrolledToBottom(true)
}

if (highlightAnimation) {
EventBus.emit('highlight-message', messageId)
if (highlightAnimation && scrollElement === element) {
// element is visible, highlight it
element.classList.add('message--highlighted')
}
this.isFocusingMessage = false

Expand Down
Loading