Skip to content

Commit

Permalink
fix: unread message clearing on convo change (#17380)
Browse files Browse the repository at this point in the history
* fix: unread message clearing on convo change

* chore: failing test

* runfix: remove incoming messages after moving them to unordered messages

* test: move incoming messages to regular messages after releasing conversation

* docs: add a comment to release conversaiton

---------

Co-authored-by: PatrykBuniX <patrykbunix@gmail.com>
  • Loading branch information
tlebon and PatrykBuniX committed May 13, 2024
1 parent 88e2b22 commit 3d4a120
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/script/entity/Conversation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/script/entity/Conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 3d4a120

Please sign in to comment.