Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add batch unread endpoint #1212

Merged
merged 4 commits into from
Jan 25, 2024
Merged

feat: add batch unread endpoint #1212

merged 4 commits into from
Jan 25, 2024

Conversation

JimmyPettersson85
Copy link
Contributor

CLA

  • I have signed the Stream CLA (required).
  • Code changes are tested

Description of the changes, What, Why and How?

add support for the new batch unread endpoint

Copy link
Contributor

Size Change: +753 B (0%)

Total Size: 329 kB

Filename Size Change
dist/browser.es.js 70.8 kB +193 B (0%)
dist/browser.full-bundle.min.js 43.9 kB +29 B (0%)
dist/browser.js 71.7 kB +172 B (0%)
dist/index.es.js 70.8 kB +186 B (0%)
dist/index.js 71.8 kB +173 B (0%)

compressed-size-action

* @return {<GetUnreadCountBatchAPIResponse>}
*/
async getUnreadCountBatch(userIDs: string[]) {
return await this.post<GetUnreadCountBatchAPIResponse>(this.baseURL + '/unread_batch', { user_ids: userIDs });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JimmyPettersson85 just out of curiosity, why for a GET request is used POST method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future proofing the backend we chose POST for this endpoint as we might hit querystring limits if we increase the limit of number of users. Currently the limit is 100 user IDs, and with a max length of 255 for a user ID that means a querystring of ~25k chars.

In going with POST we can handle > 100 user IDs in the future as well as support compression.

src/types.ts Outdated
@@ -513,6 +513,10 @@ export type GetUnreadCountAPIResponse = APIResponse & {
total_unread_count: number;
};

export type GetUnreadCountBatchAPIResponse = APIResponse & {
counts_by_user: GetUnreadCountAPIResponse[];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a map (object), instead of an array? AFAIK, the key of the map is the user id

I think this should work (not tested)

Suggested change
counts_by_user: GetUnreadCountAPIResponse[];
counts_by_user: { [string]: GetUnreadCountAPIResponse };

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, the other parts of this code seems to be using Record so maybe
counts_by_user: Record<string, GetUnreadCountAPIResponse>;?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah probably, but my Typescript-foo isn't strong enough to say for sure 😆 @MartinCupela probably knows

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or @vishalnarkhede, help us Go devs out 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jumping in here... counts_by_user: Record<string, GetUnreadCountAPIResponse>; should be good.
But probably it will be better if we are a bit more explicit and have:
{ [userId: string]: GetUnreadCountAPIResponse }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the input, pushed a fix for this

@JimmyPettersson85 JimmyPettersson85 merged commit 5ea11db into master Jan 25, 2024
6 checks passed
@JimmyPettersson85 JimmyPettersson85 deleted the PBE-1250 branch January 25, 2024 13:57
This was referenced Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants