From 593294c45428a4fc77193d90cd4bfe4e2d184628 Mon Sep 17 00:00:00 2001 From: Timothy Le Bon Date: Wed, 8 May 2024 16:49:08 +0200 Subject: [PATCH 1/5] fix: unread message clearing on convo change --- src/script/entity/Conversation.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/script/entity/Conversation.ts b/src/script/entity/Conversation.ts index 63ff9b9c41a..6d5c11692bc 100644 --- a/src/script/entity/Conversation.ts +++ b/src/script/entity/Conversation.ts @@ -612,15 +612,13 @@ export class Conversation { * If there are any incoming messages, they will be moved to the regular messages. */ release(): void { - this.messages_unordered.removeAll(); - if (!this.unreadState().allEvents.length) { + this.removeMessages(); this.hasAdditionalMessages(true); } if (this.incomingMessages().length) { this.messages_unordered.push(...this.incomingMessages()); - this.incomingMessages.removeAll(); } } From ad42e8df681b8482d91b8d4fc2d2dc4b050a0e3a Mon Sep 17 00:00:00 2001 From: Timothy Le Bon Date: Wed, 8 May 2024 17:29:48 +0200 Subject: [PATCH 2/5] chore: failing test --- src/script/entity/Conversation.test.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/script/entity/Conversation.test.ts b/src/script/entity/Conversation.test.ts index 1071d42fbe3..1ea4170ac1d 100644 --- a/src/script/entity/Conversation.test.ts +++ b/src/script/entity/Conversation.test.ts @@ -734,9 +734,8 @@ describe('Conversation', () => { conversation_et.release(); - expect(conversation_et.messages().length).toBe(1); - expect(conversation_et.messages()).toEqual([incomingMessage]); - expect(conversation_et.unreadState().allEvents.length).toBe(1); + expect(conversation_et.messages().length).toBe(2); + expect(conversation_et.unreadState().allEvents.length).toBe(3); }); it('should release messages if conversation has no unread messages', () => { From 9ff0d6bfe5f0fe78596aec0f7f45f18076b42b07 Mon Sep 17 00:00:00 2001 From: PatrykBuniX Date: Thu, 9 May 2024 11:09:50 +0200 Subject: [PATCH 3/5] runfix: remove incoming messages after moving them to unordered messages --- src/script/entity/Conversation.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/script/entity/Conversation.ts b/src/script/entity/Conversation.ts index 6d5c11692bc..6dfe9ea6705 100644 --- a/src/script/entity/Conversation.ts +++ b/src/script/entity/Conversation.ts @@ -619,6 +619,7 @@ export class Conversation { if (this.incomingMessages().length) { this.messages_unordered.push(...this.incomingMessages()); + this.incomingMessages.removeAll(); } } From 711fdec5b34081c14b8be7930aa7712d710c668c Mon Sep 17 00:00:00 2001 From: PatrykBuniX Date: Thu, 9 May 2024 11:32:28 +0200 Subject: [PATCH 4/5] test: move incoming messages to regular messages after releasing conversation --- src/script/entity/Conversation.test.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/script/entity/Conversation.test.ts b/src/script/entity/Conversation.test.ts index 1ea4170ac1d..109038cc92f 100644 --- a/src/script/entity/Conversation.test.ts +++ b/src/script/entity/Conversation.test.ts @@ -729,13 +729,14 @@ describe('Conversation', () => { conversation_et.last_event_timestamp(third_timestamp); conversation_et.addMessage(incomingMessage); - expect(conversation_et.messages().length).toBe(1); + expect(conversation_et.messages()).toEqual([message_et]); expect(conversation_et.unreadState().allEvents.length).toBe(2); conversation_et.release(); - expect(conversation_et.messages().length).toBe(2); - expect(conversation_et.unreadState().allEvents.length).toBe(3); + // Incoming message should be moved to regular messages + expect(conversation_et.messages()).toEqual([message_et, incomingMessage]); + expect(conversation_et.unreadState().allEvents.length).toBe(2); }); it('should release messages if conversation has no unread messages', () => { From ea7eb8332c7ca9294afd1c4072b2e7bd45879d33 Mon Sep 17 00:00:00 2001 From: PatrykBuniX Date: Thu, 9 May 2024 11:36:46 +0200 Subject: [PATCH 5/5] docs: add a comment to release conversaiton --- src/script/entity/Conversation.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/script/entity/Conversation.ts b/src/script/entity/Conversation.ts index 6dfe9ea6705..2b918c5359e 100644 --- a/src/script/entity/Conversation.ts +++ b/src/script/entity/Conversation.ts @@ -612,6 +612,7 @@ export class Conversation { * If there are any incoming messages, they will be moved to the regular messages. */ release(): void { + // If there are no unread messages, we can remove all messages from memory (we will keep the unread messages) if (!this.unreadState().allEvents.length) { this.removeMessages(); this.hasAdditionalMessages(true);