|
| 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 | +} |
0 commit comments