Skip to content

Commit

Permalink
chore: remove meteor.startup from follow message (#34077)
Browse files Browse the repository at this point in the history
Co-authored-by: Tasso Evangelista <[email protected]>
  • Loading branch information
MartinSchoeler and tassoevan authored Dec 4, 2024
1 parent 6cfc6ce commit 6e22e5a
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 55 deletions.
1 change: 0 additions & 1 deletion apps/meteor/app/threads/client/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
import './messageAction/follow';
import './messageAction/replyInThread';
import './threads.css';
52 changes: 0 additions & 52 deletions apps/meteor/app/threads/client/messageAction/follow.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import React, { memo, useMemo, useRef } from 'react';

import MessageActionMenu from './MessageActionMenu';
import MessageToolbarStarsActionMenu from './MessageToolbarStarsActionMenu';
import { useFollowMessageAction } from './useFollowMessageAction';
import { useJumpToMessageContextAction } from './useJumpToMessageContextAction';
import { useNewDiscussionMessageAction } from './useNewDiscussionMessageAction';
import { usePermalinkStar } from './usePermalinkStar';
Expand Down Expand Up @@ -99,14 +100,13 @@ const MessageToolbar = ({
useStarMessageAction(message, { room, user });
useUnstarMessageAction(message, { room, user });
usePermalinkStar(message, { subscription, user });
useFollowMessageAction(message, { room, user, context });
useUnFollowMessageAction(message, { room, user, context });

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,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import type { IMessage, IRoom, IUser } from '@rocket.chat/core-typings';
import { isOmnichannelRoom } from '@rocket.chat/core-typings';
import { useSetting, useToastMessageDispatch } from '@rocket.chat/ui-contexts';
import { useQueryClient } from '@tanstack/react-query';
import { useEffect } from 'react';

import { Messages } from '../../../../app/models/client';
import { MessageAction } from '../../../../app/ui-utils/client';
import type { MessageActionContext } from '../../../../app/ui-utils/client/lib/MessageAction';
import { t } from '../../../../app/utils/lib/i18n';
import { useReactiveQuery } from '../../../hooks/useReactiveQuery';
import { roomsQueryKeys } from '../../../lib/queryKeys';
import { useToggleFollowingThreadMutation } from '../../../views/room/contextualBar/Threads/hooks/useToggleFollowingThreadMutation';

export const useFollowMessageAction = (
message: IMessage,
{ room, user, context }: { room: IRoom; user: IUser | undefined; context: MessageActionContext },
) => {
const threadsEnabled = useSetting('Threads_enabled');

const dispatchToastMessage = useToastMessageDispatch();

const queryClient = useQueryClient();

const { mutate: toggleFollowingThread } = useToggleFollowingThreadMutation({
onSuccess: () => {
dispatchToastMessage({
type: 'success',
message: t('You_followed_this_message'),
});
},
});

const { tmid, _id } = message;
const messageQuery = useReactiveQuery(roomsQueryKeys.message(message.rid, message._id), () =>
Messages.findOne({ _id: tmid || _id }, { fields: { replies: 1 } }),
);

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

let { replies = [] } = message;
if (tmid || context) {
const parentMessage = messageQuery.data;
if (parentMessage) {
replies = parentMessage.replies || [];
}
}

if (!user?._id) {
return;
}

if ((replies as string[]).includes(user._id)) {
return;
}

MessageAction.addButton({
id: 'follow-message',
icon: 'bell',
label: 'Follow_message',
type: 'interaction',
context: ['message', 'message-mobile', 'threads', 'federated', 'videoconf', 'videoconf-threads'],
action() {
toggleFollowingThread({ tmid: tmid || _id, follow: true, rid: room._id });
},
order: 1,
group: 'menu',
});

return () => MessageAction.removeButton('follow-message');
}, [_id, context, message, messageQuery, messageQuery.data, queryClient, room, threadsEnabled, tmid, toggleFollowingThread, user]);
};

0 comments on commit 6e22e5a

Please sign in to comment.