diff --git a/apps/meteor/app/threads/client/index.ts b/apps/meteor/app/threads/client/index.ts deleted file mode 100644 index 5809a93f01d4..000000000000 --- a/apps/meteor/app/threads/client/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -import './messageAction/replyInThread'; -import './threads.css'; diff --git a/apps/meteor/app/threads/client/messageAction/replyInThread.ts b/apps/meteor/app/threads/client/messageAction/replyInThread.ts deleted file mode 100644 index 9d0ab8566e04..000000000000 --- a/apps/meteor/app/threads/client/messageAction/replyInThread.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { Meteor } from 'meteor/meteor'; -import { Tracker } from 'meteor/tracker'; - -import { roomCoordinator } from '../../../../client/lib/rooms/roomCoordinator'; -import { router } from '../../../../client/providers/RouterProvider'; -import { settings } from '../../../settings/client'; -import { MessageAction } from '../../../ui-utils/client'; - -Meteor.startup(() => { - Tracker.autorun(() => { - if (!settings.get('Threads_enabled')) { - return MessageAction.removeButton('reply-in-thread'); - } - MessageAction.addButton({ - id: 'reply-in-thread', - icon: 'thread', - label: 'Reply_in_thread', - context: ['message', 'message-mobile', 'federated', 'videoconf'], - action(e, { message }) { - e?.stopPropagation(); - router.navigate({ - name: router.getRouteName()!, - params: { - ...router.getRouteParameters(), - tab: 'thread', - context: message.tmid || message._id, - }, - }); - }, - condition({ subscription, room }) { - const isLivechatRoom = roomCoordinator.isLivechatRoom(room.t); - if (isLivechatRoom) { - return false; - } - return Boolean(subscription); - }, - order: -1, - group: 'message', - }); - }); -}); diff --git a/apps/meteor/client/components/message/toolbar/MessageToolbar.tsx b/apps/meteor/client/components/message/toolbar/MessageToolbar.tsx index 5af0529e5d67..464cb51bc175 100644 --- a/apps/meteor/client/components/message/toolbar/MessageToolbar.tsx +++ b/apps/meteor/client/components/message/toolbar/MessageToolbar.tsx @@ -15,6 +15,7 @@ import { useJumpToMessageContextAction } from './useJumpToMessageContextAction'; import { useNewDiscussionMessageAction } from './useNewDiscussionMessageAction'; import { usePermalinkStar } from './usePermalinkStar'; import { usePinMessageAction } from './usePinMessageAction'; +import { useReplyInThreadMessageAction } from './useReplyInThreadMessageAction'; import { useStarMessageAction } from './useStarMessageAction'; import { useUnFollowMessageAction } from './useUnFollowMessageAction'; import { useUnpinMessageAction } from './useUnpinMessageAction'; @@ -104,6 +105,7 @@ const MessageToolbar = ({ usePermalinkStar(message, { subscription, user }); useFollowMessageAction(message, { room, user, context }); useUnFollowMessageAction(message, { room, user, context }); + useReplyInThreadMessageAction(message, { room, subscription }); useJumpToMessageContextAction(message, { id: 'jump-to-message', order: 100, diff --git a/apps/meteor/client/components/message/toolbar/useReplyInThreadMessageAction.ts b/apps/meteor/client/components/message/toolbar/useReplyInThreadMessageAction.ts new file mode 100644 index 000000000000..1920ae68dd36 --- /dev/null +++ b/apps/meteor/client/components/message/toolbar/useReplyInThreadMessageAction.ts @@ -0,0 +1,46 @@ +import { isOmnichannelRoom } from '@rocket.chat/core-typings'; +import type { IMessage, IRoom, ISubscription } from '@rocket.chat/core-typings'; +import { useSetting, useRouter } from '@rocket.chat/ui-contexts'; +import { useEffect } from 'react'; + +import { MessageAction } from '../../../../app/ui-utils/client'; + +export const useReplyInThreadMessageAction = ( + message: IMessage, + { room, subscription }: { room: IRoom; subscription: ISubscription | undefined }, +) => { + const threadsEnabled = useSetting('Threads_enabled'); + + const route = useRouter(); + + useEffect(() => { + if (!threadsEnabled || isOmnichannelRoom(room) || !subscription) { + return; + } + + MessageAction.addButton({ + id: 'reply-in-thread', + icon: 'thread', + label: 'Reply_in_thread', + context: ['message', 'message-mobile', 'federated', 'videoconf'], + action(e) { + e?.stopPropagation(); + const routeName = route.getRouteName(); + if (routeName) { + route.navigate({ + name: routeName, + params: { + ...route.getRouteParameters(), + tab: 'thread', + context: message.tmid || message._id, + }, + }); + } + }, + order: -1, + group: 'message', + }); + + return () => MessageAction.removeButton('unfollow-message'); + }, [message._id, message.tmid, room, route, subscription, threadsEnabled]); +}; diff --git a/apps/meteor/client/importPackages.ts b/apps/meteor/client/importPackages.ts index e08260b53032..f51e51335c9b 100644 --- a/apps/meteor/client/importPackages.ts +++ b/apps/meteor/client/importPackages.ts @@ -36,7 +36,6 @@ import '../app/tokenpass/client'; import '../app/webrtc/client'; import '../app/wordpress/client'; import '../app/e2e/client'; -import '../app/threads/client'; import '../app/utils/client'; import '../app/settings/client'; import '../app/models/client'; diff --git a/apps/meteor/app/threads/client/lib/normalizeThreadTitle.ts b/apps/meteor/client/lib/normalizeThreadTitle.ts similarity index 81% rename from apps/meteor/app/threads/client/lib/normalizeThreadTitle.ts rename to apps/meteor/client/lib/normalizeThreadTitle.ts index c3d10b531b6b..99bd95d34021 100644 --- a/apps/meteor/app/threads/client/lib/normalizeThreadTitle.ts +++ b/apps/meteor/client/lib/normalizeThreadTitle.ts @@ -2,11 +2,11 @@ import type { IMessage } from '@rocket.chat/core-typings'; import { escapeHTML } from '@rocket.chat/string-helpers'; import { Meteor } from 'meteor/meteor'; -import { emojiParser } from '../../../emoji/client/emojiParser'; -import { filterMarkdown } from '../../../markdown/lib/markdown'; -import { MentionsParser } from '../../../mentions/lib/MentionsParser'; -import { Users } from '../../../models/client'; -import { settings } from '../../../settings/client'; +import { emojiParser } from '../../app/emoji/client/emojiParser'; +import { filterMarkdown } from '../../app/markdown/lib/markdown'; +import { MentionsParser } from '../../app/mentions/lib/MentionsParser'; +import { Users } from '../../app/models/client'; +import { settings } from '../../app/settings/client'; export function normalizeThreadTitle({ ...message }: Readonly) { if (message.msg) { diff --git a/apps/meteor/client/views/room/contextualBar/Threads/components/ThreadMessageList.tsx b/apps/meteor/client/views/room/contextualBar/Threads/components/ThreadMessageList.tsx index fff5d55e31c1..28d024c103b0 100644 --- a/apps/meteor/client/views/room/contextualBar/Threads/components/ThreadMessageList.tsx +++ b/apps/meteor/client/views/room/contextualBar/Threads/components/ThreadMessageList.tsx @@ -21,6 +21,7 @@ import { useMessageListNavigation } from '../../../hooks/useMessageListNavigatio import { useLegacyThreadMessageJump } from '../hooks/useLegacyThreadMessageJump'; import { useLegacyThreadMessageListScrolling } from '../hooks/useLegacyThreadMessageListScrolling'; import { useLegacyThreadMessages } from '../hooks/useLegacyThreadMessages'; +import './threads.css'; const isMessageSequential = (current: IMessage, previous: IMessage | undefined, groupingRange: number): boolean => { if (!previous) { diff --git a/apps/meteor/client/views/room/contextualBar/Threads/components/ThreadTitle.tsx b/apps/meteor/client/views/room/contextualBar/Threads/components/ThreadTitle.tsx index ada559d7af7d..c1921d3f00e5 100644 --- a/apps/meteor/client/views/room/contextualBar/Threads/components/ThreadTitle.tsx +++ b/apps/meteor/client/views/room/contextualBar/Threads/components/ThreadTitle.tsx @@ -1,8 +1,8 @@ import type { IThreadMainMessage } from '@rocket.chat/core-typings'; import React, { useMemo } from 'react'; -import { normalizeThreadTitle } from '../../../../../../app/threads/client/lib/normalizeThreadTitle'; import { ContextualbarTitle } from '../../../../../components/Contextualbar'; +import { normalizeThreadTitle } from '../../../../../lib/normalizeThreadTitle'; type ThreadTitleProps = { mainMessage: IThreadMainMessage; diff --git a/apps/meteor/app/threads/client/threads.css b/apps/meteor/client/views/room/contextualBar/Threads/components/threads.css similarity index 100% rename from apps/meteor/app/threads/client/threads.css rename to apps/meteor/client/views/room/contextualBar/Threads/components/threads.css