Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Hide system messages setting not being respected. #27151

Merged
merged 11 commits into from
Nov 4, 2022
28 changes: 18 additions & 10 deletions apps/meteor/app/lib/lib/MessageTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,31 +263,31 @@ Meteor.startup(function () {

export const MessageTypesValues = [
{
key: 'uj',
key: 'uj', // user joined
i18nLabel: 'Message_HideType_uj',
},
{
key: 'ujt',
key: 'ujt', // user joined team
i18nLabel: 'Message_HideType_ujt',
},
{
key: 'ul',
key: 'ul', // user left
i18nLabel: 'Message_HideType_ul',
},
{
key: 'ult',
key: 'ult', // user left team
i18nLabel: 'Message_HideType_ult',
},
{
key: 'ru',
key: 'ru', // user removed
i18nLabel: 'Message_HideType_ru',
},
{
key: 'removed-user-from-team',
i18nLabel: 'Message_HideType_removed_user_from_team',
},
{
key: 'au',
key: 'au', // added user
i18nLabel: 'Message_HideType_au',
},
{
Expand All @@ -299,19 +299,19 @@ export const MessageTypesValues = [
i18nLabel: 'Message_HideType_mute_unmute',
},
{
key: 'r',
key: 'r', // room name changed
i18nLabel: 'Message_HideType_r',
},
{
key: 'ut',
key: 'ut', // user joined conversation
i18nLabel: 'Message_HideType_ut',
},
{
key: 'wm',
key: 'wm', // welcome
i18nLabel: 'Message_HideType_wm',
},
{
key: 'rm',
key: 'rm', // message removed
i18nLabel: 'Message_HideType_rm',
},
{
Expand Down Expand Up @@ -386,4 +386,12 @@ export const MessageTypesValues = [
key: 'user-removed-room-from-team',
i18nLabel: 'Message_HideType_user_removed_room_from_team',
},
{
key: 'room_changed_announcement',
i18nLabel: 'Message_HideType_changed_announcement',
},
{
key: 'room_changed_description',
i18nLabel: 'Message_HideType_changed_description',
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const MessageSystem: FC<{ message: IMessage }> = ({ message }) => {
isSelected={isSelected}
data-qa-selected={isSelected}
data-qa='system-message'
data-system-message-type={message.t}
>
<MessageSystemLeftContainer>
{!isSelecting && <UserAvatar username={message.u.username} size='x18' />}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { IRoom, IMessage } from '@rocket.chat/core-typings';
import { useStableArray } from '@rocket.chat/fuselage-hooks';
import { useSetting } from '@rocket.chat/ui-contexts';
import { Mongo } from 'meteor/mongo';
import { useCallback, useMemo } from 'react';

Expand All @@ -19,6 +21,9 @@ const options = {

export const useMessages = ({ rid }: { rid: IRoom['_id'] }): MessageWithMdEnforced[] => {
const { autoTranslateLanguage, katex, showColors, useShowTranslated } = useMessageListContext();
const hideSysMes = useSetting('Hide_System_Messages');

const hideSysMessagesStable = useStableArray(Array.isArray(hideSysMes) ? hideSysMes : []);

const normalizeMessage = useMemo(() => {
const parseOptions = {
Expand All @@ -39,9 +44,10 @@ export const useMessages = ({ rid }: { rid: IRoom['_id'] }): MessageWithMdEnforc
() => ({
rid,
_hidden: { $ne: true },
t: { $nin: hideSysMessagesStable },
$or: [{ tmid: { $exists: false } }, { tshow: { $eq: true } }],
}),
[rid],
[rid, hideSysMessagesStable],
);

return useReactiveValue<MessageWithMdEnforced[]>(
Expand Down
2 changes: 2 additions & 0 deletions apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -3248,6 +3248,8 @@
"Message_HideType_user_converted_to_team": "Hide \"User converted channel to a Team\" messages",
"Message_HideType_user_deleted_room_from_team": "Hide \"User deleted room from Team\" messages",
"Message_HideType_user_removed_room_from_team": "Hide \"User removed room from Team\" messages",
"Message_HideType_changed_description": "Hide \"Room description changed to\" messages",
"Message_HideType_changed_announcement": "Hide \"Room announcement changed to\" messages",
"Message_HideType_ut": "Hide \"User Joined Conversation\" messages",
"Message_HideType_wm": "Hide \"Welcome\" messages",
"Message_Id": "Message Id",
Expand Down
87 changes: 87 additions & 0 deletions apps/meteor/tests/e2e/system-messages.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import type { IRoom, IUser } from '@rocket.chat/core-typings';
import type { Locator, Page } from '@playwright/test';
import faker from '@faker-js/faker';

import { test, expect } from './utils/test';
import { setSettingValueById } from './utils/setSettingValueById';
import { HomeChannel } from './page-objects';

test.use({ storageState: 'admin-session.json' });

const userData = {
username: faker.datatype.uuid(),
name: faker.name.firstName(),
email: faker.internet.email(),
password: faker.internet.password(),
};

// There currently are over 33 system messages. Testing only a couple due to test being too slow right now.
// Ideally, we should test all.
test.describe.serial('System Messages', () => {
let adminPage: Page;
let poHomeChannel: HomeChannel;
let group: IRoom;
let user: IUser;

const findSysMes = (id: string): Locator => {
return adminPage.locator(`[data-qa="system-message"][data-system-message-type="${id}"]`);
};

test.beforeAll(async ({ api, browser }) => {
expect((await setSettingValueById(api, 'Hide_System_Messages', [])).status()).toBe(200);

expect(
(
await api.post('/groups.create', { name: faker.datatype.uuid() }).then(async (response) => {
group = (await response.json()).group;
// console.log(group);
return response;
})
).status(),
).toBe(200);

expect(
(
await api.post('/users.create', userData).then(async (result) => {
user = (await result.json()).user;
return result;
})
).status(),
).toBe(200);

adminPage = await browser.newPage({ storageState: 'admin-session.json' });
poHomeChannel = new HomeChannel(adminPage);
});

test.beforeEach(async () => {
if (!group.name) {
return;
}
await adminPage.goto('/home');
await poHomeChannel.sidenav.openChat(group.name as string);
});

test('expect "User added" system message to be visible', async ({ api }) => {
expect((await api.post('/groups.invite', { roomId: group._id, userId: user._id })).status()).toBe(200);
await expect(findSysMes('au')).toBeVisible();
});

test('expect "User added" system message to be hidden', async ({ api }) => {
expect((await setSettingValueById(api, 'Hide_System_Messages', ['au'])).status()).toBe(200);
await expect(findSysMes('au')).not.toBeVisible();
});

test('expect "User removed" system message to be visible', async ({ api }) => {
expect((await api.post('/groups.kick', { roomId: group._id, userId: user._id })).status()).toBe(200);
await expect(findSysMes('ru')).toBeVisible();
});

test('expect "User removed" system message to be hidden', async ({ api }) => {
expect((await setSettingValueById(api, 'Hide_System_Messages', ['ru'])).status()).toBe(200);
await expect(findSysMes('ru')).not.toBeVisible();
});

test.afterAll(async ({ api }) => {
expect((await api.post('/groups.delete', { roomId: group._id })).status()).toBe(200);
});
});
7 changes: 7 additions & 0 deletions apps/meteor/tests/e2e/utils/setSettingValueById.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { APIResponse } from '@playwright/test';

import type { BaseTest } from './test';

export const setSettingValueById = (api: BaseTest['api'], settingId: string, value: unknown): Promise<APIResponse> => {
return api.post(`/settings/${settingId}`, { value });
};