From c594af8f81f8e7ec38440731d09b24afe2cc9ad5 Mon Sep 17 00:00:00 2001 From: Tiago Evangelista Date: Thu, 9 Jan 2025 15:14:52 -0300 Subject: [PATCH] fix --- .../ui-utils/client/lib/LegacyRoomManager.ts | 8 ++++- .../views/room/composer/ComposerMessage.tsx | 29 ++++++++++++++++--- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/apps/meteor/app/ui-utils/client/lib/LegacyRoomManager.ts b/apps/meteor/app/ui-utils/client/lib/LegacyRoomManager.ts index bf33821de4a4..bde3a19a8a23 100644 --- a/apps/meteor/app/ui-utils/client/lib/LegacyRoomManager.ts +++ b/apps/meteor/app/ui-utils/client/lib/LegacyRoomManager.ts @@ -10,6 +10,7 @@ import { roomCoordinator } from '../../../../client/lib/rooms/roomCoordinator'; import { fireGlobalEvent } from '../../../../client/lib/utils/fireGlobalEvent'; import { getConfig } from '../../../../client/lib/utils/getConfig'; import { callbacks } from '../../../../lib/callbacks'; +import { hasPermission } from '../../../authorization/client'; import { Messages, Subscriptions, CachedChatSubscription } from '../../../models/client'; import { sdk } from '../../../utils/client/lib/SDKClient'; @@ -82,6 +83,7 @@ const computation = Tracker.autorun(() => { if (!mainReady.get()) { return; } + Tracker.nonreactive(() => Object.entries(openedRooms).forEach(([typeName, record]) => { if (record.active !== true || record.ready === true) { @@ -96,6 +98,11 @@ const computation = Tracker.autorun(() => { void RoomHistoryManager.getMoreIfIsEmpty(record.rid); if (room) { + const subscription = Subscriptions.findOne({ rid: record.rid }, { reactive: false }); + if (!hasPermission('preview-c-room') && room.t === 'c' && !subscription) { + return; + } + if (record.streamActive !== true) { void sdk .stream('room-messages', [record.rid], async (msg) => { @@ -105,7 +112,6 @@ const computation = Tracker.autorun(() => { // } // Do not load command messages into channel if (msg.t !== 'command') { - const subscription = Subscriptions.findOne({ rid: record.rid }, { reactive: false }); const isNew = !Messages.findOne({ _id: msg._id, temp: { $ne: true } }); await upsertMessage({ msg, subscription }); diff --git a/apps/meteor/client/views/room/composer/ComposerMessage.tsx b/apps/meteor/client/views/room/composer/ComposerMessage.tsx index 49500509830c..a79d74ad9bb8 100644 --- a/apps/meteor/client/views/room/composer/ComposerMessage.tsx +++ b/apps/meteor/client/views/room/composer/ComposerMessage.tsx @@ -1,5 +1,5 @@ import type { IMessage, ISubscription } from '@rocket.chat/core-typings'; -import { useToastMessageDispatch } from '@rocket.chat/ui-contexts'; +import { usePermission, useToastMessageDispatch } from '@rocket.chat/ui-contexts'; import type { ReactElement, ReactNode } from 'react'; import { memo, useCallback, useMemo } from 'react'; @@ -29,6 +29,7 @@ const ComposerMessage = ({ tmid, onSend, ...props }: ComposerMessageProps): Reac const chat = useChat(); const room = useRoom(); const dispatchToastMessage = useToastMessageDispatch(); + const hasPreviewPublicRoomPermission = usePermission('preview-c-room'); const composerProps = useMemo( () => ({ @@ -53,7 +54,7 @@ const ComposerMessage = ({ tmid, onSend, ...props }: ComposerMessageProps): Reac isSlashCommandAllowed?: boolean; }): Promise => { try { - await chat?.action.stop('typing'); + chat?.action.stop('typing'); const newMessageSent = await chat?.flows.sendMessage({ text, tshow, @@ -85,11 +86,31 @@ const ComposerMessage = ({ tmid, onSend, ...props }: ComposerMessageProps): Reac useCallback(() => LegacyRoomManager.getOpenedRoomByRid(room._id)?.streamActive ?? false, [room._id]), ); - if (!publicationReady) { + if (!publicationReady && hasPreviewPublicRoomPermission) { return ; } - return ; + const subscribe = () => { + if (!hasPreviewPublicRoomPermission) { + // Get room subscription + LegacyRoomManager.open({ rid: room._id, typeName: room.t }); + LegacyRoomManager.computation.invalidate(); + } + }; + + return ( + { + await composerProps.onJoin(); + subscribe(); + }} + {...props} + /> + ); }; export default memo(ComposerMessage);