Skip to content

Commit f1cb726

Browse files
authored
Merge pull request #475 from GetStream/thread-new-message
fix: misplaced messages in active thread
2 parents 8d18c9c + 7c32c74 commit f1cb726

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,28 @@ describe('ChannelService - threads', () => {
335335
expect(activeChannel.markRead).toHaveBeenCalledWith();
336336
});
337337

338+
it('should only add new message to thread, if the parent id is the same as active thread id', async () => {
339+
await init();
340+
const spy = jasmine.createSpy();
341+
const parentMessage = mockMessage();
342+
await service.setAsActiveParentMessage(parentMessage);
343+
service.activeThreadMessages$.subscribe(spy);
344+
spy.calls.reset();
345+
let activeChannel!: Channel<DefaultStreamChatGenerics>;
346+
service.activeChannel$.subscribe((c) => (activeChannel = c!));
347+
const newMessage = mockMessage();
348+
newMessage.parent_id = 'not' + parentMessage.id;
349+
activeChannel.state.threads = {
350+
[newMessage.parent_id]: [newMessage],
351+
[parentMessage.id]: [],
352+
};
353+
(activeChannel as MockChannel).handleEvent('message.new', {
354+
message: newMessage,
355+
});
356+
357+
expect(spy).not.toHaveBeenCalled();
358+
});
359+
338360
it('should watch for message update events', async () => {
339361
await init();
340362
const parentMessage = mockMessage();

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,9 +1120,12 @@ export class ChannelService<
11201120
channel.on('message.new', (event) => {
11211121
this.ngZone.run(() => {
11221122
event.message && event.message.parent_id
1123-
? this.activeThreadMessagesSubject.next([
1124-
...channel.state.threads[event.message.parent_id],
1125-
])
1123+
? event.message.parent_id ===
1124+
this.activeParentMessageIdSubject.getValue()
1125+
? this.activeThreadMessagesSubject.next([
1126+
...channel.state.threads[event.message.parent_id],
1127+
])
1128+
: null
11261129
: this.activeChannelMessagesSubject.next([
11271130
...channel.state.messages,
11281131
]);

0 commit comments

Comments
 (0)