diff options
author | Maksim Sukharev <antreesy.web@gmail.com> | 2024-03-01 18:20:26 +0100 |
---|---|---|
committer | Maksim Sukharev <antreesy.web@gmail.com> | 2024-03-01 23:30:55 +0100 |
commit | 2ba818493fd4d10fa291a275cf7523e70799c0ed (patch) | |
tree | 0eb1008beab0016a03d234cd883832105057cd5b | |
parent | 784442eabb8131abd3396bdae56d9d1c17c81e6d (diff) |
fix(MessagesList): update group also when fetching old messages
Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
-rw-r--r-- | src/components/MessagesList/MessagesList.vue | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/components/MessagesList/MessagesList.vue b/src/components/MessagesList/MessagesList.vue index 887e3e709..245c8b0a6 100644 --- a/src/components/MessagesList/MessagesList.vue +++ b/src/components/MessagesList/MessagesList.vue @@ -414,24 +414,32 @@ export default { return groupsByDate }, - softUpdateByDateGroups(oldGroups, newGroups) { - const oldGroupsMap = new Map(Object.entries(oldGroups)) + softUpdateByDateGroups(oldDateGroups, newDateGroups) { // Check if we have this group in the old list already and it is unchanged - Object.keys(newGroups).forEach(dateTimestamp => { - if (oldGroupsMap.has(dateTimestamp)) { + Object.keys(newDateGroups).forEach(dateTimestamp => { + if (oldDateGroups[dateTimestamp]) { // the group by date has changed, we update its content (groups by author) - this.softUpdateAuthorGroups(oldGroupsMap.get(dateTimestamp), newGroups[dateTimestamp], dateTimestamp) + this.softUpdateAuthorGroups(oldDateGroups[dateTimestamp], newDateGroups[dateTimestamp], dateTimestamp) } else { // the group is new - this.messagesGroupedByDateByAuthor[dateTimestamp] = newGroups[dateTimestamp] + this.messagesGroupedByDateByAuthor[dateTimestamp] = newDateGroups[dateTimestamp] } }) }, softUpdateAuthorGroups(oldGroups, newGroups, dateTimestamp) { - const oldGroupsMap = new Map(Object.entries(oldGroups)) + const oldKeys = Object.keys(oldGroups) Object.entries(newGroups).forEach(([id, newGroup]) => { - if (!oldGroupsMap.has(id) || (oldGroupsMap.has(id) && !this.areGroupsIdentical(newGroup, oldGroupsMap.get(id)))) { + if (!oldGroups[id]) { + const oldId = oldKeys.find(key => id < key && oldGroups[key].nextMessageId <= newGroup.nextMessageId) + if (oldId) { + // newGroup includes oldGroup and more old messages, remove oldGroup + delete this.messagesGroupedByDateByAuthor[dateTimestamp][oldId] + } + // newGroup is not presented in the list, add it + this.messagesGroupedByDateByAuthor[dateTimestamp][id] = newGroup + } else if (!this.areGroupsIdentical(newGroup, oldGroups[id])) { + // newGroup includes oldGroup and more recent messages this.messagesGroupedByDateByAuthor[dateTimestamp][id] = newGroup } }) |