Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: readBy not sent when editing a message #662

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading