Skip to content

Commit 25fb44f

Browse files
committed
feat: added channel batch updater
1 parent 5d76dfb commit 25fb44f

File tree

4 files changed

+230
-0
lines changed

4 files changed

+230
-0
lines changed

src/channel_batch_updater.ts

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
import type { StreamChat } from './client';
2+
import type {
3+
APIResponse,
4+
BatchChannelDataUpdate,
5+
NewMemberPayload,
6+
UpdateChannelsBatchFilters,
7+
UpdateChannelsBatchResponse,
8+
} from './types';
9+
10+
/**
11+
* ChannelBatchUpdater - A class that provides convenience methods for batch channel operations
12+
*/
13+
export class ChannelBatchUpdater {
14+
client: StreamChat;
15+
16+
constructor(client: StreamChat) {
17+
this.client = client;
18+
}
19+
20+
// Member operations
21+
22+
/**
23+
* addMembers - Add members to channels matching the filter
24+
*
25+
* @param {UpdateChannelsBatchFilters} filter Filter to select channels
26+
* @param {string[] | NewMemberPayload[]} members Members to add
27+
* @return {Promise<APIResponse & UpdateChannelsBatchResponse>} The server response
28+
*/
29+
async addMembers(
30+
filter: UpdateChannelsBatchFilters,
31+
members: string[] | NewMemberPayload[],
32+
) {
33+
return await this.client.updateChannelsBatch({
34+
operation: 'addMembers',
35+
filter,
36+
members,
37+
});
38+
}
39+
40+
/**
41+
* removeMembers - Remove members from channels matching the filter
42+
*
43+
* @param {UpdateChannelsBatchFilters} filter Filter to select channels
44+
* @param {string[]} members Member IDs to remove
45+
* @return {Promise<APIResponse & UpdateChannelsBatchResponse>} The server response
46+
*/
47+
async removeMembers(filter: UpdateChannelsBatchFilters, members: string[]) {
48+
return await this.client.updateChannelsBatch({
49+
operation: 'removeMembers',
50+
filter,
51+
members,
52+
});
53+
}
54+
55+
/**
56+
* inviteMembers - Invite members to channels matching the filter
57+
*
58+
* @param {UpdateChannelsBatchFilters} filter Filter to select channels
59+
* @param {string[] | NewMemberPayload[]} members Members to invite
60+
* @return {Promise<APIResponse & UpdateChannelsBatchResponse>} The server response
61+
*/
62+
async inviteMembers(
63+
filter: UpdateChannelsBatchFilters,
64+
members: string[] | NewMemberPayload[],
65+
) {
66+
return await this.client.updateChannelsBatch({
67+
operation: 'invites',
68+
filter,
69+
members,
70+
});
71+
}
72+
73+
/**
74+
* addModerators - Add moderators to channels matching the filter
75+
*
76+
* @param {UpdateChannelsBatchFilters} filter Filter to select channels
77+
* @param {string[]} members Member IDs to promote to moderator
78+
* @return {Promise<APIResponse & UpdateChannelsBatchResponse>} The server response
79+
*/
80+
async addModerators(filter: UpdateChannelsBatchFilters, members: string[]) {
81+
return await this.client.updateChannelsBatch({
82+
operation: 'addModerators',
83+
filter,
84+
members,
85+
});
86+
}
87+
88+
/**
89+
* demoteModerators - Remove moderator role from members in channels matching the filter
90+
*
91+
* @param {UpdateChannelsBatchFilters} filter Filter to select channels
92+
* @param {string[]} members Member IDs to demote
93+
* @return {Promise<APIResponse & UpdateChannelsBatchResponse>} The server response
94+
*/
95+
async demoteModerators(filter: UpdateChannelsBatchFilters, members: string[]) {
96+
return await this.client.updateChannelsBatch({
97+
operation: 'demoteModerators',
98+
filter,
99+
members,
100+
});
101+
}
102+
103+
/**
104+
* assignRoles - Assign roles to members in channels matching the filter
105+
*
106+
* @param {UpdateChannelsBatchFilters} filter Filter to select channels
107+
* @param {NewMemberPayload[]} members Members with role assignments
108+
* @return {Promise<APIResponse & UpdateChannelsBatchResponse>} The server response
109+
*/
110+
async assignRoles(filter: UpdateChannelsBatchFilters, members: NewMemberPayload[]) {
111+
return await this.client.updateChannelsBatch({
112+
operation: 'assignRoles',
113+
filter,
114+
members,
115+
});
116+
}
117+
118+
// Visibility operations
119+
120+
/**
121+
* hide - Hide channels matching the filter
122+
*
123+
* @param {UpdateChannelsBatchFilters} filter Filter to select channels
124+
* @return {Promise<APIResponse & UpdateChannelsBatchResponse>} The server response
125+
*/
126+
async hide(filter: UpdateChannelsBatchFilters) {
127+
return await this.client.updateChannelsBatch({
128+
operation: 'hide',
129+
filter,
130+
});
131+
}
132+
133+
/**
134+
* show - Show channels matching the filter
135+
*
136+
* @param {UpdateChannelsBatchFilters} filter Filter to select channels
137+
* @return {Promise<APIResponse & UpdateChannelsBatchResponse>} The server response
138+
*/
139+
async show(filter: UpdateChannelsBatchFilters) {
140+
return await this.client.updateChannelsBatch({
141+
operation: 'show',
142+
filter,
143+
});
144+
}
145+
146+
/**
147+
* archive - Archive channels matching the filter
148+
*
149+
* @param {UpdateChannelsBatchFilters} filter Filter to select channels
150+
* @return {Promise<APIResponse & UpdateChannelsBatchResponse>} The server response
151+
*/
152+
async archive(filter: UpdateChannelsBatchFilters) {
153+
return await this.client.updateChannelsBatch({
154+
operation: 'archive',
155+
filter,
156+
});
157+
}
158+
159+
/**
160+
* unarchive - Unarchive channels matching the filter
161+
*
162+
* @param {UpdateChannelsBatchFilters} filter Filter to select channels
163+
* @return {Promise<APIResponse & UpdateChannelsBatchResponse>} The server response
164+
*/
165+
async unarchive(filter: UpdateChannelsBatchFilters) {
166+
return await this.client.updateChannelsBatch({
167+
operation: 'unarchive',
168+
filter,
169+
});
170+
}
171+
172+
// Data operations
173+
174+
/**
175+
* updateData - Update data on channels matching the filter
176+
*
177+
* @param {UpdateChannelsBatchFilters} filter Filter to select channels
178+
* @param {BatchChannelDataUpdate} data Data to update
179+
* @return {Promise<APIResponse & UpdateChannelsBatchResponse>} The server response
180+
*/
181+
async updateData(filter: UpdateChannelsBatchFilters, data: BatchChannelDataUpdate) {
182+
return await this.client.updateChannelsBatch({
183+
operation: 'updateData',
184+
filter,
185+
data,
186+
});
187+
}
188+
189+
/**
190+
* addFilterTags - Add filter tags to channels matching the filter
191+
*
192+
* @param {UpdateChannelsBatchFilters} filter Filter to select channels
193+
* @param {string[]} tags Tags to add
194+
* @return {Promise<APIResponse & UpdateChannelsBatchResponse>} The server response
195+
*/
196+
async addFilterTags(filter: UpdateChannelsBatchFilters, tags: string[]) {
197+
return await this.client.updateChannelsBatch({
198+
operation: 'addFilterTags',
199+
filter,
200+
filter_tags_update: tags,
201+
});
202+
}
203+
204+
/**
205+
* removeFilterTags - Remove filter tags from channels matching the filter
206+
*
207+
* @param {UpdateChannelsBatchFilters} filter Filter to select channels
208+
* @param {string[]} tags Tags to remove
209+
* @return {Promise<APIResponse & UpdateChannelsBatchResponse>} The server response
210+
*/
211+
async removeFilterTags(filter: UpdateChannelsBatchFilters, tags: string[]) {
212+
return await this.client.updateChannelsBatch({
213+
operation: 'removeFilterTags',
214+
filter,
215+
filter_tags_update: tags,
216+
});
217+
}
218+
}

src/client.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { CheckSignature, DevToken, JWTUserToken } from './signing';
1313
import { TokenManager } from './token_manager';
1414
import { WSConnectionFallback } from './connection_fallback';
1515
import { Campaign } from './campaign';
16+
import { ChannelBatchUpdater } from './channel_batch_updater';
1617
import { Segment } from './segment';
1718
import { isErrorResponse, isWSFailure } from './errors';
1819
import {
@@ -3718,6 +3719,15 @@ export class StreamChat {
37183719
return new Campaign(this, idOrData, data);
37193720
}
37203721

3722+
/**
3723+
* channelBatchUpdater - Returns a ChannelBatchUpdater instance for batch channel operations
3724+
*
3725+
* @return {ChannelBatchUpdater} A ChannelBatchUpdater instance
3726+
*/
3727+
channelBatchUpdater() {
3728+
return new ChannelBatchUpdater(this);
3729+
}
3730+
37213731
segment(type: SegmentType, idOrData: string | SegmentData, data?: SegmentData) {
37223732
if (typeof idOrData === 'string') {
37233733
return new Segment(this, type, idOrData, data);

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export * from './base64';
22
export * from './campaign';
3+
export * from './channel_batch_updater';
34
export * from './client';
45
export * from './client_state';
56
export * from './channel';

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4490,6 +4490,7 @@ export type UpdateChannelsBatchOptions = {
44904490
filter: UpdateChannelsBatchFilters;
44914491
members?: string[] | Array<NewMemberPayload>;
44924492
data?: BatchChannelDataUpdate;
4493+
filter_tags_update?: string[];
44934494
};
44944495

44954496
export type UpdateChannelsBatchFilters = QueryFilters<{

0 commit comments

Comments
 (0)