Skip to content

Commit

Permalink
fix: misplaced messages in active thread
Browse files Browse the repository at this point in the history
  • Loading branch information
szuperaz committed Sep 21, 2023
1 parent 8d18c9c commit 7c32c74
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,28 @@ describe('ChannelService - threads', () => {
expect(activeChannel.markRead).toHaveBeenCalledWith();
});

it('should only add new message to thread, if the parent id is the same as active thread id', async () => {
await init();
const spy = jasmine.createSpy();
const parentMessage = mockMessage();
await service.setAsActiveParentMessage(parentMessage);
service.activeThreadMessages$.subscribe(spy);
spy.calls.reset();
let activeChannel!: Channel<DefaultStreamChatGenerics>;
service.activeChannel$.subscribe((c) => (activeChannel = c!));
const newMessage = mockMessage();
newMessage.parent_id = 'not' + parentMessage.id;
activeChannel.state.threads = {
[newMessage.parent_id]: [newMessage],
[parentMessage.id]: [],
};
(activeChannel as MockChannel).handleEvent('message.new', {
message: newMessage,
});

expect(spy).not.toHaveBeenCalled();
});

it('should watch for message update events', async () => {
await init();
const parentMessage = mockMessage();
Expand Down
9 changes: 6 additions & 3 deletions projects/stream-chat-angular/src/lib/channel.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1120,9 +1120,12 @@ export class ChannelService<
channel.on('message.new', (event) => {
this.ngZone.run(() => {
event.message && event.message.parent_id
? this.activeThreadMessagesSubject.next([
...channel.state.threads[event.message.parent_id],
])
? event.message.parent_id ===
this.activeParentMessageIdSubject.getValue()
? this.activeThreadMessagesSubject.next([
...channel.state.threads[event.message.parent_id],
])
: null
: this.activeChannelMessagesSubject.next([
...channel.state.messages,
]);
Expand Down

0 comments on commit 7c32c74

Please sign in to comment.