snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
import type { IRoom, IUser } from '@rocket.chat/core-typings';
|
||||
import { isRoomFederated, isRoomNativeFederated } from '@rocket.chat/core-typings';
|
||||
import { useStableCallback } from '@rocket.chat/fuselage-hooks';
|
||||
import {
|
||||
useTranslation,
|
||||
useUser,
|
||||
useUserRoom,
|
||||
useUserSubscription,
|
||||
useToastMessageDispatch,
|
||||
useAtLeastOnePermission,
|
||||
useEndpoint,
|
||||
} from '@rocket.chat/ui-contexts';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
import * as Federation from '../../../../../lib/federation/Federation';
|
||||
import { useAddMatrixUsers } from '../../../contextualBar/RoomMembers/AddUsers/AddMatrixUsers/useAddMatrixUsers';
|
||||
import { getRoomDirectives } from '../../../lib/getRoomDirectives';
|
||||
import type { UserInfoAction } from '../useUserInfoActions';
|
||||
|
||||
const inviteUserEndpoints = {
|
||||
c: '/v1/channels.invite',
|
||||
p: '/v1/groups.invite',
|
||||
} as const;
|
||||
|
||||
export const useAddUserAction = (
|
||||
user: Pick<IUser, '_id' | 'username'>,
|
||||
rid: IRoom['_id'],
|
||||
reload?: () => void,
|
||||
): UserInfoAction | undefined => {
|
||||
const t = useTranslation();
|
||||
const room = useUserRoom(rid);
|
||||
const currentUser = useUser();
|
||||
const subscription = useUserSubscription(rid);
|
||||
const dispatchToastMessage = useToastMessageDispatch();
|
||||
|
||||
const { username, _id: uid } = user;
|
||||
|
||||
if (!room) {
|
||||
throw Error('Room not provided');
|
||||
}
|
||||
|
||||
const hasPermissionToAddUsers = useAtLeastOnePermission(
|
||||
useMemo(() => [room?.t === 'p' ? 'add-user-to-any-p-room' : 'add-user-to-any-c-room', 'add-user-to-joined-room'], [room?.t]),
|
||||
rid,
|
||||
);
|
||||
|
||||
const roomIsFederated = isRoomFederated(room);
|
||||
|
||||
const isFederationBlocked = room && !isRoomNativeFederated(room);
|
||||
|
||||
const userCanAdd =
|
||||
room && user && roomIsFederated
|
||||
? !isFederationBlocked && Federation.isEditableByTheUser(currentUser || undefined, room, subscription)
|
||||
: hasPermissionToAddUsers;
|
||||
|
||||
const { roomCanInvite } = getRoomDirectives({ room, showingUserId: uid, userSubscription: subscription });
|
||||
|
||||
const inviteUser = useEndpoint('POST', inviteUserEndpoints[room.t === 'p' ? 'p' : 'c']);
|
||||
|
||||
const handleAddUser = useStableCallback(async ({ users }: { users: string[] }) => {
|
||||
const [username] = users;
|
||||
await inviteUser({ roomId: rid, username });
|
||||
reload?.();
|
||||
});
|
||||
|
||||
const addClickHandler = useAddMatrixUsers();
|
||||
|
||||
const addUserOptionAction = useStableCallback(async () => {
|
||||
try {
|
||||
const users = [username as string];
|
||||
if (isRoomFederated(room)) {
|
||||
addClickHandler.mutate({
|
||||
users,
|
||||
handleSave: handleAddUser,
|
||||
});
|
||||
} else {
|
||||
await handleAddUser({ users });
|
||||
}
|
||||
dispatchToastMessage({ type: 'success', message: t('User_added') });
|
||||
} catch (error) {
|
||||
dispatchToastMessage({ type: 'error', message: error as Error });
|
||||
}
|
||||
});
|
||||
|
||||
const addUserOption = useMemo(
|
||||
() =>
|
||||
roomCanInvite && userCanAdd && room.archived !== true
|
||||
? {
|
||||
content: t('add-to-room'),
|
||||
icon: 'user-plus' as const,
|
||||
onClick: addUserOptionAction,
|
||||
type: 'management' as const,
|
||||
}
|
||||
: undefined,
|
||||
[roomCanInvite, userCanAdd, room.archived, t, addUserOptionAction],
|
||||
);
|
||||
|
||||
return addUserOption;
|
||||
};
|
||||
@@ -0,0 +1,44 @@
|
||||
import type { IRoom, IUser } from '@rocket.chat/core-typings';
|
||||
import { usePermission, useUserRoom, useUserSubscription } from '@rocket.chat/ui-contexts';
|
||||
import { useMemo } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { getRoomDirectives } from '../../../lib/getRoomDirectives';
|
||||
import { useBanUser } from '../../useBanUser';
|
||||
import type { UserInfoAction } from '../useUserInfoActions';
|
||||
|
||||
export const useBanUserAction = (user: Pick<IUser, '_id' | 'username'>, roomId: IRoom['_id']): UserInfoAction | undefined => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const room = useUserRoom(roomId);
|
||||
const subscription = useUserSubscription(roomId);
|
||||
|
||||
if (!room) {
|
||||
throw new Error('error-invalid-room');
|
||||
}
|
||||
|
||||
if (!user.username) {
|
||||
throw new Error('error-invalid-username');
|
||||
}
|
||||
|
||||
const { _id: uid, username } = user;
|
||||
const hasPermissionToBan = usePermission('ban-user', roomId);
|
||||
|
||||
const { roomCanBan } = getRoomDirectives({ room, showingUserId: uid, userSubscription: subscription });
|
||||
|
||||
const handleBan = useBanUser({ roomId });
|
||||
|
||||
return useMemo(() => {
|
||||
if (!hasPermissionToBan || !roomCanBan) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return {
|
||||
content: t('Ban_user_from_room'),
|
||||
icon: 'ban' as const,
|
||||
onClick: () => handleBan(username),
|
||||
type: 'moderation' as const,
|
||||
variant: 'danger' as const,
|
||||
};
|
||||
}, [handleBan, roomCanBan, hasPermissionToBan, t, username]);
|
||||
};
|
||||
@@ -0,0 +1,58 @@
|
||||
import type { IRoom, IUser } from '@rocket.chat/core-typings';
|
||||
import { useStableCallback } from '@rocket.chat/fuselage-hooks';
|
||||
import {
|
||||
useTranslation,
|
||||
useEndpoint,
|
||||
useToastMessageDispatch,
|
||||
useUserId,
|
||||
useUserSubscription,
|
||||
useUserRoom,
|
||||
} from '@rocket.chat/ui-contexts';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
import { getRoomDirectives } from '../../../lib/getRoomDirectives';
|
||||
import type { UserInfoAction } from '../useUserInfoActions';
|
||||
|
||||
export const useBlockUserAction = (user: Pick<IUser, '_id' | 'username'>, rid: IRoom['_id']): UserInfoAction | undefined => {
|
||||
const t = useTranslation();
|
||||
const dispatchToastMessage = useToastMessageDispatch();
|
||||
const currentSubscription = useUserSubscription(rid);
|
||||
const ownUserId = useUserId();
|
||||
const { _id: uid } = user;
|
||||
const room = useUserRoom(rid);
|
||||
|
||||
if (!room) {
|
||||
throw Error('Room not provided');
|
||||
}
|
||||
|
||||
const { roomCanBlock } = getRoomDirectives({ room, showingUserId: uid, userSubscription: currentSubscription });
|
||||
|
||||
const isUserBlocked = Boolean(currentSubscription?.blocker);
|
||||
const toggleBlockUser = useEndpoint('POST', '/v1/im.blockUser');
|
||||
|
||||
const toggleBlockUserAction = useStableCallback(async () => {
|
||||
try {
|
||||
await toggleBlockUser({ roomId: rid, block: !isUserBlocked });
|
||||
dispatchToastMessage({
|
||||
type: 'success',
|
||||
message: t(isUserBlocked ? 'User_is_unblocked' : 'User_is_blocked'),
|
||||
});
|
||||
} catch (error: unknown) {
|
||||
dispatchToastMessage({ type: 'error', message: error });
|
||||
}
|
||||
});
|
||||
|
||||
const toggleBlockUserOption = useMemo(
|
||||
() =>
|
||||
roomCanBlock && uid !== ownUserId
|
||||
? {
|
||||
content: t(isUserBlocked ? 'Unblock' : 'Block'),
|
||||
icon: 'ban' as const,
|
||||
onClick: toggleBlockUserAction,
|
||||
}
|
||||
: undefined,
|
||||
[isUserBlocked, ownUserId, roomCanBlock, t, toggleBlockUserAction, uid],
|
||||
);
|
||||
|
||||
return toggleBlockUserOption;
|
||||
};
|
||||
@@ -0,0 +1,72 @@
|
||||
import type { IRoom, IUser } from '@rocket.chat/core-typings';
|
||||
import { useStableCallback } from '@rocket.chat/fuselage-hooks';
|
||||
import {
|
||||
useTranslation,
|
||||
usePermission,
|
||||
useUserRoom,
|
||||
useUserSubscription,
|
||||
useEndpoint,
|
||||
useToastMessageDispatch,
|
||||
} from '@rocket.chat/ui-contexts';
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
import { getRoomDirectives } from '../../../lib/getRoomDirectives';
|
||||
import { useUserHasRoomRole } from '../../useUserHasRoomRole';
|
||||
import type { UserInfoAction, UserInfoActionType } from '../useUserInfoActions';
|
||||
|
||||
const getEndpoint = (roomType: string, isLeader: boolean) => {
|
||||
if (roomType === 'p') {
|
||||
return isLeader ? '/v1/groups.removeLeader' : '/v1/groups.addLeader';
|
||||
}
|
||||
return isLeader ? '/v1/channels.removeLeader' : '/v1/channels.addLeader';
|
||||
};
|
||||
|
||||
export const useChangeLeaderAction = (user: Pick<IUser, '_id' | 'username'>, rid: IRoom['_id']): UserInfoAction | undefined => {
|
||||
const t = useTranslation();
|
||||
const room = useUserRoom(rid);
|
||||
const { _id: uid, username } = user;
|
||||
const userCanSetLeader = usePermission('set-leader', rid);
|
||||
const userSubscription = useUserSubscription(rid);
|
||||
const dispatchToastMessage = useToastMessageDispatch();
|
||||
|
||||
if (!room) {
|
||||
throw Error('Room not provided');
|
||||
}
|
||||
|
||||
const { roomCanSetLeader } = getRoomDirectives({ room, showingUserId: uid, userSubscription });
|
||||
const isLeader = useUserHasRoomRole(uid, rid, 'leader');
|
||||
|
||||
const toggleLeaderEndpoint = useEndpoint('POST', getEndpoint(room.t, isLeader));
|
||||
|
||||
const toggleOwnerMutation = useMutation({
|
||||
mutationFn: async ({ roomId, userId }: { roomId: string; userId: string }) => {
|
||||
await toggleLeaderEndpoint({ roomId, userId });
|
||||
|
||||
return t(isLeader ? 'removed__username__as__role_' : 'set__username__as__role_', { username, role: 'leader' });
|
||||
},
|
||||
onSuccess: (message) => {
|
||||
dispatchToastMessage({ type: 'success', message });
|
||||
},
|
||||
onError: (error) => {
|
||||
dispatchToastMessage({ type: 'error', message: error });
|
||||
},
|
||||
});
|
||||
|
||||
const changeLeaderAction = useStableCallback(async () => toggleOwnerMutation.mutateAsync({ roomId: rid, userId: uid }));
|
||||
|
||||
const changeLeaderOption = useMemo(
|
||||
() =>
|
||||
roomCanSetLeader && userCanSetLeader
|
||||
? {
|
||||
content: t(isLeader ? 'Remove_as_leader' : 'Set_as_leader'),
|
||||
icon: 'shield-alt' as const,
|
||||
onClick: changeLeaderAction,
|
||||
type: 'privileges' as UserInfoActionType,
|
||||
}
|
||||
: undefined,
|
||||
[isLeader, roomCanSetLeader, t, userCanSetLeader, changeLeaderAction],
|
||||
);
|
||||
|
||||
return changeLeaderOption;
|
||||
};
|
||||
@@ -0,0 +1,163 @@
|
||||
import type { IRoom, IUser } from '@rocket.chat/core-typings';
|
||||
import { isRoomFederated, isRoomNativeFederated } from '@rocket.chat/core-typings';
|
||||
import { useStableCallback } from '@rocket.chat/fuselage-hooks';
|
||||
import { escapeHTML } from '@rocket.chat/tools';
|
||||
import { GenericModal } from '@rocket.chat/ui-client';
|
||||
import {
|
||||
useTranslation,
|
||||
usePermission,
|
||||
useUserRoom,
|
||||
useUserSubscription,
|
||||
useUser,
|
||||
useSetModal,
|
||||
useEndpoint,
|
||||
useToastMessageDispatch,
|
||||
} from '@rocket.chat/ui-contexts';
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
|
||||
import { roomCoordinator } from '../../../../../lib/rooms/roomCoordinator';
|
||||
import { getRoomDirectives } from '../../../lib/getRoomDirectives';
|
||||
import { useUserHasRoomRole } from '../../useUserHasRoomRole';
|
||||
import type { UserInfoAction, UserInfoActionType } from '../useUserInfoActions';
|
||||
|
||||
const getWarningModalForFederatedRooms = (
|
||||
closeModalFn: () => void,
|
||||
handleConfirmFn: () => void,
|
||||
title: string,
|
||||
confirmText: string,
|
||||
bodyText: string,
|
||||
) => (
|
||||
<GenericModal
|
||||
variant='warning'
|
||||
onClose={closeModalFn}
|
||||
onConfirm={handleConfirmFn}
|
||||
onCancel={closeModalFn}
|
||||
title={title}
|
||||
confirmText={confirmText}
|
||||
>
|
||||
{bodyText}
|
||||
</GenericModal>
|
||||
);
|
||||
|
||||
const getEndpoint = (roomType: string, isModerator: boolean) => {
|
||||
if (roomType === 'p') {
|
||||
return isModerator ? '/v1/groups.removeModerator' : '/v1/groups.addModerator';
|
||||
}
|
||||
return isModerator ? '/v1/channels.removeModerator' : '/v1/channels.addModerator';
|
||||
};
|
||||
|
||||
export const useChangeModeratorAction = (user: Pick<IUser, '_id' | 'username'>, rid: IRoom['_id']): UserInfoAction | undefined => {
|
||||
const t = useTranslation();
|
||||
const room = useUserRoom(rid);
|
||||
const { _id: uid } = user;
|
||||
|
||||
const userCanSetModerator = usePermission('set-moderator', rid);
|
||||
const isModerator = useUserHasRoomRole(uid, rid, 'moderator');
|
||||
const userSubscription = useUserSubscription(rid);
|
||||
const { _id: loggedUserId = '' } = useUser() || {};
|
||||
const loggedUserIsModerator = useUserHasRoomRole(loggedUserId, rid, 'moderator');
|
||||
const loggedUserIsOwner = useUserHasRoomRole(loggedUserId, rid, 'owner');
|
||||
const setModal = useSetModal();
|
||||
const dispatchToastMessage = useToastMessageDispatch();
|
||||
|
||||
if (!room) {
|
||||
throw Error('Room not provided');
|
||||
}
|
||||
|
||||
const { roomCanSetModerator } = getRoomDirectives({ room, showingUserId: uid, userSubscription });
|
||||
const roomName = room?.t && escapeHTML(roomCoordinator.getRoomName(room.t, room));
|
||||
|
||||
const toggleModeratorEndpoint = useEndpoint('POST', getEndpoint(room.t, isModerator));
|
||||
const toggleModerator = useMutation({
|
||||
mutationFn: async ({ roomId, userId }: { roomId: string; userId: string }) => {
|
||||
await toggleModeratorEndpoint({ roomId, userId });
|
||||
|
||||
return t(isModerator ? 'User__username__removed_from__room_name__moderators' : 'User__username__is_now_a_moderator_of__room_name_', {
|
||||
username: user.username,
|
||||
room_name: roomName,
|
||||
});
|
||||
},
|
||||
onSuccess: (message) => {
|
||||
dispatchToastMessage({ type: 'success', message });
|
||||
},
|
||||
onError: (error) => {
|
||||
dispatchToastMessage({ type: 'error', message: error });
|
||||
},
|
||||
});
|
||||
|
||||
const handleChangeModerator = useCallback(
|
||||
({ userId }: { userId: string }) => {
|
||||
if (!isRoomFederated(room)) {
|
||||
return toggleModerator.mutateAsync({ roomId: rid, userId: uid });
|
||||
}
|
||||
|
||||
const closeModal = () => setModal(null);
|
||||
const handleConfirm = async () => {
|
||||
await toggleModerator.mutateAsync({ roomId: rid, userId: uid });
|
||||
closeModal();
|
||||
};
|
||||
|
||||
const changingOwnRole = userId === loggedUserId;
|
||||
if (changingOwnRole && loggedUserIsModerator) {
|
||||
return setModal(
|
||||
getWarningModalForFederatedRooms(
|
||||
closeModal,
|
||||
handleConfirm,
|
||||
t('Federation_Matrix_losing_privileges'),
|
||||
t('Yes_continue'),
|
||||
t('Federation_Matrix_losing_privileges_warning'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (changingOwnRole && loggedUserIsOwner) {
|
||||
return setModal(
|
||||
getWarningModalForFederatedRooms(
|
||||
closeModal,
|
||||
handleConfirm,
|
||||
t('Federation_Matrix_losing_privileges'),
|
||||
t('Yes_continue'),
|
||||
t('Federation_Matrix_losing_privileges_warning'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (!changingOwnRole && loggedUserIsModerator) {
|
||||
return setModal(
|
||||
getWarningModalForFederatedRooms(
|
||||
closeModal,
|
||||
handleConfirm,
|
||||
t('Warning'),
|
||||
t('Yes_continue'),
|
||||
t('Federation_Matrix_giving_same_permission_warning'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
toggleModerator.mutateAsync({ roomId: rid, userId: uid });
|
||||
},
|
||||
[setModal, loggedUserId, loggedUserIsModerator, loggedUserIsOwner, t, rid, uid, toggleModerator, room],
|
||||
);
|
||||
|
||||
const changeModeratorAction = useStableCallback(() => handleChangeModerator({ userId: uid }));
|
||||
|
||||
const roomIsFederated = isRoomFederated(room);
|
||||
|
||||
const isFederationBlocked = room && !isRoomNativeFederated(room);
|
||||
|
||||
const changeModeratorOption = useMemo(
|
||||
() =>
|
||||
(roomIsFederated && !isFederationBlocked && roomCanSetModerator) || (!roomIsFederated && roomCanSetModerator && userCanSetModerator)
|
||||
? {
|
||||
content: t(isModerator ? 'Remove_as_moderator' : 'Set_as_moderator'),
|
||||
icon: 'shield-blank' as const,
|
||||
onClick: changeModeratorAction,
|
||||
type: 'privileges' as UserInfoActionType,
|
||||
}
|
||||
: undefined,
|
||||
[changeModeratorAction, isModerator, roomCanSetModerator, t, userCanSetModerator, roomIsFederated, isFederationBlocked],
|
||||
);
|
||||
|
||||
return changeModeratorOption;
|
||||
};
|
||||
@@ -0,0 +1,149 @@
|
||||
import type { IRoom, IUser } from '@rocket.chat/core-typings';
|
||||
import { isRoomFederated, isRoomNativeFederated } from '@rocket.chat/core-typings';
|
||||
import { useStableCallback } from '@rocket.chat/fuselage-hooks';
|
||||
import { escapeHTML } from '@rocket.chat/tools';
|
||||
import { GenericModal } from '@rocket.chat/ui-client';
|
||||
import {
|
||||
useTranslation,
|
||||
usePermission,
|
||||
useUserRoom,
|
||||
useUserSubscription,
|
||||
useSetModal,
|
||||
useUser,
|
||||
useToastMessageDispatch,
|
||||
useEndpoint,
|
||||
} from '@rocket.chat/ui-contexts';
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
|
||||
import { roomCoordinator } from '../../../../../lib/rooms/roomCoordinator';
|
||||
import { getRoomDirectives } from '../../../lib/getRoomDirectives';
|
||||
import { useUserHasRoomRole } from '../../useUserHasRoomRole';
|
||||
import type { UserInfoAction, UserInfoActionType } from '../useUserInfoActions';
|
||||
|
||||
const getWarningModalForFederatedRooms = (
|
||||
closeModalFn: () => void,
|
||||
handleConfirmFn: () => void,
|
||||
title: string,
|
||||
confirmText: string,
|
||||
bodyText: string,
|
||||
) => (
|
||||
<GenericModal
|
||||
variant='warning'
|
||||
onClose={closeModalFn}
|
||||
onConfirm={handleConfirmFn}
|
||||
onCancel={closeModalFn}
|
||||
title={title}
|
||||
confirmText={confirmText}
|
||||
>
|
||||
{bodyText}
|
||||
</GenericModal>
|
||||
);
|
||||
|
||||
const getEndpoint = (roomType: string, isOwner: boolean) => {
|
||||
if (roomType === 'p') {
|
||||
return isOwner ? '/v1/groups.removeOwner' : '/v1/groups.addOwner';
|
||||
}
|
||||
return isOwner ? '/v1/channels.removeOwner' : '/v1/channels.addOwner';
|
||||
};
|
||||
|
||||
export const useChangeOwnerAction = (user: Pick<IUser, '_id' | 'username'>, rid: IRoom['_id']): UserInfoAction | undefined => {
|
||||
const t = useTranslation();
|
||||
const room = useUserRoom(rid);
|
||||
const { _id: uid, username } = user;
|
||||
const userCanSetOwner = usePermission('set-owner', rid);
|
||||
const isOwner = useUserHasRoomRole(uid, rid, 'owner');
|
||||
const userSubscription = useUserSubscription(rid);
|
||||
const setModal = useSetModal();
|
||||
const { _id: loggedUserId = '' } = useUser() || {};
|
||||
const loggedUserIsOwner = useUserHasRoomRole(loggedUserId, rid, 'owner');
|
||||
const dispatchToastMessage = useToastMessageDispatch();
|
||||
|
||||
if (!room) {
|
||||
throw Error('Room not provided');
|
||||
}
|
||||
|
||||
const { roomCanSetOwner } = getRoomDirectives({ room, showingUserId: uid, userSubscription });
|
||||
const roomName = room?.t && escapeHTML(roomCoordinator.getRoomName(room.t, room));
|
||||
|
||||
const toggleOwnerEndpoint = useEndpoint('POST', getEndpoint(room.t, isOwner));
|
||||
|
||||
const toggleOwnerMutation = useMutation({
|
||||
mutationFn: async ({ roomId, userId }: { roomId: string; userId: string }) => {
|
||||
await toggleOwnerEndpoint({ roomId, userId });
|
||||
|
||||
return t(isOwner ? 'User__username__removed_from__room_name__owners' : 'User__username__is_now_an_owner_of__room_name_', {
|
||||
username,
|
||||
room_name: roomName,
|
||||
});
|
||||
},
|
||||
onSuccess: (message) => {
|
||||
dispatchToastMessage({ type: 'success', message });
|
||||
},
|
||||
onError: (error) => {
|
||||
dispatchToastMessage({ type: 'error', message: error });
|
||||
},
|
||||
});
|
||||
|
||||
const handleChangeOwner = useCallback(() => {
|
||||
if (!isRoomFederated(room)) {
|
||||
return toggleOwnerMutation.mutateAsync({ roomId: rid, userId: uid });
|
||||
}
|
||||
|
||||
const changingOwnRole = uid === loggedUserId;
|
||||
|
||||
const closeModal = () => {
|
||||
setModal(null);
|
||||
};
|
||||
|
||||
const handleConfirm = () => {
|
||||
toggleOwnerMutation.mutateAsync({ roomId: rid, userId: uid });
|
||||
closeModal();
|
||||
};
|
||||
|
||||
if (changingOwnRole && loggedUserIsOwner) {
|
||||
return setModal(
|
||||
getWarningModalForFederatedRooms(
|
||||
closeModal,
|
||||
handleConfirm,
|
||||
t('Federation_Matrix_losing_privileges'),
|
||||
t('Yes_continue'),
|
||||
t('Federation_Matrix_losing_privileges_warning'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (!changingOwnRole && loggedUserIsOwner) {
|
||||
return setModal(
|
||||
getWarningModalForFederatedRooms(
|
||||
closeModal,
|
||||
handleConfirm,
|
||||
t('Warning'),
|
||||
t('Yes_continue'),
|
||||
t('Federation_Matrix_giving_same_permission_warning'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
toggleOwnerMutation.mutateAsync({ roomId: rid, userId: uid });
|
||||
}, [room, loggedUserId, loggedUserIsOwner, toggleOwnerMutation, rid, uid, t, setModal]);
|
||||
|
||||
const changeOwnerAction = useStableCallback(async () => handleChangeOwner());
|
||||
|
||||
const roomIsFederated = isRoomFederated(room);
|
||||
const isFederationBlocked = room && !isRoomNativeFederated(room);
|
||||
const changeOwnerOption = useMemo(
|
||||
() =>
|
||||
(roomIsFederated && !isFederationBlocked && roomCanSetOwner) || (!roomIsFederated && roomCanSetOwner && userCanSetOwner)
|
||||
? {
|
||||
content: t(isOwner ? 'Remove_as_owner' : 'Set_as_owner'),
|
||||
icon: 'shield-check' as const,
|
||||
onClick: changeOwnerAction,
|
||||
type: 'privileges' as UserInfoActionType,
|
||||
}
|
||||
: undefined,
|
||||
[changeOwnerAction, roomCanSetOwner, userCanSetOwner, isOwner, t, roomIsFederated, isFederationBlocked],
|
||||
);
|
||||
|
||||
return changeOwnerOption;
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
import type { IRoom, IUser } from '@rocket.chat/core-typings';
|
||||
import { useGoToDirectMessage } from '@rocket.chat/ui-client';
|
||||
import { useMemo } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import type { UserInfoAction } from '../useUserInfoActions';
|
||||
|
||||
export const useDirectMessageAction = (user: Pick<IUser, '_id' | 'username'>, rid: IRoom['_id']): UserInfoAction | undefined => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const openDirectMessage = useGoToDirectMessage(user, rid);
|
||||
|
||||
const openDirectMessageOption = useMemo(() => {
|
||||
if (!openDirectMessage) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return {
|
||||
content: t('Direct_Message'),
|
||||
icon: 'balloon' as const,
|
||||
onClick: openDirectMessage,
|
||||
type: 'communication',
|
||||
} as const;
|
||||
}, [openDirectMessage, t]);
|
||||
|
||||
return openDirectMessageOption;
|
||||
};
|
||||
@@ -0,0 +1,60 @@
|
||||
import type { IRoom, IUser } from '@rocket.chat/core-typings';
|
||||
import { useStableCallback } from '@rocket.chat/fuselage-hooks';
|
||||
import {
|
||||
useTranslation,
|
||||
useUserSubscription,
|
||||
useUserRoom,
|
||||
useUserId,
|
||||
useToastMessageDispatch,
|
||||
useEndpoint,
|
||||
} from '@rocket.chat/ui-contexts';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
import { getRoomDirectives } from '../../../lib/getRoomDirectives';
|
||||
import type { UserInfoAction, UserInfoActionType } from '../useUserInfoActions';
|
||||
|
||||
export const useIgnoreUserAction = (user: Pick<IUser, '_id' | 'username'>, rid: IRoom['_id']): UserInfoAction | undefined => {
|
||||
const t = useTranslation();
|
||||
const room = useUserRoom(rid);
|
||||
const { _id: uid } = user;
|
||||
const ownUserId = useUserId();
|
||||
const dispatchToastMessage = useToastMessageDispatch();
|
||||
const currentSubscription = useUserSubscription(rid);
|
||||
const ignoreUser = useEndpoint('GET', '/v1/chat.ignoreUser');
|
||||
|
||||
const isIgnored = currentSubscription?.ignored && currentSubscription.ignored.indexOf(uid) > -1;
|
||||
|
||||
if (!room) {
|
||||
throw Error('Room not provided');
|
||||
}
|
||||
|
||||
const { roomCanIgnore } = getRoomDirectives({ room, showingUserId: uid, userSubscription: currentSubscription });
|
||||
|
||||
const ignoreUserAction = useStableCallback(async () => {
|
||||
try {
|
||||
await ignoreUser({ rid, userId: uid, ignore: String(!isIgnored) });
|
||||
if (isIgnored) {
|
||||
dispatchToastMessage({ type: 'success', message: t('User_has_been_unignored') });
|
||||
} else {
|
||||
dispatchToastMessage({ type: 'success', message: t('User_has_been_ignored') });
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
dispatchToastMessage({ type: 'error', message: error });
|
||||
}
|
||||
});
|
||||
|
||||
const ignoreUserOption = useMemo(
|
||||
() =>
|
||||
roomCanIgnore && uid !== ownUserId
|
||||
? {
|
||||
content: t(isIgnored ? 'Unignore' : 'Ignore'),
|
||||
icon: 'ban' as const,
|
||||
onClick: ignoreUserAction,
|
||||
type: 'management' as UserInfoActionType,
|
||||
}
|
||||
: undefined,
|
||||
[ignoreUserAction, isIgnored, ownUserId, roomCanIgnore, t, uid],
|
||||
);
|
||||
|
||||
return ignoreUserOption;
|
||||
};
|
||||
@@ -0,0 +1,126 @@
|
||||
import type { IRoom, IUser } from '@rocket.chat/core-typings';
|
||||
import { useStableCallback } from '@rocket.chat/fuselage-hooks';
|
||||
import { escapeHTML } from '@rocket.chat/tools';
|
||||
import { GenericModal } from '@rocket.chat/ui-client';
|
||||
import {
|
||||
useAllPermissions,
|
||||
usePermission,
|
||||
useSetModal,
|
||||
useToastMessageDispatch,
|
||||
useTranslation,
|
||||
useUserRoom,
|
||||
useUserSubscription,
|
||||
useEndpoint,
|
||||
} from '@rocket.chat/ui-contexts';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
import { roomCoordinator } from '../../../../../lib/rooms/roomCoordinator';
|
||||
import { getRoomDirectives } from '../../../lib/getRoomDirectives';
|
||||
import type { UserInfoAction, UserInfoActionType } from '../useUserInfoActions';
|
||||
|
||||
const getUserIsMuted = (
|
||||
user: Pick<IUser, '_id' | 'username'>,
|
||||
room: IRoom | undefined,
|
||||
userCanPostReadonly: boolean,
|
||||
): boolean | undefined => {
|
||||
if (room?.ro) {
|
||||
if (Array.isArray(room.unmuted) && room.unmuted.indexOf(user.username ?? '') !== -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (userCanPostReadonly) {
|
||||
return Array.isArray(room.muted) && room.muted.indexOf(user.username ?? '') !== -1;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return room && Array.isArray(room.muted) && room.muted.indexOf(user.username ?? '') > -1;
|
||||
};
|
||||
|
||||
export const useMuteUserAction = (user: Pick<IUser, '_id' | 'username'>, rid: IRoom['_id']): UserInfoAction | undefined => {
|
||||
const t = useTranslation();
|
||||
const room = useUserRoom(rid);
|
||||
const userCanMute = usePermission('mute-user', rid);
|
||||
const dispatchToastMessage = useToastMessageDispatch();
|
||||
const setModal = useSetModal();
|
||||
const closeModal = useStableCallback(() => setModal(null));
|
||||
const otherUserCanPostReadonly = useAllPermissions(
|
||||
useMemo(() => ['post-readonly'], []),
|
||||
rid,
|
||||
);
|
||||
const userSubscription = useUserSubscription(rid);
|
||||
|
||||
const isMuted = getUserIsMuted(user, room, otherUserCanPostReadonly);
|
||||
const roomName = room?.t && escapeHTML(roomCoordinator.getRoomName(room.t, room));
|
||||
|
||||
if (!room) {
|
||||
throw Error('Room not provided');
|
||||
}
|
||||
|
||||
const { roomCanMute } = getRoomDirectives({ room, showingUserId: user._id, userSubscription });
|
||||
|
||||
const mutedMessage = isMuted ? 'User__username__unmuted_in_room__roomName__' : 'User__username__muted_in_room__roomName__';
|
||||
|
||||
const muteUser = useEndpoint('POST', isMuted ? '/v1/rooms.unmuteUser' : '/v1/rooms.muteUser');
|
||||
|
||||
const muteUserOption = useMemo(() => {
|
||||
const action = (): Promise<void> | void => {
|
||||
const onConfirm = async (): Promise<void> => {
|
||||
try {
|
||||
if (!user.username) {
|
||||
throw new Error('User without username');
|
||||
}
|
||||
|
||||
await muteUser({ roomId: rid, username: user.username });
|
||||
|
||||
return dispatchToastMessage({
|
||||
type: 'success',
|
||||
message: t(mutedMessage, {
|
||||
username: user.username,
|
||||
roomName,
|
||||
}),
|
||||
});
|
||||
} catch (error: unknown) {
|
||||
dispatchToastMessage({ type: 'error', message: error });
|
||||
} finally {
|
||||
closeModal();
|
||||
}
|
||||
};
|
||||
|
||||
if (isMuted) {
|
||||
return onConfirm();
|
||||
}
|
||||
|
||||
return setModal(
|
||||
<GenericModal variant='danger' confirmText={t('Yes_mute_user')} onClose={closeModal} onCancel={closeModal} onConfirm={onConfirm}>
|
||||
{t('The_user_wont_be_able_to_type_in_s', { roomName })}
|
||||
</GenericModal>,
|
||||
);
|
||||
};
|
||||
|
||||
return roomCanMute && userCanMute
|
||||
? {
|
||||
content: t(isMuted ? 'Unmute_user' : 'Mute_user'),
|
||||
icon: isMuted ? ('mic' as const) : ('mic-off' as const),
|
||||
onClick: action,
|
||||
type: 'management' as UserInfoActionType,
|
||||
}
|
||||
: undefined;
|
||||
}, [
|
||||
closeModal,
|
||||
mutedMessage,
|
||||
dispatchToastMessage,
|
||||
isMuted,
|
||||
muteUser,
|
||||
rid,
|
||||
roomCanMute,
|
||||
roomName,
|
||||
setModal,
|
||||
t,
|
||||
user.username,
|
||||
userCanMute,
|
||||
]);
|
||||
|
||||
return muteUserOption;
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
import type { IUser } from '@rocket.chat/core-typings';
|
||||
import { usePermission, useRoute } from '@rocket.chat/ui-contexts';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import type { UserInfoAction, UserInfoActionType } from '../useUserInfoActions';
|
||||
|
||||
export const useRedirectModerationConsole = (uid: IUser['_id']): UserInfoAction | undefined => {
|
||||
const { t } = useTranslation();
|
||||
const hasPermissionToView = usePermission('view-moderation-console');
|
||||
const router = useRoute('moderation-console');
|
||||
|
||||
// only rediret if user has permission else return undefined
|
||||
if (!hasPermissionToView) {
|
||||
return;
|
||||
}
|
||||
|
||||
const redirectModerationConsoleAction = () => {
|
||||
router.push({ uid });
|
||||
};
|
||||
|
||||
return {
|
||||
content: t('Moderation_Action_View_reports'),
|
||||
icon: 'warning',
|
||||
onClick: redirectModerationConsoleAction,
|
||||
type: 'privileges' as UserInfoActionType,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,145 @@
|
||||
import type { IRoom, IUser, Serialized } from '@rocket.chat/core-typings';
|
||||
import { isRoomFederated, isRoomNativeFederated } from '@rocket.chat/core-typings';
|
||||
import { useStableCallback } from '@rocket.chat/fuselage-hooks';
|
||||
import { escapeHTML } from '@rocket.chat/tools';
|
||||
import { GenericModal } from '@rocket.chat/ui-client';
|
||||
import {
|
||||
usePermission,
|
||||
useSetModal,
|
||||
useToastMessageDispatch,
|
||||
useTranslation,
|
||||
useUser,
|
||||
useUserRoom,
|
||||
useUserSubscription,
|
||||
} from '@rocket.chat/ui-contexts';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
import { useEndpointMutation } from '../../../../../hooks/useEndpointMutation';
|
||||
import * as Federation from '../../../../../lib/federation/Federation';
|
||||
import { roomsQueryKeys } from '../../../../../lib/queryKeys';
|
||||
import { roomCoordinator } from '../../../../../lib/rooms/roomCoordinator';
|
||||
import RemoveUsersModal from '../../../../teams/contextualBar/members/RemoveUsersModal';
|
||||
import { getRoomDirectives } from '../../../lib/getRoomDirectives';
|
||||
import type { UserInfoAction } from '../useUserInfoActions';
|
||||
|
||||
export const useRemoveUserAction = (
|
||||
user: Pick<IUser, '_id' | 'username'>,
|
||||
rid: IRoom['_id'],
|
||||
reload?: () => void,
|
||||
invited?: boolean,
|
||||
): UserInfoAction | undefined => {
|
||||
const room = useUserRoom(rid);
|
||||
|
||||
if (!room) {
|
||||
throw Error('Room not provided');
|
||||
}
|
||||
|
||||
const t = useTranslation();
|
||||
const queryClient = useQueryClient();
|
||||
const currentUser = useUser();
|
||||
const subscription = useUserSubscription(rid);
|
||||
|
||||
const { _id: uid } = user;
|
||||
|
||||
const hasPermissionToRemove = usePermission('remove-user', rid);
|
||||
|
||||
const roomIsFederated = isRoomFederated(room);
|
||||
|
||||
const isFederationBlocked = room && !isRoomNativeFederated(room);
|
||||
const userCanRemove = roomIsFederated
|
||||
? !isFederationBlocked && Federation.isEditableByTheUser(currentUser || undefined, room, subscription)
|
||||
: hasPermissionToRemove;
|
||||
const setModal = useSetModal();
|
||||
const closeModal = useStableCallback(() => setModal(null));
|
||||
const roomName = room?.t && escapeHTML(roomCoordinator.getRoomName(room.t, room));
|
||||
|
||||
const { roomCanRemove } = getRoomDirectives({ room, showingUserId: uid, userSubscription: subscription });
|
||||
|
||||
const dispatchToastMessage = useToastMessageDispatch();
|
||||
|
||||
const { mutateAsync: removeFromTeam } = useEndpointMutation('POST', '/v1/teams.removeMember', {
|
||||
onSuccess: () => {
|
||||
dispatchToastMessage({ type: 'success', message: t('User_has_been_removed_from_team') });
|
||||
},
|
||||
onSettled: () => {
|
||||
closeModal();
|
||||
reload?.();
|
||||
},
|
||||
});
|
||||
|
||||
const removeFromRoomEndpoint = room.t === 'p' ? '/v1/groups.kick' : '/v1/channels.kick';
|
||||
const { mutateAsync: removeFromRoom } = useEndpointMutation('POST', removeFromRoomEndpoint, {
|
||||
onSuccess: () => {
|
||||
dispatchToastMessage({ type: 'success', message: t('User_has_been_removed_from_s', { roomName }) });
|
||||
queryClient.invalidateQueries({ queryKey: roomsQueryKeys.members(room._id, room.t) });
|
||||
},
|
||||
onSettled: () => {
|
||||
closeModal();
|
||||
reload?.();
|
||||
},
|
||||
});
|
||||
|
||||
const removeUserOptionAction = useStableCallback(() => {
|
||||
const handleRemoveFromTeam = async (rooms: Record<string, Serialized<IRoom>>) => {
|
||||
if (room.teamId) {
|
||||
const roomKeys = Object.keys(rooms);
|
||||
await removeFromTeam({
|
||||
teamId: room.teamId,
|
||||
userId: uid,
|
||||
...(roomKeys.length && { rooms: roomKeys }),
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const handleRemoveFromRoom = async (rid: IRoom['_id'], uid: IUser['_id']) => {
|
||||
await removeFromRoom({ roomId: rid, userId: uid });
|
||||
};
|
||||
|
||||
if (room.teamMain && room.teamId) {
|
||||
return setModal(
|
||||
<RemoveUsersModal teamId={room?.teamId} userId={uid} onClose={closeModal} onCancel={closeModal} onConfirm={handleRemoveFromTeam} />,
|
||||
);
|
||||
}
|
||||
|
||||
setModal(
|
||||
<GenericModal
|
||||
variant='danger'
|
||||
confirmText={invited ? t('Revoke_invitation') : t('Yes_remove_user')}
|
||||
onClose={closeModal}
|
||||
onCancel={closeModal}
|
||||
onConfirm={(): Promise<void> => handleRemoveFromRoom(rid, uid)}
|
||||
>
|
||||
{t('The_user_will_be_removed_from_s', { roomName })}
|
||||
</GenericModal>,
|
||||
);
|
||||
});
|
||||
|
||||
const content = useMemo(() => {
|
||||
if (invited) {
|
||||
return t('Revoke_invitation');
|
||||
}
|
||||
|
||||
if (room?.teamMain) {
|
||||
return t('Remove_from_team');
|
||||
}
|
||||
|
||||
return t('Remove_from_room');
|
||||
}, [invited, room?.teamMain, t]);
|
||||
|
||||
const removeUserOption = useMemo(() => {
|
||||
if (!roomCanRemove || !userCanRemove) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return {
|
||||
content,
|
||||
icon: 'cross' as const,
|
||||
onClick: removeUserOptionAction,
|
||||
type: 'moderation' as const,
|
||||
variant: 'danger' as const,
|
||||
};
|
||||
}, [roomCanRemove, userCanRemove, removeUserOptionAction, content]);
|
||||
|
||||
return removeUserOption;
|
||||
};
|
||||
@@ -0,0 +1,56 @@
|
||||
import type { IUser } from '@rocket.chat/core-typings';
|
||||
import { useUserDisplayName } from '@rocket.chat/ui-client';
|
||||
import { useEndpoint, useSetModal, useToastMessageDispatch, useUserId } from '@rocket.chat/ui-contexts';
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import { useMemo } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import ReportUserModal from '../../../contextualBar/UserInfo/ReportUserModal';
|
||||
import type { UserInfoAction } from '../useUserInfoActions';
|
||||
|
||||
export const useReportUser = (user: Pick<IUser, '_id' | 'username' | 'name'>): UserInfoAction | undefined => {
|
||||
const { _id: uid, username, name } = user;
|
||||
const ownUserId = useUserId();
|
||||
const setModal = useSetModal();
|
||||
|
||||
const { t } = useTranslation();
|
||||
const dispatchToastMessage = useToastMessageDispatch();
|
||||
const displayName = useUserDisplayName({ username, name });
|
||||
|
||||
const reportUser = useEndpoint('POST', '/v1/moderation.reportUser');
|
||||
const reportUserMutation = useMutation({
|
||||
mutationKey: ['reportUser', uid],
|
||||
|
||||
mutationFn: async (description: string) => {
|
||||
reportUser({ description, userId: uid });
|
||||
},
|
||||
|
||||
onSuccess: () => dispatchToastMessage({ type: 'success', message: t('Report_has_been_sent') }),
|
||||
onError: (error) => dispatchToastMessage({ type: 'error', message: error }),
|
||||
onSettled: () => setModal(),
|
||||
});
|
||||
|
||||
const openReportUserModal = useMemo(() => {
|
||||
const action = () =>
|
||||
setModal(
|
||||
<ReportUserModal
|
||||
onConfirm={reportUserMutation.mutate}
|
||||
onClose={() => setModal()}
|
||||
displayName={displayName || ''}
|
||||
username={username || ''}
|
||||
/>,
|
||||
);
|
||||
|
||||
return ownUserId !== uid
|
||||
? {
|
||||
icon: 'warning' as const,
|
||||
content: t('Report'),
|
||||
onClick: action,
|
||||
type: 'moderation' as const,
|
||||
variant: 'danger' as const,
|
||||
}
|
||||
: undefined;
|
||||
}, [ownUserId, uid, t, setModal, username, reportUserMutation.mutate, displayName]);
|
||||
|
||||
return openReportUserModal;
|
||||
};
|
||||
@@ -0,0 +1,128 @@
|
||||
import { mockAppRoot } from '@rocket.chat/mock-providers';
|
||||
import { act, renderHook } from '@testing-library/react';
|
||||
|
||||
import { useUserMediaCallAction } from './useUserMediaCallAction';
|
||||
import { createFakeRoom, createFakeSubscription, createFakeUser } from '../../../../../../tests/mocks/data';
|
||||
|
||||
const usePeekMediaSessionStateMock = jest.fn().mockReturnValue('available');
|
||||
const toggleWidgetMock = jest.fn();
|
||||
|
||||
jest.mock('@rocket.chat/ui-contexts', () => ({
|
||||
...jest.requireActual('@rocket.chat/ui-contexts'),
|
||||
useUserAvatarPath: jest.fn().mockReturnValue((_args: any) => 'avatar-url'),
|
||||
useUserCard: jest.fn().mockReturnValue({ closeUserCard: jest.fn() }),
|
||||
}));
|
||||
|
||||
jest.mock('@rocket.chat/ui-voip', () => ({
|
||||
...jest.requireActual('@rocket.chat/ui-voip'),
|
||||
useWidgetExternalControls: jest.fn().mockReturnValue({ toggleWidget: (...args: any[]) => toggleWidgetMock(...args) }),
|
||||
usePeekMediaSessionState: () => usePeekMediaSessionStateMock(),
|
||||
}));
|
||||
|
||||
describe('useUserMediaCallAction', () => {
|
||||
const fakeUser = createFakeUser({ _id: 'own-uid' });
|
||||
const mockRid = 'room-id';
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
usePeekMediaSessionStateMock.mockReturnValue('available');
|
||||
});
|
||||
|
||||
it('should return undefined if room is federated', () => {
|
||||
const { result } = renderHook(() => useUserMediaCallAction(fakeUser, mockRid), {
|
||||
wrapper: mockAppRoot()
|
||||
.withJohnDoe()
|
||||
.withRoom(createFakeRoom({ federated: true }))
|
||||
.build(),
|
||||
});
|
||||
|
||||
expect(result.current).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should return undefined if state is unauthorized', () => {
|
||||
usePeekMediaSessionStateMock.mockReturnValueOnce('unavailable');
|
||||
|
||||
const { result } = renderHook(() => useUserMediaCallAction(fakeUser, mockRid), { wrapper: mockAppRoot().build() });
|
||||
expect(result.current).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should return undefined if subscription is blocked', () => {
|
||||
const { result } = renderHook(() => useUserMediaCallAction(fakeUser, mockRid), {
|
||||
wrapper: mockAppRoot()
|
||||
.withJohnDoe()
|
||||
.withRoom(createFakeRoom())
|
||||
.withSubscription(createFakeSubscription({ blocker: false, blocked: true }))
|
||||
.build(),
|
||||
});
|
||||
|
||||
expect(result.current).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should return undefined if subscription is blocker', () => {
|
||||
const { result } = renderHook(() => useUserMediaCallAction(fakeUser, mockRid), {
|
||||
wrapper: mockAppRoot()
|
||||
.withJohnDoe()
|
||||
.withRoom(createFakeRoom())
|
||||
.withSubscription(createFakeSubscription({ blocker: true, blocked: false }))
|
||||
.build(),
|
||||
});
|
||||
|
||||
expect(result.current).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should return undefined if user is own user', () => {
|
||||
const { result } = renderHook(() => useUserMediaCallAction(fakeUser, mockRid), {
|
||||
wrapper: mockAppRoot().withUser(fakeUser).withRoom(createFakeRoom()).withSubscription(createFakeSubscription()).build(),
|
||||
});
|
||||
|
||||
expect(result.current).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should return action if conditions are met', () => {
|
||||
const fakeUser = createFakeUser();
|
||||
const { result } = renderHook(() => useUserMediaCallAction(fakeUser, mockRid), {
|
||||
wrapper: mockAppRoot()
|
||||
.withJohnDoe()
|
||||
.withRoom(createFakeRoom())
|
||||
.withSubscription(createFakeSubscription())
|
||||
.withTranslations('en', 'core', {
|
||||
Voice_call__user_: 'Voice call {{user}}',
|
||||
})
|
||||
.build(),
|
||||
});
|
||||
|
||||
expect(result.current).toEqual(
|
||||
expect.objectContaining({
|
||||
type: 'communication',
|
||||
icon: 'phone',
|
||||
title: `Voice call ${fakeUser.name}`,
|
||||
disabled: false,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('should call onClick handler correctly', () => {
|
||||
usePeekMediaSessionStateMock.mockReturnValueOnce('available');
|
||||
|
||||
const { result } = renderHook(() => useUserMediaCallAction(fakeUser, mockRid));
|
||||
|
||||
act(() => result.current?.onClick());
|
||||
|
||||
expect(toggleWidgetMock).toHaveBeenCalledWith({
|
||||
userId: fakeUser._id,
|
||||
displayName: fakeUser.name,
|
||||
avatarUrl: 'avatar-url',
|
||||
});
|
||||
});
|
||||
|
||||
it('should be disabled if state is not closed, new, or unlicensed', () => {
|
||||
usePeekMediaSessionStateMock.mockReturnValueOnce('calling');
|
||||
|
||||
const { result } = renderHook(() => useUserMediaCallAction(fakeUser, mockRid));
|
||||
|
||||
expect(result.current?.disabled).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,56 @@
|
||||
import { isRoomFederated } from '@rocket.chat/core-typings';
|
||||
import type { IRoom, IUser } from '@rocket.chat/core-typings';
|
||||
import { useUserAvatarPath, useUserId, useUserSubscription, useUserCard, useUserRoom } from '@rocket.chat/ui-contexts';
|
||||
import { usePeekMediaSessionState, useWidgetExternalControls } from '@rocket.chat/ui-voip';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import type { UserInfoAction } from '../useUserInfoActions';
|
||||
|
||||
export const useUserMediaCallAction = (user: Pick<IUser, '_id' | 'username' | 'name'>, rid: IRoom['_id']): UserInfoAction | undefined => {
|
||||
const { t } = useTranslation();
|
||||
const ownUserId = useUserId();
|
||||
const { closeUserCard } = useUserCard();
|
||||
const state = usePeekMediaSessionState();
|
||||
const { toggleWidget } = useWidgetExternalControls();
|
||||
const getAvatarUrl = useUserAvatarPath();
|
||||
|
||||
const currentSubscription = useUserSubscription(rid);
|
||||
const room = useUserRoom(rid);
|
||||
|
||||
const blocked = currentSubscription?.blocked || currentSubscription?.blocker;
|
||||
|
||||
if (room && isRoomFederated(room)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (state === 'unavailable') {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (blocked) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const disabled = state !== 'available';
|
||||
|
||||
if (user._id === ownUserId) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const avatarUrl = user.username ? getAvatarUrl({ username: user.username }) : getAvatarUrl({ userId: user._id });
|
||||
|
||||
return {
|
||||
type: 'communication',
|
||||
title: t('Voice_call__user_', { user: user.name || user.username || '' }),
|
||||
icon: 'phone',
|
||||
onClick: () => {
|
||||
closeUserCard();
|
||||
toggleWidget({
|
||||
userId: user._id,
|
||||
displayName: user.name || user.username || '',
|
||||
avatarUrl,
|
||||
});
|
||||
},
|
||||
disabled,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,81 @@
|
||||
import type { IUser } from '@rocket.chat/core-typings';
|
||||
import { isRoomFederated } from '@rocket.chat/core-typings';
|
||||
import {
|
||||
useTranslation,
|
||||
useUserRoom,
|
||||
useUserId,
|
||||
useUserSubscriptionByName,
|
||||
useSetting,
|
||||
usePermission,
|
||||
useUserCard,
|
||||
} from '@rocket.chat/ui-contexts';
|
||||
import {
|
||||
useVideoConfDispatchOutgoing,
|
||||
useVideoConfIsCalling,
|
||||
useVideoConfIsRinging,
|
||||
useVideoConfLoadCapabilities,
|
||||
} from '@rocket.chat/ui-video-conf';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
import { useVideoConfWarning } from '../../../contextualBar/VideoConference/hooks/useVideoConfWarning';
|
||||
import type { UserInfoAction } from '../useUserInfoActions';
|
||||
|
||||
export const useVideoCallAction = (user: Pick<IUser, '_id' | 'username'>): UserInfoAction | undefined => {
|
||||
const t = useTranslation();
|
||||
const usernameSubscription = useUserSubscriptionByName(user.username ?? '');
|
||||
const room = useUserRoom(usernameSubscription?.rid || '');
|
||||
const { closeUserCard } = useUserCard();
|
||||
|
||||
const loadCapabilities = useVideoConfLoadCapabilities();
|
||||
const dispatchWarning = useVideoConfWarning();
|
||||
const dispatchPopup = useVideoConfDispatchOutgoing();
|
||||
const isCalling = useVideoConfIsCalling();
|
||||
const isRinging = useVideoConfIsRinging();
|
||||
const ownUserId = useUserId();
|
||||
|
||||
const enabledForDMs = useSetting('VideoConf_Enable_DMs');
|
||||
const permittedToCallManagement = usePermission('call-management', room?._id);
|
||||
|
||||
const videoCallOption = useMemo<UserInfoAction | undefined>(() => {
|
||||
const action = async (): Promise<void> => {
|
||||
if (isCalling || isRinging || !room) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await loadCapabilities();
|
||||
closeUserCard();
|
||||
dispatchPopup({ rid: room._id });
|
||||
} catch (error: any) {
|
||||
dispatchWarning(error.error);
|
||||
}
|
||||
};
|
||||
|
||||
const shouldShowStartCall =
|
||||
room && !isRoomFederated(room) && user._id !== ownUserId && enabledForDMs && permittedToCallManagement && !isCalling && !isRinging;
|
||||
|
||||
return shouldShowStartCall
|
||||
? {
|
||||
type: 'communication',
|
||||
title: t('Video_call'),
|
||||
icon: 'video',
|
||||
onClick: action,
|
||||
}
|
||||
: undefined;
|
||||
}, [
|
||||
room,
|
||||
user._id,
|
||||
ownUserId,
|
||||
enabledForDMs,
|
||||
permittedToCallManagement,
|
||||
isCalling,
|
||||
isRinging,
|
||||
t,
|
||||
dispatchPopup,
|
||||
dispatchWarning,
|
||||
closeUserCard,
|
||||
loadCapabilities,
|
||||
]);
|
||||
|
||||
return videoCallOption;
|
||||
};
|
||||
Reference in New Issue
Block a user