Skip to content

Commit

Permalink
chore: remove meteor.startup from permalink-pinned
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinSchoeler committed Nov 21, 2024
1 parent 726cfbe commit 75eeaec
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import React, { memo, useMemo, useRef } from 'react';
import MessageActionMenu from './MessageActionMenu';
import MessageToolbarStarsActionMenu from './MessageToolbarStarsActionMenu';
import { useNewDiscussionMessageAction } from './useNewDiscussionMessageAction';
import { usePermalinkPinned } from './usePermalinkPinned';
import { useWebDAVMessageAction } from './useWebDAVMessageAction';
import type { MessageActionContext } from '../../../../app/ui-utils/client/lib/MessageAction';
import { MessageAction } from '../../../../app/ui-utils/client/lib/MessageAction';
Expand Down Expand Up @@ -87,6 +88,7 @@ const MessageToolbar = ({
// TODO: move this to another place
useWebDAVMessageAction();
useNewDiscussionMessageAction();
usePermalinkPinned();

const actionsQueryResult = useQuery(['rooms', room._id, 'messages', message._id, 'actions'] as const, async () => {
const props = { message, room, user, subscription, settings: mapSettings, chat };
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { isE2EEMessage } from '@rocket.chat/core-typings';
import { useToastMessageDispatch } from '@rocket.chat/ui-contexts';
import { useEffect } from 'react';
import { useTranslation } from 'react-i18next';

import { MessageAction } from '../../../../app/ui-utils/client/lib/MessageAction';
import { getPermaLink } from '../../../lib/getPermaLink';

export const usePermalinkPinned = () => {
const { t } = useTranslation();

const dispatchToastMessage = useToastMessageDispatch();

useEffect(() => {
MessageAction.addButton({
id: 'permalink-pinned',
icon: 'permalink',
label: 'Copy_link',
context: ['pinned'],
async action(_, { message }) {
try {
const permalink = await getPermaLink(message._id);
navigator.clipboard.writeText(permalink);
dispatchToastMessage({ type: 'success', message: t('Copied') });
} catch (e) {
dispatchToastMessage({ type: 'error', message: e });
}
},
condition({ subscription }) {
return !!subscription;
},
order: 5,
group: 'menu',
disabled({ message }) {
return isE2EEMessage(message);
},
});

return () => {
MessageAction.removeButton('permalink-pinned');
};
}, [dispatchToastMessage, t]);
};
1 change: 0 additions & 1 deletion apps/meteor/client/startup/actionButtons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import './jumpToMessage';
import './jumpToPinMessage';
import './jumpToSearchMessage';
import './jumpToStarMessage';
import './permalinkPinned';
import './permalinkStar';
import './pinMessage';
import './starMessage';
Expand Down
33 changes: 0 additions & 33 deletions apps/meteor/client/startup/actionButtons/permalinkPinned.ts

This file was deleted.

0 comments on commit 75eeaec

Please sign in to comment.