From 830e060568ff7406b4633b5b97dabda5cd705dcf Mon Sep 17 00:00:00 2001 From: JC Brand Date: Wed, 3 Jun 2020 09:17:13 +0200 Subject: [PATCH] Rename `api.settings.update` to `api.settings.extend` This is to try and make it clearer that this method won't override initialization settings, and is instead simply to add to the default settings. --- CHANGES.md | 1 + spec/converse.js | 30 ++++++++++++++++-------------- spec/messages.js | 3 +++ src/converse-bookmark-views.js | 2 +- src/converse-chatboxviews.js | 2 +- src/converse-chatview.js | 2 +- src/converse-controlbox.js | 2 +- src/converse-dragresize.js | 2 +- src/converse-emoji-views.js | 2 +- src/converse-fullscreen.js | 6 ++---- src/converse-minimize.js | 2 +- src/converse-muc-views.js | 2 +- src/converse-notification.js | 2 +- src/converse-oauth.js | 2 +- src/converse-omemo.js | 2 +- src/converse-profile.js | 2 +- src/converse-push.js | 2 +- src/converse-register.js | 2 +- src/converse-rosterview.js | 2 +- src/converse-singleton.js | 2 +- src/headless/converse-bookmarks.js | 2 +- src/headless/converse-bosh.js | 2 +- src/headless/converse-chat.js | 2 +- src/headless/converse-core.js | 16 +++++++++++++--- src/headless/converse-emoji.js | 2 +- src/headless/converse-mam.js | 2 +- src/headless/converse-muc.js | 2 +- src/headless/converse-ping.js | 2 +- src/headless/converse-roster.js | 2 +- src/headless/converse-smacks.js | 2 +- src/headless/converse-status.js | 2 +- 31 files changed, 61 insertions(+), 47 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 7818d3de7..86954b22d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -25,6 +25,7 @@ Soon we'll deprecate the latter, so prepare now. - #2002: fix rendering of `muc_roomid_policy_hint` - #2006: fix rendering of emojis in case `use_system_emojis == false` - #2028: Implement XEP-0333 `displayed` chat marker +- 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). - Allow ignoring of bootstrap modules at build using environment variable. For xample: `export BOOTSTRAP_IGNORE_MODULES="Modal,Dropdown" && make dist` - Bugfix. Handle stanza that clears the MUC subject diff --git a/spec/converse.js b/spec/converse.js index 94e0d95dc..b6ba8d722 100644 --- a/spec/converse.js +++ b/spec/converse.js @@ -4,19 +4,6 @@ describe("Converse", function() { describe("Settings", function () { - it("extended via settings.update don't override settings passed in via converse.initialize", - mock.initConverse([], {'emoji_categories': {"travel": ":rocket:"}}, (done, _converse) => { - - expect(_converse.api.settings.get('emoji_categories')?.travel).toBe(':rocket:'); - - // Test that the update command doesn't override user-provided site - // settings (i.e. settings passed in via converse.initialize). - _converse.api.settings.update({'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("Authentication", function () { @@ -340,7 +327,7 @@ describe("Converse", function() { it("has methods 'get' and 'set' to set configuration settings", mock.initConverse(null, {'play_sounds': true}, (done, _converse) => { - expect(Object.keys(_converse.api.settings)).toEqual(["update", "get", "set"]); + expect(Object.keys(_converse.api.settings)).toEqual(["extend", "update", "get", "set"]); expect(_converse.api.settings.get("play_sounds")).toBe(true); _converse.api.settings.set("play_sounds", false); expect(_converse.api.settings.get("play_sounds")).toBe(false); @@ -352,6 +339,21 @@ describe("Converse", function() { expect(typeof _converse.api.settings.get("non_existing")).toBe("undefined"); done(); })); + + it("extended via settings.extend don't override settings passed in via converse.initialize", + mock.initConverse([], {'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() { diff --git a/spec/messages.js b/spec/messages.js index 869e0fe70..3d7a94444 100644 --- a/spec/messages.js +++ b/spec/messages.js @@ -15,6 +15,9 @@ describe("A Chat Message", function () { await mock.openChatBoxFor(_converse, contact_jid); const view = _converse.api.chatviews.get(contact_jid); await _converse.handleMessageStanza(mock.createChatMessage(_converse, contact_jid, 'This message will be read')); + const msg_el = await u.waitUntil(() => view.el.querySelector('converse-chat-message')); + expect(msg_el.querySelector('.chat-msg__text').textContent).toBe('This message will be read'); + expect(view.model.get('num_unread')).toBe(0); _converse.windowState = 'hidden'; await _converse.handleMessageStanza(mock.createChatMessage(_converse, contact_jid, 'This message will be new')); diff --git a/src/converse-bookmark-views.js b/src/converse-bookmark-views.js index 1d1efa97b..25ff82131 100644 --- a/src/converse-bookmark-views.js +++ b/src/converse-bookmark-views.js @@ -40,7 +40,7 @@ converse.plugins.add('converse-bookmark-views', { // ==================================== // Refer to docs/source/configuration.rst for explanations of these // configuration settings. - api.settings.update({ + api.settings.extend({ hide_open_bookmarks: true, }); diff --git a/src/converse-chatboxviews.js b/src/converse-chatboxviews.js index 440c84290..8eb26558b 100644 --- a/src/converse-chatboxviews.js +++ b/src/converse-chatboxviews.js @@ -54,7 +54,7 @@ converse.plugins.add('converse-chatboxviews', { // ==================================== // Refer to docs/source/configuration.rst for explanations of these // configuration settings. - api.settings.update({ + api.settings.extend({ 'animate': true, 'theme': 'default' }); diff --git a/src/converse-chatview.js b/src/converse-chatview.js index 523245854..6386be6a5 100644 --- a/src/converse-chatview.js +++ b/src/converse-chatview.js @@ -51,7 +51,7 @@ converse.plugins.add('converse-chatview', { /* The initialize function gets called as soon as the plugin is * loaded by converse.js's plugin machinery. */ - api.settings.update({ + api.settings.extend({ 'auto_focus': true, 'message_limit': 0, 'muc_hats_from_vcard': false, diff --git a/src/converse-controlbox.js b/src/converse-controlbox.js index ca9367459..e8b8a177d 100644 --- a/src/converse-controlbox.js +++ b/src/converse-controlbox.js @@ -99,7 +99,7 @@ converse.plugins.add('converse-controlbox', { /* The initialize function gets called as soon as the plugin is * loaded by converse.js's plugin machinery. */ - api.settings.update({ + api.settings.extend({ allow_logout: true, default_domain: undefined, locked_domain: undefined, diff --git a/src/converse-dragresize.js b/src/converse-dragresize.js index 4a7787880..044c6861d 100644 --- a/src/converse-dragresize.js +++ b/src/converse-dragresize.js @@ -133,7 +133,7 @@ converse.plugins.add('converse-dragresize', { /* The initialize function gets called as soon as the plugin is * loaded by converse.js's plugin machinery. */ - api.settings.update({ + api.settings.extend({ 'allow_dragresize': true, }); diff --git a/src/converse-emoji-views.js b/src/converse-emoji-views.js index 23ca50bfc..0c7410eae 100644 --- a/src/converse-emoji-views.js +++ b/src/converse-emoji-views.js @@ -69,7 +69,7 @@ converse.plugins.add('converse-emoji-views', { /* The initialize function gets called as soon as the plugin is * loaded by converse.js's plugin machinery. */ - api.settings.update({ + api.settings.extend({ 'use_system_emojis': true, 'visible_toolbar_buttons': { 'emoji': true diff --git a/src/converse-fullscreen.js b/src/converse-fullscreen.js index f056e0e3e..0cc5ca86b 100644 --- a/src/converse-fullscreen.js +++ b/src/converse-fullscreen.js @@ -7,7 +7,7 @@ import "@converse/headless/converse-muc"; import "converse-chatview"; import "converse-controlbox"; import "converse-singleton"; -import { converse } from "@converse/headless/converse-core"; +import { _converse, api, converse } from "@converse/headless/converse-core"; import tpl_brand_heading from "templates/inverse_brand_heading.html"; @@ -26,14 +26,12 @@ converse.plugins.add('converse-fullscreen', { ControlBoxView: { createBrandHeadingHTML() { - const { _converse } = this.__super__; return tpl_brand_heading({ 'version_name': _converse.VERSION_NAME }); }, insertBrandHeading () { - const { _converse } = this.__super__; const el = _converse.root.getElementById('converse-login-panel'); el.parentNode.insertAdjacentHTML( 'afterbegin', @@ -44,7 +42,7 @@ converse.plugins.add('converse-fullscreen', { }, initialize () { - this._converse.api.settings.update({ + api.settings.extend({ chatview_avatar_height: 50, chatview_avatar_width: 50, hide_open_bookmarks: true, diff --git a/src/converse-minimize.js b/src/converse-minimize.js index 24b8f3a92..272fa5354 100644 --- a/src/converse-minimize.js +++ b/src/converse-minimize.js @@ -114,7 +114,7 @@ converse.plugins.add('converse-minimize', { * loaded by Converse.js's plugin machinery. */ - api.settings.update({'no_trimming': false}); + api.settings.extend({'no_trimming': false}); const minimizableChatBox = { maximize () { diff --git a/src/converse-muc-views.js b/src/converse-muc-views.js index 24809762f..72a47958c 100644 --- a/src/converse-muc-views.js +++ b/src/converse-muc-views.js @@ -92,7 +92,7 @@ converse.plugins.add('converse-muc-views', { // ==================================== // Refer to docs/source/configuration.rst for explanations of these // configuration settings. - api.settings.update({ + api.settings.extend({ 'auto_list_rooms': false, 'cache_muc_messages': true, 'locked_muc_nickname': false, diff --git a/src/converse-notification.js b/src/converse-notification.js index 333640c52..f962aa7c1 100644 --- a/src/converse-notification.js +++ b/src/converse-notification.js @@ -22,7 +22,7 @@ converse.plugins.add('converse-notification', { */ _converse.supports_html5_notification = "Notification" in window; - api.settings.update({ + api.settings.extend({ notify_all_room_messages: false, show_desktop_notifications: true, show_chat_state_notifications: false, diff --git a/src/converse-oauth.js b/src/converse-oauth.js index 6728e1af8..512227aa1 100644 --- a/src/converse-oauth.js +++ b/src/converse-oauth.js @@ -73,7 +73,7 @@ converse.plugins.add("converse-oauth", { const { api } = _converse; const { __ } = _converse; - api.settings.update({ + api.settings.extend({ 'oauth_providers': [], }); diff --git a/src/converse-omemo.js b/src/converse-omemo.js index a25f8cbf1..50c5f6c23 100644 --- a/src/converse-omemo.js +++ b/src/converse-omemo.js @@ -215,7 +215,7 @@ converse.plugins.add('converse-omemo', { * loaded by Converse.js's plugin machinery. */ - api.settings.update({'omemo_default': false}); + api.settings.extend({'omemo_default': false}); api.promises.add(['OMEMOInitialized']); diff --git a/src/converse-profile.js b/src/converse-profile.js index 9696a75ec..d3fe97226 100644 --- a/src/converse-profile.js +++ b/src/converse-profile.js @@ -29,7 +29,7 @@ converse.plugins.add('converse-profile', { * loaded by converse.js's plugin machinery. */ - api.settings.update({ + api.settings.extend({ 'allow_adhoc_commands': true, 'show_client_info': true }); diff --git a/src/converse-push.js b/src/converse-push.js index 89f549980..d4e7ad98b 100644 --- a/src/converse-push.js +++ b/src/converse-push.js @@ -21,7 +21,7 @@ converse.plugins.add('converse-push', { /* The initialize function gets called as soon as the plugin is * loaded by converse.js's plugin machinery. */ - api.settings.update({ + api.settings.extend({ 'push_app_servers': [], 'enable_muc_push': false }); diff --git a/src/converse-register.js b/src/converse-register.js index 6a62394ac..9c88a30f9 100644 --- a/src/converse-register.js +++ b/src/converse-register.js @@ -69,7 +69,7 @@ converse.plugins.add('converse-register', { _converse.CONNECTION_STATUS[Strophe.Status.CONFLICT] = 'CONFLICT'; _converse.CONNECTION_STATUS[Strophe.Status.NOTACCEPTABLE] = 'NOTACCEPTABLE'; - api.settings.update({ + api.settings.extend({ 'allow_registration': true, 'domain_placeholder': __(" e.g. conversejs.org"), // Placeholder text shown in the domain input on the registration form 'providers_link': 'https://compliance.conversations.im/', // Link to XMPP providers shown on registration page diff --git a/src/converse-rosterview.js b/src/converse-rosterview.js index 5980e0bb7..2af54bb64 100644 --- a/src/converse-rosterview.js +++ b/src/converse-rosterview.js @@ -35,7 +35,7 @@ converse.plugins.add('converse-rosterview', { * loaded by converse.js's plugin machinery. */ - api.settings.update({ + api.settings.extend({ 'autocomplete_add_contact': true, 'allow_chat_pending_contacts': true, 'allow_contact_removal': true, diff --git a/src/converse-singleton.js b/src/converse-singleton.js index d0b292228..a1ddcb72e 100644 --- a/src/converse-singleton.js +++ b/src/converse-singleton.js @@ -17,7 +17,7 @@ converse.plugins.add('converse-singleton', { /* The initialize function gets called as soon as the plugin is * loaded by converse.js's plugin machinery. */ - this._converse.api.settings.update({ + this._converse.api.settings.extend({ 'allow_logout': false, // No point in logging out when we have auto_login as true. 'allow_muc_invitations': false, // Doesn't make sense to allow because only // roster contacts can be invited diff --git a/src/headless/converse-bookmarks.js b/src/headless/converse-bookmarks.js index 7d197d942..c06b6af6a 100644 --- a/src/headless/converse-bookmarks.js +++ b/src/headless/converse-bookmarks.js @@ -66,7 +66,7 @@ converse.plugins.add('converse-bookmarks', { // ==================================== // Refer to docs/source/configuration.rst for explanations of these // configuration settings. - api.settings.update({ + api.settings.extend({ allow_bookmarks: true, allow_public_bookmarks: false, muc_respect_autojoin: true diff --git a/src/headless/converse-bosh.js b/src/headless/converse-bosh.js index ff87092e9..80eb62a7a 100644 --- a/src/headless/converse-bosh.js +++ b/src/headless/converse-bosh.js @@ -21,7 +21,7 @@ converse.plugins.add('converse-bosh', { }, initialize () { - api.settings.update({ + api.settings.extend({ bosh_service_url: undefined, prebind_url: null }); diff --git a/src/headless/converse-chat.js b/src/headless/converse-chat.js index e98f9a3a1..4341e986b 100644 --- a/src/headless/converse-chat.js +++ b/src/headless/converse-chat.js @@ -40,7 +40,7 @@ converse.plugins.add('converse-chat', { // ==================================== // Refer to docs/source/configuration.rst for explanations of these // configuration settings. - api.settings.update({ + api.settings.extend({ 'allow_message_corrections': 'all', 'allow_message_retraction': 'all', 'auto_join_private_chats': [], diff --git a/src/headless/converse-core.js b/src/headless/converse-core.js index bb7d4ab35..564364a43 100644 --- a/src/headless/converse-core.js +++ b/src/headless/converse-core.js @@ -637,10 +637,14 @@ export const api = _converse.api = { * Allows new configuration settings to be specified, or new default values for * existing configuration settings to be specified. * - * @method _converse.api.settings.update + * Note, calling this method *after* converse.initialize has been + * called will *not* change the initialization settings provided via + * `converse.initialize`. + * + * @method _converse.api.settings.extend * @param {object} settings The configuration settings * @example - * _converse.api.settings.update({ + * _converse.api.settings.extend({ * 'enable_foo': true * }); * @@ -650,7 +654,7 @@ export const api = _converse.api = { * 'enable_foo': false * }); */ - update (settings) { + extend (settings) { 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). @@ -661,6 +665,12 @@ export const api = _converse.api = { u.merge(_converse, updated_settings); // FIXME: remove }, + update (settings) { + log.warn("The api.settings.extend method has been deprecated and will be removed. "+ + "Please use api.settings.extend instead."); + return this.extend(settings); + }, + /** * @method _converse.api.settings.get * @returns {*} Value of the particular configuration setting. diff --git a/src/headless/converse-emoji.js b/src/headless/converse-emoji.js index 4e86c0e6a..9c97e3ce0 100644 --- a/src/headless/converse-emoji.js +++ b/src/headless/converse-emoji.js @@ -62,7 +62,7 @@ converse.plugins.add('converse-emoji', { */ const { ___ } = _converse; - api.settings.update({ + api.settings.extend({ 'emoji_image_path': twemoji.default.base, 'emoji_categories': { "smileys": ":grinning:", diff --git a/src/headless/converse-mam.js b/src/headless/converse-mam.js index 1538ad2d2..4ed8a6ff4 100644 --- a/src/headless/converse-mam.js +++ b/src/headless/converse-mam.js @@ -131,7 +131,7 @@ converse.plugins.add('converse-mam', { /* The initialize function gets called as soon as the plugin is * loaded by Converse.js's plugin machinery. */ - api.settings.update({ + api.settings.extend({ archived_messages_page_size: '50', message_archiving: undefined, // Supported values are 'always', 'never', 'roster' (https://xmpp.org/extensions/xep-0313.html#prefs) message_archiving_timeout: 20000, // Time (in milliseconds) to wait before aborting MAM request diff --git a/src/headless/converse-muc.js b/src/headless/converse-muc.js index cc1b1346c..872cea990 100644 --- a/src/headless/converse-muc.js +++ b/src/headless/converse-muc.js @@ -114,7 +114,7 @@ converse.plugins.add('converse-muc', { // ==================================== // Refer to docs/source/configuration.rst for explanations of these // configuration settings. - api.settings.update({ + api.settings.extend({ 'allow_muc': true, 'allow_muc_invitations': true, 'auto_join_on_invite': false, diff --git a/src/headless/converse-ping.js b/src/headless/converse-ping.js index e5280debe..1b440f51e 100644 --- a/src/headless/converse-ping.js +++ b/src/headless/converse-ping.js @@ -23,7 +23,7 @@ converse.plugins.add('converse-ping', { */ let lastStanzaDate; - api.settings.update({ + api.settings.extend({ ping_interval: 60 //in seconds }); diff --git a/src/headless/converse-roster.js b/src/headless/converse-roster.js index aaffac87e..93841c7d6 100644 --- a/src/headless/converse-roster.js +++ b/src/headless/converse-roster.js @@ -24,7 +24,7 @@ converse.plugins.add('converse-roster', { */ const { __ } = _converse; - api.settings.update({ + api.settings.extend({ 'allow_contact_requests': true, 'auto_subscribe': false, 'synchronize_availability': true, diff --git a/src/headless/converse-smacks.js b/src/headless/converse-smacks.js index c41a9416d..341fc0971 100644 --- a/src/headless/converse-smacks.js +++ b/src/headless/converse-smacks.js @@ -22,7 +22,7 @@ converse.plugins.add('converse-smacks', { // ==================================== // Refer to docs/source/configuration.rst for explanations of these // configuration settings. - api.settings.update({ + api.settings.extend({ 'enable_smacks': true, 'smacks_max_unacked_stanzas': 5, }); diff --git a/src/headless/converse-status.js b/src/headless/converse-status.js index eb92ff81c..e2bde2212 100644 --- a/src/headless/converse-status.js +++ b/src/headless/converse-status.js @@ -14,7 +14,7 @@ converse.plugins.add('converse-status', { initialize () { - api.settings.update({ + api.settings.extend({ auto_away: 0, // Seconds after which user status is set to 'away' auto_xa: 0, // Seconds after which user status is set to 'xa' csi_waiting_time: 0, // Support for XEP-0352. Seconds before client is considered idle and CSI is sent out.