Skip to content

Commit

Permalink
feat: block user endpoints (#1314)
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmeadi committed Jun 4, 2024
1 parent 74c8599 commit 1be14f7
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
BaseDeviceFields,
BlockList,
BlockListResponse,
BlockUserAPIResponse,
CampaignResponse,
CampaignData,
CampaignFilters,
Expand Down Expand Up @@ -179,6 +180,7 @@ import {
QuerySegmentTargetsFilter,
SortParam,
GetMessageOptions,
GetBlockedUsersAPIResponse,
QueryVotesFilters,
VoteSort,
CreatePollAPIResponse,
Expand Down Expand Up @@ -2188,7 +2190,24 @@ export class StreamChat<StreamChatGenerics extends ExtendableGenerics = DefaultG
...options,
});
}
async blockUser(blockedUserID: string, user_id?: string) {
return await this.post<BlockUserAPIResponse>(this.baseURL + '/users/block', {
blocked_user_id: blockedUserID,
...(user_id ? { user_id } : {}),
});
}

async getBlockedUsers(user_id?: string) {
return await this.get<GetBlockedUsersAPIResponse>(this.baseURL + '/users/block', {
...(user_id ? { user_id } : {}),
});
}
async unBlockUser(blockedUserID: string, userID?: string) {
return await this.post<APIResponse>(this.baseURL + '/users/unblock', {
blocked_user_id: blockedUserID,
...(userID ? { user_id: userID } : {}),
});
}
/** muteUser - mutes a user
*
* @param {string} targetID
Expand Down
25 changes: 25 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,30 @@ export type MuteUserResponse<StreamChatGenerics extends ExtendableGenerics = Def
own_user?: OwnUserResponse<StreamChatGenerics>;
};

export type BlockUserResponse = APIResponse & {
blocked_at: string;
blocked_by_user_id: string;
blocked_user_id: string;
};

export type BlockUserAPIResponse = APIResponse & {
blocked_users: BlockUserResponse[];
};

export type GetBlockedUsersAPIResponse = APIResponse & {
blocks: BlockedUser[];
};
export type BlockedUser = APIResponse & {
blocked_user: UserResponse;
blocked_user_id: string;

created_at: string;

user: UserResponse;

user_id: string;
};

export type OwnUserBase<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = {
channel_mutes: ChannelMute<StreamChatGenerics>[];
devices: Device<StreamChatGenerics>[];
Expand Down Expand Up @@ -2040,6 +2064,7 @@ export type ChannelConfigWithInfo<
export type ChannelData<
StreamChatGenerics extends ExtendableGenerics = DefaultGenerics
> = StreamChatGenerics['channelType'] & {
blocked?: boolean;
members?: string[];
name?: string;
};
Expand Down

0 comments on commit 1be14f7

Please sign in to comment.