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:
Xavi 2020-08-12 08:12:10 +00:00 committed by GitHub
parent bd21f27f4f
commit 7cdc592ed9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 1 deletions

View File

@ -26,6 +26,7 @@ Soon we'll deprecate the latter, so prepare now.
- #2006: fix rendering of emojis in case `use_system_emojis == false` - #2006: fix rendering of emojis in case `use_system_emojis == false`
- #2028: Implement XEP-0333 `displayed` chat marker - #2028: Implement XEP-0333 `displayed` chat marker
- #2101: Improve contrast of text in control box - #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. - 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`. - 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). - Filter roster contacts via all available information (JID, nickname and VCard full name).

View File

@ -354,6 +354,28 @@ describe("Converse", function() {
done(); 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();
}
)
);
}); });
describe("The \"plugins\" API", function() { describe("The \"plugins\" API", function() {

View File

@ -659,7 +659,7 @@ export const api = _converse.api = {
u.merge(DEFAULT_SETTINGS, settings); u.merge(DEFAULT_SETTINGS, settings);
// When updating the settings, we need to avoid overwriting the // When updating the settings, we need to avoid overwriting the
// initialization_settings (i.e. the settings passed in via converse.initialize). // 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 allowed_site_settings = pick(initialization_settings, allowed_keys);
const updated_settings = assignIn(pick(settings, allowed_keys), allowed_site_settings); const updated_settings = assignIn(pick(settings, allowed_keys), allowed_site_settings);
u.merge(_converse.settings, updated_settings); u.merge(_converse.settings, updated_settings);