Skip to content

Commit bac5848

Browse files
authored
fix: hydrate poll state with thread parent messages when querying thread (#1696)
1 parent ef2169f commit bac5848

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

src/client.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3358,6 +3358,10 @@ export class StreamChat {
33583358
requestBody,
33593359
);
33603360

3361+
// Hydrate the polls for the parent messages of the threads
3362+
const parentMessages = response.threads.map((thread) => thread.parent_message);
3363+
this.polls.hydratePollCache(parentMessages);
3364+
33613365
return {
33623366
threads: response.threads.map(
33633367
(thread) => new Thread({ client: this, threadData: thread }),

test/unit/client.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { StreamChat } from '../../src/client';
77
import { ConnectionState } from '../../src/connection_fallback';
88
import { StableWSConnection } from '../../src/connection';
99
import { mockChannelQueryResponse } from './test-utils/mockChannelQueryResponse';
10+
import { generateThreadResponse } from './test-utils/generateThreadResponse';
1011
import { DEFAULT_QUERY_CHANNEL_MESSAGE_LIST_PAGE_SIZE } from '../../src/constants';
1112

1213
import {
@@ -787,6 +788,32 @@ describe('StreamChat.queryChannels', async () => {
787788
});
788789
});
789790

791+
describe('StreamChat.queryThreads', () => {
792+
it('returns threads and next, and hydrates poll cache with parent messages', async () => {
793+
const client = await getClientWithUser();
794+
const parentMessage = generateMsg();
795+
const rawThread = generateThreadResponse(
796+
mockChannelQueryResponse.channel,
797+
parentMessage,
798+
);
799+
const apiResponse = { threads: [rawThread], next: undefined };
800+
801+
const postStub = sinon.stub(client, 'post');
802+
postStub.onFirstCall().resolves(apiResponse);
803+
const hydratePollCacheSpy = sinon.spy(client.polls, 'hydratePollCache');
804+
805+
const result = await client.queryThreads();
806+
807+
expect(result.threads).to.have.lengthOf(1);
808+
expect(result.threads[0].id).to.equal(parentMessage.id);
809+
expect(result.next).to.be.undefined;
810+
expect(hydratePollCacheSpy.calledOnce).to.be.true;
811+
expect(hydratePollCacheSpy.calledWith([parentMessage])).to.be.true;
812+
813+
postStub.restore();
814+
});
815+
});
816+
790817
describe('StreamChat.queryReactions', () => {
791818
let client;
792819
let dispatchSpy;

0 commit comments

Comments
 (0)