Skip to content

Commit 04ac57e

Browse files
oliverlazszuperaz
andauthored
feat: ring individual members (#105)
Co-authored-by: Zita Szupera <[email protected]>
1 parent 030654b commit 04ac57e

File tree

8 files changed

+925
-115
lines changed

8 files changed

+925
-115
lines changed

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v24

__tests__/ring-call.test.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { beforeAll, describe, expect, it } from 'vitest';
2+
import { createTestClient } from './create-test-client';
3+
import { StreamCall } from '../src/StreamCall';
4+
import { StreamClient } from '../src/StreamClient';
5+
import { v4 as uuidv4 } from 'uuid';
6+
7+
describe('ring call API', () => {
8+
let client: StreamClient;
9+
const callId = `call${uuidv4()}`;
10+
let call: StreamCall;
11+
12+
beforeAll(async () => {
13+
client = createTestClient();
14+
15+
call = client.video.call('default', callId);
16+
17+
await client.upsertUsers([
18+
{ id: 'myself' },
19+
{ id: 'my-friend' },
20+
{ id: 'my-other-friend' },
21+
]);
22+
});
23+
24+
it(`create call without ringing`, async () => {
25+
const response = await call.getOrCreate({
26+
ring: false, // set to false to avoid ringing the whole call
27+
data: {
28+
created_by_id: 'myself',
29+
members: [{ user_id: 'myself' }, { user_id: 'my-friend' }],
30+
},
31+
});
32+
33+
// Dummy expect
34+
expect(response.call.id).toBe(callId);
35+
});
36+
37+
it(`ring my-friend`, async () => {
38+
const response = await call.ring({ members_ids: ['my-friend'] });
39+
expect(response.members_ids).toEqual(['my-friend']);
40+
});
41+
42+
it(`ring my-other-friend`, async () => {
43+
await call.updateCallMembers({
44+
update_members: [{ user_id: 'my-other-friend' }],
45+
});
46+
const response = await call.ring({ members_ids: ['my-other-friend'] });
47+
expect(response.members_ids).toEqual(['my-other-friend']);
48+
});
49+
50+
it('delete call', async () => {
51+
try {
52+
await call.delete({ hard: true });
53+
} catch (e) {
54+
// the first request fails on backend sometimes
55+
// retry it
56+
await new Promise<void>((resolve) => {
57+
setTimeout(() => resolve(), 2000);
58+
});
59+
60+
await call.delete({ hard: true });
61+
}
62+
});
63+
});

src/gen/chat/ChatApi.ts

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ import {
3636
ListChannelTypesResponse,
3737
ListCommandsResponse,
3838
MarkChannelsReadRequest,
39+
MarkDeliveredRequest,
40+
MarkDeliveredResponse,
3941
MarkReadRequest,
4042
MarkReadResponse,
4143
MarkUnreadRequest,
@@ -278,6 +280,32 @@ export class ChatApi {
278280
return { ...response.body, metadata: response.metadata };
279281
}
280282

283+
async markDelivered(
284+
request?: MarkDeliveredRequest & { user_id?: string },
285+
): Promise<StreamResponse<MarkDeliveredResponse>> {
286+
const queryParams = {
287+
user_id: request?.user_id,
288+
};
289+
const body = {
290+
latest_delivered_messages: request?.latest_delivered_messages,
291+
};
292+
293+
const response = await this.apiClient.sendRequest<
294+
StreamResponse<MarkDeliveredResponse>
295+
>(
296+
'POST',
297+
'/api/v2/chat/channels/delivered',
298+
undefined,
299+
queryParams,
300+
body,
301+
'application/json',
302+
);
303+
304+
decoders.MarkDeliveredResponse?.(response.body);
305+
306+
return { ...response.body, metadata: response.metadata };
307+
}
308+
281309
async markChannelsRead(
282310
request?: MarkChannelsReadRequest,
283311
): Promise<StreamResponse<MarkReadResponse>> {
@@ -398,14 +426,17 @@ export class ChatApi {
398426
accept_invite: request?.accept_invite,
399427
cooldown: request?.cooldown,
400428
hide_history: request?.hide_history,
429+
hide_history_before: request?.hide_history_before,
401430
reject_invite: request?.reject_invite,
402431
skip_push: request?.skip_push,
403432
user_id: request?.user_id,
433+
add_filter_tags: request?.add_filter_tags,
404434
add_members: request?.add_members,
405435
add_moderators: request?.add_moderators,
406436
assign_roles: request?.assign_roles,
407437
demote_moderators: request?.demote_moderators,
408438
invites: request?.invites,
439+
remove_filter_tags: request?.remove_filter_tags,
409440
remove_members: request?.remove_members,
410441
data: request?.data,
411442
message: request?.message,
@@ -875,6 +906,7 @@ export class ChatApi {
875906
};
876907
const body = {
877908
message_id: request?.message_id,
909+
message_timestamp: request?.message_timestamp,
878910
thread_id: request?.thread_id,
879911
user_id: request?.user_id,
880912
user: request?.user,
@@ -2122,10 +2154,16 @@ export class ChatApi {
21222154
return { ...response.body, metadata: response.metadata };
21232155
}
21242156

2125-
async unreadCounts(): Promise<StreamResponse<WrappedUnreadCountsResponse>> {
2157+
async unreadCounts(request?: {
2158+
user_id?: string;
2159+
}): Promise<StreamResponse<WrappedUnreadCountsResponse>> {
2160+
const queryParams = {
2161+
user_id: request?.user_id,
2162+
};
2163+
21262164
const response = await this.apiClient.sendRequest<
21272165
StreamResponse<WrappedUnreadCountsResponse>
2128-
>('GET', '/api/v2/chat/unread', undefined, undefined);
2166+
>('GET', '/api/v2/chat/unread', undefined, queryParams);
21292167

21302168
decoders.WrappedUnreadCountsResponse?.(response.body);
21312169

0 commit comments

Comments
 (0)