Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/dull-boats-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@rocket.chat/meteor': patch
'@rocket.chat/ui-client': patch
---

Fixed 'Reply in Direct Message' action visibility by removing redundant local store checks
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { type IMessage, type ISubscription, type IRoom, isE2EEMessage } from '@rocket.chat/core-typings';
import { useEmbeddedLayout } from '@rocket.chat/ui-client';
import { usePermission, useRouter, useUser } from '@rocket.chat/ui-contexts';
import { useCallback, useMemo } from 'react';
import { useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { useShallow } from 'zustand/shallow';

import type { MessageActionConfig } from '../../../../app/ui-utils/client/lib/MessageAction';
import { roomCoordinator } from '../../../lib/rooms/roomCoordinator';
import { Rooms, Subscriptions } from '../../../stores';

export const useReplyInDMAction = (
message: IMessage,
Expand All @@ -21,23 +19,6 @@ export const useReplyInDMAction = (
const isLayoutEmbedded = useEmbeddedLayout();
const { t } = useTranslation();

const roomPredicate = useCallback(
(record: IRoom): boolean => {
const ids = [user?._id, message.u._id].sort().join('');
return ids.includes(record._id);
},
[message.u._id, user],
);

const shouldFindRoom = useMemo(() => !!user && canCreateDM && user._id !== message.u._id, [canCreateDM, message.u._id, user]);
const dmRoom = Rooms.use(useShallow((state) => (shouldFindRoom ? state.find(roomPredicate) : undefined)));

const subsPredicate = useCallback(
(record: ISubscription) => record.rid === dmRoom?._id || record.u._id === user?._id,
[dmRoom, user?._id],
);
const dmSubs = Subscriptions.use(useShallow((state) => state.find(subsPredicate)));

const tooltip = useMemo(() => {
if (encrypted) {
return t('Action_not_available_encrypted_content', { action: t('Reply_in_direct_message') });
Expand All @@ -52,13 +33,11 @@ export const useReplyInDMAction = (
if (!subscription || room.t === 'd' || room.t === 'l' || isLayoutEmbedded) {
return false;
}
if (!!user && user._id !== message.u._id && canCreateDM) {
if (!dmRoom || !dmSubs) {
return false;
}
if (!user || user._id === message.u._id || !canCreateDM) {
return false;
}
return true;
}, [canCreateDM, dmRoom, dmSubs, isLayoutEmbedded, message.u._id, room.t, subscription, user]);
}, [canCreateDM, isLayoutEmbedded, message.u._id, room.t, subscription, user]);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

if (!canReplyInDM) {
return null;
Expand Down