-
Notifications
You must be signed in to change notification settings - Fork 78
feat: batch channel updates #1656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
efa18bd
72008f8
ba42acc
10a6ab5
6d97dee
5d76dfb
25fb44f
b21d638
abab045
bd11ab9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,247 @@ | ||
| import type { StreamChat } from './client'; | ||
| import type { | ||
| APIResponse, | ||
| BatchChannelDataUpdate, | ||
| NewMemberPayload, | ||
| UpdateChannelsBatchFilters, | ||
| UpdateChannelsBatchResponse, | ||
| } from './types'; | ||
|
|
||
| /** | ||
| * ChannelBatchUpdater - A class that provides convenience methods for batch channel operations | ||
| */ | ||
| export class ChannelBatchUpdater { | ||
| client: StreamChat; | ||
|
|
||
| constructor(client: StreamChat) { | ||
| this.client = client; | ||
| } | ||
|
|
||
| // Member operations | ||
|
|
||
| /** | ||
| * addMembers - Add members to channels matching the filter | ||
| * | ||
| * @param {UpdateChannelsBatchFilters} filter Filter to select channels | ||
| * @param {string[] | NewMemberPayload[]} members Members to add | ||
| * @return {Promise<APIResponse & UpdateChannelsBatchResponse>} The server response | ||
| */ | ||
| async addMembers( | ||
| filter: UpdateChannelsBatchFilters, | ||
| members: string[] | NewMemberPayload[], | ||
| ): Promise<APIResponse & UpdateChannelsBatchResponse> { | ||
| return await this.client.updateChannelsBatch({ | ||
| operation: 'addMembers', | ||
| filter, | ||
| members, | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * removeMembers - Remove members from channels matching the filter | ||
| * | ||
| * @param {UpdateChannelsBatchFilters} filter Filter to select channels | ||
| * @param {string[]} members Member IDs to remove | ||
| * @return {Promise<APIResponse & UpdateChannelsBatchResponse>} The server response | ||
| */ | ||
| async removeMembers( | ||
| filter: UpdateChannelsBatchFilters, | ||
| members: string[], | ||
| ): Promise<APIResponse & UpdateChannelsBatchResponse> { | ||
| return await this.client.updateChannelsBatch({ | ||
| operation: 'removeMembers', | ||
| filter, | ||
| members, | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * inviteMembers - Invite members to channels matching the filter | ||
| * | ||
| * @param {UpdateChannelsBatchFilters} filter Filter to select channels | ||
| * @param {string[] | NewMemberPayload[]} members Members to invite | ||
| * @return {Promise<APIResponse & UpdateChannelsBatchResponse>} The server response | ||
| */ | ||
| async inviteMembers( | ||
| filter: UpdateChannelsBatchFilters, | ||
| members: string[] | NewMemberPayload[], | ||
| ): Promise<APIResponse & UpdateChannelsBatchResponse> { | ||
| return await this.client.updateChannelsBatch({ | ||
| operation: 'invites', | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if possible, but to be consistent with removeMembers, the operation should be called
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @javierdfm can answer this more properly, but I think the idea is it should be something clear with the abstraction layer for example: channel.inviteMembers() -> client.updateChannelsBatch() the operation will be the "user level" layer and the string indicating the operation will be more internal |
||
| filter, | ||
| members, | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * addModerators - Add moderators to channels matching the filter | ||
| * | ||
| * @param {UpdateChannelsBatchFilters} filter Filter to select channels | ||
| * @param {string[]} members Member IDs to promote to moderator | ||
| * @return {Promise<APIResponse & UpdateChannelsBatchResponse>} The server response | ||
| */ | ||
| async addModerators( | ||
| filter: UpdateChannelsBatchFilters, | ||
| members: string[], | ||
| ): Promise<APIResponse & UpdateChannelsBatchResponse> { | ||
| return await this.client.updateChannelsBatch({ | ||
| operation: 'addModerators', | ||
| filter, | ||
| members, | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * demoteModerators - Remove moderator role from members in channels matching the filter | ||
| * | ||
| * @param {UpdateChannelsBatchFilters} filter Filter to select channels | ||
| * @param {string[]} members Member IDs to demote | ||
| * @return {Promise<APIResponse & UpdateChannelsBatchResponse>} The server response | ||
| */ | ||
| async demoteModerators( | ||
| filter: UpdateChannelsBatchFilters, | ||
| members: string[], | ||
| ): Promise<APIResponse & UpdateChannelsBatchResponse> { | ||
| return await this.client.updateChannelsBatch({ | ||
| operation: 'demoteModerators', | ||
| filter, | ||
| members, | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * assignRoles - Assign roles to members in channels matching the filter | ||
| * | ||
| * @param {UpdateChannelsBatchFilters} filter Filter to select channels | ||
| * @param {NewMemberPayload[]} members Members with role assignments | ||
| * @return {Promise<APIResponse & UpdateChannelsBatchResponse>} The server response | ||
| */ | ||
| async assignRoles( | ||
| filter: UpdateChannelsBatchFilters, | ||
| members: NewMemberPayload[], | ||
| ): Promise<APIResponse & UpdateChannelsBatchResponse> { | ||
| return await this.client.updateChannelsBatch({ | ||
| operation: 'assignRoles', | ||
| filter, | ||
| members, | ||
| }); | ||
| } | ||
|
|
||
| // Visibility operations | ||
|
|
||
| /** | ||
| * hide - Hide channels matching the filter | ||
| * | ||
| * @param {UpdateChannelsBatchFilters} filter Filter to select channels | ||
| * @return {Promise<APIResponse & UpdateChannelsBatchResponse>} The server response | ||
| */ | ||
| async hide( | ||
| filter: UpdateChannelsBatchFilters, | ||
| ): Promise<APIResponse & UpdateChannelsBatchResponse> { | ||
| return await this.client.updateChannelsBatch({ | ||
| operation: 'hide', | ||
| filter, | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * show - Show channels matching the filter | ||
| * | ||
| * @param {UpdateChannelsBatchFilters} filter Filter to select channels | ||
| * @return {Promise<APIResponse & UpdateChannelsBatchResponse>} The server response | ||
| */ | ||
| async show( | ||
| filter: UpdateChannelsBatchFilters, | ||
| ): Promise<APIResponse & UpdateChannelsBatchResponse> { | ||
| return await this.client.updateChannelsBatch({ | ||
| operation: 'show', | ||
| filter, | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * archive - Archive channels matching the filter | ||
| * | ||
| * @param {UpdateChannelsBatchFilters} filter Filter to select channels | ||
| * @return {Promise<APIResponse & UpdateChannelsBatchResponse>} The server response | ||
| */ | ||
| async archive( | ||
| filter: UpdateChannelsBatchFilters, | ||
| ): Promise<APIResponse & UpdateChannelsBatchResponse> { | ||
| return await this.client.updateChannelsBatch({ | ||
| operation: 'archive', | ||
| filter, | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * unarchive - Unarchive channels matching the filter | ||
| * | ||
| * @param {UpdateChannelsBatchFilters} filter Filter to select channels | ||
| * @return {Promise<APIResponse & UpdateChannelsBatchResponse>} The server response | ||
| */ | ||
| async unarchive( | ||
| filter: UpdateChannelsBatchFilters, | ||
| ): Promise<APIResponse & UpdateChannelsBatchResponse> { | ||
| return await this.client.updateChannelsBatch({ | ||
| operation: 'unarchive', | ||
| filter, | ||
| }); | ||
| } | ||
|
|
||
| // Data operations | ||
|
|
||
| /** | ||
| * updateData - Update data on channels matching the filter | ||
| * | ||
| * @param {UpdateChannelsBatchFilters} filter Filter to select channels | ||
| * @param {BatchChannelDataUpdate} data Data to update | ||
| * @return {Promise<APIResponse & UpdateChannelsBatchResponse>} The server response | ||
| */ | ||
| async updateData( | ||
| filter: UpdateChannelsBatchFilters, | ||
| data: BatchChannelDataUpdate, | ||
| ): Promise<APIResponse & UpdateChannelsBatchResponse> { | ||
| return await this.client.updateChannelsBatch({ | ||
| operation: 'updateData', | ||
| filter, | ||
| data, | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * addFilterTags - Add filter tags to channels matching the filter | ||
| * | ||
| * @param {UpdateChannelsBatchFilters} filter Filter to select channels | ||
| * @param {string[]} tags Tags to add | ||
| * @return {Promise<APIResponse & UpdateChannelsBatchResponse>} The server response | ||
| */ | ||
| async addFilterTags( | ||
| filter: UpdateChannelsBatchFilters, | ||
| tags: string[], | ||
| ): Promise<APIResponse & UpdateChannelsBatchResponse> { | ||
| return await this.client.updateChannelsBatch({ | ||
| operation: 'addFilterTags', | ||
| filter, | ||
| filter_tags_update: tags, | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * removeFilterTags - Remove filter tags from channels matching the filter | ||
| * | ||
| * @param {UpdateChannelsBatchFilters} filter Filter to select channels | ||
| * @param {string[]} tags Tags to remove | ||
| * @return {Promise<APIResponse & UpdateChannelsBatchResponse>} The server response | ||
| */ | ||
| async removeFilterTags( | ||
| filter: UpdateChannelsBatchFilters, | ||
| tags: string[], | ||
| ): Promise<APIResponse & UpdateChannelsBatchResponse> { | ||
| return await this.client.updateChannelsBatch({ | ||
| operation: 'removeFilterTags', | ||
| filter, | ||
| filter_tags_update: tags, | ||
| }); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a question. What happens under the hood, when we call inviteMembers? How does it differ from addMembers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have this two options, or just add the member "without permission" or invite the member, this second one needs the member agree with that, the user can disagree and will not be added as a member