Skip to content

Commit bc930f6

Browse files
committed
api: Add getReadReceipts binding (GET messages/{message_id}/read_receipts)
We'll use this for #5367, "Make it possible to view read receipts".
1 parent 3cb8b70 commit bc930f6

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/api/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import createUser from './users/createUser';
5555
import getUserProfile from './users/getUserProfile';
5656
import updateUserStatus from './users/updateUserStatus';
5757
import getFileTemporaryUrl from './messages/getFileTemporaryUrl';
58+
import getReadReceipts from './messages/getReadReceipts';
5859

5960
export {
6061
fetchServerEmojiData,
@@ -104,4 +105,5 @@ export {
104105
getUserProfile,
105106
updateUserStatus,
106107
getFileTemporaryUrl,
108+
getReadReceipts,
107109
};

src/api/messages/getReadReceipts.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* @flow strict-local */
2+
import invariant from 'invariant';
3+
4+
import type { Auth, ApiResponseSuccess } from '../transportTypes';
5+
import { apiGet } from '../apiFetch';
6+
import type { UserId } from '../idTypes';
7+
8+
type ServerApiResponseReadReceipts = {|
9+
...$Exact<ApiResponseSuccess>,
10+
+user_ids: $ReadOnlyArray<UserId>,
11+
|};
12+
13+
/**
14+
* See https://zulip.com/api/get-read-receipts
15+
*
16+
* Should only be called for servers with FL 137+.
17+
*/
18+
// TODO(server-6.0): Stop mentioning a FL 137 condition.
19+
export default async (
20+
auth: Auth,
21+
args: {|
22+
+message_id: number,
23+
|},
24+
25+
// TODO(#4659): Don't get this from callers.
26+
zulipFeatureLevel: number,
27+
): Promise<$ReadOnlyArray<UserId>> => {
28+
invariant(zulipFeatureLevel >= 137, 'api.getReadReceipts called for unsupporting server');
29+
30+
const { message_id } = args;
31+
const response: ServerApiResponseReadReceipts = await apiGet(
32+
auth,
33+
`messages/${message_id}/read_receipts`,
34+
);
35+
36+
return response.user_ids;
37+
};

0 commit comments

Comments
 (0)