Commit f032af91 authored by JC Brand's avatar JC Brand

Initial work on moving certain settings into a model

parent b02c70b4
...@@ -722,7 +722,7 @@ ...@@ -722,7 +722,7 @@
_converse.root.appendChild(el); _converse.root.appendChild(el);
} }
} }
if (_.includes(['mobile', 'fullscreen'], _converse.view_mode)) { if (_.includes(['mobile', 'fullscreen'], _converse.settings.get('view_mode'))) {
el.classList.add('fullscreen'); el.classList.add('fullscreen');
} }
el.innerHTML = ''; el.innerHTML = '';
...@@ -735,7 +735,7 @@ ...@@ -735,7 +735,7 @@
initialize () { initialize () {
this.model.on("add", this.onChatBoxAdded, this); this.model.on("add", this.onChatBoxAdded, this);
this.model.on("destroy", this.removeChat, this); this.model.on("destroy", this.removeChat, this);
this.el.classList.add(`converse-${_converse.view_mode}`); this.el.classList.add(`converse-${_converse.settings.get('view_mode')}`);
this.render(); this.render();
}, },
......
...@@ -406,8 +406,8 @@ ...@@ -406,8 +406,8 @@
this.render(); this.render();
_.forEach(this.el.querySelectorAll('[data-title]'), (el) => { _.forEach(this.el.querySelectorAll('[data-title]'), (el) => {
const popover = new bootstrap.Popover(el, { const popover = new bootstrap.Popover(el, {
'trigger': _converse.view_mode === 'mobile' && 'click' || 'hover', 'trigger': _converse.settings.get('view_mode') === 'mobile' && 'click' || 'hover',
'dismissible': _converse.view_mode === 'mobile' && true || false, 'dismissible': _converse.settings.get('view_mode') === 'mobile' && true || false,
'container': _converse.chatboxviews.el 'container': _converse.chatboxviews.el
}) })
}); });
...@@ -465,9 +465,10 @@ ...@@ -465,9 +465,10 @@
if (!this.validate()) { return; } if (!this.validate()) { return; }
const form_data = new FormData(ev.target); const form_data = new FormData(ev.target);
_converse.trusted = form_data.get('trusted'); _converse.settings.save({
_converse.storage = form_data.get('trusted') ? 'local' : 'session'; 'trusted': form_data.get('trusted'),
'storage': form_data.get('trusted') ? 'local' : 'session'
});
let jid = form_data.get('jid'); let jid = form_data.get('jid');
if (_converse.locked_domain) { if (_converse.locked_domain) {
jid = Strophe.escapeNode(jid) + '@' + _converse.locked_domain; jid = Strophe.escapeNode(jid) + '@' + _converse.locked_domain;
...@@ -578,7 +579,7 @@ ...@@ -578,7 +579,7 @@
}); });
_converse.on('clearSession', () => { _converse.on('clearSession', () => {
if (_converse.trusted) { if (_converse.settings.get('trusted')) {
const chatboxes = _.get(_converse, 'chatboxes', null); const chatboxes = _.get(_converse, 'chatboxes', null);
if (!_.isNil(chatboxes)) { if (!_.isNil(chatboxes)) {
const controlbox = chatboxes.get('controlbox'); const controlbox = chatboxes.get('controlbox');
......
This diff is collapsed.
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
dependencies: ["converse-chatview", "converse-headline", "converse-muc-views"], dependencies: ["converse-chatview", "converse-headline", "converse-muc-views"],
enabled (_converse) { enabled (_converse) {
return _converse.view_mode == 'overlayed'; return _converse.settings.get('view_mode') == 'overlayed';
}, },
overrides: { overrides: {
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
converse.plugins.add('converse-embedded', { converse.plugins.add('converse-embedded', {
enabled (_converse) { enabled (_converse) {
return _converse.view_mode === 'embedded'; return _converse.settings.get('view_mode') === 'embedded';
}, },
initialize () { initialize () {
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
converse.plugins.add('converse-fullscreen', { converse.plugins.add('converse-fullscreen', {
enabled (_converse) { enabled (_converse) {
return _.includes(['fullscreen', 'embedded'], _converse.view_mode); return _.includes(['fullscreen', 'embedded'], _converse.settings.get('view_mode'));
}, },
overrides: { overrides: {
......
...@@ -129,7 +129,7 @@ ...@@ -129,7 +129,7 @@
/* Handler method for all incoming messages of type "headline". */ /* Handler method for all incoming messages of type "headline". */
const from_jid = message.getAttribute('from'); const from_jid = message.getAttribute('from');
if (utils.isHeadlineMessage(_converse, message)) { if (utils.isHeadlineMessage(_converse, message)) {
if (_.includes(from_jid, '@') && !_converse.allow_non_roster_messaging) { if (_.includes(from_jid, '@') && !_converse.settings.get('allow_non_roster_messaging')) {
return; return;
} }
const chatbox = _converse.chatboxes.create({ const chatbox = _converse.chatboxes.create({
......
...@@ -221,7 +221,7 @@ ...@@ -221,7 +221,7 @@
processMessageText () { processMessageText () {
var text = this.get('message'); var text = this.get('message');
text = u.geoUriToHttp(text, _converse.geouri_replacement); text = u.geoUriToHttp(text, _converse.ggeouri_replacementeouri_replacement);
}, },
getExtraMessageClasses () { getExtraMessageClasses () {
......
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
dependencies: ["converse-chatview", "converse-controlbox", "converse-muc", "converse-muc-views", "converse-headline"], dependencies: ["converse-chatview", "converse-controlbox", "converse-muc", "converse-muc-views", "converse-headline"],
enabled (_converse) { enabled (_converse) {
return _converse.view_mode == 'overlayed'; return _converse.settings.get('view_mode') == 'overlayed';
}, },
overrides: { overrides: {
......
...@@ -108,14 +108,14 @@ ...@@ -108,14 +108,14 @@
// Refer to docs/source/configuration.rst for explanations of these // Refer to docs/source/configuration.rst for explanations of these
// configuration settings. // configuration settings.
_converse.api.settings.update({ _converse.api.settings.update({
allow_muc: true, 'allow_muc': true,
allow_muc_invitations: true, 'allow_muc_invitations': true,
auto_join_on_invite: false, 'auto_join_on_invite': false,
auto_join_rooms: [], 'auto_join_rooms': [],
muc_domain: undefined, 'muc_domain': undefined,
muc_history_max_stanzas: undefined, 'muc_history_max_stanzas': undefined,
muc_instant_rooms: true, 'muc_instant_rooms': true,
muc_nickname_from_jid: false 'muc_nickname_from_jid': false
}); });
_converse.api.promises.add(['roomsAutoJoined']); _converse.api.promises.add(['roomsAutoJoined']);
......
...@@ -71,7 +71,7 @@ ...@@ -71,7 +71,7 @@
}; };
_converse.isMessageToHiddenChat = function (message) { _converse.isMessageToHiddenChat = function (message) {
if (_.includes(['mobile', 'fullscreen', 'embedded'], _converse.view_mode)) { if (_.includes(['mobile', 'fullscreen', 'embedded'], _converse.settings.get('view_mode'))) {
const jid = Strophe.getBareJidFromJid(message.getAttribute('from')); const jid = Strophe.getBareJidFromJid(message.getAttribute('from'));
const model = _converse.chatboxes.get(jid); const model = _converse.chatboxes.get(jid);
if (!_.isNil(model)) { if (!_.isNil(model)) {
...@@ -138,7 +138,7 @@ ...@@ -138,7 +138,7 @@
const full_from_jid = message.getAttribute('from'), const full_from_jid = message.getAttribute('from'),
from_jid = Strophe.getBareJidFromJid(full_from_jid); from_jid = Strophe.getBareJidFromJid(full_from_jid);
if (message.getAttribute('type') === 'headline') { if (message.getAttribute('type') === 'headline') {
if (!_.includes(from_jid, '@') || _converse.allow_non_roster_messaging) { if (!_.includes(from_jid, '@') || _converse.get('allow_non_roster_messaging')) {
title = __("Notification from %1$s", from_jid); title = __("Notification from %1$s", from_jid);
} else { } else {
return; return;
...@@ -159,7 +159,7 @@ ...@@ -159,7 +159,7 @@
if (!_.isUndefined(roster_item)) { if (!_.isUndefined(roster_item)) {
title = __("%1$s says", roster_item.getDisplayName()); title = __("%1$s says", roster_item.getDisplayName());
} else { } else {
if (_converse.allow_non_roster_messaging) { if (_converse.get('allow_non_roster_messaging')) {
title = __("%1$s says", from_jid); title = __("%1$s says", from_jid);
} else { } else {
return; return;
......
...@@ -821,7 +821,7 @@ ...@@ -821,7 +821,7 @@
} }
this.filter_view.showOrHide(); this.filter_view.showOrHide();
return this; return this;
}, _converse.animate ? 100 : 0), }, _converse.get('animate') ? 100 : 0),
filter (query, type) { filter (query, type) {
// First we make sure the filter is restored to its // First we make sure the filter is restored to its
......
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
ChatBoxes: { ChatBoxes: {
chatBoxMayBeShown (chatbox) { chatBoxMayBeShown (chatbox) {
if (_.includes(['mobile', 'fullscreen', 'embedded'], this.__super__._converse.view_mode)) { if (_.includes(['mobile', 'fullscreen', 'embedded'], this.__super__._converse.settings.get('view_mode'))) {
return !chatbox.get('hidden'); return !chatbox.get('hidden');
} else { } else {
return this.__super__.chatBoxMayBeShown.apply(this, arguments); return this.__super__.chatBoxMayBeShown.apply(this, arguments);
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
createChatBox (jid, attrs) { createChatBox (jid, attrs) {
/* Make sure new chat boxes are hidden by default. */ /* Make sure new chat boxes are hidden by default. */
if (_.includes(['mobile', 'fullscreen', 'embedded'], this.__super__._converse.view_mode)) { if (_.includes(['mobile', 'fullscreen', 'embedded'], this.__super__._converse.settings.get('view_mode'))) {
attrs = attrs || {}; attrs = attrs || {};
attrs.hidden = true; attrs.hidden = true;
} }
...@@ -65,7 +65,7 @@ ...@@ -65,7 +65,7 @@
ChatBoxView: { ChatBoxView: {
shouldShowOnTextMessage () { shouldShowOnTextMessage () {
if (_.includes(['mobile', 'fullscreen', 'embedded'], this.__super__._converse.view_mode)) { if (_.includes(['mobile', 'fullscreen', 'embedded'], this.__super__._converse.settings.get('view_mode'))) {
return false; return false;
} else { } else {
return this.__super__.shouldShowOnTextMessage.apply(this, arguments); return this.__super__.shouldShowOnTextMessage.apply(this, arguments);
...@@ -77,7 +77,7 @@ ...@@ -77,7 +77,7 @@
* time. So before opening a chat, we make sure all other * time. So before opening a chat, we make sure all other
* chats are hidden. * chats are hidden.
*/ */
if (_.includes(['mobile', 'fullscreen', 'embedded'], this.__super__._converse.view_mode)) { if (_.includes(['mobile', 'fullscreen', 'embedded'], this.__super__._converse.settings.get('view_mode'))) {
_.each(this.__super__._converse.chatboxviews.xget(this.model.get('id')), hideChat); _.each(this.__super__._converse.chatboxviews.xget(this.model.get('id')), hideChat);
this.model.set('hidden', false); this.model.set('hidden', false);
} }
...@@ -87,7 +87,7 @@ ...@@ -87,7 +87,7 @@
ChatRoomView: { ChatRoomView: {
show (focus) { show (focus) {
if (_.includes(['mobile', 'fullscreen', 'embedded'], this.__super__._converse.view_mode)) { if (_.includes(['mobile', 'fullscreen', 'embedded'], this.__super__._converse.settings.get('view_mode'))) {
_.each(this.__super__._converse.chatboxviews.xget(this.model.get('id')), hideChat); _.each(this.__super__._converse.chatboxviews.xget(this.model.get('id')), hideChat);
this.model.set('hidden', false); this.model.set('hidden', false);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment