Skip to content

Commit

Permalink
Revert useEffect removal
Browse files Browse the repository at this point in the history
  • Loading branch information
tassoevan committed Nov 22, 2024
1 parent f42863c commit 5f1b589
Showing 1 changed file with 25 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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';
Expand All @@ -10,26 +11,30 @@ export const useStarMessageAction = (message: IMessage, { room, user }: { room:

const { mutateAsync: starMessage } = useStarMessageMutation();

if (!allowStarring || isOmnichannelRoom(room)) {
MessageAction.removeButton('star-message');
return;
}
useEffect(() => {
if (!allowStarring || isOmnichannelRoom(room)) {
return;
}

if (Array.isArray(message.starred) && message.starred.find((star) => star._id === user?._id)) {
MessageAction.removeButton('star-message');
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',
});
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]);
};

0 comments on commit 5f1b589

Please sign in to comment.