Skip to content

Commit

Permalink
Merge pull request #475 from GetStream/thread-new-message
Browse files Browse the repository at this point in the history
fix: misplaced messages in active thread
  • Loading branch information
szuperaz authored Sep 21, 2023
2 parents 8d18c9c + 7c32c74 commit f1cb726
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 f1cb726

Please sign in to comment.