Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v24
63 changes: 63 additions & 0 deletions __tests__/ring-call.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { beforeAll, describe, expect, it } from 'vitest';
import { createTestClient } from './create-test-client';
import { StreamCall } from '../src/StreamCall';
import { StreamClient } from '../src/StreamClient';
import { v4 as uuidv4 } from 'uuid';

describe('ring call API', () => {
let client: StreamClient;
const callId = `call${uuidv4()}`;
let call: StreamCall;

beforeAll(async () => {
client = createTestClient();

call = client.video.call('default', callId);

await client.upsertUsers([
{ id: 'myself' },
{ id: 'my-friend' },
{ id: 'my-other-friend' },
]);
});

it(`create call without ringing`, async () => {
const response = await call.getOrCreate({
ring: false, // set to false to avoid ringing the whole call
data: {
created_by_id: 'myself',
members: [{ user_id: 'myself' }, { user_id: 'my-friend' }],
},
});

// Dummy expect
expect(response.call.id).toBe(callId);
});

it(`ring my-friend`, async () => {
const response = await call.ring({ members_ids: ['my-friend'] });
expect(response.members_ids).toEqual(['my-friend']);
});

it(`ring my-other-friend`, async () => {
await call.updateCallMembers({
update_members: [{ user_id: 'my-other-friend' }],
});
const response = await call.ring({ members_ids: ['my-other-friend'] });
expect(response.members_ids).toEqual(['my-other-friend']);
});

it('delete call', async () => {
try {
await call.delete({ hard: true });
} catch (e) {
// the first request fails on backend sometimes
// retry it
await new Promise<void>((resolve) => {
setTimeout(() => resolve(), 2000);
});

await call.delete({ hard: true });
}
});
});
42 changes: 40 additions & 2 deletions src/gen/chat/ChatApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import {
ListChannelTypesResponse,
ListCommandsResponse,
MarkChannelsReadRequest,
MarkDeliveredRequest,
MarkDeliveredResponse,
MarkReadRequest,
MarkReadResponse,
MarkUnreadRequest,
Expand Down Expand Up @@ -278,6 +280,32 @@ export class ChatApi {
return { ...response.body, metadata: response.metadata };
}

async markDelivered(
request?: MarkDeliveredRequest & { user_id?: string },
): Promise<StreamResponse<MarkDeliveredResponse>> {
const queryParams = {
user_id: request?.user_id,
};
const body = {
latest_delivered_messages: request?.latest_delivered_messages,
};

const response = await this.apiClient.sendRequest<
StreamResponse<MarkDeliveredResponse>
>(
'POST',
'/api/v2/chat/channels/delivered',
undefined,
queryParams,
body,
'application/json',
);

decoders.MarkDeliveredResponse?.(response.body);

return { ...response.body, metadata: response.metadata };
}

async markChannelsRead(
request?: MarkChannelsReadRequest,
): Promise<StreamResponse<MarkReadResponse>> {
Expand Down Expand Up @@ -398,14 +426,17 @@ export class ChatApi {
accept_invite: request?.accept_invite,
cooldown: request?.cooldown,
hide_history: request?.hide_history,
hide_history_before: request?.hide_history_before,
reject_invite: request?.reject_invite,
skip_push: request?.skip_push,
user_id: request?.user_id,
add_filter_tags: request?.add_filter_tags,
add_members: request?.add_members,
add_moderators: request?.add_moderators,
assign_roles: request?.assign_roles,
demote_moderators: request?.demote_moderators,
invites: request?.invites,
remove_filter_tags: request?.remove_filter_tags,
remove_members: request?.remove_members,
data: request?.data,
message: request?.message,
Expand Down Expand Up @@ -875,6 +906,7 @@ export class ChatApi {
};
const body = {
message_id: request?.message_id,
message_timestamp: request?.message_timestamp,
thread_id: request?.thread_id,
user_id: request?.user_id,
user: request?.user,
Expand Down Expand Up @@ -2122,10 +2154,16 @@ export class ChatApi {
return { ...response.body, metadata: response.metadata };
}

async unreadCounts(): Promise<StreamResponse<WrappedUnreadCountsResponse>> {
async unreadCounts(request?: {
user_id?: string;
}): Promise<StreamResponse<WrappedUnreadCountsResponse>> {
const queryParams = {
user_id: request?.user_id,
};

const response = await this.apiClient.sendRequest<
StreamResponse<WrappedUnreadCountsResponse>
>('GET', '/api/v2/chat/unread', undefined, undefined);
>('GET', '/api/v2/chat/unread', undefined, queryParams);

decoders.WrappedUnreadCountsResponse?.(response.body);

Expand Down
Loading
Loading