The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/apps/meteor/client/components/message/toolbar/usePermalinkAction.ts

51 lines
1.6 KiB

import type { IMessage, IRoom } from '@rocket.chat/core-typings';
import { isE2EEMessage } from '@rocket.chat/core-typings';
import { useToastMessageDispatch } from '@rocket.chat/ui-contexts';
import { useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import type { MessageActionConfig, MessageActionContext } from '../../../../app/ui-utils/client/lib/MessageAction';
import { getPermaLink } from '../../../lib/getPermaLink';
export const usePermalinkAction = (
message: IMessage,
{ id, context, type, order }: { context: MessageActionContext[]; order: number } & Pick<MessageActionConfig, 'id' | 'type'>,
{ room }: { room: IRoom },
): MessageActionConfig | null => {
const { t } = useTranslation();
const dispatchToastMessage = useToastMessageDispatch();
const isABACEnabled = !!room.abacAttributes;
const encrypted = isE2EEMessage(message);
const tooltip = useMemo(() => {
if (encrypted) {
return t('Action_not_available_encrypted_content', { action: t('Copy_link') });
}
if (isABACEnabled) {
return t('Not_available_for_ABAC_enabled_rooms');
}
return null;
}, [encrypted, isABACEnabled, t]);
return {
id,
icon: 'permalink',
label: 'Copy_link',
context,
type,
async action() {
try {
const permalink = await getPermaLink(message._id);
navigator.clipboard.writeText(permalink);
dispatchToastMessage({ type: 'success', message: t('Copied') });
} catch (e) {
dispatchToastMessage({ type: 'error', message: e });
}
},
order,
group: 'menu',
disabled: encrypted || isABACEnabled,
...(tooltip && { tooltip }),
};
};