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

[BREAK] Hide system messages #16243

Merged
merged 26 commits into from
Jan 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
34f581b
created multi select
dudizilla Jan 10, 2020
cb1f0e3
MultiSelect using Fuselage
ggazzo Jan 11, 2020
f762b84
fix lint
ggazzo Jan 11, 2020
153ca2b
Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into hide…
dudizilla Jan 13, 2020
103aadf
Merge branch 'hide-system-messages' of github.com:RocketChat/Rocket.C…
dudizilla Jan 13, 2020
23fded4
renamed multiSelect
dudizilla Jan 13, 2020
af8cefc
adding functions and code refactoring
dudizilla Jan 13, 2020
2b36647
Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into hide…
dudizilla Jan 13, 2020
8450d5c
set multiselect array to null
dudizilla Jan 14, 2020
37496a2
Changed Help wanted section (#16197)
gabriellsh Jan 10, 2020
0d18ae5
MultiSelect using Fuselage
ggazzo Jan 11, 2020
95c98b0
fix lint
ggazzo Jan 11, 2020
d3a96ef
renamed multiSelect
dudizilla Jan 13, 2020
6971289
adding functions and code refactoring
dudizilla Jan 13, 2020
5b5fd2c
[FIX] Integrations admin page (#16183)
gabriellsh Jan 13, 2020
5e19676
Add a converter on getting the file buffer from Apps-Engine.
renatobecker Jan 13, 2020
5c574c1
Merge branch 'hide-system-messages' of github.com:RocketChat/Rocket.C…
ggazzo Jan 14, 2020
5a4143f
revert changes
ggazzo Jan 14, 2020
0130b8d
Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into hide…
ggazzo Jan 14, 2020
8e85693
Merge branch 'hide-system-messages' of github.com:RocketChat/Rocket.C…
dudizilla Jan 14, 2020
8b52893
revert highlight
ggazzo Jan 14, 2020
dafcbc7
updating a migration
dudizilla Jan 14, 2020
a7be99b
resolving lint errors
dudizilla Jan 14, 2020
083bf4e
Merge branch 'hide-system-messages' of github.com:RocketChat/Rocket.C…
dudizilla Jan 14, 2020
43c9af8
package-lock
dudizilla Jan 14, 2020
0f1a283
Merge branch 'develop' of github.com:RocketChat/Rocket.Chat into hide…
ggazzo Jan 29, 2020
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
30 changes: 7 additions & 23 deletions app/lib/server/functions/loadMessageHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,12 @@ import { settings } from '../../../settings';
import { Messages } from '../../../models';
import { normalizeMessagesForUser } from '../../../utils/server/lib/normalizeMessagesForUser';

const hideMessagesOfType = [];
const hideMessagesOfType = new Set();

settings.get(/Message_HideType_.+/, function(key, value) {
const type = key.replace('Message_HideType_', '');
const types = type === 'mute_unmute' ? ['user-muted', 'user-unmuted'] : [type];

return types.forEach((type) => {
const index = hideMessagesOfType.indexOf(type);

if (value === true && index === -1) {
return hideMessagesOfType.push(type);
}

if (index > -1) {
return hideMessagesOfType.splice(index, 1);
}
});
settings.get('Hide_System_Messages', function(key, values) {
const hiddenTypes = values.reduce((array, value) => [...array, ...value === 'mute_unmute' ? ['user-muted', 'user-unmuted'] : [value]], []);
hideMessagesOfType.clear();
hiddenTypes.forEach((item) => hideMessagesOfType.add(item));
});

export const loadMessageHistory = function loadMessageHistory({ userId, rid, end, limit = 20, ls }) {
Expand All @@ -35,12 +24,7 @@ export const loadMessageHistory = function loadMessageHistory({ userId, rid, end
};
}

let records;
if (end != null) {
records = Messages.findVisibleByRoomIdBeforeTimestampNotContainingTypes(rid, end, hideMessagesOfType, options).fetch();
} else {
records = Messages.findVisibleByRoomIdNotContainingTypes(rid, hideMessagesOfType, options).fetch();
}
const records = end != null ? Messages.findVisibleByRoomIdBeforeTimestampNotContainingTypes(rid, end, Array.from(hideMessagesOfType.values()), options).fetch() : Messages.findVisibleByRoomIdNotContainingTypes(rid, Array.from(hideMessagesOfType.values()), options).fetch();
const messages = normalizeMessagesForUser(records, userId);
let unreadNotLoaded = 0;
let firstUnread;
Expand All @@ -51,7 +35,7 @@ export const loadMessageHistory = function loadMessageHistory({ userId, rid, end
if ((firstMessage != null ? firstMessage.ts : undefined) > ls) {
delete options.limit;

const unreadMessages = Messages.findVisibleByRoomIdBetweenTimestampsNotContainingTypes(rid, ls, firstMessage.ts, hideMessagesOfType, {
const unreadMessages = Messages.findVisibleByRoomIdBetweenTimestampsNotContainingTypes(rid, ls, firstMessage.ts, Array.from(hideMessagesOfType.values()), {
limit: 1,
sort: {
ts: 1,
Expand Down
3 changes: 3 additions & 0 deletions app/lib/server/methods/saveSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ Meteor.methods({
case 'int':
check(value, Number);
break;
case 'multiSelect':
check(value, Array);
break;
default:
check(value, String);
break;
Expand Down
64 changes: 46 additions & 18 deletions app/lib/server/startup/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -1093,28 +1093,56 @@ settings.addGroup('Message', function() {
type: 'int',
public: true,
});
this.add('Message_HideType_uj', false, {
type: 'boolean',
public: true,
});
this.add('Message_HideType_ul', false, {
type: 'boolean',
public: true,
});
this.add('Message_HideType_ru', false, {
type: 'boolean',
public: true,
});
this.add('Message_HideType_au', false, {
type: 'boolean',
public: true,
});

this.add('Message_HideType_mute_unmute', false, {
type: 'boolean',

this.add('Hide_System_Messages', [], {
type: 'multiSelect',
public: true,
values: [
{
key: 'uj',
i18nLabel: 'Message_HideType_uj',
}, {
key: 'ul',
i18nLabel: 'Message_HideType_ul',
}, {
key: 'ru',
i18nLabel: 'Message_HideType_ru',
}, {
key: 'au',
i18nLabel: 'Message_HideType_au',
}, {
key: 'mute_unmute',
i18nLabel: 'Message_HideType_mute_unmute',
}, {
key: 'r',
i18nLabel: 'Message_HideType_r',
}, {
key: 'ut',
i18nLabel: 'Message_HideType_ut',
}, {
key: 'wm',
i18nLabel: 'Message_HideType_wm',
}, {
key: 'rm',
i18nLabel: 'Message_HideType_rm',
}, {
key: 'subscription_role_added',
i18nLabel: 'Message_HideType_subscription_role_added',
}, {
key: 'subscription_role_removed',
i18nLabel: 'Message_HideType_subscription_role_removed',
}, {
key: 'room_archived',
i18nLabel: 'Message_HideType_room_archived',
}, {
key: 'room_unarchived',
i18nLabel: 'Message_HideType_room_unarchived',
},
],
});


this.add('Message_ErasureType', 'Delete', {
type: 'select',
public: true,
Expand Down
27 changes: 4 additions & 23 deletions app/ui/client/views/app/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,27 +296,8 @@ Template.room.helpers({

messagesHistory() {
const { rid } = Template.instance();
const hideMessagesOfType = [];
settings.collection.find({ _id: /Message_HideType_.+/ }).forEach(function(record) {
let types;
const type = record._id.replace('Message_HideType_', '');
switch (type) {
case 'mute_unmute':
types = ['user-muted', 'user-unmuted'];
break;
default:
types = [type];
}
return types.forEach(function(type) {
const index = hideMessagesOfType.indexOf(type);

if ((record.value === true) && (index === -1)) {
hideMessagesOfType.push(type);
} else if (index > -1) {
hideMessagesOfType.splice(index, 1);
}
});
});
const { value: settingValues = [] } = settings.collection.findOne('Hide_System_Messages') || {};
const hideMessagesOfType = new Set(settingValues.reduce((array, value) => [...array, ...value === 'mute_unmute' ? ['user-muted', 'user-unmuted'] : [value]], []));

const modes = ['', 'cozy', 'compact'];
const viewMode = getUserPreference(Meteor.userId(), 'messageViewMode');
Expand All @@ -326,8 +307,8 @@ Template.room.helpers({
...(ignoreReplies || modes[viewMode] === 'compact') && { tmid: { $exists: 0 } },
};

if (hideMessagesOfType.length > 0) {
query.t = { $nin: hideMessagesOfType };
if (hideMessagesOfType.size) {
query.t = { $nin: Array.from(hideMessagesOfType.values()) };
}

const options = {
Expand Down
2 changes: 2 additions & 0 deletions client/components/admin/settings/Setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { RelativeUrlSettingInput } from './inputs/RelativeUrlSettingInput';
import { PasswordSettingInput } from './inputs/PasswordSettingInput';
import { IntSettingInput } from './inputs/IntSettingInput';
import { SelectSettingInput } from './inputs/SelectSettingInput';
import { MultiSelectSettingInput } from './inputs/MultiSelectSettingInput';
import { LanguageSettingInput } from './inputs/LanguageSettingInput';
import { ColorSettingInput } from './inputs/ColorSettingInput';
import { FontSettingInput } from './inputs/FontSettingInput';
Expand All @@ -37,6 +38,7 @@ export const MemoizedSetting = memo(function MemoizedSetting({
password: PasswordSettingInput,
int: IntSettingInput,
select: SelectSettingInput,
multiSelect: MultiSelectSettingInput,
language: LanguageSettingInput,
color: ColorSettingInput,
font: FontSettingInput,
Expand Down
58 changes: 58 additions & 0 deletions client/components/admin/settings/inputs/MultiSelectSettingInput.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { Field, Flex, Box, MultiSelectFiltered, MultiSelect } from '@rocket.chat/fuselage';
import React from 'react';

import { useTranslation } from '../../../../contexts/TranslationContext';
import { ResetSettingButton } from '../ResetSettingButton';

export function MultiSelectSettingInput({
_id,
label,
value = [],
placeholder,
readonly,
disabled,
values = [],
hasResetButton,
onChangeValue,
onResetButtonClick,
autocomplete,
}) {
const t = useTranslation();

const handleChange = (value) => {
onChangeValue && onChangeValue(value);
// onChangeValue && onChangeValue([...event.currentTarget.querySelectorAll('option')].filter((e) => e.selected).map((el) => el.value));
};
const Component = autocomplete ? MultiSelectFiltered : MultiSelect;
return (
<>
<Flex.Container>
<Box>
<Field.Label htmlFor={_id} title={_id}>
{label}
</Field.Label>
{hasResetButton && (
<ResetSettingButton
data-qa-reset-setting-id={_id}
onClick={onResetButtonClick}
/>
)}
</Box>
</Flex.Container>
<Component
data-qa-setting-id={_id}
id={_id}
value={value}
placeholder={placeholder}
disabled={disabled}
readOnly={readonly}
// autoComplete={autocomplete === false ? 'off' : undefined}
onChange={handleChange}
options={values.map(({ key, i18nLabel }) => [
key,
t(i18nLabel),
])}
/>
</>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { Field } from '@rocket.chat/fuselage';
import { action } from '@storybook/addon-actions';
import React from 'react';

import { MultiSelectSettingInput } from './MultiSelectSettingInput';

export default {
title: 'admin/settings/inputs/MultiSelectSettingInput',
component: MultiSelectSettingInput,
decorators: [
(storyFn) => <Field>{storyFn()}</Field>,
],
};
const options = [
{ key: '1', i18nLabel: '1' },
{ key: '2', i18nLabel: '2' },
{ key: '3', i18nLabel: '3' },
];

export const _default = () =>
<MultiSelectSettingInput
_id='setting_id'
label='Label'
placeholder='Placeholder'
values={options}
onChangeValue={action('changeValue')}
onChangeEditor={action('changeEditor')}
/>;

export const disabled = () =>
<MultiSelectSettingInput
_id='setting_id'
label='Label'
placeholder='Placeholder'
values={options}
disabled
/>;

export const withValue = () =>
<MultiSelectSettingInput
_id='setting_id'
label='Label'
placeholder='Placeholder'
value='1'
values={options}
/>;

export const withResetButton = () =>
<MultiSelectSettingInput
_id='setting_id'
label='Label'
placeholder='Placeholder'
values={options}
hasResetButton
onChangeValue={action('changeValue')}
onResetButtonClick={action('resetButtonClick')}
/>;
17 changes: 14 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -2214,6 +2214,15 @@
"Message_HideType_ru": "Hide \"User Removed\" messages",
"Message_HideType_uj": "Hide \"User Join\" messages",
"Message_HideType_ul": "Hide \"User Leave\" messages",
"Message_HideType_r": "Hide \"Room Name Changed\" messages",
"Message_HideType_ut": "Hide \"User Joined Conversation\" messages",
"Message_HideType_wm": "Hide \"Welcome\" messages",
"Message_HideType_rm": "Hide \"Message Removed\" messages",
"Message_HideType_subscription_role_added": "Hide \"Was Set Role\" messages",
"Message_HideType_subscription_role_removed": "Hide \"Role No Longer Defined\" messages",
"Message_HideType_room_archived": "Hide \"Room Archived\" messages",
"Message_HideType_room_unarchived": "Hide \"Room Unarchived\" messages",
"Hide_System_Messages": "Hide System Messages",
"Message_Id": "Message Id",
"Message_Ignored": "This message was ignored",
"Message_info": "Message info",
Expand Down
21 changes: 5 additions & 16 deletions server/methods/loadHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,12 @@ import { hasPermission } from '../../app/authorization';
import { settings } from '../../app/settings';
import { loadMessageHistory } from '../../app/lib';

const hideMessagesOfType = [];
const hideMessagesOfType = new Set();

settings.get(/Message_HideType_.+/, function(key, value) {
const type = key.replace('Message_HideType_', '');
const types = type === 'mute_unmute' ? ['user-muted', 'user-unmuted'] : [type];

return types.forEach((type) => {
const index = hideMessagesOfType.indexOf(type);

if (value === true && index === -1) {
return hideMessagesOfType.push(type);
}

if (index > -1) {
return hideMessagesOfType.splice(index, 1);
}
});
settings.get('Hide_System_Messages', function(key, values) {
const hiddenTypes = values.reduce((array, value) => [...array, ...value === 'mute_unmute' ? ['user-muted', 'user-unmuted'] : [value]], []);
hideMessagesOfType.clear();
hiddenTypes.forEach((item) => hideMessagesOfType.add(item));
});

Meteor.methods({
Expand Down
1 change: 1 addition & 0 deletions server/startup/migrations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,5 @@ import './v168';
import './v169';
import './v170';
import './v171';
import './v172';
import './xrun';
Loading