diff --git a/apps/meteor/client/components/message/toolbar/MessageToolbar.tsx b/apps/meteor/client/components/message/toolbar/MessageToolbar.tsx index 2f52ebe42fa9..dc6f208bdecb 100644 --- a/apps/meteor/client/components/message/toolbar/MessageToolbar.tsx +++ b/apps/meteor/client/components/message/toolbar/MessageToolbar.tsx @@ -10,6 +10,7 @@ import React, { memo, useMemo, useRef } from 'react'; import MessageActionMenu from './MessageActionMenu'; import MessageToolbarStarsActionMenu from './MessageToolbarStarsActionMenu'; +import { useJumpToStarMessage } from './useJumpToStarMessage'; import { useNewDiscussionMessageAction } from './useNewDiscussionMessageAction'; import { useWebDAVMessageAction } from './useWebDAVMessageAction'; import type { MessageActionContext } from '../../../../app/ui-utils/client/lib/MessageAction'; @@ -87,6 +88,7 @@ const MessageToolbar = ({ // TODO: move this to another place useWebDAVMessageAction(); useNewDiscussionMessageAction(); + useJumpToStarMessage(); const actionsQueryResult = useQuery(['rooms', room._id, 'messages', message._id, 'actions'] as const, async () => { const props = { message, room, user, subscription, settings: mapSettings, chat }; diff --git a/apps/meteor/client/components/message/toolbar/useJumpToStarMessage.tsx b/apps/meteor/client/components/message/toolbar/useJumpToStarMessage.tsx new file mode 100644 index 000000000000..b2ae560f0da0 --- /dev/null +++ b/apps/meteor/client/components/message/toolbar/useJumpToStarMessage.tsx @@ -0,0 +1,34 @@ +import { useSetting } from '@rocket.chat/ui-contexts'; +import { useEffect } from 'react'; + +import { MessageAction } from '../../../../app/ui-utils/client/lib/MessageAction'; +import { setMessageJumpQueryStringParameter } from '../../../lib/utils/setMessageJumpQueryStringParameter'; + +export const useJumpToStarMessage = () => { + const allowStarring = useSetting('Message_AllowStarring'); + + useEffect(() => { + MessageAction.addButton({ + id: 'jump-to-star-message', + icon: 'jump', + label: 'Jump_to_message', + context: ['starred', 'threads', 'message-mobile', 'videoconf-threads'], + action(_, { message }) { + setMessageJumpQueryStringParameter(message._id); + }, + condition({ message, subscription, user }) { + if (subscription == null || !allowStarring) { + return false; + } + + return Boolean(message.starred?.find((star) => star._id === user?._id)); + }, + order: 100, + group: 'message', + }); + + return () => { + MessageAction.removeButton('jump-to-star-message'); + }; + }, [allowStarring]); +}; diff --git a/apps/meteor/client/startup/actionButtons/index.ts b/apps/meteor/client/startup/actionButtons/index.ts index 97ccf359d567..aa54addaf331 100644 --- a/apps/meteor/client/startup/actionButtons/index.ts +++ b/apps/meteor/client/startup/actionButtons/index.ts @@ -1,7 +1,6 @@ import './jumpToMessage'; import './jumpToPinMessage'; import './jumpToSearchMessage'; -import './jumpToStarMessage'; import './permalinkPinned'; import './permalinkStar'; import './pinMessage'; diff --git a/apps/meteor/client/startup/actionButtons/jumpToStarMessage.ts b/apps/meteor/client/startup/actionButtons/jumpToStarMessage.ts deleted file mode 100644 index 73ac085d9edb..000000000000 --- a/apps/meteor/client/startup/actionButtons/jumpToStarMessage.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { Meteor } from 'meteor/meteor'; - -import { settings } from '../../../app/settings/client'; -import { MessageAction } from '../../../app/ui-utils/client'; -import { setMessageJumpQueryStringParameter } from '../../lib/utils/setMessageJumpQueryStringParameter'; - -Meteor.startup(() => { - MessageAction.addButton({ - id: 'jump-to-star-message', - icon: 'jump', - label: 'Jump_to_message', - context: ['starred', 'threads', 'message-mobile', 'videoconf-threads'], - action(_, { message }) { - setMessageJumpQueryStringParameter(message._id); - }, - condition({ message, subscription, user }) { - if (subscription == null || !settings.get('Message_AllowStarring')) { - return false; - } - - return Boolean(message.starred?.find((star) => star._id === user?._id)); - }, - order: 100, - group: 'message', - }); -});