Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove meteor.startup from star-message #34017

Merged
merged 5 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type { IMessage } from '@rocket.chat/core-typings';
import { useToastMessageDispatch, useEndpoint } from '@rocket.chat/ui-contexts';
import { useQueryClient, useMutation } from '@tanstack/react-query';

import { toggleStarredMessage } from '../../../lib/mutationEffects/starredMessage';
import { roomsQueryKeys } from '../../../lib/queryKeys';

export const useStarMessageMutation = () => {
const dispatchToastMessage = useToastMessageDispatch();

const queryClient = useQueryClient();

const starMessage = useEndpoint('POST', '/v1/chat.starMessage');

return useMutation({
mutationFn: async (message: IMessage) => {
await starMessage({ messageId: message._id });
},
onSuccess: (_data, message) => {
toggleStarredMessage(message, true);
},
onError: (error) => {
dispatchToastMessage({ type: 'error', message: error });
},
onSettled: (_data, _error, message) => {
queryClient.invalidateQueries(roomsQueryKeys.starredMessages(message.rid));
queryClient.invalidateQueries(roomsQueryKeys.messageActions(message.rid, message._id));
},
});
};
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 { useStarMessageAction } from './useStarMessageAction';
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 @@ -88,6 +89,7 @@ const MessageToolbar = ({
// TODO: move this to another place
useWebDAVMessageAction();
useNewDiscussionMessageAction();
useStarMessageAction(message, { room, user });

const actionsQueryResult = useQuery({
queryKey: roomsQueryKeys.messageActionsWithParameters(room._id, message),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import type { IMessage, IRoom, IUser } from '@rocket.chat/core-typings';
import { isOmnichannelRoom } from '@rocket.chat/core-typings';
import { useSetting } from '@rocket.chat/ui-contexts';
import { useEffect } from 'react';

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

export const useStarMessageAction = (message: IMessage, { room, user }: { room: IRoom; user: IUser | undefined }) => {
const allowStarring = useSetting('Message_AllowStarring', true);

const { mutateAsync: starMessage } = useStarMessageMutation();

useEffect(() => {
if (!allowStarring || isOmnichannelRoom(room)) {
return;
}

if (Array.isArray(message.starred) && message.starred.find((star) => star._id === user?._id)) {
return;
}

MessageAction.addButton({
id: 'star-message',
icon: 'star',
label: 'Star',
type: 'interaction',
context: ['starred', 'message', 'message-mobile', 'threads', 'federated', 'videoconf', 'videoconf-threads'],
async action() {
await starMessage(message);
},
order: 3,
group: 'menu',
});

return () => {
MessageAction.removeButton('star-message');
};
}, [allowStarring, message, room, starMessage, user?._id]);
};
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 @@ -5,6 +5,5 @@ import './jumpToStarMessage';
import './permalinkPinned';
import './permalinkStar';
import './pinMessage';
import './starMessage';
import './unpinMessage';
import './unstarMessage';
44 changes: 0 additions & 44 deletions apps/meteor/client/startup/actionButtons/starMessage.ts

This file was deleted.

Loading