Skip to content

Commit 82fa481

Browse files
authored
Merge pull request #348 from GetStream/fix-own-reactions-disappear
fix: Message update event handler doesn't respect order change and deletion
2 parents 23d54be + 9451bef commit 82fa481

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

projects/stream-chat-angular/src/lib/channel.service.spec.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,8 @@ describe('ChannelService', () => {
436436
spy.calls.reset();
437437
let activeChannel!: Channel<DefaultStreamChatGenerics>;
438438
service.activeChannel$.subscribe((c) => (activeChannel = c!));
439-
const message = {
440-
...activeChannel.state.messages[activeChannel.state.messages.length - 1],
441-
};
439+
const message =
440+
activeChannel.state.messages[activeChannel.state.messages.length - 1];
442441
message.deleted_at = new Date().toISOString();
443442
(activeChannel as MockChannel).handleEvent('message.deleted', { message });
444443

projects/stream-chat-angular/src/lib/channel.service.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -997,14 +997,21 @@ export class ChannelService<
997997
private messageUpdated(event: Event<T>) {
998998
this.ngZone.run(() => {
999999
const isThreadReply = event.message && event.message.parent_id;
1000-
const messages = isThreadReply
1001-
? this.activeThreadMessagesSubject.getValue()
1002-
: this.activeChannelMessagesSubject.getValue();
1000+
const channel = this.activeChannelSubject.getValue();
1001+
if (!channel) {
1002+
return;
1003+
}
1004+
// Get messages from state as message order could change, and message could've been deleted
1005+
const messages: FormatMessageResponse<T>[] = isThreadReply
1006+
? channel.state.threads[event?.message?.parent_id || '']
1007+
: channel.state.messages;
1008+
if (!messages) {
1009+
return;
1010+
}
10031011
const messageIndex = messages.findIndex(
1004-
(m) => m.id === event.message?.id
1012+
(m) => m.id === event?.message?.id
10051013
);
1006-
if (messageIndex !== -1 && event.message) {
1007-
messages[messageIndex] = event.message;
1014+
if (messageIndex !== -1) {
10081015
isThreadReply
10091016
? this.activeThreadMessagesSubject.next([...messages])
10101017
: this.activeChannelMessagesSubject.next([...messages]);

0 commit comments

Comments
 (0)