Skip to content

Commit f5de700

Browse files
committed
feat: add blockedUsers state to StreamChat class
1 parent 91f6758 commit f5de700

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/client.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ type MessageComposerSetupFunction = ({
273273
composer: MessageComposer;
274274
}) => void | MessageComposerTearDownFunction;
275275

276+
export type BlockedUsersState = { userIds: string[] };
277+
276278
export type MessageComposerSetupState = {
277279
/**
278280
* Each `MessageComposer` runs this function each time its signature changes or
@@ -322,6 +324,7 @@ export class StreamChat {
322324
moderation: Moderation;
323325
mutedChannels: ChannelMute[];
324326
mutedUsers: Mute[];
327+
blockedUsers: StateStore<BlockedUsersState>;
325328
node: boolean;
326329
options: StreamChatOptions;
327330
secret?: string;
@@ -382,6 +385,7 @@ export class StreamChat {
382385
// a list of channels to hide ws events from
383386
this.mutedChannels = [];
384387
this.mutedUsers = [];
388+
this.blockedUsers = new StateStore<BlockedUsersState>({ userIds: [] });
385389

386390
this.moderation = new Moderation(this);
387391

@@ -1547,6 +1551,7 @@ export class StreamChat {
15471551
client.state.updateUser(event.me);
15481552
client.mutedChannels = event.me.channel_mutes;
15491553
client.mutedUsers = event.me.mutes;
1554+
client.blockedUsers.partialNext({ userIds: event.me.blocked_user_ids ?? [] });
15501555
}
15511556

15521557
if (event.channel && event.type === 'notification.message_new') {
@@ -2637,10 +2642,12 @@ export class StreamChat {
26372642
});
26382643
}
26392644
async blockUser(blockedUserID: string, user_id?: string) {
2640-
return await this.post<BlockUserAPIResponse>(this.baseURL + '/users/block', {
2645+
const result = await this.post<BlockUserAPIResponse>(this.baseURL + '/users/block', {
26412646
blocked_user_id: blockedUserID,
26422647
...(user_id ? { user_id } : {}),
26432648
});
2649+
this.blockedUsers.next(({ userIds }) => ({ userIds: userIds.concat(blockedUserID) }));
2650+
return result;
26442651
}
26452652

26462653
async getBlockedUsers(user_id?: string) {
@@ -2650,10 +2657,14 @@ export class StreamChat {
26502657
}
26512658

26522659
async unBlockUser(blockedUserID: string, userID?: string) {
2653-
return await this.post<APIResponse>(this.baseURL + '/users/unblock', {
2660+
const result = await this.post<APIResponse>(this.baseURL + '/users/unblock', {
26542661
blocked_user_id: blockedUserID,
26552662
...(userID ? { user_id: userID } : {}),
26562663
});
2664+
this.blockedUsers.next(({ userIds }) => ({
2665+
userIds: userIds.filter((id) => id !== blockedUserID),
2666+
}));
2667+
return result;
26572668
}
26582669

26592670
/** getSharedLocations

0 commit comments

Comments
 (0)