Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/odd-needles-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Fixes "Reply in direct message" action not being shown when user has permission to create DMs but no existing conversation exists.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const useReplyInDMAction = (
[message.u._id, user],
);

const shouldFindRoom = useMemo(() => !!user && canCreateDM && user._id !== message.u._id, [canCreateDM, 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(
Expand All @@ -52,7 +52,7 @@ export const useReplyInDMAction = (
if (!subscription || room.t === 'd' || room.t === 'l' || isLayoutEmbedded) {
return false;
}
if (!!user && user._id !== message.u._id && canCreateDM) {
if (!!user && user._id !== message.u._id && !canCreateDM) {
Comment thread
aleksandernsilva marked this conversation as resolved.
Comment thread
nazabucciarelli marked this conversation as resolved.
if (!dmRoom || !dmSubs) {
return false;
}
Expand Down
43 changes: 34 additions & 9 deletions apps/meteor/tests/e2e/message-actions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ADMIN_CREDENTIALS } from './config/constants';
import { Users } from './fixtures/userStates';
import { HomeChannel } from './page-objects';
import { CreateNewDiscussionModal } from './page-objects/fragments';
import { createTargetChannel, createTargetTeam } from './utils';
import { createTargetChannel, createTargetTeam, sendTargetChannelMessage } from './utils';
import { setUserPreferences } from './utils/setUserPreferences';
import { expect, test } from './utils/test';

Expand All @@ -13,7 +13,7 @@ test.describe.serial('message-actions', () => {
let forwardChannel: string;
let forwardTeam: string;
test.beforeAll(async ({ api }) => {
targetChannel = await createTargetChannel(api);
targetChannel = await createTargetChannel(api, { members: ['user2'] });
forwardChannel = await createTargetChannel(api);
forwardTeam = await createTargetTeam(api);
});
Expand All @@ -22,13 +22,6 @@ test.describe.serial('message-actions', () => {
await page.goto('/home');
await poHomeChannel.navbar.openChat(targetChannel);
});
test('expect reply the message in direct', async ({ page }) => {
await poHomeChannel.content.sendMessage('this is a message for reply in direct');
await poHomeChannel.content.openLastMessageMenu();
await page.locator('role=menuitem[name="Reply in direct message"]').click();

await expect(page).toHaveURL(/.*reply/);
});

test('expect reply the message', async ({ page }) => {
await poHomeChannel.content.sendMessage('this is a message for reply');
Expand Down Expand Up @@ -169,6 +162,38 @@ test.describe.serial('message-actions', () => {
expect(clipboardText).toContain('http');
});

test.describe.serial('expect reply in direct message', () => {
test.use({ storageState: Users.user2.state });

test.beforeAll(async ({ api }) => {
await sendTargetChannelMessage(api, targetChannel, { msg: 'message from admin for reply in DM' });
});

test('expect option not be visible without create-d permission and no existing DM', async ({ page, api }) => {
expect((await api.post('/permissions.update', { permissions: [{ _id: 'create-d', roles: ['admin'] }] })).status()).toBe(200);

await poHomeChannel.content.openLastMessageMenu();
await expect(page.locator('role=menuitem[name="Reply in direct message"]')).toBeHidden();
Comment thread
ricardogarim marked this conversation as resolved.
Outdated
});

test('expect option be visible and redirect to DM', async ({ page, api }) => {
expect(
(await api.post('/permissions.update', { permissions: [{ _id: 'create-d', roles: ['admin', 'user', 'bot', 'app'] }] })).status(),
).toBe(200);

await poHomeChannel.content.openLastMessageMenu();
await page.locator('role=menuitem[name="Reply in direct message"]').click();
Comment thread
ricardogarim marked this conversation as resolved.
Outdated

await expect(page).toHaveURL(/.*reply/);
});

test.afterAll(async ({ api }) => {
Comment thread
dougfabris marked this conversation as resolved.
expect(
(await api.post('/permissions.update', { permissions: [{ _id: 'create-d', roles: ['admin', 'user', 'bot', 'app'] }] })).status(),
).toBe(200);
});
});

test.describe('Preference Hide Contextual Bar by clicking outside of it Enabled', () => {
test.beforeAll(async ({ api }) => {
await setUserPreferences(api, { hideFlexTab: true });
Expand Down
Loading