Skip to content

Commit

Permalink
fix: readBy not sent when editing a message
Browse files Browse the repository at this point in the history
  • Loading branch information
szuperaz committed Nov 5, 2024
1 parent 9874b6d commit 6e097cc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 6 additions & 1 deletion projects/stream-chat-angular/src/lib/channel.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 9 additions & 2 deletions projects/stream-chat-angular/src/lib/channel.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -891,10 +891,17 @@ export class ChannelService<
* @param message Mesage to be updated
*/
async updateMessage(message: StreamMessage<T>) {
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<StreamMessage<T>, 'readBy'>).readBy;
}
if (message.moderation_details) {
return this.resendMessage(message);
Expand Down

0 comments on commit 6e097cc

Please sign in to comment.