Skip to content

Commit

Permalink
refactor: moved watch to backend
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalnarkhede committed Jan 28, 2024
1 parent 62753be commit e584fe8
Showing 1 changed file with 4 additions and 23 deletions.
27 changes: 4 additions & 23 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2591,12 +2591,12 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
watch?: boolean;
}) {
// eslint-disable-next-line
const { watch, ...optionsWithoutWatch } = options || {};
const opts = {
limit: 10,
participant_limit: 10,
reply_limit: 3,
...optionsWithoutWatch,
watch: true,
...options,
};

const res = await this.post<QueryThreadsAPIResponse<StreamChatGenerics>>(this.baseURL + `/threads`, opts);
Expand All @@ -2607,22 +2607,6 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
threads.push(thread);
}

// TODO: Currently we are handling watch on client level. We should move this to server side.
const cids = threads.map((thread) => thread.channel.cid);
if (options?.watch && cids.length > 0) {
await this.queryChannels(
{
cid: { $in: cids },
} as ChannelFilters<StreamChatGenerics>,
{},
{
limit: 30,
message_limit: 0,
watch: true,
},
);
}

return {
threads,
next: res.next,
Expand All @@ -2636,18 +2620,15 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
const opts = {
participant_limit: 100,
reply_limit: 3,
watch: true,
...options,
};

const res = await this.get<GetThreadAPIResponse<StreamChatGenerics>>(this.baseURL + `/threads/${messageId}`, opts);

if (options?.watch) {
const channel = this.channel(res.thread.channel.type, res.thread.channel.id);
await channel.watch();
}

return new Thread<StreamChatGenerics>(this, res.thread);
}

async partialUpdateThread(messageId: string, partialThreadObject: PartialThreadUpdate) {
if (!messageId) {
throw Error('Please specify the message id when calling updateThread');
Expand Down

0 comments on commit e584fe8

Please sign in to comment.