From 6e097cc354cdc60f4563549acf5feb7d6710594c Mon Sep 17 00:00:00 2001 From: Zita Szupera Date: Tue, 5 Nov 2024 17:37:59 +0100 Subject: [PATCH] fix: readBy not sent when editing a message --- .../src/lib/channel.service.spec.ts | 7 ++++++- .../stream-chat-angular/src/lib/channel.service.ts | 11 +++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/projects/stream-chat-angular/src/lib/channel.service.spec.ts b/projects/stream-chat-angular/src/lib/channel.service.spec.ts index 33a1ff3b..88063b30 100644 --- a/projects/stream-chat-angular/src/lib/channel.service.spec.ts +++ b/projects/stream-chat-angular/src/lib/channel.service.spec.ts @@ -1365,6 +1365,8 @@ describe('ChannelService', () => { it('should update message', () => { const message = mockMessage(); + // @ts-expect-error we exclude this + delete message.readBy; void service.updateMessage(message); expect(mockChatClient.updateMessage).toHaveBeenCalledWith(message); @@ -1408,11 +1410,14 @@ describe('ChannelService', () => { ); }); - it('should remove translation object before updating message', () => { + it('should remove translation object and readyBy before updating message', () => { const message = mockMessage(); + // @ts-expect-error we exclude this + delete message.readBy; void service.updateMessage({ ...message, i18n: { en_text: 'Translation', language: 'en' }, + readBy: [], }); expect(mockChatClient.updateMessage).toHaveBeenCalledWith(message); diff --git a/projects/stream-chat-angular/src/lib/channel.service.ts b/projects/stream-chat-angular/src/lib/channel.service.ts index ae5dc59c..a6e7b895 100644 --- a/projects/stream-chat-angular/src/lib/channel.service.ts +++ b/projects/stream-chat-angular/src/lib/channel.service.ts @@ -891,10 +891,17 @@ export class ChannelService< * @param message Mesage to be updated */ async updateMessage(message: StreamMessage) { - let messageToUpdate = { ...message }; + let messageToUpdate = { + ...message, + }; delete messageToUpdate.i18n; if (this.beforeUpdateMessage) { - messageToUpdate = await this.beforeUpdateMessage(messageToUpdate); + messageToUpdate = await this.beforeUpdateMessage( + messageToUpdate as StreamMessage + ); + } + if (messageToUpdate.readBy) { + delete (messageToUpdate as Omit, 'readBy'>).readBy; } if (message.moderation_details) { return this.resendMessage(message);