Skip to content

Commit 77a2d78

Browse files
Serverside removal phase 1
1 parent 0a48288 commit 77a2d78

12 files changed

Lines changed: 120 additions & 3681 deletions

src/campaign.ts

Lines changed: 1 addition & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1 @@
1-
import type { StreamChat } from './client';
2-
import type { CampaignData, GetCampaignOptions } from './types';
3-
4-
export class Campaign {
5-
id: string | null;
6-
data?: CampaignData;
7-
client: StreamChat;
8-
9-
constructor(client: StreamChat, id: string | null, data?: CampaignData) {
10-
this.client = client;
11-
this.id = id;
12-
this.data = data;
13-
}
14-
15-
async create() {
16-
const body = {
17-
id: this.id,
18-
message_template: this.data?.message_template,
19-
segment_ids: this.data?.segment_ids,
20-
sender_id: this.data?.sender_id,
21-
sender_mode: this.data?.sender_mode,
22-
sender_visibility: this.data?.sender_visibility,
23-
channel_template: this.data?.channel_template,
24-
create_channels: this.data?.create_channels,
25-
show_channels: this.data?.show_channels,
26-
description: this.data?.description,
27-
name: this.data?.name,
28-
skip_push: this.data?.skip_push,
29-
skip_webhook: this.data?.skip_webhook,
30-
user_ids: this.data?.user_ids,
31-
};
32-
33-
const result = await this.client.createCampaign(body);
34-
35-
this.id = result.campaign.id;
36-
this.data = result.campaign;
37-
return result;
38-
}
39-
40-
verifyCampaignId() {
41-
if (!this.id) {
42-
throw new Error(
43-
'Campaign id is missing. Either create the campaign using campaign.create() or set the id during instantiation - const campaign = client.campaign(id)',
44-
);
45-
}
46-
}
47-
48-
async start(options?: { scheduledFor?: string; stopAt?: string }) {
49-
this.verifyCampaignId();
50-
51-
return await this.client.startCampaign(this.id as string, options);
52-
}
53-
54-
update(data: Partial<CampaignData>) {
55-
this.verifyCampaignId();
56-
57-
return this.client.updateCampaign(this.id as string, data);
58-
}
59-
60-
async delete() {
61-
this.verifyCampaignId();
62-
63-
return await this.client.deleteCampaign(this.id as string);
64-
}
65-
66-
stop() {
67-
this.verifyCampaignId();
68-
69-
return this.client.stopCampaign(this.id as string);
70-
}
71-
72-
get(options?: GetCampaignOptions) {
73-
this.verifyCampaignId();
74-
75-
return this.client.getCampaign(this.id as string, options);
76-
}
77-
}
1+
// Campaign functionality has been moved to the server-side SDK.

src/channel.ts

Lines changed: 10 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import type {
4343
MessageSetType,
4444
PartialUpdateChannel,
4545
PartialUpdateMember,
46-
PartialUpdateMemberAPIResponse,
4746
PinnedMessagePaginationOptions,
4847
PinnedMessagesSort,
4948
PollVoteData,
@@ -417,26 +416,6 @@ export class Channel {
417416
});
418417
}
419418

