Initial stab at using ES2015
Mostly replaced ``var`` with ``let`` and ``const``. Also added a few arrow functions.
This commit is contained in:
parent
e1b745b71f
commit
40e7ee1ae6
@ -1,4 +1,7 @@
|
||||
{
|
||||
"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 {
|
||||
|
@ -30,7 +30,7 @@
|
||||
tpl_spinner
|
||||
) {
|
||||
"use strict";
|
||||
var $ = converse.env.jQuery,
|
||||
const $ = converse.env.jQuery,
|
||||
$msg = converse.env.$msg,
|
||||
Backbone = converse.env.Backbone,
|
||||
Strophe = converse.env.Strophe,
|
||||
@ -38,7 +38,7 @@
|
||||
moment = converse.env.moment,
|
||||
utils = converse.env.utils;
|
||||
|
||||
var KEY = {
|
||||
const KEY = {
|
||||
ENTER: 13,
|
||||
FORWARD_SLASH: 47
|
||||
};
|
||||
@ -55,8 +55,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) {
|
||||
view = new _converse.ChatBoxView({model: item});
|
||||
this.add(item.get('id'), view);
|
||||
@ -73,7 +73,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({
|
||||
@ -88,12 +88,11 @@
|
||||
},
|
||||
});
|
||||
|
||||
var onWindowStateChanged = function (data) {
|
||||
var state = data.state;
|
||||
function onWindowStateChanged (data) {
|
||||
_converse.chatboxviews.each(function (chatboxview) {
|
||||
chatboxview.onWindowStateChanged(state);
|
||||
})
|
||||
};
|
||||
chatboxview.onWindowStateChanged(data.state);
|
||||
});
|
||||
}
|
||||
|
||||
_converse.api.listen.on('windowStateChanged', onWindowStateChanged);
|
||||
|
||||
@ -173,7 +172,7 @@
|
||||
/* This method gets overridden in src/converse-controlbox.js if
|
||||
* the controlbox plugin is active.
|
||||
*/
|
||||
var container = document.querySelector('#conversejs');
|
||||
const container = document.querySelector('#conversejs');
|
||||
if (this.el.parentNode !== container) {
|
||||
container.insertBefore(this.el, container.firstChild);
|
||||
}
|
||||
@ -188,7 +187,7 @@
|
||||
if (!keep_old) {
|
||||
this.clearStatusNotification();
|
||||
}
|
||||
var $el = $('<div class="chat-info"></div>').text(message);
|
||||
const $el = $('<div class="chat-info"></div>').text(message);
|
||||
if (!permanent) {
|
||||
$el.addClass('chat-event');
|
||||
}
|
||||
@ -216,8 +215,8 @@
|
||||
* Parameters:
|
||||
* (String) date - An ISO8601 date string.
|
||||
*/
|
||||
var day_date = moment(date).startOf('day');
|
||||
var insert = prepend ? this.$content.prepend: this.$content.append;
|
||||
const day_date = moment(date).startOf('day');
|
||||
const insert = prepend ? this.$content.prepend: this.$content.append;
|
||||
insert.call(this.$content, tpl_new_day({
|
||||
isodate: day_date.format(),
|
||||
datestring: day_date.format("dddd MMM Do YYYY")
|
||||
@ -232,11 +231,9 @@
|
||||
* Parameters:
|
||||
* (Object) attrs: An object containing the message attributes.
|
||||
*/
|
||||
var that = this;
|
||||
var insert = prepend ? this.$content.prepend : this.$content.append;
|
||||
_.flow(
|
||||
function ($el) {
|
||||
insert.call(that.$content, $el);
|
||||
const insert = prepend ? this.$content.prepend : this.$content.append;
|
||||
_.flow(($el) => {
|
||||
insert.call(this.$content, $el);
|
||||
return $el;
|
||||
},
|
||||
this.scrollDown.bind(this)
|
||||
@ -255,11 +252,9 @@
|
||||
* (Object) attrs: An object containing the message
|
||||
* attributes.
|
||||
*/
|
||||
var msg_dates,
|
||||
$first_msg = this.$content.find('.chat-message:first'),
|
||||
first_msg_date = $first_msg.data('isodate'),
|
||||
current_msg_date = moment(attrs.time) || moment,
|
||||
last_msg_date = this.$content.find('.chat-message:last').data('isodate');
|
||||
let current_msg_date = moment(attrs.time) || moment;
|
||||
const $first_msg = this.$content.find('.chat-message:first'),
|
||||
first_msg_date = $first_msg.data('isodate');
|
||||
|
||||
if (!first_msg_date) {
|
||||
// This is the first received message, so we insert a
|
||||
@ -268,6 +263,8 @@
|
||||
this.insertMessage(attrs);
|
||||
return;
|
||||
}
|
||||
|
||||
const last_msg_date = this.$content.find('.chat-message:last').data('isodate');
|
||||
if (current_msg_date.isAfter(last_msg_date) ||
|
||||
current_msg_date.isSame(last_msg_date)) {
|
||||
// The new message is after the last message
|
||||
@ -294,16 +291,17 @@
|
||||
}
|
||||
// Find the correct place to position the message
|
||||
current_msg_date = current_msg_date.format();
|
||||
msg_dates = _.map(this.$content.find('.chat-message'), function (el) {
|
||||
const msg_dates = _.map(this.$content.find('.chat-message'), function (el) {
|
||||
return $(el).data('isodate');
|
||||
});
|
||||
msg_dates.push(current_msg_date);
|
||||
msg_dates.sort();
|
||||
var idx = msg_dates.indexOf(current_msg_date)-1;
|
||||
var $latest_message = this.$content.find('.chat-message[data-isodate="'+msg_dates[idx]+'"]:last');
|
||||
_.flow(
|
||||
function ($el) {
|
||||
|
||||
const idx = msg_dates.indexOf(current_msg_date)-1;
|
||||
const $latest_message = this.$content.find('.chat-message[data-isodate="'+msg_dates[idx]+'"]:last');
|
||||
_.flow(($el) => {
|
||||
$el.insertAfter($latest_message);
|
||||
return $el;
|
||||
},
|
||||
this.scrollDown.bind(this)
|
||||
)(this.renderMessage(attrs));
|
||||
@ -332,12 +330,11 @@
|
||||
* Returns:
|
||||
* The DOM element representing the message.
|
||||
*/
|
||||
var msg_time = moment(attrs.time) || moment,
|
||||
text = attrs.message,
|
||||
match = text.match(/^\/(.*?)(?: (.*))?$/),
|
||||
let text = attrs.message,
|
||||
fullname = this.model.get('fullname') || attrs.fullname,
|
||||
template, username;
|
||||
|
||||
const match = text.match(/^\/(.*?)(?: (.*))?$/);
|
||||
if ((match) && (match[1] === 'me')) {
|
||||
text = text.replace(/^\/me/, '');
|
||||
template = tpl_action;
|
||||
@ -361,7 +358,8 @@
|
||||
"Output has been shortened."),
|
||||
true, true);
|
||||
}
|
||||
var $msg = $(template(
|
||||
const msg_time = moment(attrs.time) || moment;
|
||||
const $msg = $(template(
|
||||
_.extend(this.getExtraMessageTemplateAttributes(attrs), {
|
||||
'msgid': attrs.msgid,
|
||||
'sender': attrs.sender,
|
||||
@ -379,13 +377,12 @@
|
||||
},
|
||||
|
||||
showHelpMessages: function (msgs, type, spinner) {
|
||||
var i, msgs_length = msgs.length;
|
||||
for (i=0; i<msgs_length; i++) {
|
||||
_.each(msgs, (msg) => {
|
||||
this.$content.append($(tpl_help_message({
|
||||
'type': type||'info',
|
||||
'message': msgs[i]
|
||||
'message': msgs
|
||||
})));
|
||||
}
|
||||
});
|
||||
if (spinner === true) {
|
||||
this.$content.append(tpl_spinner);
|
||||
} else if (spinner === false) {
|
||||
@ -440,7 +437,7 @@
|
||||
},
|
||||
|
||||
handleErrorMessage: function (message) {
|
||||
var $message = $('[data-msgid='+message.get('msgid')+']');
|
||||
const $message = $('[data-msgid='+message.get('msgid')+']');
|
||||
if ($message.length) {
|
||||
$message.after($('<div class="chat-info chat-error"></div>').text(message.get('message')));
|
||||
this.scrollDown();
|
||||
@ -488,7 +485,7 @@
|
||||
*/
|
||||
// TODO: We might want to send to specfic resources.
|
||||
// Especially in the OTR case.
|
||||
var messageStanza = this.createMessageStanza(message);
|
||||
const messageStanza = this.createMessageStanza(message);
|
||||
_converse.connection.send(messageStanza);
|
||||
if (_converse.forward_messages) {
|
||||
// Forward the message, so that other connected resources are also aware of it.
|
||||
@ -515,13 +512,13 @@
|
||||
'error'
|
||||
);
|
||||
}
|
||||
var match = text.replace(/^\s*/, "").match(/^\/(.*)\s*$/), msgs;
|
||||
const match = text.replace(/^\s*/, "").match(/^\/(.*)\s*$/);
|
||||
if (match) {
|
||||
if (match[1] === "clear") {
|
||||
return this.clearMessages();
|
||||
}
|
||||
else if (match[1] === "help") {
|
||||
msgs = [
|
||||
const msgs = [
|
||||
'<strong>/help</strong>:'+__('Show this menu')+'',
|
||||
'<strong>/me</strong>:'+__('Write in the third person')+'',
|
||||
'<strong>/clear</strong>:'+__('Remove messages')+''
|
||||
@ -530,9 +527,10 @@
|
||||
return;
|
||||
}
|
||||
}
|
||||
var fullname = _converse.xmppstatus.get('fullname');
|
||||
let fullname = _converse.xmppstatus.get('fullname');
|
||||
fullname = _.isEmpty(fullname)? _converse.bare_jid: fullname;
|
||||
var message = this.model.messages.create({
|
||||
|
||||
const message = this.model.messages.create({
|
||||
fullname: fullname,
|
||||
sender: 'me',
|
||||
time: moment().format(),
|
||||
@ -586,10 +584,10 @@
|
||||
keyPressed: function (ev) {
|
||||
/* Event handler for when a key is pressed in a chat box textarea.
|
||||
*/
|
||||
var textarea = ev.target, message;
|
||||
if (ev.keyCode === KEY.ENTER) {
|
||||
ev.preventDefault();
|
||||
message = textarea.value;
|
||||
const textarea = ev.target;
|
||||
const message = textarea.value;
|
||||
textarea.value = '';
|
||||
textarea.focus();
|
||||
if (message !== '') {
|
||||
@ -608,7 +606,7 @@
|
||||
/* Event handler for when a send button is clicked in a chat box textarea.
|
||||
*/
|
||||
ev.preventDefault();
|
||||
var textarea = this.el.querySelector('.chat-textarea'),
|
||||
const textarea = this.el.querySelector('.chat-textarea'),
|
||||
message = textarea.value;
|
||||
|
||||
textarea.value = '';
|
||||
@ -622,7 +620,7 @@
|
||||
|
||||
clearMessages: function (ev) {
|
||||
if (ev && ev.preventDefault) { ev.preventDefault(); }
|
||||
var result = confirm(__("Are you sure you want to clear the messages from this chat box?"));
|
||||
const result = confirm(__("Are you sure you want to clear the messages from this chat box?"));
|
||||
if (result === true) {
|
||||
this.$content.empty();
|
||||
this.model.messages.reset();
|
||||
@ -632,8 +630,8 @@
|
||||
},
|
||||
|
||||
insertIntoTextArea: function (value) {
|
||||
var $textbox = this.$el.find('textarea.chat-textarea');
|
||||
var existing = $textbox.val();
|
||||
const $textbox = this.$el.find('textarea.chat-textarea');
|
||||
let existing = $textbox.val();
|
||||
if (existing && (existing[existing.length-1] !== ' ')) {
|
||||
existing = existing + ' ';
|
||||
}
|
||||
@ -643,7 +641,7 @@
|
||||
insertEmoticon: function (ev) {
|
||||
ev.stopPropagation();
|
||||
this.$el.find('.toggle-smiley ul').slideToggle(200);
|
||||
var $target = $(ev.target);
|
||||
let $target = $(ev.target);
|
||||
$target = $target.is('a') ? $target : $target.children('a');
|
||||
this.insertIntoTextArea($target.data('emoticon'));
|
||||
},
|
||||
@ -662,8 +660,8 @@
|
||||
},
|
||||
|
||||
onChatStatusChanged: function (item) {
|
||||
var chat_status = item.get('chat_status'),
|
||||
fullname = item.get('fullname');
|
||||
const chat_status = item.get('chat_status');
|
||||
let fullname = item.get('fullname');
|
||||
fullname = _.isEmpty(fullname)? item.get('jid'): fullname;
|
||||
if (this.$el.is(':visible')) {
|
||||
if (chat_status === 'offline') {
|
||||
@ -738,9 +736,9 @@
|
||||
if (!this.model.get('image')) {
|
||||
return;
|
||||
}
|
||||
var width = _converse.chatview_avatar_width;
|
||||
var height = _converse.chatview_avatar_height;
|
||||
var img_src = 'data:'+this.model.get('image_type')+';base64,'+this.model.get('image'),
|
||||
const width = _converse.chatview_avatar_width;
|
||||
const height = _converse.chatview_avatar_height;
|
||||
const img_src = 'data:'+this.model.get('image_type')+';base64,'+this.model.get('image'),
|
||||
canvas = $(tpl_avatar({
|
||||
'width': width,
|
||||
'height': height
|
||||
@ -749,10 +747,10 @@
|
||||
if (!(canvas.getContext && canvas.getContext('2d'))) {
|
||||
return this;
|
||||
}
|
||||
var ctx = canvas.getContext('2d');
|
||||
var img = new Image(); // Create new Image object
|
||||
const ctx = canvas.getContext('2d');
|
||||
const img = new Image(); // Create new Image object
|
||||
img.onload = function () {
|
||||
var ratio = img.width/img.height;
|
||||
const ratio = img.width/img.height;
|
||||
if (ratio < 1) {
|
||||
ctx.drawImage(img, 0,0, width, height*(1/ratio));
|
||||
} else {
|
||||
@ -810,7 +808,7 @@
|
||||
},
|
||||
|
||||
hideNewMessagesIndicator: function () {
|
||||
var new_msgs_indicator = this.el.querySelector('.new-msgs-indicator');
|
||||
const new_msgs_indicator = this.el.querySelector('.new-msgs-indicator');
|
||||
if (!_.isNull(new_msgs_indicator)) {
|
||||
new_msgs_indicator.classList.add('hidden');
|
||||
}
|
||||
@ -831,8 +829,8 @@
|
||||
});
|
||||
return;
|
||||
}
|
||||
var scrolled = true;
|
||||
var is_at_bottom =
|
||||
let scrolled = true;
|
||||
const is_at_bottom =
|
||||
(this.$content.scrollTop() + this.$content.innerHeight()) >=
|
||||
this.$content[0].scrollHeight-10;
|
||||
if (is_at_bottom) {
|
||||
|
@ -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
|
||||
});
|
||||
};
|
||||
|
@ -30,14 +30,14 @@
|
||||
// "use strict";
|
||||
|
||||
// Create the FP (functional programming) version of lodash
|
||||
var fp = lodashConverter(_.runInContext());
|
||||
const fp = lodashConverter(_.runInContext());
|
||||
|
||||
// Strophe globals
|
||||
var $build = Strophe.$build;
|
||||
var $iq = Strophe.$iq;
|
||||
var $msg = Strophe.$msg;
|
||||
var $pres = Strophe.$pres;
|
||||
var b64_sha1 = Strophe.SHA1.b64_sha1;
|
||||
const $build = Strophe.$build;
|
||||
const $iq = Strophe.$iq;
|
||||
const $msg = Strophe.$msg;
|
||||
const $pres = Strophe.$pres;
|
||||
const b64_sha1 = Strophe.SHA1.b64_sha1;
|
||||
Strophe = Strophe.Strophe;
|
||||
|
||||
// Use Mustache style syntax for variable interpolation
|
||||
@ -50,7 +50,7 @@
|
||||
'interpolate': /\{\{([\s\S]+?)\}\}/g
|
||||
};
|
||||
|
||||
var _converse = {};
|
||||
const _converse = {};
|
||||
_converse.templates = {};
|
||||
_.extend(_converse, Backbone.Events);
|
||||
_converse.promises = {
|
||||
@ -66,7 +66,7 @@
|
||||
};
|
||||
_converse.emit = function (name) {
|
||||
_converse.trigger.apply(this, arguments);
|
||||
var promise = _converse.promises[name];
|
||||
const promise = _converse.promises[name];
|
||||
if (!_.isUndefined(promise)) {
|
||||
promise.resolve();
|
||||
}
|
||||
@ -121,7 +121,7 @@
|
||||
_converse.OPENED = 'opened';
|
||||
_converse.PREBIND = "prebind";
|
||||
|
||||
var PRETTY_CONNECTION_STATUS = {
|
||||
const PRETTY_CONNECTION_STATUS = {
|
||||
0: 'ERROR',
|
||||
1: 'CONNECTING',
|
||||
2: 'CONNFAIL',
|
||||
@ -134,11 +134,11 @@
|
||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AhJBoNGrutpNx6e7uPnTokC1eMU3T0um0DZPMkZER6wERQnw+n/FFSxpy7Nix3bt3WwwIIcRgIWnHkkwmjecfRgGx7DtuV/r6+iwGhDHev3+/bQF1dnYaH6E2CkiWZdsC2rt3r8WAHA5HW1ubbQGZcjajgOwTH/4qNko1Wlg4IA6IA+KAOKBWBUQIsfNojyliKIoRRfH9+/dut9umf3wzpoUNNQ4BAJubmwz+ic+OxefzWWlBhJD29nbug7iT5sIBcUAcEAfEAXFAHBAHxOVn+QMrmWpuPZx12gAAAABJRU5ErkJggg==";
|
||||
|
||||
_converse.log = function (txt, level) {
|
||||
var logger = _.assignIn({
|
||||
const logger = _.assignIn({
|
||||
'debug': _.noop,
|
||||
'error': _.noop,
|
||||
'info': _.noop,
|
||||
@ -170,7 +170,7 @@
|
||||
_converse.initialize = function (settings, callback) {
|
||||
"use strict";
|
||||
settings = !_.isUndefined(settings) ? settings : {};
|
||||
var init_deferred = new $.Deferred();
|
||||
const init_deferred = new $.Deferred();
|
||||
|
||||
if (!_.isUndefined(_converse.chatboxes)) {
|
||||
// Looks like _converse.initialized was called again without logging
|
||||
@ -182,7 +182,7 @@
|
||||
_converse._tearDown();
|
||||
}
|
||||
|
||||
var unloadevent;
|
||||
let unloadevent;
|
||||
if ('onpagehide' in window) {
|
||||
// Pagehide gets thrown in more cases than unload. Specifically it
|
||||
// gets thrown when the page is cached and not just
|
||||
@ -225,7 +225,7 @@
|
||||
moment.locale = moment.lang;
|
||||
}
|
||||
moment.locale(utils.getLocale(settings.i18n, utils.isMomentLocale));
|
||||
var __ = _converse.__ = utils.__.bind(_converse);
|
||||
const __ = _converse.__ = utils.__.bind(_converse);
|
||||
_converse.___ = utils.___;
|
||||
|
||||
// XEP-0085 Chat states
|
||||
@ -364,7 +364,7 @@
|
||||
// This can happen when the connection reconnects.
|
||||
return;
|
||||
}
|
||||
var stat = _converse.xmppstatus.getStatus();
|
||||
const stat = _converse.xmppstatus.getStatus();
|
||||
_converse.idle_seconds++;
|
||||
if (_converse.csi_waiting_time > 0 &&
|
||||
_converse.idle_seconds > _converse.csi_waiting_time &&
|
||||
@ -403,7 +403,7 @@
|
||||
};
|
||||
|
||||
this.giveFeedback = function (subject, klass, message) {
|
||||
var els = document.querySelectorAll('.conn-feedback');
|
||||
const els = document.querySelectorAll('.conn-feedback');
|
||||
_.forEach(els, function (el) {
|
||||
el.classList.add('conn-feedback');
|
||||
el.textContent = subject;
|
||||
@ -428,7 +428,7 @@
|
||||
* is being canceled.
|
||||
* (String) message - An optional message to the user
|
||||
*/
|
||||
var pres = $pres({to: jid, type: "unsubscribed"});
|
||||
const pres = $pres({to: jid, type: "unsubscribed"});
|
||||
if (message && message !== "") { pres.c("status").t(message); }
|
||||
_converse.connection.send(pres);
|
||||
};
|
||||
@ -543,7 +543,7 @@
|
||||
|
||||
this.incrementMsgCounter = function () {
|
||||
this.msg_counter += 1;
|
||||
var unreadMsgCount = this.msg_counter;
|
||||
const unreadMsgCount = this.msg_counter;
|
||||
if (document.title.search(/^Messages \(\d+\) /) === -1) {
|
||||
document.title = "Messages (" + unreadMsgCount + ") " + document.title;
|
||||
} else {
|
||||
@ -559,9 +559,9 @@
|
||||
};
|
||||
|
||||
this.initStatus = function () {
|
||||
var deferred = new $.Deferred();
|
||||
const deferred = new $.Deferred();
|
||||
this.xmppstatus = new this.XMPPStatus();
|
||||
var id = b64_sha1('converse.xmppstatus-'+_converse.bare_jid);
|
||||
const id = b64_sha1('converse.xmppstatus-'+_converse.bare_jid);
|
||||
this.xmppstatus.id = id; // Appears to be necessary for backbone.browserStorage
|
||||
this.xmppstatus.browserStorage = new Backbone.BrowserStorage[_converse.storage](id);
|
||||
this.xmppstatus.fetch({
|
||||
@ -574,7 +574,7 @@
|
||||
|
||||
this.initSession = function () {
|
||||
this.session = new this.Session();
|
||||
var id = b64_sha1('converse.bosh-session');
|
||||
const id = b64_sha1('converse.bosh-session');
|
||||
this.session.id = id; // Appears to be necessary for backbone.browserStorage
|
||||
this.session.browserStorage = new Backbone.BrowserStorage[_converse.storage](id);
|
||||
this.session.fetch();
|
||||
@ -606,16 +606,15 @@
|
||||
// XXX: eventually we should be able to just use
|
||||
// document.visibilityState (when we drop support for older
|
||||
// browsers).
|
||||
var state;
|
||||
var v = "visible", h = "hidden",
|
||||
event_map = {
|
||||
'focus': v,
|
||||
'focusin': v,
|
||||
'pageshow': v,
|
||||
'blur': h,
|
||||
'focusout': h,
|
||||
'pagehide': h
|
||||
};
|
||||
let state;
|
||||
const event_map = {
|
||||
'focus': "visible",
|
||||
'focusin': "visible",
|
||||
'pageshow': "visible",
|
||||
'blur': "hidden",
|
||||
'focusout': "hidden",
|
||||
'pagehide': "hidden"
|
||||
};
|
||||
ev = ev || document.createEvent('Events');
|
||||
if (ev.type in event_map) {
|
||||
state = event_map[ev.type];
|
||||
@ -626,13 +625,13 @@
|
||||
_converse.clearMsgCounter();
|
||||
}
|
||||
_converse.windowState = state;
|
||||
_converse.emit('windowStateChanged', {state: state})
|
||||
_converse.emit('windowStateChanged', {state: state});
|
||||
};
|
||||
|
||||
this.registerGlobalEventHandlers = function () {
|
||||
// Taken from:
|
||||
// http://stackoverflow.com/questions/1060008/is-there-a-way-to-detect-if-a-browser-window-is-not-currently-active
|
||||
var hidden = "hidden";
|
||||
let hidden = "hidden";
|
||||
// Standards:
|
||||
if (hidden in document) {
|
||||
document.addEventListener("visibilitychange", _.partial(_converse.saveWindowState, _, hidden));
|
||||
@ -662,7 +661,7 @@
|
||||
if (!this.message_carbons || this.session.get('carbons_enabled')) {
|
||||
return;
|
||||
}
|
||||
var carbons_iq = new Strophe.Builder('iq', {
|
||||
const carbons_iq = new Strophe.Builder('iq', {
|
||||
from: this.connection.jid,
|
||||
id: 'enablecarbons',
|
||||
type: 'set'
|
||||
@ -811,9 +810,9 @@
|
||||
},
|
||||
|
||||
initialize: function (attributes) {
|
||||
var jid = attributes.jid;
|
||||
var bare_jid = Strophe.getBareJidFromJid(jid).toLowerCase();
|
||||
var resource = Strophe.getResourceFromJid(jid);
|
||||
const jid = attributes.jid;
|
||||
const bare_jid = Strophe.getBareJidFromJid(jid).toLowerCase();
|
||||
const resource = Strophe.getResourceFromJid(jid);
|
||||
attributes.jid = bare_jid;
|
||||
this.set(_.assignIn({
|
||||
'id': bare_jid,
|
||||
@ -837,11 +836,11 @@
|
||||
* reason for the subscription request.
|
||||
*/
|
||||
this.save('ask', "subscribe"); // ask === 'subscribe' Means we have ask to subscribe to them.
|
||||
var pres = $pres({to: this.get('jid'), type: "subscribe"});
|
||||
const pres = $pres({to: this.get('jid'), type: "subscribe"});
|
||||
if (message && message !== "") {
|
||||
pres.c("status").t(message).up();
|
||||
}
|
||||
var nick = _converse.xmppstatus.get('fullname');
|
||||
const nick = _converse.xmppstatus.get('fullname');
|
||||
if (nick && nick !== "") {
|
||||
pres.c('nick', {'xmlns': Strophe.NS.NICK}).t(nick).up();
|
||||
}
|
||||
@ -888,7 +887,7 @@
|
||||
* Parameters:
|
||||
* (String) message - Optional message to send to the person being authorized
|
||||
*/
|
||||
var pres = $pres({to: this.get('jid'), type: "subscribed"});
|
||||
const pres = $pres({to: this.get('jid'), type: "subscribed"});
|
||||
if (message && message !== "") {
|
||||
pres.c("status").t(message);
|
||||
}
|
||||
@ -903,23 +902,23 @@
|
||||
* Also updates the contact's chat_status if the presence has
|
||||
* higher priority (and is newer).
|
||||
*/
|
||||
var jid = presence.getAttribute('from'),
|
||||
const jid = presence.getAttribute('from'),
|
||||
chat_status = _.propertyOf(presence.querySelector('show'))('textContent') || 'online',
|
||||
resource = Strophe.getResourceFromJid(jid),
|
||||
priority = _.propertyOf(presence.querySelector('priority'))('textContent') || 0,
|
||||
delay = presence.querySelector('delay[xmlns="'+Strophe.NS.DELAY+'"]'),
|
||||
timestamp = _.isNull(delay) ? moment().format() : moment(delay.getAttribute('stamp')).format();
|
||||
|
||||
let priority = _.propertyOf(presence.querySelector('priority'))('textContent') || 0;
|
||||
priority = _.isNaN(parseInt(priority, 10)) ? 0 : parseInt(priority, 10);
|
||||
|
||||
var resources = _.isObject(this.get('resources')) ? this.get('resources') : {};
|
||||
const resources = _.isObject(this.get('resources')) ? this.get('resources') : {};
|
||||
resources[resource] = {
|
||||
'priority': priority,
|
||||
'status': chat_status,
|
||||
'timestamp': timestamp
|
||||
};
|
||||
var changed = {'resources': resources};
|
||||
var hpr = this.getHighestPriorityResource();
|
||||
const changed = {'resources': resources};
|
||||
const hpr = this.getHighestPriorityResource();
|
||||
if (priority == hpr.priority && timestamp == hpr.timestamp) {
|
||||
// Only set the chat status if this is the newest resource
|
||||
// with the highest priority
|
||||
@ -935,7 +934,7 @@
|
||||
* Also recomputes the chat_status given that there's one less
|
||||
* resource.
|
||||
*/
|
||||
var resources = this.get('resources');
|
||||
let resources = this.get('resources');
|
||||
if (!_.isObject(resources)) {
|
||||
resources = {};
|
||||
} else {
|
||||
@ -954,9 +953,9 @@
|
||||
* If multiple resources have the same priority, take the
|
||||
* newest one.
|
||||
*/
|
||||
var resources = this.get('resources');
|
||||
const resources = this.get('resources');
|
||||
if (_.isObject(resources) && _.size(resources)) {
|
||||
var val = _.flow(
|
||||
const val = _.flow(
|
||||
_.values,
|
||||
_.partial(_.sortBy, _, ['priority', 'timestamp']),
|
||||
_.reverse
|
||||
@ -972,7 +971,7 @@
|
||||
* Parameters:
|
||||
* (Function) callback
|
||||
*/
|
||||
var iq = $iq({type: 'set'})
|
||||
const iq = $iq({type: 'set'})
|
||||
.c('query', {xmlns: Strophe.NS.ROSTER})
|
||||
.c('item', {jid: this.get('jid'), subscription: "remove"});
|
||||
_converse.connection.sendIQ(iq, callback, callback);
|
||||
@ -985,12 +984,11 @@
|
||||
model: _converse.RosterContact,
|
||||
|
||||
comparator: function (contact1, contact2) {
|
||||
var name1, name2;
|
||||
var status1 = contact1.get('chat_status') || 'offline';
|
||||
var status2 = contact2.get('chat_status') || 'offline';
|
||||
const status1 = contact1.get('chat_status') || 'offline';
|
||||
const status2 = contact2.get('chat_status') || 'offline';
|
||||
if (_converse.STATUS_WEIGHTS[status1] === _converse.STATUS_WEIGHTS[status2]) {
|
||||
name1 = contact1.get('fullname').toLowerCase();
|
||||
name2 = contact2.get('fullname').toLowerCase();
|
||||
const name1 = contact1.get('fullname').toLowerCase();
|
||||
const name2 = contact2.get('fullname').toLowerCase();
|
||||
return name1 < name2 ? -1 : (name1 > name2? 1 : 0);
|
||||
} else {
|
||||
return _converse.STATUS_WEIGHTS[status1] < _converse.STATUS_WEIGHTS[status2] ? -1 : 1;
|
||||
@ -1044,7 +1042,7 @@
|
||||
* Returns a promise which resolves once the contacts have been
|
||||
* fetched.
|
||||
*/
|
||||
var deferred = new $.Deferred();
|
||||
const deferred = new $.Deferred();
|
||||
this.fetch({
|
||||
add: true,
|
||||
success: function (collection) {
|
||||
@ -1112,7 +1110,7 @@
|
||||
* (Function) errback - A function to call if an error occured
|
||||
*/
|
||||
name = _.isEmpty(name)? jid: name;
|
||||
var iq = $iq({type: 'set'})
|
||||
const iq = $iq({type: 'set'})
|
||||
.c('query', {xmlns: Strophe.NS.ROSTER})
|
||||
.c('item', { jid: jid, name: name });
|
||||
_.each(groups, function (group) { iq.c('group').t(group).up(); });
|
||||
@ -1131,12 +1129,12 @@
|
||||
* (Array of Strings) groups - Any roster groups the user might belong to
|
||||
* (Object) attributes - Any additional attributes to be stored on the user's model.
|
||||
*/
|
||||
var deferred = new $.Deferred();
|
||||
const deferred = new $.Deferred();
|
||||
groups = groups || [];
|
||||
name = _.isEmpty(name)? jid: name;
|
||||
this.sendContactAddIQ(jid, name, groups,
|
||||
function () {
|
||||
var contact = this.create(_.assignIn({
|
||||
const contact = this.create(_.assignIn({
|
||||
ask: undefined,
|
||||
fullname: name,
|
||||
groups: groups,
|
||||
@ -1156,7 +1154,7 @@
|
||||
},
|
||||
|
||||
subscribeBack: function (bare_jid) {
|
||||
var contact = this.get(bare_jid);
|
||||
const contact = this.get(bare_jid);
|
||||
if (contact instanceof _converse.RosterContact) {
|
||||
contact.authorize().subscribe();
|
||||
} else {
|
||||
@ -1170,20 +1168,13 @@
|
||||
},
|
||||
|
||||
getNumOnlineContacts: function () {
|
||||
var count = 0,
|
||||
ignored = ['offline', 'unavailable'],
|
||||
models = this.models,
|
||||
models_length = models.length,
|
||||
i;
|
||||
let ignored = ['offline', 'unavailable'];
|
||||
if (_converse.show_only_online_users) {
|
||||
ignored = _.union(ignored, ['dnd', 'xa', 'away']);
|
||||
}
|
||||
for (i=0; i<models_length; i++) {
|
||||
if (!_.includes(ignored, models[i].get('chat_status'))) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
return _.sum(this.models.filter(function (model) {
|
||||
return !_.includes(ignored, model.get('chat_status'));
|
||||
}));
|
||||
},
|
||||
|
||||
onRosterPush: function (iq) {
|
||||
@ -1193,8 +1184,8 @@
|
||||
* Parameters:
|
||||
* (XMLElement) IQ - The IQ stanza received from the XMPP server.
|
||||
*/
|
||||
var id = iq.getAttribute('id');
|
||||
var from = iq.getAttribute('from');
|
||||
const id = iq.getAttribute('id');
|
||||
const from = iq.getAttribute('from');
|
||||
if (from && from !== "" && Strophe.getBareJidFromJid(from) !== _converse.bare_jid) {
|
||||
// Receiving client MUST ignore stanza unless it has no from or from = user's bare JID.
|
||||
// XXX: Some naughty servers apparently send from a full
|
||||
@ -1208,8 +1199,7 @@
|
||||
return true;
|
||||
}
|
||||
_converse.connection.send($iq({type: 'result', id: id, from: _converse.connection.jid}));
|
||||
// var items = iq.querySelectorAll('query[xmlns="'+Strophe.NS.ROSTER+'"] item');
|
||||
var items = sizzle('query[xmlns="'+Strophe.NS.ROSTER+'"] item', iq);
|
||||
const items = sizzle('query[xmlns="'+Strophe.NS.ROSTER+'"] item', iq);
|
||||
_.each(items, this.updateContact.bind(this));
|
||||
_converse.emit('rosterPush', iq);
|
||||
return true;
|
||||
@ -1217,12 +1207,11 @@
|
||||
|
||||
fetchFromServer: function (callback) {
|
||||
/* Get the roster from the XMPP server */
|
||||
var iq = $iq({type: 'get', 'id': _converse.connection.getUniqueId('roster')})
|
||||
.c('query', {xmlns: Strophe.NS.ROSTER});
|
||||
var that = this;
|
||||
return _converse.connection.sendIQ(iq, function () {
|
||||
that.onReceivedFromServer.apply(that, arguments);
|
||||
callback.apply(that, arguments);
|
||||
const iq = $iq({type: 'get', 'id': _converse.connection.getUniqueId('roster')})
|
||||
.c('query', {xmlns: Strophe.NS.ROSTER});
|
||||
return _converse.connection.sendIQ(iq, (iq) => {
|
||||
this.onReceivedFromServer(iq);
|
||||
callback.apply(this, arguments);
|
||||
});
|
||||
},
|
||||
|
||||
@ -1230,8 +1219,7 @@
|
||||
/* An IQ stanza containing the roster has been received from
|
||||
* the XMPP server.
|
||||
*/
|
||||
// var items = iq.querySelectorAll('query[xmlns="'+Strophe.NS.ROSTER+'"] item');
|
||||
var items = sizzle('query[xmlns="'+Strophe.NS.ROSTER+'"] item', iq);
|
||||
const items = sizzle('query[xmlns="'+Strophe.NS.ROSTER+'"] item', iq);
|
||||
_.each(items, this.updateContact.bind(this));
|
||||
_converse.emit('roster', iq);
|
||||
},
|
||||
@ -1240,12 +1228,14 @@
|
||||
/* Update or create RosterContact models based on items
|
||||
* received in the IQ from the server.
|
||||
*/
|
||||
var jid = item.getAttribute('jid');
|
||||
const jid = item.getAttribute('jid');
|
||||
if (this.isSelf(jid)) { return; }
|
||||
var groups = _.map(item.getElementsByTagName('group'), Strophe.getText),
|
||||
contact = this.get(jid),
|
||||
ask = item.getAttribute("ask"),
|
||||
subscription = item.getAttribute("subscription");
|
||||
|
||||
const contact = this.get(jid),
|
||||
subscription = item.getAttribute("subscription"),
|
||||
ask = item.getAttribute("ask"),
|
||||
groups = _.map(item.getElementsByTagName('group'), Strophe.getText);
|
||||
|
||||
if (!contact) {
|
||||
if ((subscription === "none" && ask === null) || (subscription === "remove")) {
|
||||
return; // We're lazy when adding contacts.
|
||||
@ -1279,9 +1269,9 @@
|
||||
*
|
||||
* Note: this method gets completely overridden by converse-vcard.js
|
||||
*/
|
||||
var bare_jid = Strophe.getBareJidFromJid(presence.getAttribute('from'));
|
||||
var nick_el = presence.querySelector('nick[xmlns="'+Strophe.NS.NICK+'"]');
|
||||
var user_data = {
|
||||
const bare_jid = Strophe.getBareJidFromJid(presence.getAttribute('from')),
|
||||
nick_el = presence.querySelector('nick[xmlns="'+Strophe.NS.NICK+'"]');
|
||||
const user_data = {
|
||||
jid: bare_jid,
|
||||
subscription: 'none',
|
||||
ask: null,
|
||||
@ -1293,9 +1283,10 @@
|
||||
},
|
||||
|
||||
handleIncomingSubscription: function (presence) {
|
||||
var jid = presence.getAttribute('from');
|
||||
var bare_jid = Strophe.getBareJidFromJid(jid);
|
||||
var contact = this.get(bare_jid);
|
||||
const jid = presence.getAttribute('from'),
|
||||
bare_jid = Strophe.getBareJidFromJid(jid),
|
||||
contact = this.get(bare_jid);
|
||||
|
||||
if (!_converse.allow_contact_requests) {
|
||||
_converse.rejectPresenceSubscription(
|
||||
jid,
|
||||
@ -1315,16 +1306,17 @@
|
||||
} else if (contact.get('ask') === "subscribe") {
|
||||
contact.authorize();
|
||||
}
|
||||
} else if (!contact) {
|
||||
} else {
|
||||
this.createRequestingContact(presence);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
presenceHandler: function (presence) {
|
||||
var presence_type = presence.getAttribute('type');
|
||||
const presence_type = presence.getAttribute('type');
|
||||
if (presence_type === 'error') { return true; }
|
||||
var jid = presence.getAttribute('from'),
|
||||
|
||||
const jid = presence.getAttribute('from'),
|
||||
bare_jid = Strophe.getBareJidFromJid(jid),
|
||||
resource = Strophe.getResourceFromJid(jid),
|
||||
chat_status = _.propertyOf(presence.querySelector('show'))('textContent') || 'online',
|
||||
@ -1390,7 +1382,7 @@
|
||||
* Returns a promise which resolves once the groups have been
|
||||
* returned.
|
||||
*/
|
||||
var deferred = new $.Deferred();
|
||||
const deferred = new $.Deferred();
|
||||
this.fetch({
|
||||
silent: true, // We need to first have all groups before
|
||||
// we can start positioning them, so we set
|
||||
@ -1442,15 +1434,13 @@
|
||||
|
||||
getMessageAttributes: function (message, delay, original_stanza) {
|
||||
delay = delay || message.querySelector('delay');
|
||||
var type = message.getAttribute('type'),
|
||||
body, stamp, time, sender, from, fullname;
|
||||
const type = message.getAttribute('type');
|
||||
|
||||
if (type === 'error') {
|
||||
body = _.propertyOf(message.querySelector('error text'))('textContent');
|
||||
} else {
|
||||
body = _.propertyOf(message.querySelector('body'))('textContent');
|
||||
}
|
||||
var delayed = !_.isNull(delay),
|
||||
const body = (type === 'error') ?
|
||||
_.propertyOf(message.querySelector('error text'))('textContent') :
|
||||
_.propertyOf(message.querySelector('body'))('textContent');
|
||||
|
||||
const delayed = !_.isNull(delay),
|
||||
is_groupchat = type === 'groupchat',
|
||||
chat_state = message.getElementsByTagName(_converse.COMPOSING).length && _converse.COMPOSING ||
|
||||
message.getElementsByTagName(_converse.PAUSED).length && _converse.PAUSED ||
|
||||
@ -1458,17 +1448,15 @@
|
||||
message.getElementsByTagName(_converse.ACTIVE).length && _converse.ACTIVE ||
|
||||
message.getElementsByTagName(_converse.GONE).length && _converse.GONE;
|
||||
|
||||
let from;
|
||||
if (is_groupchat) {
|
||||
from = Strophe.unescapeNode(Strophe.getResourceFromJid(message.getAttribute('from')));
|
||||
} else {
|
||||
from = Strophe.getBareJidFromJid(message.getAttribute('from'));
|
||||
}
|
||||
if (delayed) {
|
||||
stamp = delay.getAttribute('stamp');
|
||||
time = stamp;
|
||||
} else {
|
||||
time = moment().format();
|
||||
}
|
||||
|
||||
const time = delayed ? delay.getAttribute('stamp') : moment().format();
|
||||
let sender, fullname;
|
||||
if ((is_groupchat && from === this.get('nick')) || (!is_groupchat && from === _converse.bare_jid)) {
|
||||
sender = 'me';
|
||||
fullname = _converse.xmppstatus.get('fullname') || from;
|
||||
@ -1546,9 +1534,8 @@
|
||||
* This method gets overridden entirely in src/converse-controlbox.js
|
||||
* if the controlbox plugin is active.
|
||||
*/
|
||||
var that = this;
|
||||
collection.each(function (chatbox) {
|
||||
if (that.chatBoxMayBeShown(chatbox)) {
|
||||
collection.each((chatbox) => {
|
||||
if (this.chatBoxMayBeShown(chatbox)) {
|
||||
chatbox.trigger('show');
|
||||
}
|
||||
});
|
||||
@ -1569,12 +1556,12 @@
|
||||
/* Handler method for all incoming error message stanzas
|
||||
*/
|
||||
// TODO: we can likely just reuse "onMessage" below
|
||||
var from_jid = Strophe.getBareJidFromJid(message.getAttribute('from'));
|
||||
const from_jid = Strophe.getBareJidFromJid(message.getAttribute('from'));
|
||||
if (utils.isSameBareJID(from_jid, _converse.bare_jid)) {
|
||||
return true;
|
||||
}
|
||||
// Get chat box, but only create a new one when the message has a body.
|
||||
var chatbox = this.getChatBox(from_jid);
|
||||
const chatbox = this.getChatBox(from_jid);
|
||||
if (!chatbox) {
|
||||
return true;
|
||||
}
|
||||
@ -1586,14 +1573,14 @@
|
||||
/* Handler method for all incoming single-user chat "message"
|
||||
* stanzas.
|
||||
*/
|
||||
var original_stanza = message,
|
||||
contact_jid, delay, from_bare_jid,
|
||||
from_resource, is_me, msgid, messages,
|
||||
chatbox, resource,
|
||||
|
||||
let contact_jid, delay, resource,
|
||||
from_jid = message.getAttribute('from'),
|
||||
to_jid = message.getAttribute('to'),
|
||||
to_resource = Strophe.getResourceFromJid(to_jid),
|
||||
is_carbon = !_.isNull(message.querySelector('received[xmlns="'+Strophe.NS.CARBONS+'"]'));
|
||||
to_jid = message.getAttribute('to');
|
||||
|
||||
const original_stanza = message,
|
||||
to_resource = Strophe.getResourceFromJid(to_jid),
|
||||
is_carbon = !_.isNull(message.querySelector('received[xmlns="'+Strophe.NS.CARBONS+'"]'));
|
||||
|
||||
if (_converse.filter_by_resource && (to_resource && to_resource !== _converse.resource)) {
|
||||
_converse.log(
|
||||
@ -1611,10 +1598,10 @@
|
||||
);
|
||||
return true;
|
||||
}
|
||||
var forwarded = message.querySelector('forwarded');
|
||||
const forwarded = message.querySelector('forwarded');
|
||||
if (!_.isNull(forwarded)) {
|
||||
var forwarded_message = forwarded.querySelector('message');
|
||||
var forwarded_from = forwarded_message.getAttribute('from');
|
||||
const forwarded_message = forwarded.querySelector('message');
|
||||
const forwarded_from = forwarded_message.getAttribute('from');
|
||||
if (is_carbon && Strophe.getBareJidFromJid(forwarded_from) !== from_jid) {
|
||||
// Prevent message forging via carbons
|
||||
//
|
||||
@ -1626,9 +1613,11 @@
|
||||
from_jid = message.getAttribute('from');
|
||||
to_jid = message.getAttribute('to');
|
||||
}
|
||||
from_bare_jid = Strophe.getBareJidFromJid(from_jid);
|
||||
from_resource = Strophe.getResourceFromJid(from_jid);
|
||||
is_me = from_bare_jid === _converse.bare_jid;
|
||||
|
||||
const from_bare_jid = Strophe.getBareJidFromJid(from_jid),
|
||||
from_resource = Strophe.getResourceFromJid(from_jid),
|
||||
is_me = from_bare_jid === _converse.bare_jid;
|
||||
|
||||
if (is_me) {
|
||||
// I am the sender, so this must be a forwarded message...
|
||||
contact_jid = Strophe.getBareJidFromJid(to_jid);
|
||||
@ -1638,10 +1627,11 @@
|
||||
resource = from_resource;
|
||||
}
|
||||
// Get chat box, but only create a new one when the message has a body.
|
||||
chatbox = this.getChatBox(contact_jid, !_.isNull(message.querySelector('body')));
|
||||
msgid = message.getAttribute('id');
|
||||
const chatbox = this.getChatBox(contact_jid, !_.isNull(message.querySelector('body'))),
|
||||
msgid = message.getAttribute('id');
|
||||
|
||||
if (chatbox) {
|
||||
messages = msgid && chatbox.messages.findWhere({msgid: msgid}) || [];
|
||||
const messages = msgid && chatbox.messages.findWhere({msgid: msgid}) || [];
|
||||
if (_.isEmpty(messages)) {
|
||||
// Only create the message when we're sure it's not a
|
||||
// duplicate
|
||||
@ -1661,9 +1651,10 @@
|
||||
* gets created.
|
||||
* (Object) attrs - Optional chat box atributes.
|
||||
*/
|
||||
var bare_jid = Strophe.getBareJidFromJid(jid);
|
||||
var roster_info = {};
|
||||
var roster_item = _converse.roster.get(bare_jid);
|
||||
const bare_jid = Strophe.getBareJidFromJid(jid),
|
||||
roster_item = _converse.roster.get(bare_jid);
|
||||
let roster_info = {};
|
||||
|
||||
if (! _.isUndefined(roster_item)) {
|
||||
roster_info = {
|
||||
'fullname': _.isEmpty(roster_item.get('fullname'))? jid: roster_item.get('fullname'),
|
||||
@ -1697,7 +1688,7 @@
|
||||
* (Object) attrs - Optional chat box atributes.
|
||||
*/
|
||||
jid = jid.toLowerCase();
|
||||
var chatbox = this.get(Strophe.getBareJidFromJid(jid));
|
||||
let chatbox = this.get(Strophe.getBareJidFromJid(jid));
|
||||
if (!chatbox && create) {
|
||||
chatbox = this.createChatBox(jid, attrs);
|
||||
}
|
||||
@ -1717,7 +1708,7 @@
|
||||
* If the #conversejs element doesn't exist, create it.
|
||||
*/
|
||||
if (!this.el) {
|
||||
var el = document.querySelector('#conversejs');
|
||||
let el = document.querySelector('#conversejs');
|
||||
if (_.isNull(el)) {
|
||||
el = document.createElement('div');
|
||||
el.setAttribute('id', 'conversejs');
|
||||
@ -1755,7 +1746,7 @@
|
||||
},
|
||||
|
||||
getChatBox: function (attrs, create) {
|
||||
var chatbox = this.model.get(attrs.jid);
|
||||
let chatbox = this.model.get(attrs.jid);
|
||||
if (!chatbox && create) {
|
||||
chatbox = this.model.create(attrs, {
|
||||
'error': function (model, response) {
|
||||
@ -1770,7 +1761,7 @@
|
||||
/* Find the chat box and show it (if it may be shown).
|
||||
* If it doesn't exist, create it.
|
||||
*/
|
||||
var chatbox = this.getChatBox(attrs, true);
|
||||
const chatbox = this.getChatBox(attrs, true);
|
||||
if (this.chatBoxMayBeShown(chatbox)) {
|
||||
chatbox.trigger('show', true);
|
||||
}
|
||||
@ -1795,7 +1786,7 @@
|
||||
},
|
||||
|
||||
constructPresence: function (type, status_message) {
|
||||
var presence;
|
||||
let presence;
|
||||
type = _.isString(type) ? type : (this.get('status') || _converse.default_state);
|
||||
status_message = _.isString(status_message) ? status_message : undefined;
|
||||
// Most of these presence types are actually not explicitly sent,
|
||||
@ -1839,14 +1830,14 @@
|
||||
|
||||
setStatusMessage: function (status_message) {
|
||||
this.sendPresence(this.getStatus(), status_message);
|
||||
var prev_status = this.get('status_message');
|
||||
this.save({'status_message': status_message});
|
||||
if (this.xhr_custom_status) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', this.xhr_custom_status_url, true);
|
||||
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
|
||||
xhr.send({'msg': status_message});
|
||||
}
|
||||
const prev_status = this.get('status_message');
|
||||
if (prev_status === status_message) {
|
||||
this.trigger("update-status-ui", this);
|
||||
}
|
||||
@ -1908,12 +1899,11 @@
|
||||
},
|
||||
|
||||
onItems: function (stanza) {
|
||||
var that = this;
|
||||
_.each(stanza.querySelectorAll('query item'), function (item) {
|
||||
_.each(stanza.querySelectorAll('query item'), (item) => {
|
||||
_converse.connection.disco.info(
|
||||
item.getAttribute('jid'),
|
||||
null,
|
||||
that.onInfo.bind(that));
|
||||
this.onInfo.bind(this));
|
||||
});
|
||||
},
|
||||
|
||||
@ -1923,11 +1913,10 @@
|
||||
// This isn't an IM server component
|
||||
return;
|
||||
}
|
||||
var that = this;
|
||||
_.forEach(stanza.querySelectorAll('feature'), function (feature) {
|
||||
var namespace = feature.getAttribute('var');
|
||||
that[namespace] = true;
|
||||
that.create({
|
||||
_.forEach(stanza.querySelectorAll('feature'), (feature) => {
|
||||
const namespace = feature.getAttribute('var');
|
||||
this[namespace] = true;
|
||||
this.create({
|
||||
'var': namespace,
|
||||
'from': stanza.getAttribute('from')
|
||||
});
|
||||
@ -1950,13 +1939,13 @@
|
||||
};
|
||||
|
||||
this.fetchLoginCredentials = function () {
|
||||
var deferred = new $.Deferred();
|
||||
var xhr = new XMLHttpRequest();
|
||||
const deferred = new $.Deferred();
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', _converse.credentials_url, true);
|
||||
xhr.setRequestHeader('Accept', "application/json, text/javascript");
|
||||
xhr.onload = function() {
|
||||
if (xhr.status >= 200 && xhr.status < 400) {
|
||||
var data = JSON.parse(xhr.responseText);
|
||||
const data = JSON.parse(xhr.responseText);
|
||||
deferred.resolve({
|
||||
'jid': data.jid,
|
||||
'password': data.password
|
||||
@ -1975,12 +1964,12 @@
|
||||
};
|
||||
|
||||
this.startNewBOSHSession = function () {
|
||||
var xhr = new XMLHttpRequest();
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', _converse.prebind_url, true);
|
||||
xhr.setRequestHeader('Accept', "application/json, text/javascript");
|
||||
xhr.onload = function() {
|
||||
if (xhr.status >= 200 && xhr.status < 400) {
|
||||
var data = JSON.parse(xhr.responseText);
|
||||
const data = JSON.parse(xhr.responseText);
|
||||
_converse.connection.attach(
|
||||
data.jid, data.sid, data.rid,
|
||||
_converse.onConnectStatusChanged);
|
||||
@ -1998,8 +1987,8 @@
|
||||
this.restoreBOSHSession = function (jid_is_required) {
|
||||
/* Tries to restore a cached BOSH session. */
|
||||
if (!this.jid) {
|
||||
var msg = "restoreBOSHSession: tried to restore a \"keepalive\" session "+
|
||||
"but we don't have the JID for the user!";
|
||||
const msg = "restoreBOSHSession: tried to restore a \"keepalive\" session "+
|
||||
"but we don't have the JID for the user!";
|
||||
if (jid_is_required) {
|
||||
throw new Error(msg);
|
||||
} else {
|
||||
@ -2094,7 +2083,7 @@
|
||||
}
|
||||
this.connection.connect(this.jid.toLowerCase(), null, this.onConnectStatusChanged);
|
||||
} else if (this.authentication === _converse.LOGIN) {
|
||||
var password = _.isNil(credentials) ? (_converse.connection.pass || this.password) : credentials.password;
|
||||
const password = _.isNil(credentials) ? (_converse.connection.pass || this.password) : credentials.password;
|
||||
if (!password) {
|
||||
if (this.auto_login) {
|
||||
throw new Error("initConnection: If you use auto_login and "+
|
||||
@ -2104,7 +2093,7 @@
|
||||
_converse.disconnect();
|
||||
return;
|
||||
}
|
||||
var resource = Strophe.getResourceFromJid(this.jid);
|
||||
const resource = Strophe.getResourceFromJid(this.jid);
|
||||
if (!resource) {
|
||||
this.jid = this.jid.toLowerCase() + _converse.generateResource();
|
||||
} else {
|
||||
@ -2182,7 +2171,7 @@
|
||||
// If initialize is called for the first time, then this array is empty
|
||||
// in any case.
|
||||
_converse.pluggable.initialized_plugins = [];
|
||||
var whitelist = _converse.core_plugins.concat(
|
||||
const whitelist = _converse.core_plugins.concat(
|
||||
_converse.whitelisted_plugins);
|
||||
|
||||
_converse.pluggable.initializePlugins({
|
||||
@ -2250,7 +2239,7 @@
|
||||
return _converse.xmppstatus.get('status');
|
||||
},
|
||||
'set': function (value, message) {
|
||||
var data = {'status': value};
|
||||
const data = {'status': value};
|
||||
if (!_.includes(_.keys(_converse.STATUS_WEIGHTS), value)) {
|
||||
throw new Error('Invalid availability value. See https://xmpp.org/rfcs/rfc3921.html#rfc.section.2.2.2.1');
|
||||
}
|
||||
@ -2282,7 +2271,7 @@
|
||||
}
|
||||
},
|
||||
'set': function (key, val) {
|
||||
var o = {};
|
||||
const o = {};
|
||||
if (_.isObject(key)) {
|
||||
_.assignIn(_converse, _.pick(key, _.keys(_converse.default_settings)));
|
||||
} else if (_.isString("string")) {
|
||||
@ -2301,8 +2290,8 @@
|
||||
},
|
||||
'contacts': {
|
||||
'get': function (jids) {
|
||||
var _transform = function (jid) {
|
||||
var contact = _converse.roster.get(Strophe.getBareJidFromJid(jid));
|
||||
const _transform = function (jid) {
|
||||
const contact = _converse.roster.get(Strophe.getBareJidFromJid(jid));
|
||||
if (contact) {
|
||||
return contact.attributes;
|
||||
}
|
||||
@ -2324,26 +2313,23 @@
|
||||
},
|
||||
'chats': {
|
||||
'open': function (jids, attrs) {
|
||||
var chatbox;
|
||||
if (_.isUndefined(jids)) {
|
||||
_converse.log("chats.open: You need to provide at least one JID", Strophe.LogLevel.ERROR);
|
||||
return null;
|
||||
} else if (_.isString(jids)) {
|
||||
chatbox = _converse.getViewForChatBox(
|
||||
return _converse.getViewForChatBox(
|
||||
_converse.chatboxes.getChatBox(jids, true, attrs).trigger('show')
|
||||
);
|
||||
return chatbox;
|
||||
}
|
||||
return _.map(jids, function (jid) {
|
||||
chatbox = _converse.getViewForChatBox(
|
||||
return _converse.getViewForChatBox(
|
||||
_converse.chatboxes.getChatBox(jid, true, attrs).trigger('show')
|
||||
);
|
||||
return chatbox;
|
||||
});
|
||||
},
|
||||
'get': function (jids) {
|
||||
if (_.isUndefined(jids)) {
|
||||
var result = [];
|
||||
const result = [];
|
||||
_converse.chatboxes.each(function (chatbox) {
|
||||
// FIXME: Leaky abstraction from MUC. We need to add a
|
||||
// base type for chat boxes, and check for that.
|
||||
@ -2400,7 +2386,7 @@
|
||||
},
|
||||
},
|
||||
'waitUntil': function (name) {
|
||||
var promise = _converse.promises[name];
|
||||
const promise = _converse.promises[name];
|
||||
if (_.isUndefined(promise)) {
|
||||
return null;
|
||||
}
|
||||
|
@ -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.");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -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() });
|
||||
}
|
||||
|
10
src/utils.js
10
src/utils.js
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user