Skip to content
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

[FIX] Block user action #18950

Merged
merged 1 commit into from
Sep 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 33 additions & 13 deletions client/channel/hooks/useUserInfoActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,23 +128,25 @@ export const useUserInfoActions = (user = {}, rid) => {

const roomConfig = room && room.t && roomTypes.getConfig(room.t);

const {
const [
roomCanSetOwner,
roomCanSetLeader,
roomCanSetModerator,
roomCanIgnore,
roomCanBlock,
roomCanMute,
roomCanRemove,
} = {
...roomConfig && {
roomCanSetOwner: roomConfig.allowMemberAction(room, RoomMemberActions.SET_AS_OWNER),
roomCanSetLeader: roomConfig.allowMemberAction(room, RoomMemberActions.SET_AS_LEADER),
roomCanSetModerator: roomConfig.allowMemberAction(room, RoomMemberActions.SET_AS_MODERATOR),
roomCanBlock: roomConfig.allowMemberAction(room, RoomMemberActions.IGNORE),
roomCanMute: roomConfig.allowMemberAction(room, RoomMemberActions.MUTE),
roomCanRemove: roomConfig.allowMemberAction(room, RoomMemberActions.REMOVE_USER),
},
};
] = [
...roomConfig && [
roomConfig.allowMemberAction(room, RoomMemberActions.SET_AS_OWNER),
roomConfig.allowMemberAction(room, RoomMemberActions.SET_AS_LEADER),
roomConfig.allowMemberAction(room, RoomMemberActions.SET_AS_MODERATOR),
roomConfig.allowMemberAction(room, RoomMemberActions.IGNORE),
roomConfig.allowMemberAction(room, RoomMemberActions.BLOCK),
roomConfig.allowMemberAction(room, RoomMemberActions.MUTE),
roomConfig.allowMemberAction(room, RoomMemberActions.REMOVE_USER),
],
];

const roomName = room && room.t && s.escapeHTML(roomTypes.getRoomName(room.t, room));

Expand Down Expand Up @@ -240,11 +242,27 @@ export const useUserInfoActions = (user = {}, rid) => {
dispatchToastMessage({ type: 'error', message: error });
}
});
const ignoreUserOption = useMemo(() => roomCanBlock && uid !== ownUserId && {
const ignoreUserOption = useMemo(() => roomCanIgnore && uid !== ownUserId && {
label: t(isIgnored ? 'Unignore' : 'Ignore'),
icon: 'ban',
action: ignoreUserAction,
}, [ignoreUserAction, isIgnored, ownUserId, roomCanBlock, t, uid]);
}, [ignoreUserAction, isIgnored, ownUserId, roomCanIgnore, t, uid]);

const isUserBlocked = currentSubscription.blocker;
const toggleBlock = useMethod(isUserBlocked ? 'unblockUser' : 'blockUser');
const toggleBlockUserAction = useMutableCallback(async () => {
try {
await toggleBlock({ rid, blocked: uid });
dispatchToastMessage({ type: 'success', message: t(isUserBlocked ? 'User_is_unblocked' : 'User_is_blocked') });
} catch (error) {
dispatchToastMessage({ type: 'error', message: error });
}
});
const toggleBlockUserOption = useMemo(() => roomCanBlock && uid !== ownUserId && {
label: t(isUserBlocked ? 'Unblock' : 'Block'),
icon: 'ban',
action: toggleBlockUserAction,
}, [isUserBlocked, ownUserId, roomCanBlock, t, toggleBlockUserAction, uid]);

const muteFn = useMethod(isMuted ? 'unmuteUserInRoom' : 'muteUserInRoom');
const muteUserOption = useMemo(() => {
Expand Down Expand Up @@ -311,6 +329,7 @@ export const useUserInfoActions = (user = {}, rid) => {
...ignoreUserOption && { ignoreUser: ignoreUserOption },
...muteUserOption && { muteUser: muteUserOption },
...removeUserOption && { removeUser: removeUserOption },
...toggleBlockUserOption && { toggleBlock: toggleBlockUserOption },
}),
[
audioCallOption,
Expand All @@ -322,5 +341,6 @@ export const useUserInfoActions = (user = {}, rid) => {
openDirectMessageOption,
removeUserOption,
videoCallOption,
toggleBlockUserOption,
]);
};