Skip to content

Commit

Permalink
chore: remove meteor.startup from jump-to-*-message (#34027)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinSchoeler authored Dec 4, 2024
1 parent d9de9fb commit f8ecbd7
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 88 deletions.
23 changes: 22 additions & 1 deletion apps/meteor/client/components/message/toolbar/MessageToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import type { IMessage, IRoom, ISubscription, ITranslatedMessage } from '@rocket
import { isThreadMessage, isRoomFederated, isVideoConfMessage, isE2EEMessage } from '@rocket.chat/core-typings';
import { MessageToolbar as FuselageMessageToolbar, MessageToolbarItem } from '@rocket.chat/fuselage';
import { useFeaturePreview } from '@rocket.chat/ui-client';
import { useUser, useSettings, useTranslation, useMethod, useLayoutHiddenActions } from '@rocket.chat/ui-contexts';
import { useUser, useSettings, useTranslation, useMethod, useLayoutHiddenActions, useSetting } from '@rocket.chat/ui-contexts';
import { useQuery } from '@tanstack/react-query';
import type { ComponentProps, ReactElement } from 'react';
import React, { memo, useMemo, useRef } from 'react';

import MessageActionMenu from './MessageActionMenu';
import MessageToolbarStarsActionMenu from './MessageToolbarStarsActionMenu';
import { useJumpToMessageContextAction } from './useJumpToMessageContextAction';
import { useNewDiscussionMessageAction } from './useNewDiscussionMessageAction';
import { usePermalinkStar } from './usePermalinkStar';
import { usePinMessageAction } from './usePinMessageAction';
Expand Down Expand Up @@ -88,6 +89,7 @@ const MessageToolbar = ({
const starsAction = useMessageActionAppsActionButtons(context, 'ai');

const { messageToolbox: hiddenActions } = useLayoutHiddenActions();
const allowStarring = useSetting('Message_AllowStarring');

// TODO: move this to another place
useWebDAVMessageAction();
Expand All @@ -97,6 +99,25 @@ const MessageToolbar = ({
useUnstarMessageAction(message, { room, user });
usePermalinkStar(message, { subscription, user });

useJumpToMessageContextAction(message, {
id: 'jump-to-message',
order: 100,
context: ['mentions', 'threads', 'videoconf-threads', 'message-mobile', 'search'],
});

useJumpToMessageContextAction(message, {
id: 'jump-to-pin-message',
order: 100,
hidden: !subscription,
context: ['pinned', 'direct'],
});
useJumpToMessageContextAction(message, {
id: 'jump-to-star-message',
hidden: !allowStarring || !subscription,
order: 100,
context: ['starred'],
});

const actionsQueryResult = useQuery({
queryKey: roomsQueryKeys.messageActionsWithParameters(room._id, message),
queryFn: async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { IMessage } from '@rocket.chat/core-typings';
import { useEffect } from 'react';

import type { MessageActionContext } from '../../../../app/ui-utils/client/lib/MessageAction';
import { MessageAction } from '../../../../app/ui-utils/client/lib/MessageAction';
import { setMessageJumpQueryStringParameter } from '../../../lib/utils/setMessageJumpQueryStringParameter';

export const useJumpToMessageContextAction = (
message: IMessage,
{ id, order, hidden, context }: { id: string; order: number; hidden?: boolean; context: MessageActionContext[] },
) => {
useEffect(() => {
if (hidden) {
return;
}

MessageAction.addButton({
id,
icon: 'jump',
label: 'Jump_to_message',
context,
async action() {
setMessageJumpQueryStringParameter(message._id);
},
order,
group: 'message',
});

return () => {
MessageAction.removeButton(id);
};
}, [hidden, context, id, message._id, order]);
};
4 changes: 0 additions & 4 deletions apps/meteor/client/startup/actionButtons/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
import './jumpToMessage';
import './jumpToPinMessage';
import './jumpToSearchMessage';
import './jumpToStarMessage';
import './permalinkPinned';
import './unpinMessage';
18 changes: 0 additions & 18 deletions apps/meteor/client/startup/actionButtons/jumpToMessage.ts

This file was deleted.

21 changes: 0 additions & 21 deletions apps/meteor/client/startup/actionButtons/jumpToPinMessage.ts

This file was deleted.

18 changes: 0 additions & 18 deletions apps/meteor/client/startup/actionButtons/jumpToSearchMessage.ts

This file was deleted.

26 changes: 0 additions & 26 deletions apps/meteor/client/startup/actionButtons/jumpToStarMessage.ts

This file was deleted.

0 comments on commit f8ecbd7

Please sign in to comment.