Skip to content

Commit

Permalink
feat: add batch unread endpoint (#1212)
Browse files Browse the repository at this point in the history
Co-authored-by: Vishal Narkhede <[email protected]>
  • Loading branch information
JimmyPettersson85 and vishalnarkhede authored Jan 25, 2024
1 parent 33f09b9 commit 5ea11db
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ import {
GetMessageAPIResponse,
GetRateLimitsResponse,
GetUnreadCountAPIResponse,
GetUnreadCountBatchAPIResponse,
ListChannelResponse,
ListCommandsResponse,
ListImportsPaginationOptions,
Expand Down Expand Up @@ -1688,10 +1689,28 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
);
}

/**
* getUnreadCount - Returns unread counts for a single user
*
* @param {string} [userID] User ID.
*
* @return {<GetUnreadCountAPIResponse>}
*/
async getUnreadCount(userID?: string) {
return await this.get<GetUnreadCountAPIResponse>(this.baseURL + '/unread', userID ? { user_id: userID } : {});
}

/**
* getUnreadCountBatch - Returns unread counts for multiple users at once. Only works server side.
*
* @param {string[]} [userIDs] List of user IDs to fetch unread counts for.
*
* @return {<GetUnreadCountBatchAPIResponse>}
*/
async getUnreadCountBatch(userIDs: string[]) {
return await this.post<GetUnreadCountBatchAPIResponse>(this.baseURL + '/unread_batch', { user_ids: userIDs });
}

/**
* removeDevice - Removes the device with the given id. Clientside users can only delete their own devices
*
Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,10 @@ export type GetUnreadCountAPIResponse = APIResponse & {
total_unread_count: number;
};

export type GetUnreadCountBatchAPIResponse = APIResponse & {
counts_by_user: { [userId: string]: GetUnreadCountAPIResponse };
};

export type ListChannelResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & {
channel_types: Record<
string,
Expand Down

0 comments on commit 5ea11db

Please sign in to comment.