merge only relevant settings when calling api.settings.extend (#2187)
* merge only relevant settings when calling api.settings.extend * test behaviour is the one expected and change doesn't break previous tests
This commit is contained in:
parent
bd21f27f4f
commit
7cdc592ed9
@ -26,6 +26,7 @@ Soon we'll deprecate the latter, so prepare now.
|
||||
- #2006: fix rendering of emojis in case `use_system_emojis == false`
|
||||
- #2028: Implement XEP-0333 `displayed` chat marker
|
||||
- #2101: Improve contrast of text in control box
|
||||
- #2187: Avoid merging initial settings with themselves every time settings are extended.
|
||||
- Removed the mockups from the project. Recommended to use tests instead.
|
||||
- The API method `api.settings.update` has been deprecated in favor of `api.settings.extend`.
|
||||
- Filter roster contacts via all available information (JID, nickname and VCard full name).
|
||||
|
@ -353,6 +353,28 @@ describe("Converse", function() {
|
||||
expect(_converse.api.settings.get('emoji_categories')?.food).toBe(undefined);
|
||||
done();
|
||||
}));
|
||||
|
||||
it("only overrides the passed in properties",
|
||||
mock.initConverse([],
|
||||
{
|
||||
'root': document.createElement('div').attachShadow({ 'mode': 'open' }),
|
||||
'emoji_categories': { 'travel': ':rocket:' },
|
||||
},
|
||||
(done, _converse) => {
|
||||
expect(_converse.api.settings.get('emoji_categories')?.travel).toBe(':rocket:');
|
||||
|
||||
// Test that the extend command doesn't override user-provided site
|
||||
// settings (i.e. settings passed in via converse.initialize).
|
||||
_converse.api.settings.extend({
|
||||
'emoji_categories': { 'travel': ':motorcycle:', 'food': ':burger:' },
|
||||
});
|
||||
|
||||
expect(_converse.api.settings.get('emoji_categories').travel).toBe(':rocket:');
|
||||
expect(_converse.api.settings.get('emoji_categories').food).toBe(undefined);
|
||||
done();
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
});
|
||||
|
||||
|
@ -659,7 +659,7 @@ export const api = _converse.api = {
|
||||
u.merge(DEFAULT_SETTINGS, settings);
|
||||
// When updating the settings, we need to avoid overwriting the
|
||||
// initialization_settings (i.e. the settings passed in via converse.initialize).
|
||||
const allowed_keys = Object.keys(DEFAULT_SETTINGS);
|
||||
const allowed_keys = Object.keys(pick(settings,Object.keys(DEFAULT_SETTINGS)));
|
||||
const allowed_site_settings = pick(initialization_settings, allowed_keys);
|
||||
const updated_settings = assignIn(pick(settings, allowed_keys), allowed_site_settings);
|
||||
u.merge(_converse.settings, updated_settings);
|
||||
|
Loading…
Reference in New Issue
Block a user