Skip to content

Commit

Permalink
chore: Discussion message action meteor removal (#33962)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinSchoeler authored Nov 19, 2024
1 parent eccd40d commit c71d5de
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 68 deletions.
65 changes: 0 additions & 65 deletions apps/meteor/app/discussion/client/createDiscussionMessageAction.ts

This file was deleted.

2 changes: 0 additions & 2 deletions apps/meteor/app/discussion/client/index.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 { useNewDiscussionMessageAction } from './useNewDiscussionMessageAction';
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 @@ -85,6 +86,7 @@ const MessageToolbar = ({

// TODO: move this to another place
useWebDAVMessageAction();
useNewDiscussionMessageAction();

const actionsQueryResult = useQuery(['rooms', room._id, 'messages', message._id, 'actions'] as const, async () => {
const props = { message, room, user, subscription, settings: mapSettings, chat };
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { useSetModal, useSetting } from '@rocket.chat/ui-contexts';
import React, { useEffect } from 'react';

import { hasPermission } from '../../../../app/authorization/client';
import { MessageAction } from '../../../../app/ui-utils/client/lib/MessageAction';
import { roomCoordinator } from '../../../lib/rooms/roomCoordinator';
import CreateDiscussion from '../../CreateDiscussion';

export const useNewDiscussionMessageAction = () => {
const enabled = useSetting('Discussion_enabled', false);

const setModal = useSetModal();

useEffect(() => {
if (!enabled) {
return MessageAction.removeButton('start-discussion');
}
MessageAction.addButton({
id: 'start-discussion',
icon: 'discussion',
label: 'Discussion_start',
type: 'communication',
context: ['message', 'message-mobile', 'videoconf'],
async action(_, { message, room }) {
setModal(
<CreateDiscussion
defaultParentRoom={room?.prid || room?._id}
onClose={() => setModal(undefined)}
parentMessageId={message._id}
nameSuggestion={message?.msg?.substr(0, 140)}
/>,
);
},
condition({
message: {
u: { _id: uid },
drid,
dcount,
},
room,
subscription,
user,
}) {
if (drid || !Number.isNaN(Number(dcount))) {
return false;
}
if (!subscription) {
return false;
}
const isLivechatRoom = roomCoordinator.isLivechatRoom(room.t);
if (isLivechatRoom) {
return false;
}

if (!user) {
return false;
}

return uid !== user._id ? hasPermission('start-discussion-other-user', room._id) : hasPermission('start-discussion', room._id);
},
order: 1,
group: 'menu',
});
return () => {
MessageAction.removeButton('start-discussion');
};
}, [enabled, setModal]);
};
1 change: 0 additions & 1 deletion apps/meteor/client/importPackages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import '../app/tokenpass/client';
import '../app/webrtc/client';
import '../app/wordpress/client';
import '../app/e2e/client';
import '../app/discussion/client';
import '../app/threads/client';
import '../app/utils/client';
import '../app/settings/client';
Expand Down

0 comments on commit c71d5de

Please sign in to comment.