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 2s
150 lines
5.6 KiB
TypeScript
150 lines
5.6 KiB
TypeScript
import { isE2EEMessage, type IMessage, type IRoom, type ISubscription } from '@rocket.chat/core-typings';
|
|
import { isTruthy } from '@rocket.chat/tools';
|
|
import { GenericMenu, type GenericMenuItemProps } from '@rocket.chat/ui-client';
|
|
import { useLayoutHiddenActions } from '@rocket.chat/ui-contexts';
|
|
import { useId } from 'react';
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
import { useCopyAction } from './useCopyAction';
|
|
import { useDeleteMessageAction } from './useDeleteMessageAction';
|
|
import { useEditMessageAction } from './useEditMessageAction';
|
|
import { useFollowMessageAction } from './useFollowMessageAction';
|
|
import { useMarkAsUnreadMessageAction } from './useMarkAsUnreadMessageAction';
|
|
import { useMessageActionAppsActionButtons } from './useMessageActionAppsActionButtons';
|
|
import { useNewDiscussionMessageAction } from './useNewDiscussionMessageAction';
|
|
import { usePermalinkAction } from './usePermalinkAction';
|
|
import { usePinMessageAction } from './usePinMessageAction';
|
|
import { useReadReceiptsDetailsAction } from './useReadReceiptsDetailsAction';
|
|
import { useReplyInDMAction } from './useReplyInDMAction';
|
|
import { useReportMessageAction } from './useReportMessageAction';
|
|
import { useShowMessageReactionsAction } from './useShowMessageReactionsAction';
|
|
import { useStarMessageAction } from './useStarMessageAction';
|
|
import { useTranslateAction } from './useTranslateAction';
|
|
import { useUnFollowMessageAction } from './useUnFollowMessageAction';
|
|
import { useUnpinMessageAction } from './useUnpinMessageAction';
|
|
import { useUnstarMessageAction } from './useUnstarMessageAction';
|
|
import { useViewOriginalTranslationAction } from './useViewOriginalTranslationAction';
|
|
import { useWebDAVMessageAction } from './useWebDAVMessageAction';
|
|
import type { MessageActionContext } from '../../../lib/MessageAction';
|
|
|
|
type MessageActionSection = {
|
|
id: string;
|
|
title: string;
|
|
items: GenericMenuItemProps[];
|
|
};
|
|
|
|
export type MessageToolbarActionMenuProps = {
|
|
message: IMessage;
|
|
context: MessageActionContext;
|
|
room: IRoom;
|
|
subscription: ISubscription | undefined;
|
|
onChangeMenuVisibility: (visible: boolean) => void;
|
|
};
|
|
|
|
const MessageToolbarActionMenu = ({ message, context, room, subscription, onChangeMenuVisibility }: MessageToolbarActionMenuProps) => {
|
|
// TODO: move this to another place
|
|
const menuItems = [
|
|
useWebDAVMessageAction(message, { subscription }),
|
|
useNewDiscussionMessageAction(message, { room, subscription }),
|
|
useUnpinMessageAction(message, { room, subscription }),
|
|
usePinMessageAction(message, { room, subscription }),
|
|
useStarMessageAction(message, { room }),
|
|
useUnstarMessageAction(message, { room }),
|
|
usePermalinkAction(message, { id: 'permalink-star', context: ['starred'], order: 10 }, { room }),
|
|
usePermalinkAction(message, { id: 'permalink-pinned', context: ['pinned'], order: 5 }, { room }),
|
|
usePermalinkAction(
|
|
message,
|
|
{
|
|
id: 'permalink',
|
|
context: ['message', 'message-mobile', 'threads', 'federated', 'videoconf', 'videoconf-threads'],
|
|
type: 'duplication',
|
|
order: 5,
|
|
},
|
|
{ room },
|
|
),
|
|
useFollowMessageAction(message, { room, context }),
|
|
useUnFollowMessageAction(message, { room, context }),
|
|
useMarkAsUnreadMessageAction(message, { room, subscription }),
|
|
useTranslateAction(message, { room, subscription }),
|
|
useViewOriginalTranslationAction(message, { room, subscription }),
|
|
useReplyInDMAction(message, { room, subscription }),
|
|
useCopyAction(message, { subscription }),
|
|
useEditMessageAction(message, { room, subscription }),
|
|
useDeleteMessageAction(message, { room, subscription }),
|
|
useReportMessageAction(message, { room, subscription }),
|
|
useShowMessageReactionsAction(message),
|
|
useReadReceiptsDetailsAction(message),
|
|
];
|
|
|
|
const hiddenActions = useLayoutHiddenActions().messageToolbox;
|
|
const data = menuItems
|
|
.filter(isTruthy)
|
|
.filter((button) => button.group === 'menu')
|
|
.filter((button) => !button.context || button.context.includes(context))
|
|
.filter((action) => !hiddenActions.includes(action.id))
|
|
.sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
|
|
|
const actionButtonApps = useMessageActionAppsActionButtons(message, context);
|
|
|
|
const id = useId();
|
|
const { t } = useTranslation();
|
|
|
|
if (data.length === 0) {
|
|
return null;
|
|
}
|
|
|
|
const isMessageEncrypted = isE2EEMessage(message);
|
|
|
|
const groupOptions = [...data, ...(actionButtonApps.data ?? [])]
|
|
.map((option) => ({
|
|
variant: option.variant,
|
|
id: option.id,
|
|
icon: option.icon,
|
|
content: t(option.label),
|
|
onClick: option.action,
|
|
type: option.type,
|
|
...(option.tooltip && { tooltip: option.tooltip }),
|
|
...(typeof option.disabled === 'boolean' && { disabled: option.disabled }),
|
|
}))
|
|
.reduce((acc, option) => {
|
|
const group = option.type ? option.type : '';
|
|
const section = acc.find((section: { id: string }) => section.id === group);
|
|
if (section) {
|
|
section.items.push(option);
|
|
return acc;
|
|
}
|
|
const newSection = { id: group, title: group === 'apps' ? t('Apps') : '', items: [option] };
|
|
acc.push(newSection);
|
|
|
|
return acc;
|
|
}, [] as MessageActionSection[])
|
|
.map((section) => {
|
|
if (section.id !== 'apps') {
|
|
return section;
|
|
}
|
|
|
|
if (!isMessageEncrypted) {
|
|
return section;
|
|
}
|
|
|
|
return {
|
|
id: 'apps',
|
|
title: t('Apps'),
|
|
items: [
|
|
{
|
|
content: t('Unavailable'),
|
|
type: 'apps',
|
|
id,
|
|
disabled: true,
|
|
gap: false,
|
|
tooltip: t('Action_not_available_encrypted_content', { action: t('Apps') }),
|
|
},
|
|
],
|
|
};
|
|
});
|
|
|
|
return <GenericMenu onOpenChange={onChangeMenuVisibility} detached title={t('More')} sections={groupOptions} placement='bottom-end' />;
|
|
};
|
|
|
|
export default MessageToolbarActionMenu;
|