Skip to content

Commit

Permalink
Add update options into a couple places for channel (#821)
Browse files Browse the repository at this point in the history
* Add options into a couple places

* Update src/channel.ts

Co-authored-by: Amin Mahboubi <amin@getstream.io>

* Update src/channel.ts

Co-authored-by: Amin Mahboubi <amin@getstream.io>

* Update src/channel.ts

Co-authored-by: Amin Mahboubi <amin@getstream.io>

* Update src/channel.ts

Co-authored-by: Amin Mahboubi <amin@getstream.io>

* Update src/channel.ts

Co-authored-by: Amin Mahboubi <amin@getstream.io>

* fix linter err

Co-authored-by: Amin Mahboubi <amin@getstream.io>
Co-authored-by: Amin Mahboubi <aminmahboobi@gmail.com>
  • Loading branch information
3 people authored Nov 25, 2021
1 parent e613710 commit 7b58eef
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 44 deletions.
80 changes: 36 additions & 44 deletions src/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
ChannelAPIResponse,
ChannelData,
ChannelFilters,
ChannelUpdateOptions,
ChannelMemberAPIResponse,
ChannelMemberResponse,
ChannelQueryOptions,
Expand Down Expand Up @@ -370,13 +371,13 @@ export class Channel<
*
* @param {ChannelData<ChannelType>} channelData The object to update the custom properties of this channel with
* @param {Message<AttachmentType, MessageType, UserType>} [updateMessage] Optional message object for channel members notification
* @param {{ skip_push?: boolean }} [options] Option object, {skip_push: true} to skip sending push notifications
* @param {ChannelUpdateOptions} [options] Option object, configuration to control the behavior while updating
* @return {Promise<UpdateChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} The server response
*/
async update(
channelData: Partial<ChannelData<ChannelType>> | Partial<ChannelResponse<ChannelType, CommandType, UserType>> = {},
updateMessage?: Message<AttachmentType, MessageType, UserType>,
options?: { skip_push?: boolean },
options?: ChannelUpdateOptions,
) {
// Strip out reserved names that will result in API errors.
const reserved = [
Expand Down Expand Up @@ -480,10 +481,7 @@ export class Channel<
async acceptInvite(
options: InviteOptions<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType> = {},
) {
return await this._update({
accept_invite: true,
...options,
});
return await this._update({ accept_invite: true, ...options });
}

/**
Expand All @@ -496,106 +494,103 @@ export class Channel<
async rejectInvite(
options: InviteOptions<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType> = {},
) {
return await this._update({
reject_invite: true,
...options,
});
return await this._update({ reject_invite: true, ...options });
}

/**
* addMembers - add members to the channel
*
* @param {{user_id: string, channel_role?: Role}[]} members An array of members to add to the channel
* @param {Message<AttachmentType, MessageType, UserType>} [message] Optional message object for channel members notification
* @param {{ hide_history?: boolean }} [options] Option object, {hide_history: true} to hide channel's history for new members
* @param {ChannelUpdateOptions} [options] Option object, configuration to control the behavior while updating
* @return {Promise<UpdateChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} The server response
*/
async addMembers(
members: string[] | { user_id: string; channel_role?: Role }[],
message?: Message<AttachmentType, MessageType, UserType>,
options?: { hide_history?: boolean },
options: ChannelUpdateOptions = {},
) {
return await this._update({
add_members: members,
message,
...options,
});
return await this._update({ add_members: members, message, ...options });
}

/**
* addModerators - add moderators to the channel
*
* @param {string[]} members An array of member identifiers
* @param {Message<AttachmentType, MessageType, UserType>} [message] Optional message object for channel members notification
* @param {ChannelUpdateOptions} [options] Option object, configuration to control the behavior while updating
* @return {Promise<UpdateChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} The server response
*/
async addModerators(members: string[], message?: Message<AttachmentType, MessageType, UserType>) {
return await this._update({
add_moderators: members,
message,
});
async addModerators(
members: string[],
message?: Message<AttachmentType, MessageType, UserType>,
options: ChannelUpdateOptions = {},
) {
return await this._update({ add_moderators: members, message, ...options });
}

/**
* assignRoles - sets member roles in a channel
*
* @param {{channel_role: Role, user_id: string}[]} roles List of role assignments
* @param {Message<AttachmentType, MessageType, UserType>} [message] Optional message object for channel members notification
* @param {ChannelUpdateOptions} [options] Option object, configuration to control the behavior while updating
* @return {Promise<UpdateChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} The server response
*/
async assignRoles(
roles: { channel_role: Role; user_id: string }[],
message?: Message<AttachmentType, MessageType, UserType>,
options: ChannelUpdateOptions = {},
) {
return await this._update({
assign_roles: roles,
message,
});
return await this._update({ assign_roles: roles, message, ...options });
}

/**
* inviteMembers - invite members to the channel
*
* @param {{user_id: string, channel_role?: Role}[]} members An array of members to invite to the channel
* @param {Message<AttachmentType, MessageType, UserType>} [message] Optional message object for channel members notification
* @param {ChannelUpdateOptions} [options] Option object, configuration to control the behavior while updating
* @return {Promise<UpdateChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} The server response
*/
async inviteMembers(
members: { user_id: string; channel_role?: Role }[] | string[],
message?: Message<AttachmentType, MessageType, UserType>,
options: ChannelUpdateOptions = {},
) {
return await this._update({
invites: members,
message,
});
return await this._update({ invites: members, message, ...options });
}

/**
* removeMembers - remove members from channel
*
* @param {string[]} members An array of member identifiers
* @param {Message<AttachmentType, MessageType, UserType>} [message] Optional message object for channel members notification
* @param {ChannelUpdateOptions} [options] Option object, configuration to control the behavior while updating
* @return {Promise<UpdateChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} The server response
*/
async removeMembers(members: string[], message?: Message<AttachmentType, MessageType, UserType>) {
return await this._update({
remove_members: members,
message,
});
async removeMembers(
members: string[],
message?: Message<AttachmentType, MessageType, UserType>,
options: ChannelUpdateOptions = {},
) {
return await this._update({ remove_members: members, message, ...options });
}

/**
* demoteModerators - remove moderator role from channel members
*
* @param {string[]} members An array of member identifiers
* @param {Message<AttachmentType, MessageType, UserType>} [message] Optional message object for channel members notification
* @param {ChannelUpdateOptions} [options] Option object, configuration to control the behavior while updating
* @return {Promise<UpdateChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} The server response
*/
async demoteModerators(members: string[], message?: Message<AttachmentType, MessageType, UserType>) {
return await this._update({
demote_moderators: members,
message,
});
async demoteModerators(
members: string[],
message?: Message<AttachmentType, MessageType, UserType>,
options: ChannelUpdateOptions = {},
) {
return await this._update({ demote_moderators: members, message, ...options });
}

/**
Expand Down Expand Up @@ -627,10 +622,7 @@ export class Channel<
async mute(opts: { expiration?: number; user_id?: string } = {}) {
return await this.getClient().post<MuteChannelAPIResponse<ChannelType, CommandType, UserType>>(
this.getClient().baseURL + '/moderation/mute/channel',
{
channel_cid: this.cid,
...opts,
},
{ channel_cid: this.cid, ...opts },
);
}

Expand Down
5 changes: 5 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ export type ChannelAPIResponse<
watchers?: UserResponse<UserType>[];
};

export type ChannelUpdateOptions = {
hide_history?: boolean;
skip_push?: boolean;
};

export type ChannelMemberAPIResponse<UserType = UR> = APIResponse & {
members: ChannelMemberResponse<UserType>[];
};
Expand Down

0 comments on commit 7b58eef

Please sign in to comment.