diff --git a/src/script/entity/Conversation.test.ts b/src/script/entity/Conversation.test.ts index 1071d42fbe3..109038cc92f 100644 --- a/src/script/entity/Conversation.test.ts +++ b/src/script/entity/Conversation.test.ts @@ -729,14 +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(1); - expect(conversation_et.messages()).toEqual([incomingMessage]); - expect(conversation_et.unreadState().allEvents.length).toBe(1); + // 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', () => { diff --git a/src/script/entity/Conversation.ts b/src/script/entity/Conversation.ts index 63ff9b9c41a..2b918c5359e 100644 --- a/src/script/entity/Conversation.ts +++ b/src/script/entity/Conversation.ts @@ -612,9 +612,9 @@ export class Conversation { * If there are any incoming messages, they will be moved to the regular messages. */ release(): void { - this.messages_unordered.removeAll(); - + // 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); }