-
Notifications
You must be signed in to change notification settings - Fork 434
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
Fix duplicating messages and improve performance #10058
Conversation
src/store/conversationsStore.js
Outdated
patchConversation(state, conversation) { | ||
patchObject(state.conversations[conversation.token], conversation) | ||
updateConversationIfHasActivity(state, conversation) { | ||
if (state.conversations[conversation.token].lastActivity < conversation.lastActivity) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we also need to do it when the unread counter changes, because reading a chat does not update the lastactivity
@nickvergessen do you think the change in the last commit is too much and should be replaced with just direct Or it is fine and better to have this large update "just in case" and checks? |
d8b77e4
to
60e9aef
Compare
@nickvergessen @Antreesy If this is fine for you, I'll add some tests and ready to merge |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing blocking from me.
Tested with replies, works properly now
@@ -209,7 +251,9 @@ const actions = { | |||
* @param {object} conversation the conversation; | |||
*/ | |||
addConversation(context, conversation) { | |||
context.dispatch('emitUserStatusUpdatedWhenChanged', conversation) | |||
if (conversation.type === CONVERSATION.TYPE.ONE_TO_ONE) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (conversation.type === CONVERSATION.TYPE.ONE_TO_ONE) { | |
if (conversation.status) { |
Group conversations don't have a status
field, so I'm not sure if we needed that additional check before and need that now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nickvergessen Do you remember if there was a reason to add this check here: #9411
Except readability
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be that the user has no status now, but had one before. Then the event should trigger and delete the status.
Can e.g. happen when they go invisible, or when the inactive status gets purged.
That being said, it doesn't make sense with the rest of the code, so I guess no.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But not sure it's legal to trigger the event with "undefined"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we never have this request without includeStatus
, I added emit for null status as emitting about status removal.
Updated user status update emitting. Added test for all these cases around conversations updating and user status update emitting. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🦭
Signed-off-by: Grigorii K. Shartsev <me@shgk.me>
Signed-off-by: Grigorii K. Shartsev <me@shgk.me>
03723ab
to
74320c9
Compare
Rebased onto master and squashed |
/backport to stable27 |
☑️ Resolves
Steps to reproduce:
LeftSidebar
will be updatedWhy it happens:
In the
messagesStore
we updateconversation.lastMessage
in the conversation store using a new received message in the chat. Here a reference is passed to theconversationsStore
's actionspreed/src/store/messagesStore.js
Lines 1065 to 1069 in d381c9c
In the
conversationsStore
then this reference is saved in the store:spreed/src/store/conversationsStore.js
Lines 151 to 153 in d381c9c
At this step
conversationsState.conversation[token].lastMessage
stores a reference to a message object frommessagesStore
Then we patch
conversationsState.conversation[token].lastMessage
after receiveing new conversation on re-fetching. This mutates the object in the messages store.spreed/src/store/conversationsStore.js
Lines 129 to 131 in d381c9c
Another problem:
There is also
conversation.lastMessage.messageParameters
array.patchObject
is not patching sub-arrays, so it caused almost unnecessary re-renders anyway.🖼️ Screenshots
Green highlight = re-rendering. After PR there are more re-renderings in changed conversation items, but no re-renderings in not changed items.
🚧 Tasks
lastActivity
lastActivity
is enough to know if there were any changes in the conversation👀 Alternatives
lastMessage
on update frommessagesStore
patchObject
to handle arrays (check length and elements)patchObject
to handle "special" cases and list custom setters for specific keys (lastMessage
)lastMessageId
instead oflastMessage
in the conversation, same aslastCommonReadMessage
🏁 Checklist
docs/
has been updated or is not required