Remove unused settings from Rocket.Chat

Remove unused settings from Rocket.Chat

I was going to add a new setting item - Apps_Game_Center_enabled into the settings page, but some extra unwanted settings were also added to this group. Although, I've already removed these items from the MongoDB. I still saw them in the settings page, it's so weird...

By diving into the codebase, I finally found that we are using PrivateSettingsCachedCollection to cache the settings. With this finding, I solved the issue with the following code:

Inject the following code below

1
2
3
4
...
const rcSettings = settings.collectionPrivate.find({ group: groupId }, { sort: { section: 1, sorter: 1, i18nLabel: 1 } }).fetch();
const sections = {};
...

1
2
3
4
5
6
7
8
9
10
11
12
13
// the code to be injected
rcSettings.forEach(({ _id, section }) => {
const group = 'Apps';
const whitelist = [
'Apps_Framework_enabled',
'Apps_Framework_Development_Mode',
'Apps_Game_Center_enabled',
];

if (section === group && !whitelist.includes(_id)) {
settings.collectionPrivate.remove({ _id });
}
});

Lastly, run meteor shell and .reload to reload the project, you will find the extra settings have be removed from the collection 😆