420-
/**
421-
* @deprecated Use `updateMemberPartial` instead
422-
* partialUpdateMember - Partial update a member
423-
*
424-
* @param {string} user_id member user id
425-
* @param {PartialUpdateMember} updates
426-
*
427-
* @return {Promise<ChannelMemberResponse>} Updated member
428-
*/
429-
async partialUpdateMember(user_id: string, updates: PartialUpdateMember) {
430-
if (!user_id) {
431-
throw Error('Please specify the user id');
432-
}
433-
434-
return await this.getClient().api.patch<PartialUpdateMemberAPIResponse>(
435-
this._channelURL() + `/member/${encodeURIComponent(user_id)}`,
436-
updates,
437-
);
438-
}
439-
440419
/**
441420
* sendReaction - Sends a reaction to a message. If offline support is enabled, it will make sure
442421
* that sending the reaction is queued up if it fails due to bad internet conditions and executed
@@ -950,79 +929,47 @@ export class Channel {
950929
* await channel.archive({user_id: userId});
951930
*
952931
*/
953-
async archive(opts: { user_id?: string } = {}) {
954-
const cli = this.getClient();
955-
const uid = opts.user_id || cli.userId;
956-
if (!uid) {
957-
throw Error('A user_id is required for archiving a channel');
958-
}
959-
const resp = await this.partialUpdateMember(uid, { set: { archived: true } });
932+
async archive() {
933+
const resp = await this.updateMemberPartial({ set: { archived: true } });
960934
return resp.channel_member;
961935
}
962936

963937
/**
964938
* unarchive - unarchives the current channel
965-
* @param {{ user_id?: string }} opts user_id if called server side
966939
* @return {Promise<ChannelMemberResponse>} The server response
967940
*
968941
* example:
969942
* await channel.unarchive();
970943
*
971-
* example server side:
972-
* await channel.unarchive({user_id: userId});
973-
*
974944
*/
975-
async unarchive(opts: { user_id?: string } = {}) {
976-
const cli = this.getClient();
977-
const uid = opts.user_id || cli.userId;
978-
if (!uid) {
979-
throw Error('A user_id is required for unarchiving a channel');
980-
}
981-
const resp = await this.partialUpdateMember(uid, { set: { archived: false } });
945+
async unarchive() {
946+
const resp = await this.updateMemberPartial({ set: { archived: false } });
982947
return resp.channel_member;
983948
}
984949

985950
/**
986951
* pin - pins the current channel
987-
* @param {{ user_id?: string }} opts user_id if called server side
988952
* @return {Promise<ChannelMemberResponse>} The server response
989953
*
990954
* example:
991955
* await channel.pin();
992956
*
993-
* example server side:
994-
* await channel.pin({user_id: userId});
995-
*
996957
*/
997-
async pin(opts: { user_id?: string } = {}) {
998-
const cli = this.getClient();
999-
const uid = opts.user_id || cli.userId;
1000-
if (!uid) {
1001-
throw new Error('A user_id is required for pinning a channel');
1002-
}
1003-
const resp = await this.partialUpdateMember(uid, { set: { pinned: true } });
958+
async pin() {
959+
const resp = await this.updateMemberPartial({ set: { pinned: true } });
1004960
return resp.channel_member;
1005961
}
1006962

1007963
/**
1008964
* unpin - unpins the current channel
1009-
* @param {{ user_id?: string }} opts user_id if called server side
1010965
* @return {Promise<ChannelMemberResponse>} The server response
1011966
*
1012967
* example:
1013968
* await channel.unpin();
1014969
*
1015-
* example server side:
1016-
* await channel.unpin({user_id: userId});
1017-
*
1018970
*/
1019-
async unpin(opts: { user_id?: string } = {}) {
1020-
const cli = this.getClient();
1021-
const uid = opts.user_id || cli.userId;
1022-
if (!uid) {
1023-
throw new Error('A user_id is required for unpinning a channel');
1024-
}
1025-
const resp = await this.partialUpdateMember(uid, { set: { pinned: false } });
971+
async unpin() {
972+
const resp = await this.updateMemberPartial({ set: { pinned: false } });
1026973
return resp.channel_member;
1027974
}
1028975

@@ -1319,13 +1266,13 @@ export class Channel {
13191266
/**
13201267
* getPinnedMessages - List list pinned messages of the channel
13211268
*
1322-
* @param {PinnedMessagePaginationOptions & { user?: UserResponse; user_id?: string }} options Pagination params, ie {limit:10, id_lte: 10}
1269+
* @param {PinnedMessagePaginationOptions} options Pagination params, ie {limit:10, id_lte: 10}
13231270
* @param {PinnedMessagesSort} sort defines sorting direction of pinned messages
13241271
*
13251272
* @return {Promise<GetRepliesAPIResponse>} A response with a list of messages
13261273
*/
13271274
async getPinnedMessages(
1328-
options: PinnedMessagePaginationOptions & { user?: UserResponse; user_id?: string },
1275+
options: PinnedMessagePaginationOptions,
13291276
sort: PinnedMessagesSort = [],
13301277
) {
13311278
return await this.getClient().api.get<GetRepliesAPIResponse>(

0 commit comments

Comments
 (0)