Skip to content

Commit

Permalink
fix(messages): minor render enhancements
Browse files Browse the repository at this point in the history
- assign `viewId` on Options API initialising: chatIdentifier is no longer updated at `mounted()` - no cancelled requests
- add a safe check for system messages without parents
  - doesn't happen usually, but for federated conversations system conversations `getContext` response is processed as if there are no message parents - system message is rendered in the list

Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
  • Loading branch information
Antreesy committed Mar 6, 2024
1 parent 0064a95 commit cbc649d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
3 changes: 1 addition & 2 deletions src/components/MessagesList/MessagesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export default {
*/
messagesGroupedByDateByAuthor: {},

viewId: null,
viewId: uniqueId('messagesList'),

/**
* When scrolling to the top of the div .scroller we start loading previous
Expand Down Expand Up @@ -316,7 +316,6 @@ export default {
this.debounceUpdateReadMarkerPosition = debounce(this.updateReadMarkerPosition, 1000)
this.debounceHandleScroll = debounce(this.handleScroll, 50)

this.viewId = uniqueId('messagesList')
this.scrollToBottom()
EventBus.$on('scroll-chat-to-bottom', this.handleScrollChatToBottomEvent)
EventBus.$on('smooth-scroll-chat-to-bottom', this.smoothScrollToBottom)
Expand Down
18 changes: 9 additions & 9 deletions src/store/messagesStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,12 +529,15 @@ const actions = {
processMessage(context, { token, message }) {
const sharedItemsStore = useSharedItemsStore()

if (message.parent && message.systemMessage
&& (message.systemMessage === 'message_deleted'
if (message.systemMessage === 'message_deleted'
|| message.systemMessage === 'reaction'
|| message.systemMessage === 'reaction_deleted'
|| message.systemMessage === 'reaction_revoked'
|| message.systemMessage === 'message_edited')) {
|| message.systemMessage === 'message_edited') {
if (!message.parent) {
return
}

// If parent message is presented in store and is different, we update it
const parentInStore = context.getters.message(token, message.parent.id)
if (Object.keys(parentInStore).length !== 0 && JSON.stringify(parentInStore) !== JSON.stringify(message.parent)) {
Expand All @@ -544,17 +547,14 @@ const actions = {
const reactionsStore = useReactionsStore()
if (message.systemMessage === 'message_deleted') {
reactionsStore.resetReactions(token, message.parent.id)
} else {
reactionsStore.processReaction(token, message)
}

// Check existing messages for having a deleted message as parent, and update them
if (message.systemMessage === 'message_deleted') {
// Check existing messages for having a deleted message as parent, and update them
context.getters.messagesList(token)
.filter(storedMessage => storedMessage.parent?.id === message.parent.id && JSON.stringify(storedMessage.parent) !== JSON.stringify(message.parent))
.forEach(storedMessage => {
context.commit('addMessage', { token, message: Object.assign({}, storedMessage, { parent: message.parent }) })
})
} else {
reactionsStore.processReaction(token, message)
}

// Quit processing
Expand Down

0 comments on commit cbc649d

Please sign in to comment.