diff --git a/converse.js b/converse.js index 5e7f7f3b1..fe85d949c 100644 --- a/converse.js +++ b/converse.js @@ -238,7 +238,7 @@ // Default configuration values // ---------------------------- - var default_settings = { + this.default_settings = { allow_contact_requests: true, allow_dragresize: true, allow_logout: true, @@ -286,9 +286,9 @@ xhr_user_search: false, xhr_user_search_url: '' }; - _.extend(this, default_settings); + _.extend(this, this.default_settings); // Allow only whitelisted configuration attributes to be overwritten - _.extend(this, _.pick(settings, Object.keys(default_settings))); + _.extend(this, _.pick(settings, Object.keys(this.default_settings))); if (settings.visible_toolbar_buttons) { _.extend( @@ -5205,6 +5205,22 @@ 'initialize': function (settings, callback) { converse.initialize(settings, callback); }, + 'settings': { + 'get': function (key) { + if (_.contains(Object.keys(converse.default_settings), key)) { + return converse[key]; + } + }, + 'set': function (key, val) { + var o = {}; + if (typeof key === "object") { + _.extend(converse, _.pick(key, Object.keys(converse.default_settings))); + } else if (typeof key === "string") { + o[key] = val; + _.extend(converse, _.pick(o, Object.keys(converse.default_settings))); + } + } + }, 'contacts': { 'get': function (jids) { var _transform = function (jid) { diff --git a/docs/.gitattributes b/docs/.gitattributes new file mode 100644 index 000000000..6f9ff673b --- /dev/null +++ b/docs/.gitattributes @@ -0,0 +1 @@ +CHANGES.rst merge=union diff --git a/docs/CHANGES.rst b/docs/CHANGES.rst index d206ae032..7397c7eb1 100644 --- a/docs/CHANGES.rst +++ b/docs/CHANGES.rst @@ -1,20 +1,21 @@ Changelog ========= -0.8.8 (Unreleased) +0.8.7 (Unreleased) ------------------ -* Norwegian Bokmål translations. [Andreas Lorentsen] -* Updated Afrikaans translations. [jcbrand] +* Add new API method to set and get configuration settings. [jcbrand] * Add responsiveness to CSS. We now use Sass preprocessor for generating CSS. [jcbrand] * Don't send out the message carbons IQ stanza on each page load. [jcbrand] +* New Makefile.win to build in Windows environments. [gbonvehi] +* Norwegian Bokmål translations. [Andreas Lorentsen] +* Strophe.log and Strophe.error now uses converse.log to output messages. [gbonvehi] +* Updated Afrikaans translations. [jcbrand] * #204 Support websocket connections. [jcbrand] * #252, 253 Add fullname and jid to contact's tooltip in roster. [gbonvehi] * #292 Better support for XEP-0085 Chat State Notifications. [jcbrand] * #295 Document "allow_registration". [gbonvehi] * #304 Added Polish translations. [ser] -* New Makefile.win to build in Windows environments. [gbonvehi] -* Strophe.log and Strophe.error now uses converse.log to output messages. [gbonvehi] * #305 presence/show text in XMPP request isn't allowed by specification. [gbonvehi] 0.8.6 (2014-12-07) diff --git a/docs/source/configuration.rst b/docs/source/configuration.rst index c4e65c207..10960e7d6 100644 --- a/docs/source/configuration.rst +++ b/docs/source/configuration.rst @@ -54,7 +54,7 @@ Default: ``true`` Allow Off-the-record encryption of single-user chat messages. allow_registration ---------- +------------------ Default: ``true`` diff --git a/docs/source/development.rst b/docs/source/development.rst index 1307583ce..3c485d30a 100644 --- a/docs/source/development.rst +++ b/docs/source/development.rst @@ -301,6 +301,36 @@ Example:: | url | The URL of the chat box heading. | +-------------+-----------------------------------------------------+ +"settings" grouping +------------------- + +This grouping allows you to get or set the configuration settings of converse.js. + +get(key) +~~~~~~~~ + +Returns the value of a configuration settings. For example:: + + converse.settings.get("play_sounds"); // default value returned would be false; + +set(key, value) or set(object) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Set one or many configuration settings. For example:: + + converse.settings.set("play_sounds", true); + +or :: + + converse.settings.set({ + "play_sounds", true, + "hide_offline_users" true + }); + +Note, this is not an alternative to calling ``converse.initialize``, which still needs +to be called. Generally, you'd use this method after converse.js is already +running and you want to change the configuration on-the-fly. + "tokens" grouping ----------------- diff --git a/spec/converse.js b/spec/converse.js index 5b81bc87a..93b833e8d 100644 --- a/spec/converse.js +++ b/spec/converse.js @@ -87,6 +87,28 @@ }, converse)); }, converse)); + describe("The \"settings\" API", $.proxy(function() { + beforeEach($.proxy(function () { + test_utils.closeAllChatBoxes(); + test_utils.clearBrowserStorage(); + converse.rosterview.model.reset(); + test_utils.createContacts('current'); + }, converse)); + + it("has methods 'get' and 'set' to set configuration settings", $.proxy(function () { + expect(Object.keys(converse_api.settings)).toEqual(["get", "set"]); + expect(converse_api.settings.get("play_sounds")).toBe(false); + converse_api.settings.set("play_sounds", true); + 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); + // Only whitelisted settings allowed. + expect(typeof converse_api.settings.get("non_existing")).toBe("undefined"); + converse_api.settings.set("non_existing", true); + expect(typeof converse_api.settings.get("non_existing")).toBe("undefined"); + }, converse)); + }, converse)); + describe("The DEPRECATED API", $.proxy(function() { beforeEach($.proxy(function () { test_utils.closeAllChatBoxes();