Skip to content

Commit

Permalink
chore: remove meteor.startup from mark-as-unread (#34083)
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 5, 2024
1 parent 14c0d25 commit 5c9dba6
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 50 deletions.
48 changes: 0 additions & 48 deletions apps/meteor/app/message-mark-as-unread/client/actionButton.ts

This file was deleted.

1 change: 0 additions & 1 deletion apps/meteor/app/message-mark-as-unread/client/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { IMessage, ISubscription } from '@rocket.chat/core-typings';
import { useToastMessageDispatch } from '@rocket.chat/ui-contexts';
import { useMutation } from '@tanstack/react-query';

import { LegacyRoomManager } from '../../../../app/ui-utils/client';
import { sdk } from '../../../../app/utils/client/lib/SDKClient';

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

return useMutation({
mutationFn: async ({ message, subscription }: { message: IMessage; subscription: ISubscription }) => {
await LegacyRoomManager.close(subscription.t + subscription.name);
await sdk.call('unreadMessages', message);
},
onError: (error) => {
dispatchToastMessage({ type: 'error', message: error });
},
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import MessageActionMenu from './MessageActionMenu';
import MessageToolbarStarsActionMenu from './MessageToolbarStarsActionMenu';
import { useFollowMessageAction } from './useFollowMessageAction';
import { useJumpToMessageContextAction } from './useJumpToMessageContextAction';
import { useMarkAsUnreadMessageAction } from './useMarkAsUnreadMessageAction';
import { useNewDiscussionMessageAction } from './useNewDiscussionMessageAction';
import { usePermalinkAction } from './usePermalinkAction';
import { usePinMessageAction } from './usePinMessageAction';
Expand Down Expand Up @@ -133,6 +134,7 @@ const MessageToolbar = ({
context: ['starred'],
});
useReactionMessageAction(message, { user, room, subscription });
useMarkAsUnreadMessageAction(message, { user, room, subscription });

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

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

export const useMarkAsUnreadMessageAction = (
message: IMessage,
{ user, room, subscription }: { user: IUser | undefined; room: IRoom; subscription: ISubscription | undefined },
) => {
const { mutateAsync: markAsUnread } = useMarkAsUnreadMutation();

const router = useRouter();

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

if (!subscription) {
return;
}

if (message.u._id === user._id) {
return;
}

MessageAction.addButton({
id: 'mark-message-as-unread',
icon: 'flag',
label: 'Mark_unread',
context: ['message', 'message-mobile', 'threads'],
type: 'interaction',
async action() {
router.navigate('/home');
await markAsUnread({ message, subscription });
},
order: 4,
group: 'menu',
});
return () => {
MessageAction.removeButton('mark-message-as-unread');
};
}, [markAsUnread, message, room, router, subscription, user]);
};
1 change: 0 additions & 1 deletion apps/meteor/client/importPackages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import '../app/iframe-login/client';
import '../app/license/client';
import '../app/lib/client';
import '../app/livechat-enterprise/client';
import '../app/message-mark-as-unread/client';
import '../app/nextcloud/client';
import '../app/notifications/client';
import '../app/otr/client';
Expand Down

0 comments on commit 5c9dba6

Please sign in to comment.