Commit 40e7ee1a authored by JC Brand's avatar JC Brand

Initial stab at using ES2015

Mostly replaced ``var`` with ``let`` and ``const``.
Also added a few arrow functions.
parent e1b745b7
{
"parserOptions": {
"ecmaVersion": 6
},
"env": {
"browser": true,
"jasmine": true
......
......@@ -306,7 +306,7 @@
*/
var IQ_id;
expect(_.filter(_converse.connection.send.calls.all(), function (call) {
var stanza = call.args[0]
var stanza = call.args[0];
if (!(stanza instanceof Element) || stanza.nodeName !== 'iq') {
return;
}
......@@ -373,7 +373,7 @@
it("shows a list of bookmarks", mock.initConverseWithConnectionSpies(['send'], function (_converse) {
var IQ_id;
expect(_.filter(_converse.connection.send.calls.all(), function (call) {
var stanza = call.args[0]
var stanza = call.args[0];
if (!(stanza instanceof Element) || stanza.nodeName !== 'iq') {
return;
}
......@@ -421,7 +421,7 @@
mock.initConverseWithConnectionSpies(['send'], function (_converse) {
var IQ_id;
expect(_.filter(_converse.connection.send.calls.all(), function (call) {
var stanza = call.args[0]
var stanza = call.args[0];
if (!(stanza instanceof Element) || stanza.nodeName !== 'iq') {
return;
}
......
......@@ -106,7 +106,7 @@
}
return test_utils.waitUntil(function () {
return _converse.chatboxviews.keys().length > 1;
}, 500)
}, 500);
}).then(function () {
var key = _converse.chatboxviews.keys()[1];
trimmedview = trimmed_chatboxes.get(key);
......@@ -268,7 +268,7 @@
expect(_converse.emit).toHaveBeenCalledWith('chatBoxMaximized', jasmine.any(Object));
return test_utils.waitUntil(function () {
return chatview.$el.find('.chat-body').is(':visible');
}, 500)
}, 500);
}).then(function () {
expect(chatview.$el.find('.toggle-chatbox-button').hasClass('icon-minus')).toBeTruthy();
expect(chatview.$el.find('.toggle-chatbox-button').hasClass('icon-plus')).toBeFalsy();
......@@ -715,12 +715,12 @@
.then(function () {
return test_utils.waitUntil(function () {
return !chatboxview.model.get('auto_scrolled');
}, 300)
}, 300);
}).then(function () {
chatboxview.$content.scrollTop(0);
return test_utils.waitUntil(function () {
return chatboxview.model.get('scrolled');
}, 900)
}, 900);
}).then(function () {
_converse.chatboxes.onMessage($msg({
from: sender_jid,
......@@ -736,7 +736,7 @@
expect(msg_txt).toEqual(message);
return test_utils.waitUntil(function () {
return chatboxview.$('.new-msgs-indicator').is(':visible');
}, 300)
}, 300);
}).then(function () {
expect(chatboxview.model.get('scrolled')).toBe(true);
expect(chatboxview.$content.scrollTop()).toBe(0);
......@@ -745,7 +745,7 @@
chatboxview.$content.scrollTop(chatboxview.$content[0].scrollHeight);
return test_utils.waitUntil(function () {
return !chatboxview.$('.new-msgs-indicator').is(':visible');
}, 300)
}, 300);
}).then(done);
}));
......@@ -1256,7 +1256,7 @@
test_utils.sendMessage(view, message);
return test_utils.waitUntil(function () {
return view.$el.find('.chat-content').find('.chat-message img').length === 2;
}, 500)
}, 500);
}).then(function () {
expect(view.sendMessage).toHaveBeenCalled();
var msg = view.$el.find('.chat-content').find('.chat-message').last().find('.chat-msg-content');
......@@ -1351,7 +1351,7 @@
view.model.maximize();
return test_utils.waitUntil(function () {
return view.model.get('chat_state') === 'active';
}, 300)
}, 300);
}).then(function () {
expect(_converse.connection.send).toHaveBeenCalled();
var $stanza = $(_converse.connection.send.calls.argsFor(0)[0].tree());
......@@ -1496,7 +1496,7 @@
expect($stanza.children().get(0).tagName).toBe('composing');
return test_utils.waitUntil(function () {
return view.model.get('chat_state') === 'paused';
}, 500)
}, 500);
}).then(function () {
expect(_converse.connection.send).toHaveBeenCalled();
var $stanza = $(_converse.connection.send.calls.argsFor(1)[0].tree());
......@@ -1618,11 +1618,11 @@
return true;
}
return false;
}, 250)
}, 250);
}).then(function () {
return test_utils.waitUntil(function () {
return view.model.get('chat_state') === 'inactive';
}, 250)
}, 250);
}).then(function () {
expect(_converse.connection.send).toHaveBeenCalled();
var $stanza = $(_converse.connection.send.calls.first().args[0].tree());
......
......@@ -43,4 +43,4 @@
endFile: "end-no-dependencies.frag"
},
mainConfigFile: "config.js"
})
});
......@@ -6,4 +6,4 @@
startFile: "start.frag",
endFile: "end.frag"
}
})
});
......@@ -29,7 +29,7 @@
tpl_bookmarks_list
) {
var $ = converse.env.jQuery,
const $ = converse.env.jQuery,
Backbone = converse.env.Backbone,
Strophe = converse.env.Strophe,
$iq = converse.env.$iq,
......@@ -66,7 +66,7 @@
},
generateHeadingHTML: function () {
var _converse = this.__super__._converse,
const _converse = this.__super__._converse,
__ = _converse.__,
html = this.__super__.generateHeadingHTML.apply(this, arguments);
if (_converse.allow_bookmarks) {
......@@ -92,11 +92,11 @@
* for this room, and if so use it.
* Otherwise delegate to the super method.
*/
var _converse = this.__super__._converse;
const _converse = this.__super__._converse;
if (_.isUndefined(_converse.bookmarks) || !_converse.allow_bookmarks) {
return this.__super__.checkForReservedNick.apply(this, arguments);
}
var model = _converse.bookmarks.findWhere({'jid': this.model.get('jid')});
const model = _converse.bookmarks.findWhere({'jid': this.model.get('jid')});
if (!_.isUndefined(model) && model.get('nick')) {
this.join(model.get('nick'));
} else {
......
This diff is collapsed.
......@@ -42,14 +42,14 @@
) {
"use strict";
var USERS_PANEL_ID = 'users';
var CHATBOX_TYPE = 'chatbox';
const USERS_PANEL_ID = 'users';
const CHATBOX_TYPE = 'chatbox';
// Strophe methods for building stanzas
var Strophe = converse.env.Strophe,
const Strophe = converse.env.Strophe,
Backbone = converse.env.Backbone,
utils = converse.env.utils;
// Other necessary globals
var $ = converse.env.jQuery,
const $ = converse.env.jQuery,
_ = converse.env._,
fp = converse.env.fp,
moment = converse.env.moment;
......@@ -188,7 +188,7 @@
/* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery.
*/
var _converse = this._converse,
const _converse = this._converse,
__ = _converse.__;
_converse.api.settings.update({
......@@ -200,12 +200,13 @@
xhr_user_search_url: ''
});
var LABEL_CONTACTS = __('Contacts');
const LABEL_CONTACTS = __('Contacts');
_converse.addControlBox = function () {
return _converse.chatboxes.add({
id: 'controlbox',
box_id: 'controlbox',
type: 'controlbox',
closed: !_converse.show_controlbox_by_default
});
};
......
This diff is collapsed.
......@@ -16,7 +16,7 @@
], factory);
}(this, function (converse, tpl_dragresize) {
"use strict";
var $ = converse.env.jQuery,
const $ = converse.env.jQuery,
_ = converse.env._;
function renderDragResizeHandles (_converse, view) {
......
......@@ -14,7 +14,7 @@
], factory);
}(this, function (converse, tpl_chatbox) {
"use strict";
var _ = converse.env._,
const _ = converse.env._,
utils = converse.env.utils;
converse.plugins.add('converse-headline', {
......@@ -28,8 +28,8 @@
ChatBoxViews: {
onChatBoxAdded: function (item) {
var _converse = this.__super__._converse;
var view = this.get(item.get('id'));
const _converse = this.__super__._converse;
let view = this.get(item.get('id'));
if (!view && item.get('type') === 'headline') {
view = new _converse.HeadlinesBoxView({model: item});
this.add(item.get('id'), view);
......@@ -45,7 +45,7 @@
/* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery.
*/
var _converse = this._converse,
const _converse = this._converse,
__ = _converse.__;
_converse.HeadlinesBoxView = _converse.ChatBoxView.extend({
......@@ -89,14 +89,14 @@
}
});
var onHeadlineMessage = function (message) {
function onHeadlineMessage (message) {
/* Handler method for all incoming messages of type "headline". */
var from_jid = message.getAttribute('from');
const from_jid = message.getAttribute('from');
if (utils.isHeadlineMessage(message)) {
if (_.includes(from_jid, '@') && !_converse.allow_non_roster_messaging) {
return;
}
var chatbox = _converse.chatboxes.create({
const chatbox = _converse.chatboxes.create({
'id': from_jid,
'jid': from_jid,
'fullname': from_jid,
......@@ -106,12 +106,12 @@
_converse.emit('message', {'chatbox': chatbox, 'stanza': message});
}
return true;
};
}
var registerHeadlineHandler = function () {
function registerHeadlineHandler () {
_converse.connection.addHandler(
onHeadlineMessage, null, 'message');
};
}
_converse.on('connected', registerHeadlineHandler);
_converse.on('reconnected', registerHeadlineHandler);
}
......
......@@ -24,7 +24,8 @@
tpl_chats_panel
) {
"use strict";
var $ = converse.env.jQuery,
const $ = converse.env.jQuery,
_ = converse.env._,
utils = converse.env.utils,
Backbone = converse.env.Backbone,
......@@ -40,8 +41,8 @@
// New functions which don't exist yet can also be added.
initChatBoxes: function () {
var _converse = this.__super__._converse;
var result = this.__super__.initChatBoxes.apply(this, arguments);
const _converse = this.__super__._converse;
const result = this.__super__.initChatBoxes.apply(this, arguments);
_converse.minimized_chats = new _converse.MinimizedChats({
model: _converse.chatboxes
});
......@@ -49,7 +50,7 @@
},
registerGlobalEventHandlers: function () {
var _converse = this.__super__._converse;
const _converse = this.__super__._converse;
$(window).on("resize", _.debounce(function (ev) {
if (_converse.connection.connected) {
_converse.chatboxviews.trimChats();
......@@ -96,7 +97,7 @@
},
_show: function () {
var _converse = this.__super__._converse;
const _converse = this.__super__._converse;
if (!this.model.get('minimized')) {
this.__super__._show.apply(this, arguments);
_converse.chatboxviews.trimChats(this);
......
......@@ -8,7 +8,7 @@
define(["converse-core", "converse-muc"], factory);
}(this, function (converse) {
"use strict";
var Backbone = converse.env.Backbone,
const Backbone = converse.env.Backbone,
_ = converse.env._;
converse.plugins.add('converse-muc-embedded', {
......@@ -23,7 +23,7 @@
onConnected: function () {
// Override to avoid storing or fetching chat boxes from session
// storage.
var _converse = this.__super__._converse;
const _converse = this.__super__._converse;
this.browserStorage = new Backbone.BrowserStorage[_converse.storage](
converse.env.b64_sha1('converse.chatboxes-'+_converse.bare_jid));
this.registerMessageHandler();
......@@ -41,7 +41,7 @@
ChatRoomView: {
insertIntoDOM: function () {
if (!document.body.contains(this.el)) {
var container = document.querySelector('#converse-embedded-chat');
const container = document.querySelector('#converse-embedded-chat');
container.innerHTML = '';
container.appendChild(this.el);
}
......@@ -54,7 +54,7 @@
/* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery.
*/
var _converse = this._converse;
const _converse = this._converse;
if (!_.isArray(_converse.auto_join_rooms)) {
throw new Error("converse-muc-embedded: auto_join_rooms must be an Array");
}
......@@ -62,7 +62,7 @@
throw new Error("converse-muc-embedded: It doesn't make "+
"sense to have the auto_join_rooms setting to zero or "+
"more then one, since only one chat room can be open "+
"at any time.")
"at any time.");
}
}
});
......
This diff is collapsed.
......@@ -10,7 +10,7 @@
define(["converse-core"], factory);
}(this, function (converse) {
"use strict";
var utils = converse.env.utils,
const utils = converse.env.utils,
Strophe = converse.env.Strophe,
_ = converse.env._;
......@@ -20,11 +20,11 @@
/* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery.
*/
var _converse = this._converse;
const _converse = this._converse;
// For translations
var __ = _converse.__;
var ___ = _converse.___;
const __ = _converse.__;
const ___ = _converse.___;
_converse.supports_html5_notification = "Notification" in window;
......
......@@ -19,29 +19,29 @@
"use strict";
// Strophe methods for building stanzas
var Strophe = converse.env.Strophe,
const Strophe = converse.env.Strophe,
utils = converse.env.utils,
b64_sha1 = converse.env.b64_sha1;
// Other necessary globals
var $ = converse.env.jQuery,
const $ = converse.env.jQuery,
_ = converse.env._;
var HAS_CSPRNG = ((!_.isUndefined(crypto)) &&
const HAS_CSPRNG = ((!_.isUndefined(crypto)) &&
((_.isFunction(crypto.randomBytes)) || (_.isFunction(crypto.getRandomValues))
));
var HAS_CRYPTO = HAS_CSPRNG && (
const HAS_CRYPTO = HAS_CSPRNG && (
(!_.isUndefined(otr.OTR)) &&
(!_.isUndefined(otr.DSA))
);
var UNENCRYPTED = 0;
var UNVERIFIED= 1;
var VERIFIED= 2;
var FINISHED = 3;
const UNENCRYPTED = 0;
const UNVERIFIED= 1;
const VERIFIED= 2;
const FINISHED = 3;
var OTR_TRANSLATED_MAPPING = {}; // Populated in initialize
var OTR_CLASS_MAPPING = {};
const OTR_TRANSLATED_MAPPING = {}; // Populated in initialize
const OTR_CLASS_MAPPING = {};
OTR_CLASS_MAPPING[UNENCRYPTED] = 'unencrypted';
OTR_CLASS_MAPPING[UNVERIFIED] = 'unverified';
OTR_CLASS_MAPPING[VERIFIED] = 'verified';
......@@ -132,7 +132,7 @@
encrypted_key = this.get('otr_priv_key');
if (_.isString(encrypted_key)) {
instance_tag = this.get('otr_instance_tag');
saved_key = otr.DSA.parsePrivate(encrypted_key)
saved_key = otr.DSA.parsePrivate(encrypted_key);
if (saved_key && instance_tag) {
this.trigger('showHelpMessages', [__('Re-establishing encrypted session')]);
callback({
......
......@@ -14,7 +14,7 @@
}(this, function (converse) {
"use strict";
// Strophe methods for building stanzas
var Strophe = converse.env.Strophe,
const Strophe = converse.env.Strophe,
_ = converse.env._;
converse.plugins.add('converse-ping', {
......@@ -23,7 +23,7 @@
/* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery.
*/
var _converse = this._converse;
const _converse = this._converse;
_converse.api.settings.update({
ping_interval: 180 //in seconds
......
......@@ -32,12 +32,12 @@
"use strict";
// Strophe methods for building stanzas
var Strophe = converse.env.Strophe,
const Strophe = converse.env.Strophe,
Backbone = converse.env.Backbone,
utils = converse.env.utils,
$iq = converse.env.$iq;
// Other necessary globals
var $ = converse.env.jQuery,
const $ = converse.env.jQuery,
_ = converse.env._;
// Add Strophe Namespaces
......
......@@ -70,7 +70,7 @@
'toggle_state': this.list_model.get('toggle-state'),
'desc_rooms': __('Click to toggle the rooms list'),
'label_rooms': __('Open Rooms')
})
});
this.hide();
if (this.list_model.get('toggle-state') !== _converse.OPENED) {
this.$('.open-rooms-list').hide();
......@@ -111,7 +111,7 @@
}
this.removeRoomsListElement(item);
var name, bookmark
var name, bookmark;
if (item.get('bookmarked')) {
bookmark = _.head(_converse.bookmarksview.model.where({'jid': item.get('jid')}));
name = bookmark.get('name');
......
......@@ -590,7 +590,7 @@
));
} else if (subscription === 'both' || subscription === 'to') {
this.el.classList.add('current-xmpp-contact');
this.el.classList.remove(_.without(['both', 'to'], subscription)[0])
this.el.classList.remove(_.without(['both', 'to'], subscription)[0]);
this.el.classList.add(subscription);
this.renderRosterItem(item);
}
......
......@@ -72,9 +72,9 @@
* time. So before opening a chat, we make sure all other
* chats are hidden.
*/
var _converse = this.__super__._converse;
var chatbox = this.getChatBox(attrs, true);
var hidden = _.isUndefined(attrs.hidden) ? chatbox.get('hidden') : attrs.hidden;
const _converse = this.__super__._converse;
const chatbox = this.getChatBox(attrs, true);
const hidden = _.isUndefined(attrs.hidden) ? chatbox.get('hidden') : attrs.hidden;
if ((force || !hidden) && _converse.connection.authenticated) {
_.each(_converse.chatboxviews.xget(chatbox.get('id')), hideChat);
chatbox.save({'hidden': false});
......
......@@ -10,7 +10,7 @@
define(["converse-core", "strophe.vcard"], factory);
}(this, function (converse) {
"use strict";
var Strophe = converse.env.Strophe,
const Strophe = converse.env.Strophe,
$ = converse.env.jQuery,
_ = converse.env._,
moment = converse.env.moment;
......@@ -26,7 +26,7 @@
Features: {
addClientFeatures: function () {
var _converse = this.__super__._converse;
const _converse = this.__super__._converse;
this.__super__.addClientFeatures.apply(this, arguments);
if (_converse.use_vcards) {
_converse.connection.disco.addFeature(Strophe.NS.VCARD);
......@@ -36,8 +36,8 @@
RosterContacts: {
createRequestingContact: function (presence) {
var _converse = this.__super__._converse;
var bare_jid = Strophe.getBareJidFromJid(presence.getAttribute('from'));
const _converse = this.__super__._converse;
const bare_jid = Strophe.getBareJidFromJid(presence.getAttribute('from'));
_converse.getVCard(
bare_jid,
_.partial(_converse.createRequestingContactFromVCard, presence),
......@@ -58,15 +58,15 @@
/* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery.
*/
var _converse = this._converse;
const _converse = this._converse;
_converse.api.settings.update({
use_vcards: true,
});
_converse.createRequestingContactFromVCard = function (presence, iq, jid, fullname, img, img_type, url) {
var bare_jid = Strophe.getBareJidFromJid(jid);
var nick = $(presence).children('nick[xmlns="'+Strophe.NS.NICK+'"]').text();
var user_data = {
const bare_jid = Strophe.getBareJidFromJid(jid);
const nick = $(presence).children('nick[xmlns="'+Strophe.NS.NICK+'"]').text();
const user_data = {
jid: bare_jid,
subscription: 'none',
ask: null,
......@@ -82,7 +82,7 @@
};
_converse.onVCardError = function (jid, iq, errback) {
var contact = _converse.roster.get(jid);
const contact = _converse.roster.get(jid);
if (contact) {
contact.save({ 'vcard_updated': moment().format() });
}
......
......@@ -63,7 +63,7 @@
var div = document.createElement('div');
div.innerHTML = htmlEscapedText;
return div.innerText;
}
};
var isImage = function (url) {
var deferred = new $.Deferred();
......@@ -467,13 +467,13 @@
utils.isConverseLocale = function (locale) {
if (!_.isString(locale)) { return false; }
return _.includes(_.keys(locales || {}), locale)
return _.includes(_.keys(locales || {}), locale);
};
utils.isMomentLocale = function (locale) {
if (!_.isString(locale)) { return false; }
return moment.locale() !== moment.locale(locale);
}
};
utils.getLocale = function (preferred_locale, isSupportedByLibrary) {
if (_.isString(preferred_locale)) {
......@@ -492,7 +492,7 @@
utils.isOfType = function (type, item) {
return item.get('type') == type;
}
};
utils.isInstance = function (type, item) {
return item instanceof type;
......@@ -520,7 +520,7 @@
}
element.appendChild(frag); // Now, append all elements at once
frag = tmp = null;
}
};
utils.isPersistableModel = function (model) {
return model.collection && model.collection.browserStorage;
......
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