Rename the closured converse object to _converse

to indicate that it's private and to differentiate it from the outer "global"
converse object.
This commit is contained in:
JC Brand 2016-12-20 09:30:20 +00:00
parent 4dcb855562
commit b7b9711296
35 changed files with 2648 additions and 2652 deletions

View File

@ -6,26 +6,26 @@
"mock",
"test_utils"
], factory);
} (this, function ($, converse_api, utils, mock, test_utils) {
} (this, function ($, converse, utils, mock, test_utils) {
"use strict";
var $iq = converse_api.env.$iq,
Strophe = converse_api.env.Strophe,
_ = converse_api.env._;
var $iq = converse.env.$iq,
Strophe = converse.env.Strophe,
_ = converse.env._;
describe("A chat room", function () {
it("can be bookmarked", mock.initConverse(function (converse) {
it("can be bookmarked", mock.initConverse(function (_converse) {
var sent_stanza, IQ_id;
var sendIQ = converse.connection.sendIQ;
spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
var sendIQ = _converse.connection.sendIQ;
spyOn(_converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
sent_stanza = iq;
IQ_id = sendIQ.bind(this)(iq, callback, errback);
});
spyOn(converse.connection, 'getUniqueId').andCallThrough();
spyOn(_converse.connection, 'getUniqueId').andCallThrough();
test_utils.openChatRoom(converse, 'theplay', 'conference.shakespeare.lit', 'JC');
test_utils.openChatRoom(_converse, 'theplay', 'conference.shakespeare.lit', 'JC');
var jid = 'theplay@conference.shakespeare.lit';
var view = converse.chatboxviews.get(jid);
var view = _converse.chatboxviews.get(jid);
spyOn(view, 'renderBookmarkForm').andCallThrough();
spyOn(view, 'cancelConfiguration').andCallThrough();
@ -114,44 +114,44 @@
* <iq to='juliet@capulet.lit/balcony' type='result' id='pip1'/>
*/
var stanza = $iq({
'to':converse.connection.jid,
'to':_converse.connection.jid,
'type':'result',
'id':IQ_id
});
converse.connection._dataRecv(test_utils.createRequest(stanza));
_converse.connection._dataRecv(test_utils.createRequest(stanza));
// We ignore this IQ stanza... (unless it's an error stanza), so
// nothing to test for here.
}));
it("will be automatically opened if 'autojoin' is set on the bookmark", mock.initConverse(function (converse) {
it("will be automatically opened if 'autojoin' is set on the bookmark", mock.initConverse(function (_converse) {
var jid = 'lounge@localhost';
converse.bookmarks.create({
_converse.bookmarks.create({
'jid': jid,
'autojoin': false,
'name': 'The Lounge',
'nick': ' Othello'
});
expect(_.isUndefined(converse.chatboxviews.get(jid))).toBeTruthy();
expect(_.isUndefined(_converse.chatboxviews.get(jid))).toBeTruthy();
jid = 'theplay@conference.shakespeare.lit';
converse.bookmarks.create({
_converse.bookmarks.create({
'jid': jid,
'autojoin': true,
'name': 'The Play',
'nick': ' Othello'
});
expect(_.isUndefined(converse.chatboxviews.get(jid))).toBeFalsy();
expect(_.isUndefined(_converse.chatboxviews.get(jid))).toBeFalsy();
}));
describe("when bookmarked", function () {
it("displays that it's bookmarked through its bookmark icon", mock.initConverse(function (converse) {
it("displays that it's bookmarked through its bookmark icon", mock.initConverse(function (_converse) {
runs(function () {
test_utils.openChatRoom(converse, 'lounge', 'localhost', 'dummy');
test_utils.openChatRoom(_converse, 'lounge', 'localhost', 'dummy');
});
waits(100);
runs(function () {
var view = converse.chatboxviews.get('lounge@localhost');
var view = _converse.chatboxviews.get('lounge@localhost');
var $bookmark_icon = view.$('.icon-pushpin');
expect($bookmark_icon.hasClass('button-on')).toBeFalsy();
view.model.set('bookmarked', true);
@ -161,32 +161,32 @@
});
}));
it("can be unbookmarked", mock.initConverse(function (converse) {
it("can be unbookmarked", mock.initConverse(function (_converse) {
var view, sent_stanza, IQ_id;
var sendIQ = converse.connection.sendIQ;
spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
var sendIQ = _converse.connection.sendIQ;
spyOn(_converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
sent_stanza = iq;
IQ_id = sendIQ.bind(this)(iq, callback, errback);
});
spyOn(converse.connection, 'getUniqueId').andCallThrough();
spyOn(_converse.connection, 'getUniqueId').andCallThrough();
runs(function () {
test_utils.openChatRoom(converse, 'theplay', 'conference.shakespeare.lit', 'JC');
test_utils.openChatRoom(_converse, 'theplay', 'conference.shakespeare.lit', 'JC');
});
waits(100);
runs(function () {
var jid = 'theplay@conference.shakespeare.lit';
view = converse.chatboxviews.get(jid);
view = _converse.chatboxviews.get(jid);
spyOn(view, 'toggleBookmark').andCallThrough();
spyOn(converse.bookmarks, 'sendBookmarkStanza').andCallThrough();
spyOn(_converse.bookmarks, 'sendBookmarkStanza').andCallThrough();
view.delegateEvents();
converse.bookmarks.create({
_converse.bookmarks.create({
'jid': view.model.get('jid'),
'autojoin': false,
'name': 'The Play',
'nick': ' Othello'
});
expect(converse.bookmarks.length).toBe(1);
expect(_converse.bookmarks.length).toBe(1);
});
waits(100);
runs(function () {
@ -196,7 +196,7 @@
$bookmark_icon.click();
expect(view.toggleBookmark).toHaveBeenCalled();
expect($bookmark_icon.hasClass('button-on')).toBeFalsy();
expect(converse.bookmarks.length).toBe(0);
expect(_converse.bookmarks.length).toBe(0);
// Check that an IQ stanza is sent out, containing no
// conferences to bookmark (since we removed the one and
// only bookmark).
@ -230,32 +230,32 @@
describe("and when autojoin is set", function () {
it("will be be opened and joined automatically upon login", mock.initConverse(function (converse) {
spyOn(converse.api.rooms, 'open');
it("will be be opened and joined automatically upon login", mock.initConverse(function (_converse) {
spyOn(_converse.api.rooms, 'open');
var jid = 'theplay@conference.shakespeare.lit';
var model = converse.bookmarks.create({
var model = _converse.bookmarks.create({
'jid': jid,
'autojoin': false,
'name': 'The Play',
'nick': ''
});
expect(converse.api.rooms.open).not.toHaveBeenCalled();
converse.bookmarks.remove(model);
expect(_converse.api.rooms.open).not.toHaveBeenCalled();
_converse.bookmarks.remove(model);
converse.bookmarks.create({
_converse.bookmarks.create({
'jid': jid,
'autojoin': true,
'name': 'Hamlet',
'nick': ''
});
expect(converse.api.rooms.open).toHaveBeenCalled();
expect(_converse.api.rooms.open).toHaveBeenCalled();
}));
});
});
describe("Bookmarks", function () {
it("can be pushed from the XMPP server", mock.initConverse(function (converse) {
it("can be pushed from the XMPP server", mock.initConverse(function (_converse) {
// TODO
/* The stored data is automatically pushed to all of the user's
* connected resources.
@ -302,14 +302,14 @@
*/
}));
it("can be retrieved from the XMPP server", mock.initConverse(function (converse) {
it("can be retrieved from the XMPP server", mock.initConverse(function (_converse) {
var sent_stanza, IQ_id,
sendIQ = converse.connection.sendIQ;
spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
sendIQ = _converse.connection.sendIQ;
spyOn(_converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
sent_stanza = iq;
IQ_id = sendIQ.bind(this)(iq, callback, errback);
});
converse.emit('chatBoxesFetched');
_converse.emit('chatBoxesFetched');
/* Client requests all items
* -------------------------
@ -349,8 +349,8 @@
* </pubsub>
* </iq>
*/
expect(converse.bookmarks.models.length).toBe(0);
var stanza = $iq({'to': converse.connection.jid, 'type':'result', 'id':IQ_id})
expect(_converse.bookmarks.models.length).toBe(0);
var stanza = $iq({'to': _converse.connection.jid, 'type':'result', 'id':IQ_id})
.c('pubsub', {'xmlns': Strophe.NS.PUBSUB})
.c('items', {'node': 'storage:bookmarks'})
.c('item', {'id': 'current'})
@ -365,23 +365,23 @@
'autojoin': 'false',
'jid': 'another@conference.shakespeare.lit'
}).c('nick').t('JC').up().up();
converse.connection._dataRecv(test_utils.createRequest(stanza));
expect(converse.bookmarks.models.length).toBe(2);
expect(converse.bookmarks.findWhere({'jid': 'theplay@conference.shakespeare.lit'}).get('autojoin')).toBe(true);
expect(converse.bookmarks.findWhere({'jid': 'another@conference.shakespeare.lit'}).get('autojoin')).toBe(false);
_converse.connection._dataRecv(test_utils.createRequest(stanza));
expect(_converse.bookmarks.models.length).toBe(2);
expect(_converse.bookmarks.findWhere({'jid': 'theplay@conference.shakespeare.lit'}).get('autojoin')).toBe(true);
expect(_converse.bookmarks.findWhere({'jid': 'another@conference.shakespeare.lit'}).get('autojoin')).toBe(false);
}));
describe("The rooms panel", function () {
it("shows a list of bookmarks", mock.initConverse(function (converse) {
it("shows a list of bookmarks", mock.initConverse(function (_converse) {
var IQ_id;
var sendIQ = converse.connection.sendIQ;
spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
var sendIQ = _converse.connection.sendIQ;
spyOn(_converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
IQ_id = sendIQ.bind(this)(iq, callback, errback);
});
converse.chatboxviews.get('controlbox').$('#chatrooms dl.bookmarks').html('');
converse.emit('chatBoxesFetched');
var stanza = $iq({'to': converse.connection.jid, 'type':'result', 'id':IQ_id})
_converse.chatboxviews.get('controlbox').$('#chatrooms dl.bookmarks').html('');
_converse.emit('chatBoxesFetched');
var stanza = $iq({'to': _converse.connection.jid, 'type':'result', 'id':IQ_id})
.c('pubsub', {'xmlns': Strophe.NS.PUBSUB})
.c('items', {'node': 'storage:bookmarks'})
.c('item', {'id': 'current'})
@ -401,31 +401,31 @@
'autojoin': 'false',
'jid': 'another@conference.shakespeare.lit'
}).c('nick').t('JC').up().up();
converse.connection._dataRecv(test_utils.createRequest(stanza));
_converse.connection._dataRecv(test_utils.createRequest(stanza));
expect($('#chatrooms dl.bookmarks dd').length).toBe(3);
}));
it("remembers the toggle state of the bookmarks list", mock.initConverse(function (converse) {
it("remembers the toggle state of the bookmarks list", mock.initConverse(function (_converse) {
runs(function () {
converse.bookmarks.create({
_converse.bookmarks.create({
'jid': 'theplay@conference.shakespeare.lit',
'autojoin': false,
'name': 'The Play',
'nick': ''
});
converse.emit('chatBoxesFetched');
test_utils.openControlBox().openRoomsPanel(converse);
_converse.emit('chatBoxesFetched');
test_utils.openControlBox().openRoomsPanel(_converse);
});
waits(100);
runs(function () {
expect($('#chatrooms dl.bookmarks dd:visible').length).toBe(1);
expect(converse.bookmarksview.list_model.get('toggle-state')).toBe(converse.OPENED);
expect(_converse.bookmarksview.list_model.get('toggle-state')).toBe(_converse.OPENED);
$('#chatrooms .bookmarks-toggle').click();
expect($('#chatrooms dl.bookmarks dd:visible').length).toBe(0);
expect(converse.bookmarksview.list_model.get('toggle-state')).toBe(converse.CLOSED);
expect(_converse.bookmarksview.list_model.get('toggle-state')).toBe(_converse.CLOSED);
$('#chatrooms .bookmarks-toggle').click();
expect($('#chatrooms dl.bookmarks dd:visible').length).toBe(1);
expect(converse.bookmarksview.list_model.get('toggle-state')).toBe(converse.OPENED);
expect(_converse.bookmarksview.list_model.get('toggle-state')).toBe(_converse.OPENED);
});
}));
});

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,123 +1,123 @@
(function (root, factory) {
define([
"jquery",
"converse-api",
"mock",
"test_utils"], factory);
} (this, function ($, converse_api, mock, test_utils) {
var b64_sha1 = converse_api.env.b64_sha1;
var _ = converse_api.env._;
} (this, function (converse, mock, test_utils) {
var b64_sha1 = _converse.env.b64_sha1;
var _ = _converse.env._;
var $ = _converse.env.jQuery;
describe("Converse", function() {
describe("Authentication", function () {
it("needs either a bosh_service_url a websocket_url or both", mock.initConverse(function (converse) {
var url = converse.bosh_service_url;
var connection = converse.connection;
delete converse.bosh_service_url;
delete converse.connection;
expect(converse.initConnection.bind(converse)).toThrow(
it("needs either a bosh_service_url a websocket_url or both", mock.initConverse(function (_converse) {
var url = _converse.bosh_service_url;
var connection = _converse.connection;
delete _converse.bosh_service_url;
delete _converse.connection;
expect(_converse.initConnection.bind(_converse)).toThrow(
new Error("initConnection: you must supply a value for either the bosh_service_url or websocket_url or both."));
converse.bosh_service_url = url;
converse.connection = connection;
_converse.bosh_service_url = url;
_converse.connection = connection;
}));
describe("with prebind", function () {
it("needs a jid when also using keepalive", mock.initConverse(function (converse) {
var authentication = converse.authentication;
var jid = converse.jid;
delete converse.jid;
converse.keepalive = true;
converse.authentication = "prebind";
expect(converse.logIn.bind(converse)).toThrow(
it("needs a jid when also using keepalive", mock.initConverse(function (_converse) {
var authentication = _converse.authentication;
var jid = _converse.jid;
delete _converse.jid;
_converse.keepalive = true;
_converse.authentication = "prebind";
expect(_converse.logIn.bind(_converse)).toThrow(
new Error("attemptPreboundSession: when using 'keepalive' with 'prebind, you must supply the JID of the current user."));
converse.authentication= authentication;
converse.jid = jid;
converse.keepalive = false;
_converse.authentication= authentication;
_converse.jid = jid;
_converse.keepalive = false;
}));
it("needs jid, rid and sid values when not using keepalive", mock.initConverse(function (converse) {
var jid = converse.jid;
delete converse.jid;
converse.authentication = "prebind";
expect(converse.logIn.bind(converse)).toThrow(
it("needs jid, rid and sid values when not using keepalive", mock.initConverse(function (_converse) {
var jid = _converse.jid;
delete _converse.jid;
_converse.authentication = "prebind";
expect(_converse.logIn.bind(_converse)).toThrow(
new Error("attemptPreboundSession: If you use prebind and not keepalive, then you MUST supply JID, RID and SID values or a prebind_url."));
converse.bosh_service_url = undefined;
converse.jid = jid;
_converse.bosh_service_url = undefined;
_converse.jid = jid;
}));
});
});
describe("A chat state indication", function () {
it("are sent out when the client becomes or stops being idle", mock.initConverse(function (converse) {
spyOn(converse, 'sendCSI').andCallThrough();
it("are sent out when the client becomes or stops being idle", mock.initConverse(function (_converse) {
spyOn(_converse, 'sendCSI').andCallThrough();
var sent_stanza;
spyOn(converse.connection, 'send').andCallFake(function (stanza) {
spyOn(_converse.connection, 'send').andCallFake(function (stanza) {
sent_stanza = stanza;
});
var i = 0;
converse.idle_seconds = 0; // Usually initialized by registerIntervalHandler
converse.features['urn:xmpp:csi:0'] = true; // Mock that the server supports CSI
_converse.idle_seconds = 0; // Usually initialized by registerIntervalHandler
_converse.features['urn:xmpp:csi:0'] = true; // Mock that the server supports CSI
converse.csi_waiting_time = 3; // The relevant config option
while (i <= converse.csi_waiting_time) {
expect(converse.sendCSI).not.toHaveBeenCalled();
converse.onEverySecond();
_converse.csi_waiting_time = 3; // The relevant config option
while (i <= _converse.csi_waiting_time) {
expect(_converse.sendCSI).not.toHaveBeenCalled();
_converse.onEverySecond();
i++;
}
expect(converse.sendCSI).toHaveBeenCalledWith('inactive');
expect(_converse.sendCSI).toHaveBeenCalledWith('inactive');
expect(sent_stanza.toLocaleString()).toBe(
"<inactive xmlns='urn:xmpp:csi:0'/>"
);
converse.onUserActivity();
expect(converse.sendCSI).toHaveBeenCalledWith('active');
_converse.onUserActivity();
expect(_converse.sendCSI).toHaveBeenCalledWith('active');
expect(sent_stanza.toLocaleString()).toBe(
"<active xmlns='urn:xmpp:csi:0'/>"
);
// Reset values
converse.csi_waiting_time = 0;
converse.features['urn:xmpp:csi:0'] = false;
_converse.csi_waiting_time = 0;
_converse.features['urn:xmpp:csi:0'] = false;
}));
});
describe("Automatic status change", function () {
it("happens when the client is idle for long enough", mock.initConverse(function (converse) {
it("happens when the client is idle for long enough", mock.initConverse(function (_converse) {
var i = 0;
// Usually initialized by registerIntervalHandler
converse.idle_seconds = 0;
converse.auto_changed_status = false;
_converse.idle_seconds = 0;
_converse.auto_changed_status = false;
// The relevant config options
converse.auto_away = 3;
converse.auto_xa = 6;
_converse.auto_away = 3;
_converse.auto_xa = 6;
expect(converse.xmppstatus.getStatus()).toBe('online');
expect(_converse.xmppstatus.getStatus()).toBe('online');
while (i <= converse.auto_away) {
converse.onEverySecond();
while (i <= _converse.auto_away) {
_converse.onEverySecond();
i++;
}
expect(converse.auto_changed_status).toBe(true);
expect(_converse.auto_changed_status).toBe(true);
while (i <= converse.auto_xa) {
expect(converse.xmppstatus.getStatus()).toBe('away');
converse.onEverySecond();
while (i <= _converse.auto_xa) {
expect(_converse.xmppstatus.getStatus()).toBe('away');
_converse.onEverySecond();
i++;
}
expect(converse.xmppstatus.getStatus()).toBe('xa');
expect(converse.auto_changed_status).toBe(true);
expect(_converse.xmppstatus.getStatus()).toBe('xa');
expect(_converse.auto_changed_status).toBe(true);
converse.onUserActivity();
expect(converse.xmppstatus.getStatus()).toBe('online');
expect(converse.auto_changed_status).toBe(false);
_converse.onUserActivity();
expect(_converse.xmppstatus.getStatus()).toBe('online');
expect(_converse.auto_changed_status).toBe(false);
// Reset values
converse.auto_away = 0;
converse.auto_xa = 0;
converse.auto_changed_status = false;
_converse.auto_away = 0;
_converse.auto_xa = 0;
_converse.auto_changed_status = false;
}));
});
@ -125,162 +125,162 @@
describe("The \"status\" API", function () {
it("has a method for getting the user's availability", mock.initConverse(function (converse) {
converse.xmppstatus.set('status', 'online');
expect(converse.api.user.status.get()).toBe('online');
converse.xmppstatus.set('status', 'dnd');
expect(converse.api.user.status.get()).toBe('dnd');
it("has a method for getting the user's availability", mock.initConverse(function (_converse) {
_converse.xmppstatus.set('status', 'online');
expect(_converse.api.user.status.get()).toBe('online');
_converse.xmppstatus.set('status', 'dnd');
expect(_converse.api.user.status.get()).toBe('dnd');
}));
it("has a method for setting the user's availability", mock.initConverse(function (converse) {
converse.api.user.status.set('away');
expect(converse.xmppstatus.get('status')).toBe('away');
converse.api.user.status.set('dnd');
expect(converse.xmppstatus.get('status')).toBe('dnd');
converse.api.user.status.set('xa');
expect(converse.xmppstatus.get('status')).toBe('xa');
converse.api.user.status.set('chat');
expect(converse.xmppstatus.get('status')).toBe('chat');
expect(_.partial(converse.api.user.status.set, 'invalid')).toThrow(
it("has a method for setting the user's availability", mock.initConverse(function (_converse) {
_converse.api.user.status.set('away');
expect(_converse.xmppstatus.get('status')).toBe('away');
_converse.api.user.status.set('dnd');
expect(_converse.xmppstatus.get('status')).toBe('dnd');
_converse.api.user.status.set('xa');
expect(_converse.xmppstatus.get('status')).toBe('xa');
_converse.api.user.status.set('chat');
expect(_converse.xmppstatus.get('status')).toBe('chat');
expect(_.partial(_converse.api.user.status.set, 'invalid')).toThrow(
new Error('Invalid availability value. See https://xmpp.org/rfcs/rfc3921.html#rfc.section.2.2.2.1')
);
}));
it("allows setting the status message as well", mock.initConverse(function (converse) {
converse.api.user.status.set('away', "I'm in a meeting");
expect(converse.xmppstatus.get('status')).toBe('away');
expect(converse.xmppstatus.get('status_message')).toBe("I'm in a meeting");
it("allows setting the status message as well", mock.initConverse(function (_converse) {
_converse.api.user.status.set('away', "I'm in a meeting");
expect(_converse.xmppstatus.get('status')).toBe('away');
expect(_converse.xmppstatus.get('status_message')).toBe("I'm in a meeting");
}));
it("has a method for getting the user's status message", mock.initConverse(function (converse) {
converse.xmppstatus.set('status_message', undefined);
expect(converse.api.user.status.message.get()).toBe(undefined);
converse.xmppstatus.set('status_message', "I'm in a meeting");
expect(converse.api.user.status.message.get()).toBe("I'm in a meeting");
it("has a method for getting the user's status message", mock.initConverse(function (_converse) {
_converse.xmppstatus.set('status_message', undefined);
expect(_converse.api.user.status.message.get()).toBe(undefined);
_converse.xmppstatus.set('status_message', "I'm in a meeting");
expect(_converse.api.user.status.message.get()).toBe("I'm in a meeting");
}));
it("has a method for setting the user's status message", mock.initConverse(function (converse) {
converse.xmppstatus.set('status_message', undefined);
converse.api.user.status.message.set("I'm in a meeting");
expect(converse.xmppstatus.get('status_message')).toBe("I'm in a meeting");
it("has a method for setting the user's status message", mock.initConverse(function (_converse) {
_converse.xmppstatus.set('status_message', undefined);
_converse.api.user.status.message.set("I'm in a meeting");
expect(_converse.xmppstatus.get('status_message')).toBe("I'm in a meeting");
}));
});
});
describe("The \"tokens\" API", function () {
it("has a method for retrieving the next RID", mock.initConverse(function (converse) {
test_utils.createContacts(converse, 'current');
var old_connection = converse.connection;
converse.connection._proto.rid = '1234';
converse.expose_rid_and_sid = false;
expect(converse.api.tokens.get('rid')).toBe(null);
converse.expose_rid_and_sid = true;
expect(converse.api.tokens.get('rid')).toBe('1234');
converse.connection = undefined;
expect(converse.api.tokens.get('rid')).toBe(null);
it("has a method for retrieving the next RID", mock.initConverse(function (_converse) {
test_utils.createContacts(_converse, 'current');
var old_connection = _converse.connection;
_converse.connection._proto.rid = '1234';
_converse.expose_rid_and_sid = false;
expect(_converse.api.tokens.get('rid')).toBe(null);
_converse.expose_rid_and_sid = true;
expect(_converse.api.tokens.get('rid')).toBe('1234');
_converse.connection = undefined;
expect(_converse.api.tokens.get('rid')).toBe(null);
// Restore the connection
converse.connection = old_connection;
_converse.connection = old_connection;
}));
it("has a method for retrieving the SID", mock.initConverse(function (converse) {
test_utils.createContacts(converse, 'current');
var old_connection = converse.connection;
converse.connection._proto.sid = '1234';
converse.expose_rid_and_sid = false;
expect(converse.api.tokens.get('sid')).toBe(null);
converse.expose_rid_and_sid = true;
expect(converse.api.tokens.get('sid')).toBe('1234');
converse.connection = undefined;
expect(converse.api.tokens.get('sid')).toBe(null);
it("has a method for retrieving the SID", mock.initConverse(function (_converse) {
test_utils.createContacts(_converse, 'current');
var old_connection = _converse.connection;
_converse.connection._proto.sid = '1234';
_converse.expose_rid_and_sid = false;
expect(_converse.api.tokens.get('sid')).toBe(null);
_converse.expose_rid_and_sid = true;
expect(_converse.api.tokens.get('sid')).toBe('1234');
_converse.connection = undefined;
expect(_converse.api.tokens.get('sid')).toBe(null);
// Restore the connection
converse.connection = old_connection;
_converse.connection = old_connection;
}));
});
describe("The \"contacts\" API", function () {
it("has a method 'get' which returns wrapped contacts", mock.initConverse(function (converse) {
it("has a method 'get' which returns wrapped contacts", mock.initConverse(function (_converse) {
// Check that it returns nothing if a non-existing JID is given
test_utils.createContacts(converse, 'current');
expect(converse.api.contacts.get('non-existing@jabber.org')).toBeFalsy();
test_utils.createContacts(_converse, 'current');
expect(_converse.api.contacts.get('non-existing@jabber.org')).toBeFalsy();
// Check when a single jid is given
var jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
var attrs = converse.api.contacts.get(jid);
var attrs = _converse.api.contacts.get(jid);
expect(typeof attrs).toBe('object');
expect(attrs.fullname).toBe(mock.cur_names[0]);
expect(attrs.jid).toBe(jid);
// You can retrieve multiple contacts by passing in an array
var jid2 = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@localhost';
var list = converse_api.contacts.get([jid, jid2]);
var list = _converse.api.contacts.get([jid, jid2]);
expect(_.isArray(list)).toBeTruthy();
expect(list[0].fullname).toBe(mock.cur_names[0]);
expect(list[1].fullname).toBe(mock.cur_names[1]);
// Check that all JIDs are returned if you call without any parameters
list = converse.api.contacts.get();
list = _converse.api.contacts.get();
expect(list.length).toBe(mock.cur_names.length);
}));
it("has a method 'add' with which contacts can be added", mock.initConverse(function (converse) {
test_utils.createContacts(converse, 'current');
it("has a method 'add' with which contacts can be added", mock.initConverse(function (_converse) {
test_utils.createContacts(_converse, 'current');
var error = new TypeError('contacts.add: invalid jid');
expect(converse.api.contacts.add).toThrow(error);
expect(converse.api.contacts.add.bind(converse.api, "invalid jid")).toThrow(error);
spyOn(converse.roster, 'addAndSubscribe');
converse.api.contacts.add("newcontact@example.org");
expect(converse.roster.addAndSubscribe).toHaveBeenCalled();
expect(_converse.api.contacts.add).toThrow(error);
expect(_converse.api.contacts.add.bind(_converse.api, "invalid jid")).toThrow(error);
spyOn(_converse.roster, 'addAndSubscribe');
_converse.api.contacts.add("newcontact@example.org");
expect(_converse.roster.addAndSubscribe).toHaveBeenCalled();
}));
});
describe("The \"chats\" API", function() {
it("has a method 'get' which returns a wrapped chat box", mock.initConverse(function (converse) {
test_utils.createContacts(converse, 'current');
it("has a method 'get' which returns a wrapped chat box", mock.initConverse(function (_converse) {
test_utils.createContacts(_converse, 'current');
// Test on chat that doesn't exist.
expect(converse.api.chats.get('non-existing@jabber.org')).toBeFalsy();
expect(_converse.api.chats.get('non-existing@jabber.org')).toBeFalsy();
var jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
// Test on chat that's not open
var box = converse.api.chats.get(jid);
var box = _converse.api.chats.get(jid);
expect(typeof box === 'undefined').toBeTruthy();
var chatboxview = converse.chatboxviews.get(jid);
var chatboxview = _converse.chatboxviews.get(jid);
// Test for single JID
test_utils.openChatBoxFor(converse, jid);
box = converse.api.chats.get(jid);
test_utils.openChatBoxFor(_converse, jid);
box = _converse.api.chats.get(jid);
expect(box instanceof Object).toBeTruthy();
expect(box.get('box_id')).toBe(b64_sha1(jid));
chatboxview = converse.chatboxviews.get(jid);
chatboxview = _converse.chatboxviews.get(jid);
expect(chatboxview.$el.is(':visible')).toBeTruthy();
// Test for multiple JIDs
var jid2 = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@localhost';
test_utils.openChatBoxFor(converse, jid2);
var list = converse_api.chats.get([jid, jid2]);
test_utils.openChatBoxFor(_converse, jid2);
var list = _converse.api.chats.get([jid, jid2]);
expect(_.isArray(list)).toBeTruthy();
expect(list[0].get('box_id')).toBe(b64_sha1(jid));
expect(list[1].get('box_id')).toBe(b64_sha1(jid2));
}));
it("has a method 'open' which opens and returns a wrapped chat box", mock.initConverse(function (converse) {
test_utils.createContacts(converse, 'current');
it("has a method 'open' which opens and returns a wrapped chat box", mock.initConverse(function (_converse) {
test_utils.createContacts(_converse, 'current');
var jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
var chatboxview;
waits('300'); // ChatBox.show() is debounced for 250ms
runs(function () {
// Test on chat that doesn't exist.
expect(converse.api.chats.get('non-existing@jabber.org')).toBeFalsy();
var box = converse.api.chats.open(jid);
expect(_converse.api.chats.get('non-existing@jabber.org')).toBeFalsy();
var box = _converse.api.chats.open(jid);
expect(box instanceof Object).toBeTruthy();
expect(box.get('box_id')).toBe(b64_sha1(jid));
expect(
_.keys(box),
['close', 'endOTR', 'focus', 'get', 'initiateOTR', 'is_chatroom', 'maximize', 'minimize', 'open', 'set']
);
chatboxview = converse.chatboxviews.get(jid);
chatboxview = _converse.chatboxviews.get(jid);
expect(chatboxview.$el.is(':visible')).toBeTruthy();
// Test for multiple JIDs
var jid2 = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@localhost';
var list = converse_api.chats.open([jid, jid2]);
var list = converse.chats.open([jid, jid2]);
expect(_.isArray(list)).toBeTruthy();
expect(list[0].get('box_id')).toBe(b64_sha1(jid));
expect(list[1].get('box_id')).toBe(b64_sha1(jid2));
@ -289,17 +289,17 @@
});
describe("The \"settings\" API", function() {
it("has methods 'get' and 'set' to set configuration settings", mock.initConverse(function (converse) {
expect(_.keys(converse_api.settings)).toEqual(["get", "set"]);
expect(converse_api.settings.get("play_sounds")).toBe(false);
converse_api.settings.set("play_sounds", true);
expect(converse_api.settings.get("play_sounds")).toBe(true);
converse_api.settings.set({"play_sounds": false});
expect(converse_api.settings.get("play_sounds")).toBe(false);
it("has methods 'get' and 'set' to set configuration settings", mock.initConverse(function (_converse) {
expect(_.keys(converse.settings)).toEqual(["get", "set"]);
expect(converse.settings.get("play_sounds")).toBe(false);
converse.settings.set("play_sounds", true);
expect(converse.settings.get("play_sounds")).toBe(true);
converse.settings.set({"play_sounds": false});
expect(converse.settings.get("play_sounds")).toBe(false);
// Only whitelisted settings allowed.
expect(typeof converse.api.settings.get("non_existing")).toBe("undefined");
converse.api.settings.set("non_existing", true);
expect(typeof converse.api.settings.get("non_existing")).toBe("undefined");
expect(typeof _converse.api.settings.get("non_existing")).toBe("undefined");
_converse.api.settings.set("non_existing", true);
expect(typeof _converse.api.settings.get("non_existing")).toBe("undefined");
}));
});
});

View File

@ -4,19 +4,19 @@
"converse-api",
"mock",
"test_utils"], factory);
} (this, function ($, converse_api, mock, test_utils) {
} (this, function ($, converse, mock, test_utils) {
"use strict";
var Strophe = converse_api.env.Strophe;
var Strophe = converse.env.Strophe;
describe("Service Discovery", function () {
describe("Whenever converse.js discovers a new server feature", function () {
describe("Whenever _converse.js discovers a new server feature", function () {
it("emits the serviceDiscovered event", mock.initConverse(function (converse) {
spyOn(converse, 'emit');
converse.features.create({'var': Strophe.NS.MAM});
expect(converse.emit).toHaveBeenCalled();
expect(converse.emit.argsForCall[0][1].get('var')).toBe(Strophe.NS.MAM);
it("emits the serviceDiscovered event", mock.initConverse(function (_converse) {
spyOn(_converse, 'emit');
_converse.features.create({'var': Strophe.NS.MAM});
expect(_converse.emit).toHaveBeenCalled();
expect(_converse.emit.argsForCall[0][1].get('var')).toBe(Strophe.NS.MAM);
}));
});
});

View File

@ -1,34 +1,34 @@
(function (root, factory) {
define(["mock", "converse-api", "test_utils"], factory);
} (this, function (mock, converse_api, test_utils) {
} (this, function (mock, converse, test_utils) {
return describe("The Converse Event Emitter", function() {
return describe("The _converse Event Emitter", function() {
it("allows you to subscribe to emitted events", mock.initConverse(function (converse) {
it("allows you to subscribe to emitted events", mock.initConverse(function (_converse) {
this.callback = function () {};
spyOn(this, 'callback');
converse.on('connected', this.callback);
converse.emit('connected');
_converse.on('connected', this.callback);
_converse.emit('connected');
expect(this.callback).toHaveBeenCalled();
converse.emit('connected');
_converse.emit('connected');
expect(this.callback.callCount, 2);
converse.emit('connected');
_converse.emit('connected');
expect(this.callback.callCount, 3);
}));
it("allows you to listen once for an emitted event", mock.initConverse(function (converse) {
it("allows you to listen once for an emitted event", mock.initConverse(function (_converse) {
this.callback = function () {};
spyOn(this, 'callback');
converse.once('connected', this.callback);
converse.emit('connected');
_converse.once('connected', this.callback);
_converse.emit('connected');
expect(this.callback).toHaveBeenCalled();
converse.emit('connected');
_converse.emit('connected');
expect(this.callback.callCount, 1);
converse.emit('connected');
_converse.emit('connected');
expect(this.callback.callCount, 1);
}));
it("allows you to stop listening or subscribing to an event", mock.initConverse(function (converse) {
it("allows you to stop listening or subscribing to an event", mock.initConverse(function (_converse) {
this.callback = function () {};
this.anotherCallback = function () {};
this.neverCalled = function () {};
@ -36,23 +36,23 @@
spyOn(this, 'callback');
spyOn(this, 'anotherCallback');
spyOn(this, 'neverCalled');
converse.on('connected', this.callback);
converse.on('connected', this.anotherCallback);
_converse.on('connected', this.callback);
_converse.on('connected', this.anotherCallback);
converse.emit('connected');
_converse.emit('connected');
expect(this.callback).toHaveBeenCalled();
expect(this.anotherCallback).toHaveBeenCalled();
converse.off('connected', this.callback);
_converse.off('connected', this.callback);
converse.emit('connected');
_converse.emit('connected');
expect(this.callback.callCount, 1);
expect(this.anotherCallback.callCount, 2);
converse.once('connected', this.neverCalled);
converse.off('connected', this.neverCalled);
_converse.once('connected', this.neverCalled);
_converse.off('connected', this.neverCalled);
converse.emit('connected');
_converse.emit('connected');
expect(this.callback.callCount, 1);
expect(this.anotherCallback.callCount, 3);
expect(this.neverCalled).not.toHaveBeenCalled();

View File

@ -6,14 +6,14 @@
"mock",
"test_utils"
], factory);
} (this, function ($, converse_api, utils, mock, test_utils) {
} (this, function ($, converse, utils, mock, test_utils) {
"use strict";
var $msg = converse_api.env.$msg,
_ = converse_api.env._;
var $msg = converse.env.$msg,
_ = converse.env._;
describe("A headlines box", function () {
it("will not open nor display non-headline messages", mock.initConverse(function (converse) {
it("will not open nor display non-headline messages", mock.initConverse(function (_converse) {
/* XMPP spam message:
*
* <message xmlns="jabber:client"
@ -25,7 +25,7 @@
* </message
*/
test_utils.openControlBox();
test_utils.openContactsPanel(converse);
test_utils.openContactsPanel(_converse);
sinon.spy(utils, 'isHeadlineMessage');
runs(function () {
var stanza = $msg({
@ -36,7 +36,7 @@
})
.c('nick', {'xmlns': "http://jabber.org/protocol/nick"}).t("-wwdmz").up()
.c('body').t('SORRY FOR THIS ADVERT');
converse.connection._dataRecv(test_utils.createRequest(stanza));
_converse.connection._dataRecv(test_utils.createRequest(stanza));
});
waits(250);
runs(function () {
@ -47,7 +47,7 @@
}));
it("will open and display headline messages", mock.initConverse(function (converse) {
it("will open and display headline messages", mock.initConverse(function (_converse) {
/*
* <message from='notify.example.com'
* to='romeo@im.example.com'
@ -63,7 +63,7 @@
* </message>
*/
test_utils.openControlBox();
test_utils.openContactsPanel(converse);
test_utils.openContactsPanel(_converse);
sinon.spy(utils, 'isHeadlineMessage');
runs(function () {
var stanza = $msg({
@ -76,13 +76,13 @@
.c('body').t('&lt;juliet@example.com&gt; You got mail.').up()
.c('x', {'xmlns': 'jabber:x:oob'})
.c('url').t('imap://romeo@example.com/INBOX;UIDVALIDITY=385759043/;UID=18');
converse.connection._dataRecv(test_utils.createRequest(stanza));
_converse.connection._dataRecv(test_utils.createRequest(stanza));
});
waits(250);
runs(function () {
expect(
_.includes(
converse.chatboxviews.keys(),
_converse.chatboxviews.keys(),
'notify.example.com')
).toBeTruthy();
expect(utils.isHeadlineMessage.called).toBeTruthy();

View File

@ -1,13 +1,13 @@
(function (root, factory) {
define(["mock", "converse-api", "test_utils"], factory);
} (this, function (mock, converse_api, test_utils) {
} (this, function (mock, converse, test_utils) {
"use strict";
var _ = converse_api.env._;
var $ = converse_api.env.jQuery;
var Strophe = converse_api.env.Strophe;
var $iq = converse_api.env.$iq;
var $msg = converse_api.env.$msg;
var moment = converse_api.env.moment;
var _ = converse.env._;
var $ = converse.env.jQuery;
var Strophe = converse.env.Strophe;
var $iq = converse.env.$iq;
var $msg = converse.env.$msg;
var moment = converse.env.moment;
// See: https://xmpp.org/rfcs/rfc3921.html
describe("Message Archive Management", function () {
@ -15,33 +15,33 @@
describe("The archive.query API", function () {
it("can be used to query for all archived messages", mock.initConverse(function (converse) {
it("can be used to query for all archived messages", mock.initConverse(function (_converse) {
var sent_stanza, IQ_id;
var sendIQ = converse.connection.sendIQ;
spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
var sendIQ = _converse.connection.sendIQ;
spyOn(_converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
sent_stanza = iq;
IQ_id = sendIQ.bind(this)(iq, callback, errback);
});
if (!converse.features.findWhere({'var': Strophe.NS.MAM})) {
converse.features.create({'var': Strophe.NS.MAM});
if (!_converse.features.findWhere({'var': Strophe.NS.MAM})) {
_converse.features.create({'var': Strophe.NS.MAM});
}
converse.api.archive.query();
_converse.api.archive.query();
var queryid = $(sent_stanza.toString()).find('query').attr('queryid');
expect(sent_stanza.toString()).toBe(
"<iq type='set' xmlns='jabber:client' id='"+IQ_id+"'><query xmlns='urn:xmpp:mam:0' queryid='"+queryid+"'/></iq>");
}));
it("can be used to query for all messages to/from a particular JID", mock.initConverse(function (converse) {
it("can be used to query for all messages to/from a particular JID", mock.initConverse(function (_converse) {
var sent_stanza, IQ_id;
var sendIQ = converse.connection.sendIQ;
spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
var sendIQ = _converse.connection.sendIQ;
spyOn(_converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
sent_stanza = iq;
IQ_id = sendIQ.bind(this)(iq, callback, errback);
});
if (!converse.features.findWhere({'var': Strophe.NS.MAM})) {
converse.features.create({'var': Strophe.NS.MAM});
if (!_converse.features.findWhere({'var': Strophe.NS.MAM})) {
_converse.features.create({'var': Strophe.NS.MAM});
}
converse.api.archive.query({'with':'juliet@capulet.lit'});
_converse.api.archive.query({'with':'juliet@capulet.lit'});
var queryid = $(sent_stanza.toString()).find('query').attr('queryid');
expect(sent_stanza.toString()).toBe(
"<iq type='set' xmlns='jabber:client' id='"+IQ_id+"'>"+
@ -59,19 +59,19 @@
);
}));
it("can be used to query for all messages in a certain timespan", mock.initConverse(function (converse) {
it("can be used to query for all messages in a certain timespan", mock.initConverse(function (_converse) {
var sent_stanza, IQ_id;
var sendIQ = converse.connection.sendIQ;
spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
var sendIQ = _converse.connection.sendIQ;
spyOn(_converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
sent_stanza = iq;
IQ_id = sendIQ.bind(this)(iq, callback, errback);
});
if (!converse.features.findWhere({'var': Strophe.NS.MAM})) {
converse.features.create({'var': Strophe.NS.MAM});
if (!_converse.features.findWhere({'var': Strophe.NS.MAM})) {
_converse.features.create({'var': Strophe.NS.MAM});
}
var start = '2010-06-07T00:00:00Z';
var end = '2010-07-07T13:23:54Z';
converse.api.archive.query({
_converse.api.archive.query({
'start': start,
'end': end
@ -96,27 +96,27 @@
);
}));
it("throws a TypeError if an invalid date is provided", mock.initConverse(function (converse) {
if (!converse.features.findWhere({'var': Strophe.NS.MAM})) {
converse.features.create({'var': Strophe.NS.MAM});
it("throws a TypeError if an invalid date is provided", mock.initConverse(function (_converse) {
if (!_converse.features.findWhere({'var': Strophe.NS.MAM})) {
_converse.features.create({'var': Strophe.NS.MAM});
}
expect(_.partial(converse.api.archive.query, {'start': 'not a real date'})).toThrow(
expect(_.partial(_converse.api.archive.query, {'start': 'not a real date'})).toThrow(
new TypeError('archive.query: invalid date provided for: start')
);
}));
it("can be used to query for all messages after a certain time", mock.initConverse(function (converse) {
it("can be used to query for all messages after a certain time", mock.initConverse(function (_converse) {
var sent_stanza, IQ_id;
var sendIQ = converse.connection.sendIQ;
spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
var sendIQ = _converse.connection.sendIQ;
spyOn(_converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
sent_stanza = iq;
IQ_id = sendIQ.bind(this)(iq, callback, errback);
});
if (!converse.features.findWhere({'var': Strophe.NS.MAM})) {
converse.features.create({'var': Strophe.NS.MAM});
if (!_converse.features.findWhere({'var': Strophe.NS.MAM})) {
_converse.features.create({'var': Strophe.NS.MAM});
}
var start = '2010-06-07T00:00:00Z';
converse.api.archive.query({'start': start});
_converse.api.archive.query({'start': start});
var queryid = $(sent_stanza.toString()).find('query').attr('queryid');
expect(sent_stanza.toString()).toBe(
"<iq type='set' xmlns='jabber:client' id='"+IQ_id+"'>"+
@ -134,18 +134,18 @@
);
}));
it("can be used to query for a limited set of results", mock.initConverse(function (converse) {
it("can be used to query for a limited set of results", mock.initConverse(function (_converse) {
var sent_stanza, IQ_id;
var sendIQ = converse.connection.sendIQ;
spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
var sendIQ = _converse.connection.sendIQ;
spyOn(_converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
sent_stanza = iq;
IQ_id = sendIQ.bind(this)(iq, callback, errback);
});
if (!converse.features.findWhere({'var': Strophe.NS.MAM})) {
converse.features.create({'var': Strophe.NS.MAM});
if (!_converse.features.findWhere({'var': Strophe.NS.MAM})) {
_converse.features.create({'var': Strophe.NS.MAM});
}
var start = '2010-06-07T00:00:00Z';
converse.api.archive.query({'start': start, 'max':10});
_converse.api.archive.query({'start': start, 'max':10});
var queryid = $(sent_stanza.toString()).find('query').attr('queryid');
expect(sent_stanza.toString()).toBe(
"<iq type='set' xmlns='jabber:client' id='"+IQ_id+"'>"+
@ -166,18 +166,18 @@
);
}));
it("can be used to page through results", mock.initConverse(function (converse) {
it("can be used to page through results", mock.initConverse(function (_converse) {
var sent_stanza, IQ_id;
var sendIQ = converse.connection.sendIQ;
spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
var sendIQ = _converse.connection.sendIQ;
spyOn(_converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
sent_stanza = iq;
IQ_id = sendIQ.bind(this)(iq, callback, errback);
});
if (!converse.features.findWhere({'var': Strophe.NS.MAM})) {
converse.features.create({'var': Strophe.NS.MAM});
if (!_converse.features.findWhere({'var': Strophe.NS.MAM})) {
_converse.features.create({'var': Strophe.NS.MAM});
}
var start = '2010-06-07T00:00:00Z';
converse.api.archive.query({
_converse.api.archive.query({
'start': start,
'after': '09af3-cc343-b409f',
'max':10
@ -203,17 +203,17 @@
);
}));
it("accepts \"before\" with an empty string as value to reverse the order", mock.initConverse(function (converse) {
it("accepts \"before\" with an empty string as value to reverse the order", mock.initConverse(function (_converse) {
var sent_stanza, IQ_id;
var sendIQ = converse.connection.sendIQ;
spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
var sendIQ = _converse.connection.sendIQ;
spyOn(_converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
sent_stanza = iq;
IQ_id = sendIQ.bind(this)(iq, callback, errback);
});
if (!converse.features.findWhere({'var': Strophe.NS.MAM})) {
converse.features.create({'var': Strophe.NS.MAM});
if (!_converse.features.findWhere({'var': Strophe.NS.MAM})) {
_converse.features.create({'var': Strophe.NS.MAM});
}
converse.api.archive.query({'before': '', 'max':10});
_converse.api.archive.query({'before': '', 'max':10});
var queryid = $(sent_stanza.toString()).find('query').attr('queryid');
expect(sent_stanza.toString()).toBe(
"<iq type='set' xmlns='jabber:client' id='"+IQ_id+"'>"+
@ -232,24 +232,24 @@
);
}));
it("accepts a Strophe.RSM object for the query options", mock.initConverse(function (converse) {
it("accepts a Strophe.RSM object for the query options", mock.initConverse(function (_converse) {
// Normally the user wouldn't manually make a Strophe.RSM object
// and pass it in. However, in the callback method an RSM object is
// returned which can be reused for easy paging. This test is
// more for that usecase.
if (!converse.features.findWhere({'var': Strophe.NS.MAM})) {
converse.features.create({'var': Strophe.NS.MAM});
if (!_converse.features.findWhere({'var': Strophe.NS.MAM})) {
_converse.features.create({'var': Strophe.NS.MAM});
}
var sent_stanza, IQ_id;
var sendIQ = converse.connection.sendIQ;
spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
var sendIQ = _converse.connection.sendIQ;
spyOn(_converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
sent_stanza = iq;
IQ_id = sendIQ.bind(this)(iq, callback, errback);
});
var rsm = new Strophe.RSM({'max': '10'});
rsm['with'] = 'romeo@montague.lit';
rsm.start = '2010-06-07T00:00:00Z';
converse.api.archive.query(rsm);
_converse.api.archive.query(rsm);
var queryid = $(sent_stanza.toString()).find('query').attr('queryid');
expect(sent_stanza.toString()).toBe(
@ -274,24 +274,24 @@
);
}));
it("accepts a callback function, which it passes the messages and a Strophe.RSM object", mock.initConverse(function (converse) {
if (!converse.features.findWhere({'var': Strophe.NS.MAM})) {
converse.features.create({'var': Strophe.NS.MAM});
it("accepts a callback function, which it passes the messages and a Strophe.RSM object", mock.initConverse(function (_converse) {
if (!_converse.features.findWhere({'var': Strophe.NS.MAM})) {
_converse.features.create({'var': Strophe.NS.MAM});
}
var sent_stanza, IQ_id;
var sendIQ = converse.connection.sendIQ;
spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
var sendIQ = _converse.connection.sendIQ;
spyOn(_converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
sent_stanza = iq;
IQ_id = sendIQ.bind(this)(iq, callback, errback);
});
var callback = jasmine.createSpy('callback');
converse.api.archive.query({'with': 'romeo@capulet.lit', 'max':'10'}, callback);
_converse.api.archive.query({'with': 'romeo@capulet.lit', 'max':'10'}, callback);
var queryid = $(sent_stanza.toString()).find('query').attr('queryid');
// Send the result stanza, so that the callback is called.
var stanza = $iq({'type': 'result', 'id': IQ_id});
converse.connection._dataRecv(test_utils.createRequest(stanza));
_converse.connection._dataRecv(test_utils.createRequest(stanza));
/* <message id='aeb213' to='juliet@capulet.lit/chamber'>
* <result xmlns='urn:xmpp:mam:0' queryid='f27' id='28482-98726-73623'>
@ -318,7 +318,7 @@
'from':'romeo@montague.lit/orchard',
'type':'chat' })
.c('body').t("Call me but love, and I'll be new baptized;");
converse.connection._dataRecv(test_utils.createRequest(msg1));
_converse.connection._dataRecv(test_utils.createRequest(msg1));
var msg2 = $msg({'id':'aeb213', 'to':'juliet@capulet.lit/chamber'})
.c('result', {'xmlns': 'urn:xmpp:mam:0', 'queryid':queryid, 'id':'28482-98726-73624'})
@ -330,7 +330,7 @@
'from':'romeo@montague.lit/orchard',
'type':'chat' })
.c('body').t("Henceforth I never will be Romeo.");
converse.connection._dataRecv(test_utils.createRequest(msg2));
_converse.connection._dataRecv(test_utils.createRequest(msg2));
/* Send a <fin> message to indicate the end of the result set.
*
@ -349,7 +349,7 @@
.c('first', {'index': '0'}).t('23452-4534-1').up()
.c('last').t('390-2342-22').up()
.c('count').t('16');
converse.connection._dataRecv(test_utils.createRequest(stanza));
_converse.connection._dataRecv(test_utils.createRequest(stanza));
expect(callback).toHaveBeenCalled();
var args = callback.argsForCall[0];
@ -367,29 +367,29 @@
describe("The default preference", function () {
it("is set once server support for MAM has been confirmed", mock.initConverse(function (converse) {
it("is set once server support for MAM has been confirmed", mock.initConverse(function (_converse) {
var sent_stanza, IQ_id;
var sendIQ = converse.connection.sendIQ;
spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
var sendIQ = _converse.connection.sendIQ;
spyOn(_converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
sent_stanza = iq;
IQ_id = sendIQ.bind(this)(iq, callback, errback);
});
spyOn(converse, 'onMAMPreferences').andCallThrough();
spyOn(_converse, 'onMAMPreferences').andCallThrough();
var feature = new converse.Feature({
var feature = new _converse.Feature({
'var': Strophe.NS.MAM
});
spyOn(feature, 'save').andCallFake(feature.set); // Save will complain about a url not being set
converse.features.onFeatureAdded(feature);
_converse.features.onFeatureAdded(feature);
expect(converse.connection.sendIQ).toHaveBeenCalled();
expect(_converse.connection.sendIQ).toHaveBeenCalled();
expect(sent_stanza.toLocaleString()).toBe(
"<iq type='get' xmlns='jabber:client' id='"+IQ_id+"'>"+
"<prefs xmlns='urn:xmpp:mam:0'/>"+
"</iq>"
);
converse.message_archiving = 'never';
_converse.message_archiving = 'never';
/* Example 15. Server responds with current preferences
*
* <iq type='result' id='juliet2'>
@ -403,11 +403,11 @@
.c('prefs', {'xmlns': Strophe.NS.MAM, 'default':'roster'})
.c('always').c('jid').t('romeo@montague.lit').up().up()
.c('never').c('jid').t('montague@montague.lit');
converse.connection._dataRecv(test_utils.createRequest(stanza));
_converse.connection._dataRecv(test_utils.createRequest(stanza));
expect(converse.onMAMPreferences).toHaveBeenCalled();
expect(_converse.onMAMPreferences).toHaveBeenCalled();
expect(converse.connection.sendIQ.callCount).toBe(2);
expect(_converse.connection.sendIQ.callCount).toBe(2);
expect(sent_stanza.toString()).toBe(
"<iq type='set' xmlns='jabber:client' id='"+IQ_id+"'>"+
"<prefs xmlns='urn:xmpp:mam:0' default='never'>"+
@ -433,12 +433,12 @@
.c('prefs', {'xmlns': Strophe.NS.MAM, 'default':'always'})
.c('always').up()
.c('never').up();
converse.connection._dataRecv(test_utils.createRequest(stanza));
_converse.connection._dataRecv(test_utils.createRequest(stanza));
expect(feature.save).toHaveBeenCalled();
expect(feature.get('preferences')['default']).toBe('never');
// Restore
converse.message_archiving = 'never';
_converse.message_archiving = 'never';
}));
});
});

View File

@ -1,125 +1,125 @@
(function (root, factory) {
define(["mock", "converse-api", "test_utils"], factory);
} (this, function (mock, converse_api, test_utils) {
var _ = converse_api.env._;
var $msg = converse_api.env.$msg;
} (this, function (mock, converse, test_utils) {
var _ = converse.env._;
var $msg = converse.env.$msg;
describe("The Minimized Chats Widget", function () {
it("shows chats that have been minimized", mock.initConverse(function (converse) {
test_utils.createContacts(converse, 'current');
it("shows chats that have been minimized", mock.initConverse(function (_converse) {
test_utils.createContacts(_converse, 'current');
test_utils.openControlBox();
test_utils.openContactsPanel(converse);
converse.minimized_chats.toggleview.model.browserStorage._clear();
converse.minimized_chats.initToggle();
test_utils.openContactsPanel(_converse);
_converse.minimized_chats.toggleview.model.browserStorage._clear();
_converse.minimized_chats.initToggle();
var contact_jid, chatview;
contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
test_utils.openChatBoxFor(converse, contact_jid);
chatview = converse.chatboxviews.get(contact_jid);
test_utils.openChatBoxFor(_converse, contact_jid);
chatview = _converse.chatboxviews.get(contact_jid);
expect(chatview.model.get('minimized')).toBeFalsy();
expect(converse.minimized_chats.$el.is(':visible')).toBeFalsy();
expect(_converse.minimized_chats.$el.is(':visible')).toBeFalsy();
chatview.$el.find('.toggle-chatbox-button').click();
expect(chatview.model.get('minimized')).toBeTruthy();
expect(converse.minimized_chats.$el.is(':visible')).toBeTruthy();
expect(converse.minimized_chats.keys().length).toBe(1);
expect(converse.minimized_chats.keys()[0]).toBe(contact_jid);
expect(_converse.minimized_chats.$el.is(':visible')).toBeTruthy();
expect(_converse.minimized_chats.keys().length).toBe(1);
expect(_converse.minimized_chats.keys()[0]).toBe(contact_jid);
contact_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@localhost';
test_utils.openChatBoxFor(converse, contact_jid);
chatview = converse.chatboxviews.get(contact_jid);
test_utils.openChatBoxFor(_converse, contact_jid);
chatview = _converse.chatboxviews.get(contact_jid);
expect(chatview.model.get('minimized')).toBeFalsy();
chatview.$el.find('.toggle-chatbox-button').click();
expect(chatview.model.get('minimized')).toBeTruthy();
expect(converse.minimized_chats.$el.is(':visible')).toBeTruthy();
expect(converse.minimized_chats.keys().length).toBe(2);
expect(_.includes(converse.minimized_chats.keys(), contact_jid)).toBeTruthy();
expect(_converse.minimized_chats.$el.is(':visible')).toBeTruthy();
expect(_converse.minimized_chats.keys().length).toBe(2);
expect(_.includes(_converse.minimized_chats.keys(), contact_jid)).toBeTruthy();
}));
it("can be toggled to hide or show minimized chats", mock.initConverse(function (converse) {
test_utils.createContacts(converse, 'current');
it("can be toggled to hide or show minimized chats", mock.initConverse(function (_converse) {
test_utils.createContacts(_converse, 'current');
test_utils.openControlBox();
test_utils.openContactsPanel(converse);
converse.minimized_chats.toggleview.model.browserStorage._clear();
converse.minimized_chats.initToggle();
test_utils.openContactsPanel(_converse);
_converse.minimized_chats.toggleview.model.browserStorage._clear();
_converse.minimized_chats.initToggle();
var contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
test_utils.openChatBoxFor(converse, contact_jid);
var chatview = converse.chatboxviews.get(contact_jid);
expect(converse.minimized_chats.$el.is(':visible')).toBeFalsy();
test_utils.openChatBoxFor(_converse, contact_jid);
var chatview = _converse.chatboxviews.get(contact_jid);
expect(_converse.minimized_chats.$el.is(':visible')).toBeFalsy();
chatview.model.set({'minimized': true});
expect(converse.minimized_chats.$el.is(':visible')).toBeTruthy();
expect(converse.minimized_chats.keys().length).toBe(1);
expect(converse.minimized_chats.keys()[0]).toBe(contact_jid);
expect(converse.minimized_chats.$('.minimized-chats-flyout').is(':visible')).toBeTruthy();
expect(converse.minimized_chats.toggleview.model.get('collapsed')).toBeFalsy();
converse.minimized_chats.$('#toggle-minimized-chats').click();
expect(converse.minimized_chats.$('.minimized-chats-flyout').is(':visible')).toBeFalsy();
expect(converse.minimized_chats.toggleview.model.get('collapsed')).toBeTruthy();
expect(_converse.minimized_chats.$el.is(':visible')).toBeTruthy();
expect(_converse.minimized_chats.keys().length).toBe(1);
expect(_converse.minimized_chats.keys()[0]).toBe(contact_jid);
expect(_converse.minimized_chats.$('.minimized-chats-flyout').is(':visible')).toBeTruthy();
expect(_converse.minimized_chats.toggleview.model.get('collapsed')).toBeFalsy();
_converse.minimized_chats.$('#toggle-minimized-chats').click();
expect(_converse.minimized_chats.$('.minimized-chats-flyout').is(':visible')).toBeFalsy();
expect(_converse.minimized_chats.toggleview.model.get('collapsed')).toBeTruthy();
}));
it("shows the number messages received to minimized chats", mock.initConverse(function (converse) {
test_utils.createContacts(converse, 'current');
it("shows the number messages received to minimized chats", mock.initConverse(function (_converse) {
test_utils.createContacts(_converse, 'current');
test_utils.openControlBox();
test_utils.openContactsPanel(converse);
converse.minimized_chats.toggleview.model.browserStorage._clear();
converse.minimized_chats.initToggle();
test_utils.openContactsPanel(_converse);
_converse.minimized_chats.toggleview.model.browserStorage._clear();
_converse.minimized_chats.initToggle();
var i, contact_jid, chatview, msg;
converse.minimized_chats.toggleview.model.set({'collapsed': true});
expect(converse.minimized_chats.toggleview.$('.unread-message-count').is(':visible')).toBeFalsy();
_converse.minimized_chats.toggleview.model.set({'collapsed': true});
expect(_converse.minimized_chats.toggleview.$('.unread-message-count').is(':visible')).toBeFalsy();
for (i=0; i<3; i++) {
contact_jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
test_utils.openChatBoxFor(converse, contact_jid);
chatview = converse.chatboxviews.get(contact_jid);
test_utils.openChatBoxFor(_converse, contact_jid);
chatview = _converse.chatboxviews.get(contact_jid);
chatview.model.set({'minimized': true});
msg = $msg({
from: contact_jid,
to: converse.connection.jid,
to: _converse.connection.jid,
type: 'chat',
id: (new Date()).getTime()
}).c('body').t('This message is sent to a minimized chatbox').up()
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
converse.chatboxes.onMessage(msg);
expect(converse.minimized_chats.toggleview.$('.unread-message-count').is(':visible')).toBeTruthy();
expect(converse.minimized_chats.toggleview.$('.unread-message-count').text()).toBe((i+1).toString());
_converse.chatboxes.onMessage(msg);
expect(_converse.minimized_chats.toggleview.$('.unread-message-count').is(':visible')).toBeTruthy();
expect(_converse.minimized_chats.toggleview.$('.unread-message-count').text()).toBe((i+1).toString());
}
// Chat state notifications don't increment the unread messages counter
// <composing> state
converse.chatboxes.onMessage($msg({
_converse.chatboxes.onMessage($msg({
from: contact_jid,
to: converse.connection.jid,
to: _converse.connection.jid,
type: 'chat',
id: (new Date()).getTime()
}).c('composing', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree());
expect(converse.minimized_chats.toggleview.$('.unread-message-count').text()).toBe((i).toString());
expect(_converse.minimized_chats.toggleview.$('.unread-message-count').text()).toBe((i).toString());
// <paused> state
converse.chatboxes.onMessage($msg({
_converse.chatboxes.onMessage($msg({
from: contact_jid,
to: converse.connection.jid,
to: _converse.connection.jid,
type: 'chat',
id: (new Date()).getTime()
}).c('paused', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree());
expect(converse.minimized_chats.toggleview.$('.unread-message-count').text()).toBe((i).toString());
expect(_converse.minimized_chats.toggleview.$('.unread-message-count').text()).toBe((i).toString());
// <gone> state
converse.chatboxes.onMessage($msg({
_converse.chatboxes.onMessage($msg({
from: contact_jid,
to: converse.connection.jid,
to: _converse.connection.jid,
type: 'chat',
id: (new Date()).getTime()
}).c('gone', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree());
expect(converse.minimized_chats.toggleview.$('.unread-message-count').text()).toBe((i).toString());
expect(_converse.minimized_chats.toggleview.$('.unread-message-count').text()).toBe((i).toString());
// <inactive> state
converse.chatboxes.onMessage($msg({
_converse.chatboxes.onMessage($msg({
from: contact_jid,
to: converse.connection.jid,
to: _converse.connection.jid,
type: 'chat',
id: (new Date()).getTime()
}).c('inactive', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree());
expect(converse.minimized_chats.toggleview.$('.unread-message-count').text()).toBe((i).toString());
expect(_converse.minimized_chats.toggleview.$('.unread-message-count').text()).toBe((i).toString());
}));
});
}));

View File

@ -1,8 +1,8 @@
(function (root, factory) {
define(["mock", "converse-api", "test_utils"], factory);
} (this, function (mock, converse_api, test_utils) {
} (this, function (mock, converse, test_utils) {
"use strict";
var $msg = converse_api.env.$msg;
var $msg = converse.env.$msg;
describe("Notifications", function () {
// Implement the protocol defined in https://xmpp.org/extensions/xep-0313.html#config
@ -11,30 +11,30 @@
describe("And the desktop is not focused", function () {
describe("an HTML5 Notification", function () {
it("is shown when a new private message is received", mock.initConverse(function (converse) {
it("is shown when a new private message is received", mock.initConverse(function (_converse) {
// TODO: not yet testing show_desktop_notifications setting
test_utils.createContacts(converse, 'current');
spyOn(converse, 'showMessageNotification');
spyOn(converse, 'areDesktopNotificationsEnabled').andReturn(true);
test_utils.createContacts(_converse, 'current');
spyOn(_converse, 'showMessageNotification');
spyOn(_converse, 'areDesktopNotificationsEnabled').andReturn(true);
var message = 'This message will show a desktop notification';
var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost',
msg = $msg({
from: sender_jid,
to: converse.connection.jid,
to: _converse.connection.jid,
type: 'chat',
id: (new Date()).getTime()
}).c('body').t(message).up()
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
converse.chatboxes.onMessage(msg); // This will emit 'message'
expect(converse.areDesktopNotificationsEnabled).toHaveBeenCalled();
expect(converse.showMessageNotification).toHaveBeenCalled();
_converse.chatboxes.onMessage(msg); // This will emit 'message'
expect(_converse.areDesktopNotificationsEnabled).toHaveBeenCalled();
expect(_converse.showMessageNotification).toHaveBeenCalled();
}));
it("is shown when you are mentioned in a chat room", mock.initConverse(function (converse) {
test_utils.createContacts(converse, 'current');
test_utils.openAndEnterChatRoom(converse, 'lounge', 'localhost', 'dummy');
var view = converse.chatboxviews.get('lounge@localhost');
it("is shown when you are mentioned in a chat room", mock.initConverse(function (_converse) {
test_utils.createContacts(_converse, 'current');
test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy');
var view = _converse.chatboxviews.get('lounge@localhost');
if (!view.$el.find('.chat-area').length) { view.renderChatArea(); }
var no_notification = false;
if (typeof window.Notification === 'undefined') {
@ -45,8 +45,8 @@
};
};
}
spyOn(converse, 'showMessageNotification').andCallThrough();
spyOn(converse, 'areDesktopNotificationsEnabled').andReturn(true);
spyOn(_converse, 'showMessageNotification').andCallThrough();
spyOn(_converse, 'areDesktopNotificationsEnabled').andReturn(true);
var message = 'dummy: This message will show a desktop notification';
var nick = mock.chatroom_names[0],
@ -56,34 +56,34 @@
to: 'dummy@localhost',
type: 'groupchat'
}).c('body').t(message).tree();
converse.chatboxes.onMessage(msg); // This will emit 'message'
expect(converse.areDesktopNotificationsEnabled).toHaveBeenCalled();
expect(converse.showMessageNotification).toHaveBeenCalled();
_converse.chatboxes.onMessage(msg); // This will emit 'message'
expect(_converse.areDesktopNotificationsEnabled).toHaveBeenCalled();
expect(_converse.showMessageNotification).toHaveBeenCalled();
if (no_notification) {
delete window.Notification;
}
}));
it("is shown when a user changes their chat state", mock.initConverse(function (converse) {
it("is shown when a user changes their chat state", mock.initConverse(function (_converse) {
// TODO: not yet testing show_desktop_notifications setting
test_utils.createContacts(converse, 'current');
spyOn(converse, 'areDesktopNotificationsEnabled').andReturn(true);
spyOn(converse, 'showChatStateNotification');
test_utils.createContacts(_converse, 'current');
spyOn(_converse, 'areDesktopNotificationsEnabled').andReturn(true);
spyOn(_converse, 'showChatStateNotification');
var jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost';
converse.roster.get(jid).set('chat_status', 'busy'); // This will emit 'contactStatusChanged'
expect(converse.areDesktopNotificationsEnabled).toHaveBeenCalled();
expect(converse.showChatStateNotification).toHaveBeenCalled();
_converse.roster.get(jid).set('chat_status', 'busy'); // This will emit 'contactStatusChanged'
expect(_converse.areDesktopNotificationsEnabled).toHaveBeenCalled();
expect(_converse.showChatStateNotification).toHaveBeenCalled();
}));
});
});
describe("When a new contact request is received", function () {
it("an HTML5 Notification is received", mock.initConverse(function (converse) {
spyOn(converse, 'areDesktopNotificationsEnabled').andReturn(true);
spyOn(converse, 'showContactRequestNotification');
converse.emit('contactRequest', {'fullname': 'Peter Parker', 'jid': 'peter@parker.com'});
expect(converse.areDesktopNotificationsEnabled).toHaveBeenCalled();
expect(converse.showContactRequestNotification).toHaveBeenCalled();
it("an HTML5 Notification is received", mock.initConverse(function (_converse) {
spyOn(_converse, 'areDesktopNotificationsEnabled').andReturn(true);
spyOn(_converse, 'showContactRequestNotification');
_converse.emit('contactRequest', {'fullname': 'Peter Parker', 'jid': 'peter@parker.com'});
expect(_converse.areDesktopNotificationsEnabled).toHaveBeenCalled();
expect(_converse.showContactRequestNotification).toHaveBeenCalled();
}));
});
});
@ -91,12 +91,12 @@
describe("When play_sounds is set to true", function () {
describe("A notification sound", function () {
it("is played when the current user is mentioned in a chat room", mock.initConverse(function (converse) {
test_utils.createContacts(converse, 'current');
test_utils.openAndEnterChatRoom(converse, 'lounge', 'localhost', 'dummy');
converse.play_sounds = true;
spyOn(converse, 'playSoundNotification');
var view = converse.chatboxviews.get('lounge@localhost');
it("is played when the current user is mentioned in a chat room", mock.initConverse(function (_converse) {
test_utils.createContacts(_converse, 'current');
test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy');
_converse.play_sounds = true;
spyOn(_converse, 'playSoundNotification');
var view = _converse.chatboxviews.get('lounge@localhost');
if (!view.$el.find('.chat-area').length) { view.renderChatArea(); }
var text = 'This message will play a sound because it mentions dummy';
var message = $msg({
@ -106,7 +106,7 @@
type: 'groupchat'
}).c('body').t(text);
view.onChatRoomMessage(message.nodeTree);
expect(converse.playSoundNotification).toHaveBeenCalled();
expect(_converse.playSoundNotification).toHaveBeenCalled();
text = "This message won't play a sound";
message = $msg({
@ -116,8 +116,8 @@
type: 'groupchat'
}).c('body').t(text);
view.onChatRoomMessage(message.nodeTree);
expect(converse.playSoundNotification, 1);
converse.play_sounds = false;
expect(_converse.playSoundNotification, 1);
_converse.play_sounds = false;
text = "This message won't play a sound because it is sent by dummy";
message = $msg({
@ -127,8 +127,8 @@
type: 'groupchat'
}).c('body').t(text);
view.onChatRoomMessage(message.nodeTree);
expect(converse.playSoundNotification, 1);
converse.play_sounds = false;
expect(_converse.playSoundNotification, 1);
_converse.play_sounds = false;
}));
});
});

View File

@ -1,49 +1,49 @@
(function (root, factory) {
define(["mock", "converse-api", "test_utils"], factory);
} (this, function (mock, converse_api, test_utils) {
var $ = converse_api.env.jQuery;
var Strophe = converse_api.env.Strophe;
var b64_sha1 = converse_api.env.b64_sha1;
} (this, function (mock, converse, test_utils) {
var $ = converse.env.jQuery;
var Strophe = converse.env.Strophe;
var b64_sha1 = converse.env.b64_sha1;
return describe("The OTR module", function() {
it("can store a session passphrase in session storage", mock.initConverse(function (converse) {
it("can store a session passphrase in session storage", mock.initConverse(function (_converse) {
// With no prebind, the user's XMPP password is used and nothing is
// stored in session storage.
test_utils.openControlBox();
test_utils.openContactsPanel(converse);
test_utils.createContacts(converse, 'current');
test_utils.openContactsPanel(_converse);
test_utils.createContacts(_converse, 'current');
var auth = converse.authentication;
var pass = converse.connection.pass;
converse.authentication = "manual";
converse.connection.pass = 's3cr3t!';
expect(converse.otr.getSessionPassphrase()).toBe(converse.connection.pass);
var auth = _converse.authentication;
var pass = _converse.connection.pass;
_converse.authentication = "manual";
_converse.connection.pass = 's3cr3t!';
expect(_converse.otr.getSessionPassphrase()).toBe(_converse.connection.pass);
// With prebind, a random passphrase is generated and stored in
// session storage.
converse.authentication = "prebind";
var pp = converse.otr.getSessionPassphrase();
expect(pp).not.toBe(converse.connection.pass);
expect(pp).toBe(window.sessionStorage[b64_sha1(converse.connection.jid)]);
_converse.authentication = "prebind";
var pp = _converse.otr.getSessionPassphrase();
expect(pp).not.toBe(_converse.connection.pass);
expect(pp).toBe(window.sessionStorage[b64_sha1(_converse.connection.jid)]);
// Clean up
converse.authentication = auth;
converse.connection.pass = pass;
_converse.authentication = auth;
_converse.connection.pass = pass;
}));
it("will add processing hints to sent out encrypted <message> stanzas", mock.initConverse(function (converse) {
it("will add processing hints to sent out encrypted <message> stanzas", mock.initConverse(function (_converse) {
test_utils.openControlBox();
test_utils.openContactsPanel(converse);
test_utils.createContacts(converse, 'current');
test_utils.openContactsPanel(_converse);
test_utils.createContacts(_converse, 'current');
var UNVERIFIED = 1, UNENCRYPTED = 0;
var contact_name = mock.cur_names[0];
var contact_jid = contact_name.replace(/ /g,'.').toLowerCase() + '@localhost';
test_utils.openChatBoxFor(converse, contact_jid);
var chatview = converse.chatboxviews.get(contact_jid);
test_utils.openChatBoxFor(_converse, contact_jid);
var chatview = _converse.chatboxviews.get(contact_jid);
chatview.model.set('otr_status', UNVERIFIED);
var stanza = chatview.createMessageStanza(new converse.Message({ message: 'hello world'}));
var stanza = chatview.createMessageStanza(new _converse.Message({ message: 'hello world'}));
var $hints = $(stanza.nodeTree).find('[xmlns="'+Strophe.NS.HINTS+'"]');
expect($hints.length).toBe(3);
expect($hints.get(0).tagName).toBe('no-store');
@ -54,19 +54,19 @@
describe("An OTR Chat Message", function () {
it("will not be carbon copied when it's sent out", mock.initConverse(function (converse) {
it("will not be carbon copied when it's sent out", mock.initConverse(function (_converse) {
test_utils.openControlBox();
test_utils.openContactsPanel(converse);
test_utils.createContacts(converse, 'current');
test_utils.openContactsPanel(_converse);
test_utils.createContacts(_converse, 'current');
var msgtext = "?OTR,1,3,?OTR:AAIDAAAAAAEAAAABAAAAwCQ8HKsag0y0DGKsneo0kzKu1ua5L93M4UKTkCf1I2kbm2RgS5kIxDTxrTj3wVRB+H5Si86E1fKtuBgsDf/bKkGTM0h/49vh5lOD9HkE8cnSrFEn5GN,";
var sender_jid = mock.cur_names[3].replace(/ /g,'.').toLowerCase() + '@localhost';
converse.api.chats.open(sender_jid);
var chatbox = converse.chatboxes.get(sender_jid);
spyOn(converse.connection, 'send');
_converse.api.chats.open(sender_jid);
var chatbox = _converse.chatboxes.get(sender_jid);
spyOn(_converse.connection, 'send');
chatbox.set('otr_status', 1); // Set OTR status to UNVERIFIED, to mock an encrypted session
chatbox.trigger('sendMessage', new converse.Message({ message: msgtext }));
var $sent = $(converse.connection.send.argsForCall[0][0].tree());
chatbox.trigger('sendMessage', new _converse.Message({ message: msgtext }));
var $sent = $(_converse.connection.send.argsForCall[0][0].tree());
expect($sent.find('body').siblings('private').length).toBe(1);
expect($sent.find('private').length).toBe(1);
expect($sent.find('private').attr('xmlns')).toBe('urn:xmpp:carbons:2');

View File

@ -6,33 +6,33 @@
describe("XMPP Ping", function () {
describe("Ping and pong handlers", function () {
it("are registered when converse.js is connected", mock.initConverse(function (converse) {
spyOn(converse, 'registerPingHandler').andCallThrough();
spyOn(converse, 'registerPongHandler').andCallThrough();
converse.emit('connected');
expect(converse.registerPingHandler).toHaveBeenCalled();
expect(converse.registerPongHandler).toHaveBeenCalled();
it("are registered when _converse.js is connected", mock.initConverse(function (_converse) {
spyOn(_converse, 'registerPingHandler').andCallThrough();
spyOn(_converse, 'registerPongHandler').andCallThrough();
_converse.emit('connected');
expect(_converse.registerPingHandler).toHaveBeenCalled();
expect(_converse.registerPongHandler).toHaveBeenCalled();
}));
it("are registered when converse.js reconnected", mock.initConverse(function (converse) {
spyOn(converse, 'registerPingHandler').andCallThrough();
spyOn(converse, 'registerPongHandler').andCallThrough();
converse.emit('reconnected');
expect(converse.registerPingHandler).toHaveBeenCalled();
expect(converse.registerPongHandler).toHaveBeenCalled();
it("are registered when _converse.js reconnected", mock.initConverse(function (_converse) {
spyOn(_converse, 'registerPingHandler').andCallThrough();
spyOn(_converse, 'registerPongHandler').andCallThrough();
_converse.emit('reconnected');
expect(_converse.registerPingHandler).toHaveBeenCalled();
expect(_converse.registerPongHandler).toHaveBeenCalled();
}));
});
describe("An IQ stanza", function () {
it("is sent out when converse.js pings a server", mock.initConverse(function (converse) {
it("is sent out when _converse.js pings a server", mock.initConverse(function (_converse) {
var sent_stanza, IQ_id;
var sendIQ = converse.connection.sendIQ;
spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
var sendIQ = _converse.connection.sendIQ;
spyOn(_converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
sent_stanza = iq;
IQ_id = sendIQ.bind(this)(iq, callback, errback);
});
converse.ping();
_converse.ping();
expect(sent_stanza.toLocaleString()).toBe(
"<iq type='get' to='localhost' id='"+IQ_id+"' xmlns='jabber:client'>"+
"<ping xmlns='urn:xmpp:ping'/>"+

View File

@ -1,17 +1,17 @@
(function (root, factory) {
define(["mock", "converse-api", "test_utils"], factory);
} (this, function (mock, converse_api, test_utils) {
var _ = converse_api.env._;
var $iq = converse_api.env.$iq;
} (this, function (mock, converse, test_utils) {
var _ = converse.env._;
var $iq = converse.env.$iq;
describe("Profiling", function() {
afterEach(function () {
converse_api.user.logout();
converse.user.logout();
test_utils.clearBrowserStorage();
});
xit("adds hundreds of contacts to the roster", mock.initConverse(function(converse) {
converse.roster_groups = false;
xit("adds hundreds of contacts to the roster", mock.initConverse(function(_converse) {
_converse.roster_groups = false;
expect(this.roster.pluck('jid').length).toBe(0);
var stanza = $iq({
to: this.connection.jid,
@ -33,9 +33,9 @@
// expect(this.roster.pluck('jid').length).toBe(400);
}));
xit("adds hundreds of contacts to the roster, with roster groups", mock.initConverse(function(converse) {
// converse.show_only_online_users = true;
converse.roster_groups = true;
xit("adds hundreds of contacts to the roster, with roster groups", mock.initConverse(function(_converse) {
// _converse.show_only_online_users = true;
_converse.roster_groups = true;
expect(this.roster.pluck('jid').length).toBe(0);
var stanza = $iq({
to: this.connection.jid,

View File

@ -4,11 +4,11 @@
"converse-api",
"mock",
"test_utils"], factory);
} (this, function ($, converse_api, mock, test_utils) {
} (this, function ($, converse, mock, test_utils) {
"use strict";
var Strophe = converse_api.env.Strophe;
var $iq = converse_api.env.$iq;
var $pres = converse_api.env.$pres;
var Strophe = converse.env.Strophe;
var $iq = converse.env.$iq;
var $pres = converse.env.$pres;
// See:
// https://xmpp.org/rfcs/rfc3921.html
@ -46,24 +46,24 @@
* that session. A client MUST acknowledge each roster push with an IQ
* stanza of type "result".
*/
it("Subscribe to contact, contact accepts and subscribes back", mock.initConverse(function (converse) {
it("Subscribe to contact, contact accepts and subscribes back", mock.initConverse(function (_converse) {
/* The process by which a user subscribes to a contact, including
* the interaction between roster items and subscription states.
*/
var contact, stanza, sent_stanza, IQ_id;
runs(function () {
test_utils.openControlBox(converse);
test_utils.openControlBox(_converse);
});
waits(100);
runs(function () {
var panel = converse.chatboxviews.get('controlbox').contactspanel;
var panel = _converse.chatboxviews.get('controlbox').contactspanel;
spyOn(panel, "addContactFromForm").andCallThrough();
spyOn(converse.roster, "addAndSubscribe").andCallThrough();
spyOn(converse.roster, "addContact").andCallThrough();
spyOn(converse.roster, "sendContactAddIQ").andCallThrough();
spyOn(converse, "getVCard").andCallThrough();
var sendIQ = converse.connection.sendIQ;
spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
spyOn(_converse.roster, "addAndSubscribe").andCallThrough();
spyOn(_converse.roster, "addContact").andCallThrough();
spyOn(_converse.roster, "sendContactAddIQ").andCallThrough();
spyOn(_converse, "getVCard").andCallThrough();
var sendIQ = _converse.connection.sendIQ;
spyOn(_converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
sent_stanza = iq;
IQ_id = sendIQ.bind(this)(iq, callback, errback);
});
@ -86,12 +86,12 @@
* for the new roster item.
*/
expect(panel.addContactFromForm).toHaveBeenCalled();
expect(converse.roster.addAndSubscribe).toHaveBeenCalled();
expect(converse.roster.addContact).toHaveBeenCalled();
expect(_converse.roster.addAndSubscribe).toHaveBeenCalled();
expect(_converse.roster.addContact).toHaveBeenCalled();
// The form should not be visible anymore.
expect($form.is(":visible")).toBeFalsy();
/* converse request consists of sending an IQ
/* _converse request consists of sending an IQ
* stanza of type='set' containing a <query/> element qualified by
* the 'jabber:iq:roster' namespace, which in turn contains an
* <item/> element that defines the new roster item; the <item/>
@ -109,7 +109,7 @@
* </query>
* </iq>
*/
expect(converse.roster.sendContactAddIQ).toHaveBeenCalled();
expect(_converse.roster.sendContactAddIQ).toHaveBeenCalled();
expect(sent_stanza.toLocaleString()).toBe(
"<iq type='set' xmlns='jabber:client' id='"+IQ_id+"'>"+
"<query xmlns='jabber:iq:roster'>"+
@ -119,7 +119,7 @@
);
/* As a result, the user's server (1) MUST initiate a roster push
* for the new roster item to all available resources associated
* with converse user that have requested the roster, setting the
* with _converse user that have requested the roster, setting the
* 'subscription' attribute to a value of "none"; and (2) MUST
* reply to the sending resource with an IQ result indicating the
* success of the roster set:
@ -135,12 +135,12 @@
* </query>
* </iq>
*/
var create = converse.roster.create;
spyOn(converse.connection, 'send').andCallFake(function (stanza) {
var create = _converse.roster.create;
spyOn(_converse.connection, 'send').andCallFake(function (stanza) {
sent_stanza = stanza;
});
spyOn(converse.roster, 'create').andCallFake(function () {
contact = create.apply(converse.roster, arguments);
spyOn(_converse.roster, 'create').andCallFake(function () {
contact = create.apply(_converse.roster, arguments);
spyOn(contact, 'subscribe').andCallThrough();
return contact;
});
@ -149,17 +149,17 @@
'jid': 'contact@example.org',
'subscription': 'none',
'name': 'contact@example.org'});
converse.connection._dataRecv(test_utils.createRequest(stanza));
_converse.connection._dataRecv(test_utils.createRequest(stanza));
/*
* <iq type='result' id='set1'/>
*/
stanza = $iq({'type': 'result', 'id':IQ_id});
converse.connection._dataRecv(test_utils.createRequest(stanza));
_converse.connection._dataRecv(test_utils.createRequest(stanza));
// A contact should now have been created
expect(converse.roster.get('contact@example.org') instanceof converse.RosterContact).toBeTruthy();
expect(_converse.roster.get('contact@example.org') instanceof _converse.RosterContact).toBeTruthy();
expect(contact.get('jid')).toBe('contact@example.org');
expect(converse.getVCard).toHaveBeenCalled();
expect(_converse.getVCard).toHaveBeenCalled();
/* To subscribe to the contact's presence information,
* the user's client MUST send a presence stanza of
@ -176,7 +176,7 @@
/* As a result, the user's server MUST initiate a second roster
* push to all of the user's available resources that have
* requested the roster, setting the contact to the pending
* sub-state of the 'none' subscription state; converse pending
* sub-state of the 'none' subscription state; _converse pending
* sub-state is denoted by the inclusion of the ask='subscribe'
* attribute in the roster item:
*
@ -192,7 +192,7 @@
* </query>
* </iq>
*/
spyOn(converse.roster, "updateContact").andCallThrough();
spyOn(_converse.roster, "updateContact").andCallThrough();
stanza = $iq({'type': 'set', 'from': 'dummy@localhost'})
.c('query', {'xmlns': 'jabber:iq:roster'})
.c('item', {
@ -200,8 +200,8 @@
'subscription': 'none',
'ask': 'subscribe',
'name': 'contact@example.org'});
converse.connection._dataRecv(test_utils.createRequest(stanza));
expect(converse.roster.updateContact).toHaveBeenCalled();
_converse.connection._dataRecv(test_utils.createRequest(stanza));
expect(_converse.roster.updateContact).toHaveBeenCalled();
});
waits(50);
runs(function () {
@ -223,12 +223,12 @@
* type='subscribed'/>
*/
stanza = $pres({
'to': converse.bare_jid,
'to': _converse.bare_jid,
'from': 'contact@example.org',
'type': 'subscribed'
});
sent_stanza = ""; // Reset
converse.connection._dataRecv(test_utils.createRequest(stanza));
_converse.connection._dataRecv(test_utils.createRequest(stanza));
/* Upon receiving the presence stanza of type "subscribed",
* the user SHOULD acknowledge receipt of that
* subscription state notification by sending a presence
@ -255,19 +255,19 @@
* </query>
* </iq>
*/
IQ_id = converse.connection.getUniqueId('roster');
IQ_id = _converse.connection.getUniqueId('roster');
stanza = $iq({'type': 'set', 'id': IQ_id})
.c('query', {'xmlns': 'jabber:iq:roster'})
.c('item', {
'jid': 'contact@example.org',
'subscription': 'to',
'name': 'contact@example.org'});
converse.connection._dataRecv(test_utils.createRequest(stanza));
_converse.connection._dataRecv(test_utils.createRequest(stanza));
// Check that the IQ set was acknowledged.
expect(sent_stanza.toLocaleString()).toBe( // Strophe adds the xmlns attr (although not in spec)
"<iq type='result' id='"+IQ_id+"' from='dummy@localhost/resource' xmlns='jabber:client'/>"
);
expect(converse.roster.updateContact).toHaveBeenCalled();
expect(_converse.roster.updateContact).toHaveBeenCalled();
// The contact should now be visible as an existing
// contact (but still offline).
@ -287,8 +287,8 @@
* from='contact@example.org/resource'
* to='user@example.com/resource'/>
*/
stanza = $pres({'to': converse.bare_jid, 'from': 'contact@example.org/resource'});
converse.connection._dataRecv(test_utils.createRequest(stanza));
stanza = $pres({'to': _converse.bare_jid, 'from': 'contact@example.org/resource'});
_converse.connection._dataRecv(test_utils.createRequest(stanza));
// Now the contact should also be online.
expect(contact.get('chat_status')).toBe('online');
@ -301,13 +301,13 @@
* <presence from='contact@example.org' to='user@example.com' type='subscribe'/>
*/
spyOn(contact, 'authorize').andCallThrough();
spyOn(converse.roster, 'handleIncomingSubscription').andCallThrough();
spyOn(_converse.roster, 'handleIncomingSubscription').andCallThrough();
stanza = $pres({
'to': converse.bare_jid,
'to': _converse.bare_jid,
'from': 'contact@example.org/resource',
'type': 'subscribe'});
converse.connection._dataRecv(test_utils.createRequest(stanza));
expect(converse.roster.handleIncomingSubscription).toHaveBeenCalled();
_converse.connection._dataRecv(test_utils.createRequest(stanza));
expect(_converse.roster.handleIncomingSubscription).toHaveBeenCalled();
/* The user's client MUST send a presence stanza of type
* "subscribed" to the contact in order to approve the
@ -341,8 +341,8 @@
'jid': 'contact@example.org',
'subscription': 'both',
'name': 'contact@example.org'});
converse.connection._dataRecv(test_utils.createRequest(stanza));
expect(converse.roster.updateContact).toHaveBeenCalled();
_converse.connection._dataRecv(test_utils.createRequest(stanza));
expect(_converse.roster.updateContact).toHaveBeenCalled();
// The class on the contact will now have switched.
expect($contacts.hasClass('to')).toBeFalsy();
@ -350,13 +350,13 @@
});
}));
it("Alternate Flow: Contact Declines Subscription Request", mock.initConverse(function (converse) {
it("Alternate Flow: Contact Declines Subscription Request", mock.initConverse(function (_converse) {
/* The process by which a user subscribes to a contact, including
* the interaction between roster items and subscription states.
*/
var contact, stanza, sent_stanza, sent_IQ;
runs(function () {
test_utils.openControlBox(converse);
test_utils.openControlBox(_converse);
});
waits(100);
runs(function () {
@ -367,19 +367,19 @@
'subscription': 'none',
'ask': 'subscribe',
'name': 'contact@example.org'});
converse.connection._dataRecv(test_utils.createRequest(stanza));
_converse.connection._dataRecv(test_utils.createRequest(stanza));
});
waits(50);
runs(function () {
// A pending contact should now exist.
contact = converse.roster.get('contact@example.org');
expect(converse.roster.get('contact@example.org') instanceof converse.RosterContact).toBeTruthy();
contact = _converse.roster.get('contact@example.org');
expect(_converse.roster.get('contact@example.org') instanceof _converse.RosterContact).toBeTruthy();
spyOn(contact, "ackUnsubscribe").andCallThrough();
spyOn(converse.connection, 'send').andCallFake(function (stanza) {
spyOn(_converse.connection, 'send').andCallFake(function (stanza) {
sent_stanza = stanza;
});
spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
spyOn(_converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
sent_IQ = iq;
});
/* We now assume the contact declines the subscription
@ -411,11 +411,11 @@
*/
// FIXME: also add the <iq>
stanza = $pres({
'to': converse.bare_jid,
'to': _converse.bare_jid,
'from': 'contact@example.org',
'type': 'unsubscribed'
});
converse.connection._dataRecv(test_utils.createRequest(stanza));
_converse.connection._dataRecv(test_utils.createRequest(stanza));
/* Upon receiving the presence stanza of type "unsubscribed",
* the user SHOULD acknowledge receipt of that subscription
@ -427,7 +427,7 @@
"<presence type='unsubscribe' to='contact@example.org' xmlns='jabber:client'/>"
);
/* Converse.js will then also automatically remove the
/* _converse.js will then also automatically remove the
* contact from the user's roster.
*/
expect(sent_IQ.toLocaleString()).toBe(
@ -440,20 +440,20 @@
});
}));
it("Unsubscribe to a contact when subscription is mutual", mock.initConverse(function (converse) {
it("Unsubscribe to a contact when subscription is mutual", mock.initConverse(function (_converse) {
var sent_IQ, IQ_id, jid = 'annegreet.gomez@localhost';
runs(function () {
test_utils.openControlBox(converse);
test_utils.createContacts(converse, 'current');
test_utils.openControlBox(_converse);
test_utils.createContacts(_converse, 'current');
});
waits(50);
runs(function () {
spyOn(window, 'confirm').andReturn(true);
// We now have a contact we want to remove
expect(converse.roster.get(jid) instanceof converse.RosterContact).toBeTruthy();
expect(_converse.roster.get(jid) instanceof _converse.RosterContact).toBeTruthy();
var sendIQ = converse.connection.sendIQ;
spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
var sendIQ = _converse.connection.sendIQ;
spyOn(_converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
sent_IQ = iq;
IQ_id = sendIQ.bind(this)(iq, callback, errback);
});
@ -492,34 +492,34 @@
// Receive confirmation from the contact's server
// <iq type='result' id='remove1'/>
var stanza = $iq({'type': 'result', 'id':IQ_id});
converse.connection._dataRecv(test_utils.createRequest(stanza));
_converse.connection._dataRecv(test_utils.createRequest(stanza));
// Our contact has now been removed
expect(typeof converse.roster.get(jid) === "undefined").toBeTruthy();
expect(typeof _converse.roster.get(jid) === "undefined").toBeTruthy();
});
}));
it("Receiving a subscription request", mock.initConverse(function (converse) {
it("Receiving a subscription request", mock.initConverse(function (_converse) {
runs(function () {
test_utils.openControlBox(converse);
test_utils.createContacts(converse, 'current'); // Create some contacts so that we can test positioning
test_utils.openControlBox(_converse);
test_utils.createContacts(_converse, 'current'); // Create some contacts so that we can test positioning
});
waits(50);
runs(function () {
spyOn(converse, "emit");
spyOn(_converse, "emit");
/* <presence
* from='user@example.com'
* to='contact@example.org'
* type='subscribe'/>
*/
var stanza = $pres({
'to': converse.bare_jid,
'to': _converse.bare_jid,
'from': 'contact@example.org',
'type': 'subscribe'
}).c('nick', {
'xmlns': Strophe.NS.NICK,
}).t('Clint Contact');
converse.connection._dataRecv(test_utils.createRequest(stanza));
expect(converse.emit).toHaveBeenCalledWith('contactRequest', jasmine.any(Object));
_converse.connection._dataRecv(test_utils.createRequest(stanza));
expect(_converse.emit).toHaveBeenCalledWith('contactRequest', jasmine.any(Object));
var $header = $('a:contains("Contact requests")');
expect($header.length).toBe(1);
expect($header.is(":visible")).toBeTruthy();

View File

@ -1,17 +1,17 @@
(function (root, factory) {
define(["mock", "converse-api", "test_utils"], factory);
} (this, function (mock, converse_api, test_utils) {
var $ = converse_api.env.jQuery;
var Strophe = converse_api.env.Strophe;
var $iq = converse_api.env.$iq;
} (this, function (mock, converse, test_utils) {
var $ = converse.env.jQuery;
var Strophe = converse.env.Strophe;
var $iq = converse.env.$iq;
describe("The Registration Panel", function () {
it("is not available unless allow_registration=true", mock.initConverse(function (converse) {
it("is not available unless allow_registration=true", mock.initConverse(function (_converse) {
runs(test_utils.openControlBox);
waits(50);
runs(function () {
var cbview = converse.chatboxviews.get('controlbox');
var cbview = _converse.chatboxviews.get('controlbox');
expect(cbview.$('#controlbox-tabs li').length).toBe(1);
expect(cbview.$('#controlbox-tabs li').text().trim()).toBe("Sign in");
});
@ -19,8 +19,8 @@
allow_registration: false,
}));
it("can be opened by clicking on the registration tab", mock.initConverse(function (converse) {
var cbview = converse.chatboxviews.get('controlbox');
it("can be opened by clicking on the registration tab", mock.initConverse(function (_converse) {
var cbview = _converse.chatboxviews.get('controlbox');
runs(test_utils.openControlBox);
waits(50);
runs(function () {
@ -42,12 +42,12 @@
allow_registration: true,
}));
it("allows the user to choose an XMPP provider's domain", mock.initConverse(function (converse) {
var cbview = converse.chatboxviews.get('controlbox');
it("allows the user to choose an XMPP provider's domain", mock.initConverse(function (_converse) {
var cbview = _converse.chatboxviews.get('controlbox');
var registerview = cbview.registerpanel;
spyOn(registerview, 'onProviderChosen').andCallThrough();
registerview.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
spyOn(converse.connection, 'connect');
spyOn(_converse.connection, 'connect');
var $tabs = cbview.$('#controlbox-tabs');
$tabs.find('li').last().find('a').click(); // Click the Register tab
// Check the form layout
@ -63,29 +63,29 @@
$form.find('input[name=domain]').val('conversejs.org');
$form.find('input[type=submit]').click();
expect(registerview.onProviderChosen).toHaveBeenCalled();
expect(converse.connection.connect).toHaveBeenCalled();
expect(_converse.connection.connect).toHaveBeenCalled();
}, { auto_login: false,
allow_registration: true,
}));
it("will render a registration form as received from the XMPP provider", mock.initConverse(function (converse) {
var cbview = converse.chatboxviews.get('controlbox');
it("will render a registration form as received from the XMPP provider", mock.initConverse(function (_converse) {
var cbview = _converse.chatboxviews.get('controlbox');
cbview.$('#controlbox-tabs').find('li').last().find('a').click(); // Click the Register tab
var registerview = converse.chatboxviews.get('controlbox').registerpanel;
var registerview = _converse.chatboxviews.get('controlbox').registerpanel;
spyOn(registerview, 'onProviderChosen').andCallThrough();
spyOn(registerview, 'getRegistrationFields').andCallThrough();
spyOn(registerview, 'onRegistrationFields').andCallThrough();
spyOn(registerview, 'renderRegistrationForm').andCallThrough();
registerview.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
spyOn(converse.connection, 'connect').andCallThrough();
spyOn(_converse.connection, 'connect').andCallThrough();
expect(registerview._registering).toBeFalsy();
expect(converse.connection.connected).toBeFalsy();
expect(_converse.connection.connected).toBeFalsy();
registerview.$('input[name=domain]').val('conversejs.org');
registerview.$('input[type=submit]').click();
expect(registerview.onProviderChosen).toHaveBeenCalled();
expect(registerview._registering).toBeTruthy();
expect(converse.connection.connect).toHaveBeenCalled();
expect(_converse.connection.connect).toHaveBeenCalled();
var stanza = new Strophe.Builder("stream:features", {
'xmlns:stream': "http://etherx.jabber.org/streams",
@ -93,10 +93,10 @@
})
.c('register', {xmlns: "http://jabber.org/features/iq-register"}).up()
.c('mechanisms', {xmlns: "urn:ietf:params:xml:ns:xmpp-sasl"});
converse.connection._connect_cb(test_utils.createRequest(stanza));
_converse.connection._connect_cb(test_utils.createRequest(stanza));
expect(registerview.getRegistrationFields).toHaveBeenCalled();
expect(converse.connection.connected).toBeTruthy();
expect(_converse.connection.connected).toBeTruthy();
stanza = $iq({
'type': 'result',
@ -107,7 +107,7 @@
.c('username').up()
.c('password').up()
.c('email');
converse.connection._dataRecv(test_utils.createRequest(stanza));
_converse.connection._dataRecv(test_utils.createRequest(stanza));
expect(registerview.onRegistrationFields).toHaveBeenCalled();
expect(registerview.renderRegistrationForm).toHaveBeenCalled();
expect(registerview.$('input').length).toBe(5);
@ -117,16 +117,16 @@
allow_registration: true,
}));
it("will set form_type to legacy and submit it as legacy", mock.initConverse(function (converse) {
var cbview = converse.chatboxviews.get('controlbox');
it("will set form_type to legacy and submit it as legacy", mock.initConverse(function (_converse) {
var cbview = _converse.chatboxviews.get('controlbox');
cbview.$('#controlbox-tabs').find('li').last().find('a').click(); // Click the Register tab
var registerview = converse.chatboxviews.get('controlbox').registerpanel;
var registerview = _converse.chatboxviews.get('controlbox').registerpanel;
spyOn(registerview, 'onProviderChosen').andCallThrough();
spyOn(registerview, 'getRegistrationFields').andCallThrough();
spyOn(registerview, 'onRegistrationFields').andCallThrough();
spyOn(registerview, 'renderRegistrationForm').andCallThrough();
registerview.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
spyOn(converse.connection, 'connect').andCallThrough();
spyOn(_converse.connection, 'connect').andCallThrough();
registerview.$('input[name=domain]').val('conversejs.org');
registerview.$('input[type=submit]').click();
@ -137,7 +137,7 @@
})
.c('register', {xmlns: "http://jabber.org/features/iq-register"}).up()
.c('mechanisms', {xmlns: "urn:ietf:params:xml:ns:xmpp-sasl"});
converse.connection._connect_cb(test_utils.createRequest(stanza));
_converse.connection._connect_cb(test_utils.createRequest(stanza));
stanza = $iq({
'type': 'result',
'id': 'reg1'
@ -147,35 +147,35 @@
.c('username').up()
.c('password').up()
.c('email');
converse.connection._dataRecv(test_utils.createRequest(stanza));
_converse.connection._dataRecv(test_utils.createRequest(stanza));
expect(registerview.form_type).toBe('legacy');
registerview.$('input[name=username]').val('testusername');
registerview.$('input[name=password]').val('testpassword');
registerview.$('input[name=email]').val('test@email.local');
spyOn(converse.connection, 'send');
spyOn(_converse.connection, 'send');
registerview.$('input[type=submit]').click();
expect(converse.connection.send).toHaveBeenCalled();
var $stanza = $(converse.connection.send.argsForCall[0][0].tree());
expect(_converse.connection.send).toHaveBeenCalled();
var $stanza = $(_converse.connection.send.argsForCall[0][0].tree());
expect($stanza.children('query').children().length).toBe(3);
expect($stanza.children('query').children()[0].tagName).toBe('username');
}, { auto_login: false,
allow_registration: true,
}));
it("will set form_type to xform and submit it as xform", mock.initConverse(function (converse) {
var cbview = converse.chatboxviews.get('controlbox');
it("will set form_type to xform and submit it as xform", mock.initConverse(function (_converse) {
var cbview = _converse.chatboxviews.get('controlbox');
cbview.$('#controlbox-tabs').find('li').last().find('a').click(); // Click the Register tab
var registerview = converse.chatboxviews.get('controlbox').registerpanel;
var registerview = _converse.chatboxviews.get('controlbox').registerpanel;
spyOn(registerview, 'onProviderChosen').andCallThrough();
spyOn(registerview, 'getRegistrationFields').andCallThrough();
spyOn(registerview, 'onRegistrationFields').andCallThrough();
spyOn(registerview, 'renderRegistrationForm').andCallThrough();
registerview.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
spyOn(converse.connection, 'connect').andCallThrough();
spyOn(_converse.connection, 'connect').andCallThrough();
registerview.$('input[name=domain]').val('conversejs.org');
registerview.$('input[type=submit]').click();
@ -186,7 +186,7 @@
})
.c('register', {xmlns: "http://jabber.org/features/iq-register"}).up()
.c('mechanisms', {xmlns: "urn:ietf:params:xml:ns:xmpp-sasl"});
converse.connection._connect_cb(test_utils.createRequest(stanza));
_converse.connection._connect_cb(test_utils.createRequest(stanza));
stanza = $iq({
'type': 'result',
'id': 'reg1'
@ -198,19 +198,19 @@
.c('field', {'type': 'text-single', 'var': 'username'}).c('required').up().up()
.c('field', {'type': 'text-private', 'var': 'password'}).c('required').up().up()
.c('field', {'type': 'text-single', 'var': 'email'}).c('required').up().up();
converse.connection._dataRecv(test_utils.createRequest(stanza));
_converse.connection._dataRecv(test_utils.createRequest(stanza));
expect(registerview.form_type).toBe('xform');
registerview.$('input[name=username]').val('testusername');
registerview.$('input[name=password]').val('testpassword');
registerview.$('input[name=email]').val('test@email.local');
spyOn(converse.connection, 'send');
spyOn(_converse.connection, 'send');
registerview.$('input[type=submit]').click();
expect(converse.connection.send).toHaveBeenCalled();
var $stanza = $(converse.connection.send.argsForCall[0][0].tree());
expect(_converse.connection.send).toHaveBeenCalled();
var $stanza = $(_converse.connection.send.argsForCall[0][0].tree());
expect($stanza.children('query').children().length).toBe(1);
expect($stanza.children('query').children().children().length).toBe(3);
expect($stanza.children('query').children().children()[0].tagName).toBe('field');

View File

@ -1,17 +1,17 @@
/*global converse */
/*global _converse */
(function (root, factory) {
define([
"converse-api",
"converse_api",
"mock",
"test_utils",
"utils",
"transcripts"
], factory
);
} (this, function (converse_api, mock, test_utils, utils, transcripts) {
var _ = converse_api.env._;
var $ = converse_api.env.jQuery;
var Strophe = converse_api.env.Strophe;
} (this, function (converse, mock, test_utils, utils, transcripts) {
var Strophe = converse.env.Strophe;
var _ = converse.env._;
var $ = converse.env.jQuery;
var IGNORED_TAGS = [
'stream:features',
'auth',
@ -55,7 +55,7 @@
});
it("can be used to replay conversations", function () {
spyOn(converse, 'areDesktopNotificationsEnabled').andReturn(true);
spyOn(_converse, 'areDesktopNotificationsEnabled').andReturn(true);
_.each(transcripts, function (transcript) {
var text = transcript();
var xml = Strophe.xmlHtmlNode(text);
@ -68,7 +68,7 @@
return;
}
var _stanza = traverseElement(el);
converse.connection._dataRecv(test_utils.createRequest(_stanza));
_converse.connection._dataRecv(test_utils.createRequest(_stanza));
});
});
});

View File

@ -1,8 +1,8 @@
(function (root, factory) {
define(["converse-api"], factory);
} (this, function (converse_api) {
var utils = converse_api.env.utils,
_ = converse_api.env._;
} (this, function (converse) {
var utils = converse.env.utils,
_ = converse.env._;
return describe("Converse.js Utilities", function() {

View File

@ -1,18 +1,18 @@
(function (root, factory) {
define(["mock", "converse-api", "test_utils"], factory);
} (this, function (mock, converse_api, test_utils) {
var $ = converse_api.env.jQuery;
} (this, function (mock, converse, test_utils) {
var $ = converse.env.jQuery;
return describe("The XMPPStatus model", function() {
it("won't send <show>online when setting a custom status message", mock.initConverse(function (converse) {
converse.xmppstatus.save({'status': 'online'});
spyOn(converse.xmppstatus, 'setStatusMessage').andCallThrough();
spyOn(converse.connection, 'send');
converse.xmppstatus.setStatusMessage("I'm also happy!");
it("won't send <show>online when setting a custom status message", mock.initConverse(function (_converse) {
_converse.xmppstatus.save({'status': 'online'});
spyOn(_converse.xmppstatus, 'setStatusMessage').andCallThrough();
spyOn(_converse.connection, 'send');
_converse.xmppstatus.setStatusMessage("I'm also happy!");
runs (function () {
expect(converse.connection.send).toHaveBeenCalled();
var $stanza = $(converse.connection.send.argsForCall[0][0].tree());
expect(_converse.connection.send).toHaveBeenCalled();
var $stanza = $(_converse.connection.send.argsForCall[0][0].tree());
expect($stanza.children().length).toBe(1);
expect($stanza.children('show').length).toBe(0);
});

View File

@ -15,82 +15,82 @@
"converse-core"
],
factory);
}(this, function ($, _, moment, strophe, utils, converse) {
}(this, function ($, _, moment, strophe, utils, _converse) {
var Strophe = strophe.Strophe;
// API methods only available to plugins
converse.api = {
_converse.api = {
'connection': {
'connected': function () {
return converse.connection && converse.connection.connected || false;
return _converse.connection && _converse.connection.connected || false;
},
'disconnect': function () {
converse.connection.disconnect();
_converse.connection.disconnect();
},
},
'user': {
'jid': function () {
return converse.connection.jid;
return _converse.connection.jid;
},
'login': function (credentials) {
converse.initConnection();
converse.logIn(credentials);
_converse.initConnection();
_converse.logIn(credentials);
},
'logout': function () {
converse.logOut();
_converse.logOut();
},
'status': {
'get': function () {
return converse.xmppstatus.get('status');
return _converse.xmppstatus.get('status');
},
'set': function (value, message) {
var data = {'status': value};
if (!_.includes(_.keys(converse.STATUS_WEIGHTS), 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');
}
if (_.isString(message)) {
data.status_message = message;
}
converse.xmppstatus.sendPresence(value);
converse.xmppstatus.save(data);
_converse.xmppstatus.sendPresence(value);
_converse.xmppstatus.save(data);
},
'message': {
'get': function () {
return converse.xmppstatus.get('status_message');
return _converse.xmppstatus.get('status_message');
},
'set': function (stat) {
converse.xmppstatus.save({'status_message': stat});
_converse.xmppstatus.save({'status_message': stat});
}
}
},
},
'settings': {
'get': function (key) {
if (_.includes(_.keys(converse.default_settings), key)) {
return converse[key];
if (_.includes(_.keys(_converse.default_settings), key)) {
return _converse[key];
}
},
'set': function (key, val) {
var o = {};
if (_.isObject(key)) {
_.assignIn(converse, _.pick(key, _.keys(converse.default_settings)));
_.assignIn(_converse, _.pick(key, _.keys(_converse.default_settings)));
} else if (_.isString("string")) {
o[key] = val;
_.assignIn(converse, _.pick(o, _.keys(converse.default_settings)));
_.assignIn(_converse, _.pick(o, _.keys(_converse.default_settings)));
}
}
},
'contacts': {
'get': function (jids) {
var _transform = function (jid) {
var contact = converse.roster.get(Strophe.getBareJidFromJid(jid));
var contact = _converse.roster.get(Strophe.getBareJidFromJid(jid));
if (contact) {
return contact.attributes;
}
return null;
};
if (_.isUndefined(jids)) {
jids = converse.roster.pluck('jid');
jids = _converse.roster.pluck('jid');
} else if (_.isString(jids)) {
return _transform(jids);
}
@ -100,24 +100,24 @@
if (!_.isString(jid) || !_.includes(jid, '@')) {
throw new TypeError('contacts.add: invalid jid');
}
converse.roster.addAndSubscribe(jid, _.isEmpty(name)? jid: name);
_converse.roster.addAndSubscribe(jid, _.isEmpty(name)? jid: name);
}
},
'chats': {
'open': function (jids) {
var chatbox;
if (_.isUndefined(jids)) {
converse.log("chats.open: You need to provide at least one JID", "error");
_converse.log("chats.open: You need to provide at least one JID", "error");
return null;
} else if (_.isString(jids)) {
chatbox = converse.wrappedChatBox(
converse.chatboxes.getChatBox(jids, true).trigger('show')
chatbox = _converse.wrappedChatBox(
_converse.chatboxes.getChatBox(jids, true).trigger('show')
);
return chatbox;
}
return _.map(jids, function (jid) {
chatbox = converse.wrappedChatBox(
converse.chatboxes.getChatBox(jid, true).trigger('show')
chatbox = _converse.wrappedChatBox(
_converse.chatboxes.getChatBox(jid, true).trigger('show')
);
return chatbox;
});
@ -125,22 +125,22 @@
'get': function (jids) {
if (_.isUndefined(jids)) {
var result = [];
converse.chatboxes.each(function (chatbox) {
_converse.chatboxes.each(function (chatbox) {
// FIXME: Leaky abstraction from MUC. We need to add a
// base type for chat boxes, and check for that.
if (chatbox.get('type') !== 'chatroom') {
result.push(converse.wrappedChatBox(chatbox));
result.push(_converse.wrappedChatBox(chatbox));
}
});
return result;
} else if (_.isString(jids)) {
return converse.wrappedChatBox(converse.chatboxes.getChatBox(jids));
return _converse.wrappedChatBox(_converse.chatboxes.getChatBox(jids));
}
return _.map(jids,
_.partial(
_.flow(
converse.chatboxes.getChatBox.bind(converse.chatboxes),
converse.wrappedChatBox.bind(converse)
_converse.chatboxes.getChatBox.bind(_converse.chatboxes),
_converse.wrappedChatBox.bind(_converse)
), _, true
)
);
@ -148,20 +148,20 @@
},
'tokens': {
'get': function (id) {
if (!converse.expose_rid_and_sid || _.isUndefined(converse.connection)) {
if (!_converse.expose_rid_and_sid || _.isUndefined(_converse.connection)) {
return null;
}
if (id.toLowerCase() === 'rid') {
return converse.connection.rid || converse.connection._proto.rid;
return _converse.connection.rid || _converse.connection._proto.rid;
} else if (id.toLowerCase() === 'sid') {
return converse.connection.sid || converse.connection._proto.sid;
return _converse.connection.sid || _converse.connection._proto.sid;
}
}
},
'listen': {
'once': converse.once,
'on': converse.on,
'not': converse.off,
'once': _converse.once,
'on': _converse.on,
'not': _converse.off,
'stanza': function (name, options, handler) {
if (_.isFunction(options)) {
handler = options;
@ -169,7 +169,7 @@
} else {
options = options || {};
}
converse.connection.addHandler(
_converse.connection.addHandler(
handler,
options.ns,
name,
@ -181,22 +181,22 @@
},
},
'send': function (stanza) {
converse.connection.send(stanza);
_converse.connection.send(stanza);
},
};
// The public API
return {
'initialize': function (settings, callback) {
return converse.initialize(settings, callback);
return _converse.initialize(settings, callback);
},
'plugins': {
'add': function (name, plugin) {
plugin.__name__ = name;
converse.pluggable.plugins[name] = plugin;
_converse.pluggable.plugins[name] = plugin;
},
'remove': function (name) {
delete converse.pluggable.plugins[name];
delete _converse.pluggable.plugins[name];
},
},
'env': {

View File

@ -27,24 +27,24 @@
factory);
}(this, function (
$, _, moment, strophe, utils,
converse, converse_api, muc,
_converse, converse_api, muc,
tpl_chatroom_bookmark_form,
tpl_chatroom_bookmark_toggle,
tpl_bookmark,
tpl_bookmarks_list
) {
var __ = utils.__.bind(converse),
var __ = utils.__.bind(_converse),
___ = utils.___,
Strophe = converse_api.env.Strophe,
$iq = converse_api.env.$iq,
b64_sha1 = converse_api.env.b64_sha1;
// Add new HTML templates.
converse.templates.chatroom_bookmark_form = tpl_chatroom_bookmark_form;
converse.templates.chatroom_bookmark_toggle = tpl_chatroom_bookmark_toggle;
converse.templates.bookmark = tpl_bookmark;
converse.templates.bookmarks_list = tpl_bookmarks_list;
_converse.templates.chatroom_bookmark_form = tpl_chatroom_bookmark_form;
_converse.templates.chatroom_bookmark_toggle = tpl_chatroom_bookmark_toggle;
_converse.templates.bookmark = tpl_bookmark;
_converse.templates.bookmarks_list = tpl_bookmarks_list;
converse_api.plugins.add('converse-bookmarks', {
overrides: {
@ -74,10 +74,10 @@
generateHeadingHTML: function () {
var html = this.__super__.generateHeadingHTML.apply(this, arguments);
if (converse.allow_bookmarks) {
if (_converse.allow_bookmarks) {
var div = document.createElement('div');
div.innerHTML = html;
var bookmark_button = converse.templates.chatroom_bookmark_toggle(
var bookmark_button = _converse.templates.chatroom_bookmark_toggle(
_.assignIn(
this.model.toJSON(),
{
@ -97,10 +97,10 @@
* for this room, and if so use it.
* Otherwise delegate to the super method.
*/
if (_.isUndefined(converse.bookmarks) || !converse.allow_bookmarks) {
if (_.isUndefined(_converse.bookmarks) || !_converse.allow_bookmarks) {
return this.__super__.checkForReservedNick.apply(this, arguments);
}
var model = converse.bookmarks.findWhere({'jid': this.model.get('jid')});
var model = _converse.bookmarks.findWhere({'jid': this.model.get('jid')});
if (!_.isUndefined(model) && model.get('nick')) {
this.join(this.model.get('nick'));
} else {
@ -119,8 +119,8 @@
setBookmarkState: function () {
/* Set whether the room is bookmarked or not.
*/
if (!_.isUndefined(converse.bookmarks)) {
var models = converse.bookmarks.where({'jid': this.model.get('jid')});
if (!_.isUndefined(_converse.bookmarks)) {
var models = _converse.bookmarks.where({'jid': this.model.get('jid')});
if (!models.length) {
this.model.save('bookmarked', false);
} else {
@ -135,7 +135,7 @@
// Remove any existing forms
$body.find('form.chatroom-form').remove();
$body.append(
converse.templates.chatroom_bookmark_form({
_converse.templates.chatroom_bookmark_form({
heading: __('Bookmark this room'),
label_name: __('The name for this bookmark:'),
label_autojoin: __('Would you like this room to be automatically joined upon startup?'),
@ -151,7 +151,7 @@
onBookmarkFormSubmitted: function (ev) {
ev.preventDefault();
var $form = $(ev.target), that = this;
converse.bookmarks.createBookmark({
_converse.bookmarks.createBookmark({
'jid': this.model.get('jid'),
'autojoin': $form.find('input[name="autojoin"]').prop('checked'),
'name': $form.find('input[name=name]').val(),
@ -169,7 +169,7 @@
ev.preventDefault();
ev.stopPropagation();
}
var models = converse.bookmarks.where({'jid': this.model.get('jid')});
var models = _converse.bookmarks.where({'jid': this.model.get('jid')});
if (!models.length) {
this.renderBookmarkForm();
} else {
@ -186,7 +186,7 @@
/* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery.
*/
var converse = this.converse;
var _converse = this.converse;
// Configuration values for this plugin
// ====================================
// Refer to docs/source/configuration.rst for explanations of these
@ -195,32 +195,32 @@
allow_bookmarks: true
});
converse.Bookmark = Backbone.Model;
_converse.Bookmark = Backbone.Model;
converse.BookmarksList = Backbone.Model.extend({
_converse.BookmarksList = Backbone.Model.extend({
defaults: {
"toggle-state": converse.OPENED
"toggle-state": _converse.OPENED
}
});
converse.Bookmarks = Backbone.Collection.extend({
model: converse.Bookmark,
_converse.Bookmarks = Backbone.Collection.extend({
model: _converse.Bookmark,
initialize: function () {
this.on('add', _.flow(this.openBookmarkedRoom, this.markRoomAsBookmarked));
this.on('remove', this.markRoomAsUnbookmarked, this);
this.on('remove', this.sendBookmarkStanza, this);
var cache_key = 'converse.room-bookmarks'+converse.bare_jid;
var cache_key = 'converse.room-bookmarks'+_converse.bare_jid;
this.cached_flag = b64_sha1(cache_key+'fetched');
this.browserStorage = new Backbone.BrowserStorage[converse.storage](
this.browserStorage = new Backbone.BrowserStorage[_converse.storage](
b64_sha1(cache_key)
);
},
openBookmarkedRoom: function (bookmark) {
if (bookmark.get('autojoin')) {
converse.api.rooms.open(bookmark.get('jid'), bookmark.get('nick'));
_converse.api.rooms.open(bookmark.get('jid'), bookmark.get('nick'));
}
return bookmark;
},
@ -250,14 +250,14 @@
},
createBookmark: function (options) {
converse.bookmarks.create(options);
converse.bookmarks.sendBookmarkStanza();
_converse.bookmarks.create(options);
_converse.bookmarks.sendBookmarkStanza();
},
sendBookmarkStanza: function () {
var stanza = $iq({
'type': 'set',
'from': converse.connection.jid,
'from': _converse.connection.jid,
})
.c('pubsub', {'xmlns': Strophe.NS.PUBSUB})
.c('publish', {'node': 'storage:bookmarks'})
@ -279,12 +279,12 @@
.c('value').t('true').up().up()
.c('field', {'var':'pubsub#access_model'})
.c('value').t('whitelist');
converse.connection.sendIQ(stanza, null, this.onBookmarkError.bind(this));
_converse.connection.sendIQ(stanza, null, this.onBookmarkError.bind(this));
},
onBookmarkError: function (iq) {
converse.log("Error while trying to add bookmark", "error");
converse.log(iq);
_converse.log("Error while trying to add bookmark", "error");
_converse.log(iq);
// We remove all locally cached bookmarks and fetch them
// again from the server.
this.reset();
@ -294,11 +294,11 @@
fetchBookmarksFromServer: function (deferred) {
var stanza = $iq({
'from': converse.connection.jid,
'from': _converse.connection.jid,
'type': 'get',
}).c('pubsub', {'xmlns': Strophe.NS.PUBSUB})
.c('items', {'node': 'storage:bookmarks'});
converse.connection.sendIQ(
_converse.connection.sendIQ(
stanza,
_.bind(this.onBookmarksReceived, this, deferred),
_.bind(this.onBookmarksReceivedError, this, deferred)
@ -306,14 +306,14 @@
},
markRoomAsBookmarked: function (bookmark) {
var room = converse.chatboxes.get(bookmark.get('jid'));
var room = _converse.chatboxes.get(bookmark.get('jid'));
if (!_.isUndefined(room)) {
room.save('bookmarked', true);
}
},
markRoomAsUnbookmarked: function (bookmark) {
var room = converse.chatboxes.get(bookmark.get('jid'));
var room = _converse.chatboxes.get(bookmark.get('jid'));
if (!_.isUndefined(room)) {
room.save('bookmarked', false);
}
@ -339,15 +339,15 @@
onBookmarksReceivedError: function (deferred, iq) {
window.sessionStorage.setItem(this.cached_flag, true);
converse.log('Error while fetching bookmarks');
converse.log(iq);
_converse.log('Error while fetching bookmarks');
_converse.log(iq);
if (!_.isUndefined(deferred)) {
return deferred.reject();
}
}
});
converse.BookmarksView = Backbone.View.extend({
_converse.BookmarksView = Backbone.View.extend({
tagName: 'div',
className: 'bookmarks-list',
events: {
@ -359,10 +359,10 @@
this.model.on('add', this.renderBookmarkListElement, this);
this.model.on('remove', this.removeBookmarkListElement, this);
var cachekey = 'converse.room-bookmarks'+converse.bare_jid+'-list-model';
this.list_model = new converse.BookmarksList();
var cachekey = 'converse.room-bookmarks'+_converse.bare_jid+'-list-model';
this.list_model = new _converse.BookmarksList();
this.list_model.id = cachekey;
this.list_model.browserStorage = new Backbone.BrowserStorage[converse.storage](
this.list_model.browserStorage = new Backbone.BrowserStorage[_converse.storage](
b64_sha1(cachekey)
);
this.list_model.fetch();
@ -370,16 +370,16 @@
},
render: function () {
this.$el.html(converse.templates.bookmarks_list({
this.$el.html(_converse.templates.bookmarks_list({
'toggle_state': this.list_model.get('toggle-state'),
'desc_bookmarks': __('Click to toggle the bookmarks list'),
'label_bookmarks': __('Bookmarked Rooms')
})).hide();
if (this.list_model.get('toggle-state') !== converse.OPENED) {
if (this.list_model.get('toggle-state') !== _converse.OPENED) {
this.$('.bookmarks').hide();
}
this.model.each(this.renderBookmarkListElement.bind(this));
var controlboxview = converse.chatboxviews.get('controlbox');
var controlboxview = _converse.chatboxviews.get('controlbox');
if (!_.isUndefined(controlboxview)) {
this.$el.prependTo(controlboxview.$('#chatrooms'));
}
@ -391,12 +391,12 @@
var name = $(ev.target).data('bookmarkName');
var jid = $(ev.target).data('roomJid');
if (confirm(__(___("Are you sure you want to remove the bookmark \"%1$s\"?"), name))) {
_.forEach(converse.bookmarks.where({'jid': jid}), function (item) { item.destroy(); });
_.invokeMap(_converse.bookmarks.where({'jid': jid}), Backbone.Model.prototype.destroy);
}
},
renderBookmarkListElement: function (item) {
var $bookmark = $(converse.templates.bookmark({
var $bookmark = $(_converse.templates.bookmark({
'name': item.get('name'),
'jid': item.get('jid'),
'open_title': __('Click to open this room'),
@ -421,40 +421,40 @@
var $el = $(ev.target);
if ($el.hasClass("icon-opened")) {
this.$('.bookmarks').slideUp('fast');
this.list_model.save({'toggle-state': converse.CLOSED});
this.list_model.save({'toggle-state': _converse.CLOSED});
$el.removeClass("icon-opened").addClass("icon-closed");
} else {
$el.removeClass("icon-closed").addClass("icon-opened");
this.$('.bookmarks').slideDown('fast');
this.list_model.save({'toggle-state': converse.OPENED});
this.list_model.save({'toggle-state': _converse.OPENED});
}
}
});
var initBookmarks = function () {
if (!converse.allow_bookmarks) {
if (!_converse.allow_bookmarks) {
return;
}
converse.bookmarks = new converse.Bookmarks();
converse.bookmarks.fetchBookmarks().always(function () {
converse.bookmarksview = new converse.BookmarksView(
{'model': converse.bookmarks}
_converse.bookmarks = new _converse.Bookmarks();
_converse.bookmarks.fetchBookmarks().always(function () {
_converse.bookmarksview = new _converse.BookmarksView(
{'model': _converse.bookmarks}
);
});
};
converse.on('chatBoxesFetched', initBookmarks);
_converse.on('chatBoxesFetched', initBookmarks);
var afterReconnection = function () {
if (!converse.allow_bookmarks) {
if (!_converse.allow_bookmarks) {
return;
}
if (_.isUndefined(converse.bookmarksview)) {
if (_.isUndefined(_converse.bookmarksview)) {
initBookmarks();
} else {
converse.bookmarksview.render();
_converse.bookmarksview.render();
}
};
converse.on('reconnected', afterReconnection);
_converse.on('reconnected', afterReconnection);
}
});
}));

View File

@ -18,7 +18,7 @@
"tpl!avatar"
], factory);
}(this, function (
converse,
_converse,
converse_api,
tpl_chatbox,
tpl_new_day,
@ -28,19 +28,19 @@
tpl_avatar
) {
"use strict";
converse.templates.chatbox = tpl_chatbox;
converse.templates.new_day = tpl_new_day;
converse.templates.action = tpl_action;
converse.templates.message = tpl_message;
converse.templates.toolbar = tpl_toolbar;
converse.templates.avatar = tpl_avatar;
_converse.templates.chatbox = tpl_chatbox;
_converse.templates.new_day = tpl_new_day;
_converse.templates.action = tpl_action;
_converse.templates.message = tpl_message;
_converse.templates.toolbar = tpl_toolbar;
_converse.templates.avatar = tpl_avatar;
var $ = converse_api.env.jQuery,
utils = converse_api.env.utils,
Strophe = converse_api.env.Strophe,
$msg = converse_api.env.$msg,
_ = converse_api.env._,
__ = utils.__.bind(converse),
__ = utils.__.bind(_converse),
moment = converse_api.env.moment;
var KEY = {
@ -62,7 +62,7 @@
onChatBoxAdded: function (item) {
var view = this.get(item.get('id'));
if (!view) {
view = new converse.ChatBoxView({model: item});
view = new _converse.ChatBoxView({model: item});
this.add(item.get('id'), view);
return view;
} else {
@ -88,7 +88,7 @@
},
});
converse.ChatBoxView = Backbone.View.extend({
_converse.ChatBoxView = Backbone.View.extend({
length: 200,
tagName: 'div',
className: 'chatbox hidden',
@ -122,14 +122,14 @@
// Which for some reason doesn't work.
// So working around that fact here:
this.$el.find('.chat-content').on('scroll', this.markScrolled.bind(this));
converse.emit('chatBoxInitialized', this);
_converse.emit('chatBoxInitialized', this);
},
render: function () {
this.$el.attr('id', this.model.get('box_id'))
.html(converse.templates.chatbox(
.html(_converse.templates.chatbox(
_.extend(this.model.toJSON(), {
show_toolbar: converse.show_toolbar,
show_toolbar: _converse.show_toolbar,
show_textarea: true,
title: this.model.get('fullname'),
unread_msgs: __('You have unread messages'),
@ -141,7 +141,7 @@
);
this.$content = this.$el.find('.chat-content');
this.renderToolbar().renderAvatar();
converse.emit('chatBoxOpened', this);
_converse.emit('chatBoxOpened', this);
utils.refreshWebkit();
return this.showStatusMessage();
},
@ -205,7 +205,7 @@
*/
var day_date = moment(date).startOf('day');
var insert = prepend ? this.$content.prepend: this.$content.append;
insert.call(this.$content, converse.templates.new_day({
insert.call(this.$content, _converse.templates.new_day({
isodate: day_date.format(),
datestring: day_date.format("dddd MMM Do YYYY")
}));
@ -319,10 +319,10 @@
if ((match) && (match[1] === 'me')) {
text = text.replace(/^\/me/, '');
template = converse.templates.action;
template = _converse.templates.action;
username = fullname;
} else {
template = converse.templates.message;
template = _converse.templates.message;
username = attrs.sender === 'me' && __('me') || fullname;
}
this.$content.find('div.chat-event').remove();
@ -354,7 +354,7 @@
$msg.find('.chat-msg-content').first()
.text(text)
.addHyperlinks()
.addEmoticons(converse.visible_toolbar_buttons.emoticons);
.addEmoticons(_converse.visible_toolbar_buttons.emoticons);
return $msg;
},
@ -372,14 +372,14 @@
},
handleChatStateMessage: function (message) {
if (message.get('chat_state') === converse.COMPOSING) {
if (message.get('chat_state') === _converse.COMPOSING) {
this.showStatusNotification(message.get('fullname')+' '+__('is typing'));
this.clear_status_timeout = window.setTimeout(this.clearStatusNotification.bind(this), 30000);
} else if (message.get('chat_state') === converse.PAUSED) {
} else if (message.get('chat_state') === _converse.PAUSED) {
this.showStatusNotification(message.get('fullname')+' '+__('has stopped typing'));
} else if (_.includes([converse.INACTIVE, converse.ACTIVE], message.get('chat_state'))) {
} else if (_.includes([_converse.INACTIVE, _converse.ACTIVE], message.get('chat_state'))) {
this.$content.find('div.chat-event').remove();
} else if (message.get('chat_state') === converse.GONE) {
} else if (message.get('chat_state') === _converse.GONE) {
this.showStatusNotification(message.get('fullname')+' '+__('has gone away'));
}
},
@ -401,8 +401,8 @@
if (this.model.get('scrolled', true)) {
this.$el.find('.new-msgs-indicator').removeClass('hidden');
}
if (converse.windowState === 'hidden' || this.model.get('scrolled', true)) {
converse.incrementMsgCounter();
if (_converse.windowState === 'hidden' || this.model.get('scrolled', true)) {
_converse.incrementMsgCounter();
}
}
},
@ -454,12 +454,12 @@
createMessageStanza: function (message) {
return $msg({
from: converse.connection.jid,
from: _converse.connection.jid,
to: this.model.get('jid'),
type: 'chat',
id: message.get('msgid')
}).c('body').t(message.get('message')).up()
.c(converse.ACTIVE, {'xmlns': Strophe.NS.CHATSTATES}).up();
.c(_converse.ACTIVE, {'xmlns': Strophe.NS.CHATSTATES}).up();
},
sendMessage: function (message) {
@ -471,11 +471,11 @@
// TODO: We might want to send to specfic resources.
// Especially in the OTR case.
var messageStanza = this.createMessageStanza(message);
converse.connection.send(messageStanza);
if (converse.forward_messages) {
_converse.connection.send(messageStanza);
if (_converse.forward_messages) {
// Forward the message, so that other connected resources are also aware of it.
converse.connection.send(
$msg({ to: converse.bare_jid, type: 'chat', id: message.get('msgid') })
_converse.connection.send(
$msg({ to: _converse.bare_jid, type: 'chat', id: message.get('msgid') })
.c('forwarded', {xmlns:'urn:xmpp:forward:0'})
.c('delay', {xmns:'urn:xmpp:delay',stamp:(new Date()).getTime()}).up()
.cnode(messageStanza.tree())
@ -490,7 +490,7 @@
* Parameters:
* (string) text - The chat message text.
*/
if (!converse.connection.authenticated) {
if (!_converse.connection.authenticated) {
return this.showHelpMessages(
['Sorry, the connection has been lost, '+
'and your message could not be sent'],
@ -512,8 +512,8 @@
return;
}
}
var fullname = converse.xmppstatus.get('fullname');
fullname = _.isEmpty(fullname)? converse.bare_jid: fullname;
var fullname = _converse.xmppstatus.get('fullname');
fullname = _.isEmpty(fullname)? _converse.bare_jid: fullname;
var message = this.model.messages.create({
fullname: fullname,
sender: 'me',
@ -528,7 +528,7 @@
* as taken from the 'chat_state' attribute of the chat box.
* See XEP-0085 Chat State Notifications.
*/
converse.connection.send(
_converse.connection.send(
$msg({'to':this.model.get('jid'), 'type': 'chat'})
.c(this.model.get('chat_state'), {'xmlns': Strophe.NS.CHATSTATES}).up()
.c('no-store', {'xmlns': Strophe.NS.HINTS}).up()
@ -552,12 +552,12 @@
window.clearTimeout(this.chat_state_timeout);
delete this.chat_state_timeout;
}
if (state === converse.COMPOSING) {
if (state === _converse.COMPOSING) {
this.chat_state_timeout = window.setTimeout(
this.setChatState.bind(this), converse.TIMEOUTS.PAUSED, converse.PAUSED);
} else if (state === converse.PAUSED) {
this.setChatState.bind(this), _converse.TIMEOUTS.PAUSED, _converse.PAUSED);
} else if (state === _converse.PAUSED) {
this.chat_state_timeout = window.setTimeout(
this.setChatState.bind(this), converse.TIMEOUTS.INACTIVE, converse.INACTIVE);
this.setChatState.bind(this), _converse.TIMEOUTS.INACTIVE, _converse.INACTIVE);
}
if (!no_save && this.model.get('chat_state') !== state) {
this.model.set('chat_state', state);
@ -576,13 +576,13 @@
textarea.focus();
if (message !== '') {
this.onMessageSubmitted(message);
converse.emit('messageSend', message);
_converse.emit('messageSend', message);
}
this.setChatState(converse.ACTIVE);
this.setChatState(_converse.ACTIVE);
} else {
// Set chat state to composing if keyCode is not a forward-slash
// (which would imply an internal command and not a message).
this.setChatState(converse.COMPOSING, ev.keyCode === KEY.FORWARD_SLASH);
this.setChatState(_converse.COMPOSING, ev.keyCode === KEY.FORWARD_SLASH);
}
},
@ -621,8 +621,8 @@
toggleCall: function (ev) {
ev.stopPropagation();
converse.emit('callButtonClicked', {
connection: converse.connection,
_converse.emit('callButtonClicked', {
connection: _converse.connection,
model: this.model
});
},
@ -646,7 +646,7 @@
onStatusChanged: function (item) {
this.showStatusMessage();
converse.emit('contactStatusMessageChanged', {
_converse.emit('contactStatusMessageChanged', {
'contact': item.attributes,
'message': item.get('status')
});
@ -662,15 +662,15 @@
close: function (ev) {
if (ev && ev.preventDefault) { ev.preventDefault(); }
if (converse.connection.connected) {
if (_converse.connection.connected) {
// Immediately sending the chat state, because the
// model is going to be destroyed afterwards.
this.model.set('chat_state', converse.INACTIVE);
this.model.set('chat_state', _converse.INACTIVE);
this.sendChatState();
this.model.destroy();
}
this.remove();
converse.emit('chatBoxClosed', this);
_converse.emit('chatBoxClosed', this);
return this;
},
@ -679,15 +679,15 @@
'label_clear': __('Clear all messages'),
'label_insert_smiley': __('Insert a smiley'),
'label_start_call': __('Start a call'),
'show_call_button': converse.visible_toolbar_buttons.call,
'show_clear_button': converse.visible_toolbar_buttons.clear,
'show_emoticons': converse.visible_toolbar_buttons.emoticons,
'show_call_button': _converse.visible_toolbar_buttons.call,
'show_clear_button': _converse.visible_toolbar_buttons.clear,
'show_emoticons': _converse.visible_toolbar_buttons.emoticons,
});
},
renderToolbar: function (toolbar, options) {
if (!converse.show_toolbar) { return; }
toolbar = toolbar || converse.templates.toolbar;
if (!_converse.show_toolbar) { return; }
toolbar = toolbar || _converse.templates.toolbar;
options = _.extend(
this.model.toJSON(),
this.getToolbarOptions(options || {})
@ -700,10 +700,10 @@
if (!this.model.get('image')) {
return;
}
var width = converse.chatview_avatar_width;
var height = converse.chatview_avatar_height;
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'),
canvas = $(converse.templates.avatar({
canvas = $(_converse.templates.avatar({
'width': width,
'height': height
})).get(0);
@ -729,7 +729,7 @@
focus: function () {
this.$el.find('.chat-textarea').focus();
converse.emit('chatBoxFocused', this);
_converse.emit('chatBoxFocused', this);
return this;
},
@ -740,12 +740,12 @@
},
afterShown: function () {
if (converse.connection.connected) {
if (_converse.connection.connected) {
// Without a connection, we haven't yet initialized
// localstorage
this.model.save();
}
this.setChatState(converse.ACTIVE);
this.setChatState(_converse.ACTIVE);
this.scrollDown();
if (focus) {
this.focus();

View File

@ -27,7 +27,7 @@
"converse-rosterview"
], factory);
}(this, function (
converse,
_converse,
converse_api,
tpl_add_contact_dropdown,
tpl_add_contact_form,
@ -44,19 +44,19 @@
tpl_status_option
) {
"use strict";
converse.templates.add_contact_dropdown = tpl_add_contact_dropdown;
converse.templates.add_contact_form = tpl_add_contact_form;
converse.templates.change_status_message = tpl_change_status_message;
converse.templates.chat_status = tpl_chat_status;
converse.templates.choose_status = tpl_choose_status;
converse.templates.contacts_panel = tpl_contacts_panel;
converse.templates.contacts_tab = tpl_contacts_tab;
converse.templates.controlbox = tpl_controlbox;
converse.templates.controlbox_toggle = tpl_controlbox_toggle;
converse.templates.login_panel = tpl_login_panel;
converse.templates.login_tab = tpl_login_tab;
converse.templates.search_contact = tpl_search_contact;
converse.templates.status_option = tpl_status_option;
_converse.templates.add_contact_dropdown = tpl_add_contact_dropdown;
_converse.templates.add_contact_form = tpl_add_contact_form;
_converse.templates.change_status_message = tpl_change_status_message;
_converse.templates.chat_status = tpl_chat_status;
_converse.templates.choose_status = tpl_choose_status;
_converse.templates.contacts_panel = tpl_contacts_panel;
_converse.templates.contacts_tab = tpl_contacts_tab;
_converse.templates.controlbox = tpl_controlbox;
_converse.templates.controlbox_toggle = tpl_controlbox_toggle;
_converse.templates.login_panel = tpl_login_panel;
_converse.templates.login_tab = tpl_login_tab;
_converse.templates.search_contact = tpl_search_contact;
_converse.templates.status_option = tpl_status_option;
var USERS_PANEL_ID = 'users';
@ -66,7 +66,7 @@
// Other necessary globals
var $ = converse_api.env.jQuery,
_ = converse_api.env._,
__ = utils.__.bind(converse),
__ = utils.__.bind(_converse),
moment = converse_api.env.moment;
@ -139,7 +139,7 @@
view.initialize();
return view;
} else {
view = new converse.ControlBoxView({model: item});
view = new _converse.ControlBoxView({model: item});
return this.add(item.get('id'), view);
}
} else {
@ -149,7 +149,7 @@
closeAllChatBoxes: function () {
this.each(function (view) {
if (converse.disconnection_cause === converse.LOGOUT ||
if (_converse.disconnection_cause === _converse.LOGOUT ||
view.model.get('id') !== 'controlbox') {
view.close();
}
@ -164,7 +164,7 @@
* depending on which is visible.
*/
if (!controlbox || !controlbox.$el.is(':visible')) {
return converse.controlboxtoggle.$el.outerWidth(true);
return _converse.controlboxtoggle.$el.outerWidth(true);
} else {
return controlbox.$el.outerWidth(true);
}
@ -191,7 +191,7 @@
ChatBoxView: {
insertIntoDOM: function () {
this.$el.insertAfter(converse.chatboxviews.get("controlbox").$el);
this.$el.insertAfter(_converse.chatboxviews.get("controlbox").$el);
return this;
}
}
@ -201,7 +201,7 @@
/* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery.
*/
var converse = this.converse;
var _converse = this.converse;
this.updateSettings({
allow_logout: true,
default_domain: undefined,
@ -213,15 +213,15 @@
var LABEL_CONTACTS = __('Contacts');
converse.addControlBox = function () {
return converse.chatboxes.add({
_converse.addControlBox = function () {
return _converse.chatboxes.add({
id: 'controlbox',
box_id: 'controlbox',
closed: !converse.show_controlbox_by_default
closed: !_converse.show_controlbox_by_default
});
};
converse.ControlBoxView = converse.ChatBoxView.extend({
_converse.ControlBoxView = _converse.ChatBoxView.extend({
tagName: 'div',
className: 'chatbox',
id: 'controlbox',
@ -231,7 +231,7 @@
},
initialize: function () {
this.$el.insertAfter(converse.controlboxtoggle.$el);
this.$el.insertAfter(_converse.controlboxtoggle.$el);
this.model.on('change:connected', this.onConnected, this);
this.model.on('destroy', this.hide, this);
this.model.on('hide', this.hide, this);
@ -242,7 +242,7 @@
this.insertRoster();
}
if (_.isUndefined(this.model.get('closed'))) {
this.model.set('closed', !converse.show_controlbox_by_default);
this.model.set('closed', !_converse.show_controlbox_by_default);
}
if (!this.model.get('closed')) {
this.show();
@ -252,12 +252,12 @@
},
render: function () {
this.$el.html(converse.templates.controlbox(
this.$el.html(_converse.templates.controlbox(
_.extend(this.model.toJSON(), {
sticky_controlbox: converse.sticky_controlbox
sticky_controlbox: _converse.sticky_controlbox
}))
);
if (!converse.connection.connected || !converse.connection.authenticated || converse.connection.disconnecting) {
if (!_converse.connection.connected || !_converse.connection.authenticated || _converse.connection.disconnecting) {
this.renderLoginPanel();
} else if (!this.contactspanel || !this.contactspanel.$el.is(':visible')) {
this.renderContactsPanel();
@ -274,12 +274,12 @@
insertRoster: function () {
/* Place the rosterview inside the "Contacts" panel.
*/
this.contactspanel.$el.append(converse.rosterview.$el);
this.contactspanel.$el.append(_converse.rosterview.$el);
return this;
},
renderLoginPanel: function () {
this.loginpanel = new converse.LoginPanel({
this.loginpanel = new _converse.LoginPanel({
'$parent': this.$el.find('.controlbox-panes'),
'model': this
});
@ -291,24 +291,24 @@
if (_.isUndefined(this.model.get('active-panel'))) {
this.model.save({'active-panel': USERS_PANEL_ID});
}
this.contactspanel = new converse.ContactsPanel({
this.contactspanel = new _converse.ContactsPanel({
'$parent': this.$el.find('.controlbox-panes')
});
this.contactspanel.render();
converse.xmppstatusview = new converse.XMPPStatusView({
'model': converse.xmppstatus
_converse.xmppstatusview = new _converse.XMPPStatusView({
'model': _converse.xmppstatus
});
converse.xmppstatusview.render();
_converse.xmppstatusview.render();
},
close: function (ev) {
if (ev && ev.preventDefault) { ev.preventDefault(); }
if (converse.connection.connected && !converse.connection.disconnecting) {
if (_converse.connection.connected && !_converse.connection.disconnecting) {
this.model.save({'closed': true});
} else {
this.model.trigger('hide');
}
converse.emit('controlBoxClosed', this);
_converse.emit('controlBoxClosed', this);
return this;
},
@ -323,25 +323,25 @@
hide: function (callback) {
this.$el.addClass('hidden');
utils.refreshWebkit();
converse.emit('chatBoxClosed', this);
if (!converse.connection.connected) {
converse.controlboxtoggle.render();
_converse.emit('chatBoxClosed', this);
if (!_converse.connection.connected) {
_converse.controlboxtoggle.render();
}
converse.controlboxtoggle.show(callback);
_converse.controlboxtoggle.show(callback);
return this;
},
onControlBoxToggleHidden: function () {
var that = this;
utils.fadeIn(this.el, function () {
converse.controlboxtoggle.updateOnlineCount();
_converse.controlboxtoggle.updateOnlineCount();
utils.refreshWebkit();
converse.emit('controlBoxOpened', that);
_converse.emit('controlBoxOpened', that);
});
},
show: function () {
converse.controlboxtoggle.hide(
_converse.controlboxtoggle.hide(
this.onControlBoxToggleHidden.bind(this)
);
return this;
@ -357,7 +357,7 @@
$sibling.removeClass('current');
$tab.addClass('current');
$tab_panel.removeClass('hidden');
if (converse.connection.connected) {
if (_converse.connection.connected) {
this.model.save({'active-panel': $tab.data('id')});
}
return this;
@ -374,7 +374,7 @@
});
converse.LoginPanel = Backbone.View.extend({
_converse.LoginPanel = Backbone.View.extend({
tagName: 'div',
id: "login-dialog",
className: 'controlbox-pane',
@ -384,18 +384,18 @@
initialize: function (cfg) {
cfg.$parent.html(this.$el.html(
converse.templates.login_panel({
'ANONYMOUS': converse.ANONYMOUS,
'EXTERNAL': converse.EXTERNAL,
'LOGIN': converse.LOGIN,
'PREBIND': converse.PREBIND,
'auto_login': converse.auto_login,
'authentication': converse.authentication,
_converse.templates.login_panel({
'ANONYMOUS': _converse.ANONYMOUS,
'EXTERNAL': _converse.EXTERNAL,
'LOGIN': _converse.LOGIN,
'PREBIND': _converse.PREBIND,
'auto_login': _converse.auto_login,
'authentication': _converse.authentication,
'label_username': __('XMPP Username:'),
'label_password': __('Password:'),
'label_anon_login': __('Click here to log in anonymously'),
'label_login': __('Log In'),
'placeholder_username': (converse.locked_domain || converse.default_domain) && __('Username') || __('user@server'),
'placeholder_username': (_converse.locked_domain || _converse.default_domain) && __('Username') || __('user@server'),
'placeholder_password': __('password')
})
));
@ -403,7 +403,7 @@
},
render: function () {
this.$tabs.append(converse.templates.login_tab({label_sign_in: __('Sign in')}));
this.$tabs.append(_converse.templates.login_tab({label_sign_in: __('Sign in')}));
this.$el.find('input#jid').focus();
if (!this.$el.is(':visible')) {
this.$el.show();
@ -414,8 +414,8 @@
authenticate: function (ev) {
if (ev && ev.preventDefault) { ev.preventDefault(); }
var $form = $(ev.target);
if (converse.authentication === converse.ANONYMOUS) {
this.connect($form, converse.jid, null);
if (_converse.authentication === _converse.ANONYMOUS) {
this.connect($form, _converse.jid, null);
return;
}
var $jid_input = $form.find('input[name=jid]'),
@ -428,15 +428,15 @@
errors = true;
$jid_input.addClass('error');
}
if (!password && converse.authentication !== converse.EXTERNAL) {
if (!password && _converse.authentication !== _converse.EXTERNAL) {
errors = true;
$pw_input.addClass('error');
}
if (errors) { return; }
if (converse.locked_domain) {
jid = Strophe.escapeNode(jid) + '@' + converse.locked_domain;
} else if (converse.default_domain && !_.includes(jid, '@')) {
jid = jid + '@' + converse.default_domain;
if (_converse.locked_domain) {
jid = Strophe.escapeNode(jid) + '@' + _converse.locked_domain;
} else if (_converse.default_domain && !_.includes(jid, '@')) {
jid = jid + '@' + _converse.default_domain;
}
this.connect($form, jid, password);
return false;
@ -450,12 +450,12 @@
if (jid) {
resource = Strophe.getResourceFromJid(jid);
if (!resource) {
jid = jid.toLowerCase() + converse.generateResource();
jid = jid.toLowerCase() + _converse.generateResource();
} else {
jid = Strophe.getBareJidFromJid(jid).toLowerCase()+'/'+resource;
}
}
converse.connection.connect(jid, password, converse.onConnectStatusChanged);
_converse.connection.connect(jid, password, _converse.onConnectStatusChanged);
},
remove: function () {
@ -465,7 +465,7 @@
});
converse.XMPPStatusView = Backbone.View.extend({
_converse.XMPPStatusView = Backbone.View.extend({
el: "span#xmpp-status-holder",
events: {
@ -488,9 +488,9 @@
options = $('option', $select),
$options_target,
options_list = [];
this.$el.html(converse.templates.choose_status());
this.$el.html(_converse.templates.choose_status());
this.$el.find('#fancy-xmpp-status-select')
.html(converse.templates.chat_status({
.html(_converse.templates.chat_status({
'status_message': this.model.get('status_message') || __("I am %1$s", this.getPrettyStatus(chat_status)),
'chat_status': chat_status,
'desc_custom_status': __('Click here to write a custom status message'),
@ -498,7 +498,7 @@
}));
// iterate through all the <option> elements and add option values
options.each(function () {
options_list.push(converse.templates.status_option({
options_list.push(_converse.templates.status_option({
'value': $(this).val(),
'text': this.text
}));
@ -517,7 +517,7 @@
renderStatusChangeForm: function (ev) {
ev.preventDefault();
var status_message = this.model.get('status') || 'offline';
var input = converse.templates.change_status_message({
var input = _converse.templates.change_status_message({
'status_message': status_message,
'label_custom_status': __('Custom status'),
'label_save': __('Save')
@ -539,7 +539,7 @@
value = $el.attr('data-value');
if (value === 'logout') {
this.$el.find(".dropdown dd ul").hide();
converse.logOut();
_converse.logOut();
} else {
this.model.setStatus(value);
this.$el.find(".dropdown dd ul").hide();
@ -568,7 +568,7 @@
// Example, I am online
var status_message = model.get('status_message') || __("I am %1$s", this.getPrettyStatus(stat));
this.$el.find('#fancy-xmpp-status-select').removeClass('no-border').html(
converse.templates.chat_status({
_converse.templates.chat_status({
'chat_status': stat,
'status_message': status_message,
'desc_custom_status': __('Click here to write a custom status message'),
@ -578,7 +578,7 @@
});
converse.ContactsPanel = Backbone.View.extend({
_converse.ContactsPanel = Backbone.View.extend({
tagName: 'div',
className: 'controlbox-pane',
id: 'users',
@ -596,33 +596,33 @@
render: function () {
var markup;
var widgets = converse.templates.contacts_panel({
var widgets = _converse.templates.contacts_panel({
label_online: __('Online'),
label_busy: __('Busy'),
label_away: __('Away'),
label_offline: __('Offline'),
label_logout: __('Log out'),
include_offline_state: converse.include_offline_state,
allow_logout: converse.allow_logout
include_offline_state: _converse.include_offline_state,
allow_logout: _converse.allow_logout
});
var controlbox = converse.chatboxes.get('controlbox');
this.$tabs.append(converse.templates.contacts_tab({
var controlbox = _converse.chatboxes.get('controlbox');
this.$tabs.append(_converse.templates.contacts_tab({
'label_contacts': LABEL_CONTACTS,
'is_current': controlbox.get('active-panel') === USERS_PANEL_ID
}));
if (converse.xhr_user_search) {
markup = converse.templates.search_contact({
if (_converse.xhr_user_search) {
markup = _converse.templates.search_contact({
label_contact_name: __('Contact name'),
label_search: __('Search')
});
} else {
markup = converse.templates.add_contact_form({
markup = _converse.templates.add_contact_form({
label_contact_username: __('e.g. user@example.org'),
label_add: __('Add')
});
}
if (converse.allow_contact_requests) {
widgets += converse.templates.add_contact_dropdown({
if (_converse.allow_contact_requests) {
widgets += _converse.templates.add_contact_dropdown({
label_click_to_chat: __('Click to add new chat contacts'),
label_add_contact: __('Add a contact')
});
@ -646,7 +646,7 @@
searchContacts: function (ev) {
ev.preventDefault();
$.getJSON(converse.xhr_user_search_url+ "?q=" + $(ev.target).find('input.username').val(), function (data) {
$.getJSON(_converse.xhr_user_search_url+ "?q=" + $(ev.target).find('input.username').val(), function (data) {
var $ul= $('.search-xmpp ul');
$ul.find('li.found-user').remove();
$ul.find('li.chat-info').remove();
@ -675,7 +675,7 @@
$input.addClass('error');
return;
}
converse.roster.addAndSubscribe(jid);
_converse.roster.addAndSubscribe(jid);
$('.search-xmpp').hide();
},
@ -684,14 +684,14 @@
var $target = $(ev.target),
jid = $target.attr('data-recipient'),
name = $target.text();
converse.roster.addAndSubscribe(jid, name);
_converse.roster.addAndSubscribe(jid, name);
$target.parent().remove();
$('.search-xmpp').hide();
}
});
converse.ControlBoxToggle = Backbone.View.extend({
_converse.ControlBoxToggle = Backbone.View.extend({
tagName: 'a',
className: 'toggle-controlbox hidden',
id: 'toggle-controlbox',
@ -703,14 +703,14 @@
},
initialize: function () {
converse.chatboxviews.$el.prepend(this.render());
_converse.chatboxviews.$el.prepend(this.render());
this.updateOnlineCount();
var that = this;
converse.on('initialized', function () {
converse.roster.on("add", that.updateOnlineCount, that);
converse.roster.on('change', that.updateOnlineCount, that);
converse.roster.on("destroy", that.updateOnlineCount, that);
converse.roster.on("remove", that.updateOnlineCount, that);
_converse.on('initialized', function () {
_converse.roster.on("add", that.updateOnlineCount, that);
_converse.roster.on('change', that.updateOnlineCount, that);
_converse.roster.on("destroy", that.updateOnlineCount, that);
_converse.roster.on("remove", that.updateOnlineCount, that);
});
},
@ -720,22 +720,22 @@
// artifacts (i.e. on page load the toggle is shown only to then
// seconds later be hidden in favor of the control box).
return this.$el.html(
converse.templates.controlbox_toggle({
_converse.templates.controlbox_toggle({
'label_toggle': __('Toggle chat')
})
);
},
updateOnlineCount: _.debounce(function () {
if (_.isUndefined(converse.roster)) {
if (_.isUndefined(_converse.roster)) {
return;
}
var $count = this.$('#online-count');
$count.text('('+converse.roster.getNumOnlineContacts()+')');
$count.text('('+_converse.roster.getNumOnlineContacts()+')');
if (!$count.is(':visible')) {
$count.show();
}
}, converse.animate ? 100 : 0),
}, _converse.animate ? 100 : 0),
hide: function (callback) {
this.el.classList.add('hidden');
@ -747,11 +747,11 @@
},
showControlBox: function () {
var controlbox = converse.chatboxes.get('controlbox');
var controlbox = _converse.chatboxes.get('controlbox');
if (!controlbox) {
controlbox = converse.addControlBox();
controlbox = _converse.addControlBox();
}
if (converse.connection.connected) {
if (_converse.connection.connected) {
controlbox.save({closed: false});
} else {
controlbox.trigger('show');
@ -761,8 +761,8 @@
onClick: function (e) {
e.preventDefault();
if ($("div#controlbox").is(':visible')) {
var controlbox = converse.chatboxes.get('controlbox');
if (converse.connection.connected) {
var controlbox = _converse.chatboxes.get('controlbox');
if (_converse.connection.connected) {
controlbox.save({closed: true});
} else {
controlbox.trigger('hide');
@ -779,25 +779,24 @@
* "onConnected" will be called, to fetch the roster again and
* to send out a presence stanza.
*/
var view = converse.chatboxviews.get('controlbox');
var view = _converse.chatboxviews.get('controlbox');
view.model.set({connected:false});
view.$('#controlbox-tabs').empty();
view.renderLoginPanel();
};
converse.on('disconnected', disconnect);
_converse.on('disconnected', disconnect);
var afterReconnected = function () {
/* After reconnection makes sure the controlbox's is aware.
*/
var view = converse.chatboxviews.get('controlbox');
var view = _converse.chatboxviews.get('controlbox');
if (view.model.get('connected')) {
converse.chatboxviews.get("controlbox").onConnected();
_converse.chatboxviews.get("controlbox").onConnected();
} else {
view.model.set({connected:true});
}
};
converse.on('reconnected', afterReconnected);
_converse.on('reconnected', afterReconnected);
}
});
}));

File diff suppressed because it is too large Load Diff

View File

@ -15,11 +15,11 @@
"converse-muc", // XXX: would like to remove this
"converse-controlbox"
], factory);
}(this, function (converse, converse_api, tpl_dragresize) {
}(this, function (_converse, converse_api, tpl_dragresize) {
"use strict";
var $ = converse_api.env.jQuery,
_ = converse_api.env._;
converse.templates.dragresize = tpl_dragresize;
_converse.templates.dragresize = tpl_dragresize;
converse_api.plugins.add('converse-dragresize', {
@ -67,8 +67,8 @@
height = this.get('height'), width = this.get('width'),
save = this.get('id') === 'controlbox' ? this.set.bind(this) : this.save.bind(this);
save({
'height': converse.applyDragResistance(height, this.get('default_height')),
'width': converse.applyDragResistance(width, this.get('default_width')),
'height': _converse.applyDragResistance(height, this.get('default_height')),
'width': _converse.applyDragResistance(width, this.get('default_width')),
});
return result;
}
@ -125,7 +125,7 @@
// Initialize last known mouse position
this.prev_pageY = 0;
this.prev_pageX = 0;
if (converse.connection.connected) {
if (_converse.connection.connected) {
this.height = this.model.get('height');
this.width = this.model.get('width');
}
@ -141,7 +141,7 @@
setChatBoxHeight: function (height) {
if (height) {
height = converse.applyDragResistance(height, this.model.get('default_height'))+'px';
height = _converse.applyDragResistance(height, this.model.get('default_height'))+'px';
} else {
height = "";
}
@ -150,7 +150,7 @@
setChatBoxWidth: function (width) {
if (width) {
width = converse.applyDragResistance(width, this.model.get('default_width'))+'px';
width = _converse.applyDragResistance(width, this.model.get('default_width'))+'px';
} else {
width = "";
}
@ -176,10 +176,10 @@
},
onStartVerticalResize: function (ev) {
if (!converse.allow_dragresize) { return true; }
if (!_converse.allow_dragresize) { return true; }
// Record element attributes for mouseMove().
this.height = this.$el.children('.box-flyout').height();
converse.resizing = {
_converse.resizing = {
'chatbox': this,
'direction': 'top'
};
@ -187,9 +187,9 @@
},
onStartHorizontalResize: function (ev) {
if (!converse.allow_dragresize) { return true; }
if (!_converse.allow_dragresize) { return true; }
this.width = this.$el.children('.box-flyout').width();
converse.resizing = {
_converse.resizing = {
'chatbox': this,
'direction': 'left'
};
@ -199,12 +199,12 @@
onStartDiagonalResize: function (ev) {
this.onStartHorizontalResize(ev);
this.onStartVerticalResize(ev);
converse.resizing.direction = 'topleft';
_converse.resizing.direction = 'topleft';
},
resizeChatBox: function (ev) {
var diff;
if (converse.resizing.direction.indexOf('top') === 0) {
if (_converse.resizing.direction.indexOf('top') === 0) {
diff = ev.pageY - this.prev_pageY;
if (diff) {
this.height = ((this.height-diff) > (this.model.get('min_height') || 0)) ? (this.height-diff) : this.model.get('min_height');
@ -212,7 +212,7 @@
this.setChatBoxHeight(this.height);
}
}
if (_.includes(converse.resizing.direction, 'left')) {
if (_.includes(_converse.resizing.direction, 'left')) {
diff = this.prev_pageX - ev.pageX;
if (diff) {
this.width = ((this.width+diff) > (this.model.get('min_width') || 0)) ? (this.width+diff) : this.model.get('min_width');
@ -288,7 +288,7 @@
renderDragResizeHandles: function () {
var flyout = this.el.querySelector('.box-flyout');
var div = document.createElement('div');
div.innerHTML = converse.templates.dragresize();
div.innerHTML = _converse.templates.dragresize();
flyout.insertBefore(
div,
flyout.firstChild
@ -301,11 +301,11 @@
/* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery.
*/
var converse = this.converse;
var _converse = this.converse;
this.updateSettings({
allow_dragresize: true,
});
converse.applyDragResistance = function (value, default_value) {
_converse.applyDragResistance = function (value, default_value) {
/* This method applies some resistance around the
* default_value. If value is close enough to
* default_value, then default_value is returned instead.

View File

@ -12,24 +12,24 @@
"converse-api",
"converse-chatview"
], factory);
}(this, function (converse, converse_api) {
}(this, function (_converse, converse_api) {
"use strict";
var _ = converse_api.env._,
utils = converse_api.env.utils,
__ = utils.__.bind(converse);
__ = utils.__.bind(_converse);
var onHeadlineMessage = function (message) {
/* Handler method for all incoming messages of type "headline".
*/
var from_jid = message.getAttribute('from');
if (utils.isHeadlineMessage(message)) {
converse.chatboxes.create({
_converse.chatboxes.create({
'id': from_jid,
'jid': from_jid,
'fullname': from_jid,
'type': 'headline'
}).createMessage(message, undefined, message);
converse.emit('message', message);
_converse.emit('message', message);
}
return true;
};
@ -47,7 +47,7 @@
onChatBoxAdded: function (item) {
var view = this.get(item.get('id'));
if (!view && item.get('type') === 'headline') {
view = new converse.HeadlinesBoxView({model: item});
view = new _converse.HeadlinesBoxView({model: item});
this.add(item.get('id'), view);
return view;
} else {
@ -61,7 +61,7 @@
/* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery.
*/
converse.HeadlinesBoxView = converse.ChatBoxView.extend({
_converse.HeadlinesBoxView = _converse.ChatBoxView.extend({
className: 'chatbox headlines',
events: {
@ -77,14 +77,14 @@
this.model.on('destroy', this.hide, this);
this.model.on('change:minimized', this.onMinimizedChanged, this);
this.render().fetchMessages().insertIntoDOM().hide();
converse.emit('chatBoxInitialized', this);
_converse.emit('chatBoxInitialized', this);
},
render: function () {
this.$el.attr('id', this.model.get('box_id'))
.html(converse.templates.chatbox(
.html(_converse.templates.chatbox(
_.extend(this.model.toJSON(), {
show_toolbar: converse.show_toolbar,
show_toolbar: _converse.show_toolbar,
show_textarea: false,
title: this.model.get('fullname'),
unread_msgs: __('You have unread messages'),
@ -95,18 +95,18 @@
)
);
this.$content = this.$el.find('.chat-content');
converse.emit('chatBoxOpened', this);
_converse.emit('chatBoxOpened', this);
utils.refreshWebkit();
return this;
}
});
var registerHeadlineHandler = function () {
converse.connection.addHandler(
_converse.connection.addHandler(
onHeadlineMessage, null, 'message');
};
converse.on('connected', registerHeadlineHandler);
converse.on('reconnected', registerHeadlineHandler);
_converse.on('connected', registerHeadlineHandler);
_converse.on('reconnected', registerHeadlineHandler);
}
});
}));

View File

@ -16,7 +16,7 @@
"converse-muc", // Could be made a soft dependency
"strophe.rsm"
], factory);
}(this, function (converse, converse_api) {
}(this, function (_converse, converse_api) {
"use strict";
var $ = converse_api.env.jQuery,
Strophe = converse_api.env.Strophe,
@ -43,7 +43,7 @@
Features: {
addClientFeatures: function () {
converse.connection.disco.addFeature(Strophe.NS.MAM);
_converse.connection.disco.addFeature(Strophe.NS.MAM);
return this.__super__.addClientFeatures.apply(this, arguments);
}
},
@ -66,16 +66,16 @@
},
afterMessagesFetched: function () {
if (this.disable_mam || !converse.features.findWhere({'var': Strophe.NS.MAM})) {
if (this.disable_mam || !_converse.features.findWhere({'var': Strophe.NS.MAM})) {
return this.__super__.afterMessagesFetched.apply(this, arguments);
}
if (!this.model.get('mam_initialized') &&
this.model.messages.length < converse.archived_messages_page_size) {
this.model.messages.length < _converse.archived_messages_page_size) {
this.fetchArchivedMessages({
'before': '', // Page backwards from the most recent message
'with': this.model.get('jid'),
'max': converse.archived_messages_page_size
'max': _converse.archived_messages_page_size
});
this.model.save({'mam_initialized': true});
}
@ -88,23 +88,23 @@
* Then, upon receiving them, call onMessage on the chat box,
* so that they are displayed inside it.
*/
if (!converse.features.findWhere({'var': Strophe.NS.MAM})) {
converse.log("Attempted to fetch archived messages but this user's server doesn't support XEP-0313");
if (!_converse.features.findWhere({'var': Strophe.NS.MAM})) {
_converse.log("Attempted to fetch archived messages but this user's server doesn't support XEP-0313");
return;
}
if (this.disable_mam) {
return;
}
this.addSpinner();
converse.queryForArchivedMessages(options, function (messages) {
_converse.queryForArchivedMessages(options, function (messages) {
this.clearSpinner();
if (messages.length) {
_.each(messages, converse.chatboxes.onMessage.bind(converse.chatboxes));
_.each(messages, _converse.chatboxes.onMessage.bind(_converse.chatboxes));
}
}.bind(this),
function () {
this.clearSpinner();
converse.log("Error or timeout while trying to fetch archived messages", "error");
_converse.log("Error or timeout while trying to fetch archived messages", "error");
}.bind(this)
);
},
@ -114,7 +114,7 @@
this.fetchArchivedMessages({
'before': this.model.messages.at(0).get('archive_id'),
'with': this.model.get('jid'),
'max': converse.archived_messages_page_size
'max': _converse.archived_messages_page_size
});
}
},
@ -136,7 +136,7 @@
initialize: function () {
/* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery.
* loaded by Converse.js's plugin machinery.
*/
this.updateSettings({
archived_messages_page_size: '20',
@ -144,7 +144,7 @@
message_archiving_timeout: 8000, // Time (in milliseconds) to wait before aborting MAM request
});
converse.queryForArchivedMessages = function (options, callback, errback) {
_converse.queryForArchivedMessages = function (options, callback, errback) {
/* Do a MAM (XEP-0313) query for archived messages.
*
* Parameters:
@ -168,13 +168,13 @@
errback = callback;
}
/*
if (!converse.features.findWhere({'var': Strophe.NS.MAM})) {
converse.log('This server does not support XEP-0313, Message Archive Management');
if (!_converse.features.findWhere({'var': Strophe.NS.MAM})) {
_converse.log('This server does not support XEP-0313, Message Archive Management');
errback(null);
return;
}
*/
var queryid = converse.connection.getUniqueId();
var queryid = _converse.connection.getUniqueId();
var attrs = {'type':'set'};
if (!_.isUndefined(options) && options.groupchat) {
if (!options['with']) {
@ -210,7 +210,7 @@
}
if (_.isFunction(callback)) {
converse.connection.addHandler(function (message) {
_converse.connection.addHandler(function (message) {
var $msg = $(message), rsm,
$fin = $msg.find('fin[xmlns="'+Strophe.NS.MAM+'"]');
if ($fin.length && $fin.attr('queryid') === queryid) {
@ -225,27 +225,27 @@
return true;
}, Strophe.NS.MAM);
}
converse.connection.sendIQ(stanza, null, errback, converse.message_archiving_timeout);
_converse.connection.sendIQ(stanza, null, errback, _converse.message_archiving_timeout);
};
_.extend(converse.api, {
_.extend(_converse.api, {
/* Extend default converse.js API to add methods specific to MAM
*/
'archive': {
'query': converse.queryForArchivedMessages.bind(converse)
'query': _converse.queryForArchivedMessages.bind(_converse)
}
});
converse.onMAMError = function (iq) {
_converse.onMAMError = function (iq) {
if ($(iq).find('feature-not-implemented').length) {
converse.log("Message Archive Management (XEP-0313) not supported by this browser");
_converse.log("Message Archive Management (XEP-0313) not supported by this browser");
} else {
converse.log("An error occured while trying to set archiving preferences.");
converse.log(iq);
_converse.log("An error occured while trying to set archiving preferences.");
_converse.log(iq);
}
};
converse.onMAMPreferences = function (feature, iq) {
_converse.onMAMPreferences = function (feature, iq) {
/* Handle returned IQ stanza containing Message Archive
* Management (XEP-0313) preferences.
*
@ -259,37 +259,37 @@
var $prefs = $(iq).find('prefs[xmlns="'+Strophe.NS.MAM+'"]');
var default_pref = $prefs.attr('default');
var stanza;
if (default_pref !== converse.message_archiving) {
stanza = $iq({'type': 'set'}).c('prefs', {'xmlns':Strophe.NS.MAM, 'default':converse.message_archiving});
if (default_pref !== _converse.message_archiving) {
stanza = $iq({'type': 'set'}).c('prefs', {'xmlns':Strophe.NS.MAM, 'default':_converse.message_archiving});
$prefs.children().each(function (idx, child) {
stanza.cnode(child).up();
});
converse.connection.sendIQ(stanza, _.partial(function (feature, iq) {
_converse.connection.sendIQ(stanza, _.partial(function (feature, iq) {
// XXX: Strictly speaking, the server should respond with the updated prefs
// (see example 18: https://xmpp.org/extensions/xep-0313.html#config)
// but Prosody doesn't do this, so we don't rely on it.
feature.save({'preferences': {'default':converse.message_archiving}});
feature.save({'preferences': {'default':_converse.message_archiving}});
}, feature),
converse.onMAMError
_converse.onMAMError
);
} else {
feature.save({'preferences': {'default':converse.message_archiving}});
feature.save({'preferences': {'default':_converse.message_archiving}});
}
};
var onFeatureAdded = function (feature) {
var prefs = feature.get('preferences') || {};
if (feature.get('var') === Strophe.NS.MAM && prefs['default'] !== converse.message_archiving) {
if (feature.get('var') === Strophe.NS.MAM && prefs['default'] !== _converse.message_archiving) {
// Ask the server for archiving preferences
converse.connection.sendIQ(
_converse.connection.sendIQ(
$iq({'type': 'get'}).c('prefs', {'xmlns': Strophe.NS.MAM}),
_.partial(converse.onMAMPreferences, feature),
_.partial(converse.onMAMError, feature)
_.partial(_converse.onMAMPreferences, feature),
_.partial(_converse.onMAMError, feature)
);
}
};
converse.on('serviceDiscovered', onFeatureAdded.bind(converse.features));
_converse.on('serviceDiscovered', onFeatureAdded.bind(_converse.features));
}
});
}));

View File

@ -19,7 +19,7 @@
"converse-muc"
], factory);
}(this, function (
converse,
_converse,
converse_api,
tpl_chatbox_minimize,
tpl_toggle_chats,
@ -27,17 +27,17 @@
tpl_chats_panel
) {
"use strict";
converse.templates.chatbox_minimize = tpl_chatbox_minimize;
converse.templates.toggle_chats = tpl_toggle_chats;
converse.templates.trimmed_chat = tpl_trimmed_chat;
converse.templates.chats_panel = tpl_chats_panel;
_converse.templates.chatbox_minimize = tpl_chatbox_minimize;
_converse.templates.toggle_chats = tpl_toggle_chats;
_converse.templates.trimmed_chat = tpl_trimmed_chat;
_converse.templates.chats_panel = tpl_chats_panel;
var $ = converse_api.env.jQuery,
_ = converse_api.env._,
b64_sha1 = converse_api.env.b64_sha1,
moment = converse_api.env.moment,
utils = converse_api.env.utils,
__ = utils.__.bind(converse);
__ = utils.__.bind(_converse);
converse_api.plugins.add('converse-minimize', {
@ -50,16 +50,16 @@
initChatBoxes: function () {
var result = this.__super__.initChatBoxes.apply(this, arguments);
converse.minimized_chats = new converse.MinimizedChats({
model: converse.chatboxes
_converse.minimized_chats = new _converse.MinimizedChats({
model: _converse.chatboxes
});
return result;
},
registerGlobalEventHandlers: function () {
$(window).on("resize", _.debounce(function (ev) {
if (converse.connection.connected) {
converse.chatboxviews.trimChats();
if (_converse.connection.connected) {
_converse.chatboxviews.trimChats();
}
}, 200));
return this.__super__.registerGlobalEventHandlers.apply(this, arguments);
@ -116,7 +116,7 @@
_show: function () {
this.__super__._show.apply(this, arguments);
if (!this.model.get('minimized')) {
converse.chatboxviews.trimChats(this);
_converse.chatboxviews.trimChats(this);
}
},
@ -147,9 +147,9 @@
maximize: function () {
// Restores a minimized chat box
this.$el.insertAfter(converse.chatboxviews.get("controlbox").$el);
this.$el.insertAfter(_converse.chatboxviews.get("controlbox").$el);
this.show();
converse.emit('chatBoxMaximized', this);
_converse.emit('chatBoxMaximized', this);
return this;
},
@ -157,9 +157,9 @@
if (ev && ev.preventDefault) { ev.preventDefault(); }
// save the scroll position to restore it on maximize
this.model.save({'scroll': this.$content.scrollTop()});
this.setChatState(converse.INACTIVE).model.minimize();
this.setChatState(_converse.INACTIVE).model.minimize();
this.hide();
converse.emit('chatBoxMinimized', this);
_converse.emit('chatBoxMinimized', this);
},
},
@ -187,7 +187,7 @@
var html = this.__super__.generateHeadingHTML.apply(this, arguments);
var div = document.createElement('div');
div.innerHTML = html;
var el = converse.templates.chatbox_minimize(
var el = _converse.templates.chatbox_minimize(
{info_minimize: __('Minimize this chat box')}
);
var button = div.querySelector('.close-chatbox-button');
@ -244,7 +244,7 @@
* to create space.
*/
var shown_chats = this.getShownChats();
if (converse.no_trimming || shown_chats.length <= 1) {
if (_converse.no_trimming || shown_chats.length <= 1) {
return;
}
if (this.getChatBoxWidth(shown_chats[0]) === $('body').outerWidth(true)) {
@ -254,7 +254,7 @@
return;
}
var oldest_chat, boxes_width, view,
$minimized = converse.minimized_chats.$el,
$minimized = _converse.minimized_chats.$el,
minimized_width = _.includes(this.model.pluck('minimized'), true) ? $minimized.outerWidth(true) : 0,
new_id = newchat ? newchat.model.get('id') : null;
@ -299,13 +299,13 @@
initialize: function () {
/* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery.
* loaded by Converse.js's plugin machinery.
*/
this.updateSettings({
no_trimming: false, // Set to true for phantomjs tests (where browser apparently has no width)
});
converse.MinimizedChatBoxView = Backbone.View.extend({
_converse.MinimizedChatBoxView = Backbone.View.extend({
tagName: 'div',
className: 'chat-head',
events: {
@ -337,7 +337,7 @@
data.title = this.model.get('fullname');
this.$el.addClass('chat-head-chatbox');
}
return this.$el.html(converse.templates.trimmed_chat(data));
return this.$el.html(_converse.templates.trimmed_chat(data));
},
clearUnreadMessagesCounter: function () {
@ -353,14 +353,14 @@
close: function (ev) {
if (ev && ev.preventDefault) { ev.preventDefault(); }
this.remove();
var view = converse.chatboxviews.get(this.model.get('id'));
var view = _converse.chatboxviews.get(this.model.get('id'));
if (view) {
// This will call model.destroy(), removing it from the
// collection and will also emit 'chatBoxClosed'
view.close();
} else {
this.model.destroy();
converse.emit('chatBoxClosed', this);
_converse.emit('chatBoxClosed', this);
}
return this;
},
@ -373,7 +373,8 @@
}, 200, {'leading': true})
});
converse.MinimizedChats = Backbone.Overview.extend({
_converse.MinimizedChats = Backbone.Overview.extend({
tagName: 'div',
id: "minimized-chats",
className: 'hidden',
@ -399,26 +400,26 @@
},
initToggle: function () {
this.toggleview = new converse.MinimizedChatsToggleView({
model: new converse.MinimizedChatsToggle()
this.toggleview = new _converse.MinimizedChatsToggleView({
model: new _converse.MinimizedChatsToggle()
});
var id = b64_sha1('converse.minchatstoggle'+converse.bare_jid);
var id = b64_sha1('converse.minchatstoggle'+_converse.bare_jid);
this.toggleview.model.id = id; // Appears to be necessary for backbone.browserStorage
this.toggleview.model.browserStorage = new Backbone.BrowserStorage[converse.storage](id);
this.toggleview.model.browserStorage = new Backbone.BrowserStorage[_converse.storage](id);
this.toggleview.model.fetch();
},
render: function () {
if (!this.el.parentElement) {
this.el.innerHTML = converse.templates.chats_panel();
converse.chatboxviews.el.appendChild(this.el);
this.el.innerHTML = _converse.templates.chats_panel();
_converse.chatboxviews.el.appendChild(this.el);
}
if (this.keys().length === 0) {
this.el.classList.add('hidden');
converse.chatboxviews.trimChats.bind(converse.chatboxviews);
_converse.chatboxviews.trimChats.bind(_converse.chatboxviews);
} else if (this.keys().length > 0 && !this.$el.is(':visible')) {
this.el.classList.remove('hidden');
converse.chatboxviews.trimChats();
_converse.chatboxviews.trimChats();
}
return this.$el;
},
@ -446,7 +447,7 @@
if (existing && existing.$el.parent().length !== 0) {
return;
}
var view = new converse.MinimizedChatBoxView({model: item});
var view = new _converse.MinimizedChatBoxView({model: item});
this.$('.minimized-chats-flyout').append(view.render());
this.add(item.get('id'), view);
this.toggleview.model.set({'num_minimized': this.keys().length});
@ -469,7 +470,7 @@
});
converse.MinimizedChatsToggle = Backbone.Model.extend({
_converse.MinimizedChatsToggle = Backbone.Model.extend({
initialize: function () {
this.set({
'collapsed': this.get('collapsed') || false,
@ -480,7 +481,7 @@
});
converse.MinimizedChatsToggleView = Backbone.View.extend({
_converse.MinimizedChatsToggleView = Backbone.View.extend({
el: '#toggle-minimized-chats',
initialize: function () {
@ -490,7 +491,7 @@
},
render: function () {
this.$el.html(converse.templates.toggle_chats(
this.$el.html(_converse.templates.toggle_chats(
_.extend(this.model.toJSON(), {
'Minimized': __('Minimized')
})
@ -507,7 +508,7 @@
var renderMinimizeButton = function (view) {
// Inserts a "minimize" button in the chatview's header
var $el = view.$el.find('.toggle-chatbox-button');
var $new_el = converse.templates.chatbox_minimize(
var $new_el = _converse.templates.chatbox_minimize(
{info_minimize: __('Minimize this chat box')}
);
if ($el.length) {
@ -516,13 +517,13 @@
view.$el.find('.close-chatbox-button').after($new_el);
}
};
converse.on('chatBoxOpened', renderMinimizeButton);
_converse.on('chatBoxOpened', renderMinimizeButton);
converse.on('controlBoxOpened', function (chatbox) {
_converse.on('controlBoxOpened', function (chatbox) {
// Wrapped in anon method because at scan time, chatboxviews
// attr not set yet.
if (converse.connection.connected) {
converse.chatboxviews.trimChats(chatbox);
if (_converse.connection.connected) {
_converse.chatboxviews.trimChats(chatbox);
}
});

View File

@ -31,7 +31,7 @@
"converse-chatview"
], factory);
}(this, function (
converse,
_converse,
converse_api,
tpl_chatarea,
tpl_chatroom,
@ -49,19 +49,19 @@
tpl_room_panel
) {
"use strict";
converse.templates.chatarea = tpl_chatarea;
converse.templates.chatroom = tpl_chatroom;
converse.templates.chatroom_form = tpl_chatroom_form;
converse.templates.chatroom_nickname_form = tpl_chatroom_nickname_form;
converse.templates.chatroom_password_form = tpl_chatroom_password_form;
converse.templates.chatroom_sidebar = tpl_chatroom_sidebar;
converse.templates.chatroom_head = tpl_chatroom_head;
converse.templates.chatrooms_tab = tpl_chatrooms_tab;
converse.templates.info = tpl_info;
converse.templates.occupant = tpl_occupant;
converse.templates.room_description = tpl_room_description;
converse.templates.room_item = tpl_room_item;
converse.templates.room_panel = tpl_room_panel;
_converse.templates.chatarea = tpl_chatarea;
_converse.templates.chatroom = tpl_chatroom;
_converse.templates.chatroom_form = tpl_chatroom_form;
_converse.templates.chatroom_nickname_form = tpl_chatroom_nickname_form;
_converse.templates.chatroom_password_form = tpl_chatroom_password_form;
_converse.templates.chatroom_sidebar = tpl_chatroom_sidebar;
_converse.templates.chatroom_head = tpl_chatroom_head;
_converse.templates.chatrooms_tab = tpl_chatrooms_tab;
_converse.templates.info = tpl_info;
_converse.templates.occupant = tpl_occupant;
_converse.templates.room_description = tpl_room_description;
_converse.templates.room_item = tpl_room_item;
_converse.templates.room_panel = tpl_room_panel;
var ROOMS_PANEL_ID = 'chatrooms';
@ -79,7 +79,7 @@
moment = converse_api.env.moment;
// For translations
var __ = utils.__.bind(converse);
var __ = utils.__.bind(_converse);
var ___ = utils.___;
// Add Strophe Namespaces
@ -112,7 +112,7 @@
* returned via the API.
*/
if (!chatbox) { return; }
var view = converse.chatboxviews.get(chatbox.get('id'));
var view = _converse.chatboxviews.get(chatbox.get('id'));
var box = this.__super__.wrappedChatBox.apply(this, arguments);
box.is_chatroom = view.is_chatroom;
return box;
@ -121,56 +121,56 @@
Features: {
addClientFeatures: function () {
this.__super__.addClientFeatures.apply(this, arguments);
if (converse.allow_muc_invitations) {
converse.connection.disco.addFeature('jabber:x:conference'); // Invites
if (_converse.allow_muc_invitations) {
_converse.connection.disco.addFeature('jabber:x:conference'); // Invites
}
if (converse.allow_muc) {
converse.connection.disco.addFeature(Strophe.NS.MUC);
if (_converse.allow_muc) {
_converse.connection.disco.addFeature(Strophe.NS.MUC);
}
}
},
ControlBoxView: {
renderContactsPanel: function () {
var converse = this.__super__.converse;
var _converse = this.__super__.converse;
this.__super__.renderContactsPanel.apply(this, arguments);
if (converse.allow_muc) {
this.roomspanel = new converse.RoomsPanel({
if (_converse.allow_muc) {
this.roomspanel = new _converse.RoomsPanel({
'$parent': this.$el.find('.controlbox-panes'),
'model': new (Backbone.Model.extend({
id: b64_sha1('converse.roomspanel'+converse.bare_jid), // Required by sessionStorage
browserStorage: new Backbone.BrowserStorage[converse.storage](
b64_sha1('converse.roomspanel'+converse.bare_jid))
id: b64_sha1('converse.roomspanel'+_converse.bare_jid), // Required by sessionStorage
browserStorage: new Backbone.BrowserStorage[_converse.storage](
b64_sha1('converse.roomspanel'+_converse.bare_jid))
}))()
});
this.roomspanel.render().model.fetch();
if (!this.roomspanel.model.get('nick')) {
this.roomspanel.model.save({
nick: Strophe.getNodeFromJid(converse.bare_jid)
nick: Strophe.getNodeFromJid(_converse.bare_jid)
});
}
}
},
onConnected: function () {
var converse = this.__super__.converse;
var _converse = this.__super__.converse;
this.__super__.onConnected.apply(this, arguments);
if (!this.model.get('connected')) {
return;
}
if (_.isUndefined(converse.muc_domain)) {
converse.features.off('add', this.featureAdded, this);
converse.features.on('add', this.featureAdded, this);
if (_.isUndefined(_converse.muc_domain)) {
_converse.features.off('add', this.featureAdded, this);
_converse.features.on('add', this.featureAdded, this);
// Features could have been added before the controlbox was
// initialized. We're only interested in MUC
var feature = converse.features.findWhere({
var feature = _converse.features.findWhere({
'var': Strophe.NS.MUC
});
if (feature) {
this.featureAdded(feature);
}
} else {
this.setMUCDomain(converse.muc_domain);
this.setMUCDomain(_converse.muc_domain);
}
},
@ -183,8 +183,8 @@
},
featureAdded: function (feature) {
var converse = this.__super__.converse;
if ((feature.get('var') === Strophe.NS.MUC) && (converse.allow_muc)) {
var _converse = this.__super__.converse;
if ((feature.get('var') === Strophe.NS.MUC) && (_converse.allow_muc)) {
this.setMUCDomain(feature.get('from'));
}
}
@ -194,7 +194,7 @@
onChatBoxAdded: function (item) {
var view = this.get(item.get('id'));
if (!view && item.get('type') === 'chatroom') {
view = new converse.ChatRoomView({'model': item});
view = new _converse.ChatRoomView({'model': item});
return this.add(item.get('id'), view);
} else {
return this.__super__.onChatBoxAdded.apply(this, arguments);
@ -207,8 +207,6 @@
/* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery.
*/
var converse = this.converse;
// XXX: Inside plugins, all calls to the translation machinery
// (e.g. utils.__) should only be done in the initialize function.
// If called before, we won't know what language the user wants,
@ -236,7 +234,7 @@
* 322 presence Removal from room Inform user that he or she is being removed from the room because the room has been changed to members-only and the user is not a member
* 332 presence Removal from room Inform user that he or she is being removed from the room because of a system shutdown
*/
converse.muc = {
_converse.muc = {
info_messages: {
100: __('This room is not anonymous'),
102: __('This room now shows unavailable members'),
@ -303,12 +301,12 @@
},
});
converse.createChatRoom = function (settings) {
_converse.createChatRoom = function (settings) {
/* Creates a new chat room, making sure that certain attributes
* are correct, for example that the "type" is set to
* "chatroom".
*/
return converse.chatboxviews.showChat(
return _converse.chatboxviews.showChat(
_.extend(settings, {
'type': 'chatroom',
'affiliation': null,
@ -330,7 +328,7 @@
);
};
converse.ChatRoomView = converse.ChatBoxView.extend({
_converse.ChatRoomView = _converse.ChatBoxView.extend({
/* Backbone View which renders a chat room, based upon the view
* for normal one-on-one chat boxes.
*/
@ -372,17 +370,17 @@
this.getRoomFeatures().always(function () {
that.join();
that.fetchMessages();
converse.emit('chatRoomOpened', that);
_converse.emit('chatRoomOpened', that);
});
},
createOccupantsView: function () {
/* Create the ChatRoomOccupantsView Backbone.View
*/
this.occupantsview = new converse.ChatRoomOccupantsView({
model: new converse.ChatRoomOccupants()
this.occupantsview = new _converse.ChatRoomOccupantsView({
model: new _converse.ChatRoomOccupants()
});
var id = b64_sha1('converse.occupants'+converse.bare_jid+this.model.get('jid'));
var id = b64_sha1('converse.occupants'+_converse.bare_jid+this.model.get('jid'));
this.occupantsview.model.browserStorage = new Backbone.BrowserStorage.session(id);
this.occupantsview.chatroomview = this;
this.occupantsview.render();
@ -390,7 +388,7 @@
},
insertIntoDOM: function () {
var view = converse.chatboxviews.get("controlbox");
var view = _converse.chatboxviews.get("controlbox");
if (view) {
this.$el.insertAfter(view.$el);
} else {
@ -401,7 +399,7 @@
render: function () {
this.$el.attr('id', this.model.get('box_id'))
.html(converse.templates.chatroom());
.html(_converse.templates.chatroom());
this.renderHeading();
this.renderChatArea();
utils.refreshWebkit();
@ -412,7 +410,7 @@
/* Pure function which returns the heading HTML to be
* rendered.
*/
return converse.templates.chatroom_head(
return _converse.templates.chatroom_head(
_.extend(this.model.toJSON(), {
info_close: __('Close and leave this room'),
info_configure: __('Configure this room'),
@ -432,9 +430,9 @@
if (!this.$('.chat-area').length) {
this.$('.chatroom-body').empty()
.append(
converse.templates.chatarea({
_converse.templates.chatarea({
'unread_msgs': __('You have unread messages'),
'show_toolbar': converse.show_toolbar,
'show_toolbar': _converse.show_toolbar,
'label_message': __('Message')
}))
.append(this.occupantsview.$el);
@ -447,10 +445,10 @@
getToolbarOptions: function () {
return _.extend(
converse.ChatBoxView.prototype.getToolbarOptions.apply(this, arguments),
_converse.ChatBoxView.prototype.getToolbarOptions.apply(this, arguments),
{
label_hide_occupants: __('Hide the list of occupants'),
show_occupants_toggle: this.is_chatroom && converse.visible_toolbar_buttons.toggle_occupants
show_occupants_toggle: this.is_chatroom && _converse.visible_toolbar_buttons.toggle_occupants
}
);
},
@ -517,7 +515,7 @@
var iq = $iq({to: chatroom_jid, type: "get"})
.c("query", {xmlns: Strophe.NS.MUC_ADMIN})
.c("item", {'affiliation': affiliation});
converse.connection.sendIQ(iq, deferred.resolve, deferred.reject);
_converse.connection.sendIQ(iq, deferred.resolve, deferred.reject);
return deferred.promise();
},
@ -753,12 +751,12 @@
if (reason !== null) { attrs.reason = reason; }
if (this.model.get('password')) { attrs.password = this.model.get('password'); }
var invitation = $msg({
from: converse.connection.jid,
from: _converse.connection.jid,
to: recipient,
id: converse.connection.getUniqueId()
id: _converse.connection.getUniqueId()
}).c('x', attrs);
converse.connection.send(invitation);
converse.emit('roomInviteSent', {
_converse.connection.send(invitation);
_converse.emit('roomInviteSent', {
'room': this,
'recipient': recipient,
'reason': reason
@ -778,8 +776,8 @@
// We ignore them here...
return;
}
if (message.get('chat_state') !== converse.GONE) {
converse.ChatBoxView.prototype.handleChatStateMessage.apply(this, arguments);
if (message.get('chat_state') !== _converse.GONE) {
_converse.ChatBoxView.prototype.handleChatStateMessage.apply(this, arguments);
}
},
@ -789,11 +787,11 @@
* See XEP-0085 Chat State Notifications.
*/
var chat_state = this.model.get('chat_state');
if (chat_state === converse.GONE) {
if (chat_state === _converse.GONE) {
// <gone/> is not applicable within MUC context
return;
}
converse.connection.send(
_converse.connection.send(
$msg({'to':this.model.get('jid'), 'type': 'groupchat'})
.c(chat_state, {'xmlns': Strophe.NS.CHATSTATES}).up()
.c('no-store', {'xmlns': Strophe.NS.HINTS}).up()
@ -808,15 +806,15 @@
* Parameters:
* (String) text: The message text to be sent.
*/
var msgid = converse.connection.getUniqueId();
var msgid = _converse.connection.getUniqueId();
var msg = $msg({
to: this.model.get('jid'),
from: converse.connection.jid,
from: _converse.connection.jid,
type: 'groupchat',
id: msgid
}).c("body").t(text).up()
.c("x", {xmlns: "jabber:x:event"}).c(converse.COMPOSING);
converse.connection.send(msg);
.c("x", {xmlns: "jabber:x:event"}).c(_converse.COMPOSING);
_converse.connection.send(msg);
this.model.messages.create({
fullname: this.model.get('nick'),
sender: 'me',
@ -830,7 +828,7 @@
var item = $build("item", {nick: nick, role: role});
var iq = $iq({to: room, type: "set"}).c("query", {xmlns: Strophe.NS.MUC_ADMIN}).cnode(item.node);
if (reason !== null) { iq.c("reason", reason); }
return converse.connection.sendIQ(iq.tree(), onSuccess, onError);
return _converse.connection.sendIQ(iq.tree(), onSuccess, onError);
},
validateRoleChangeCommand: function (command, args) {
@ -870,7 +868,7 @@
* Parameters:
* (String) text - The message text.
*/
if (converse.muc_disable_moderator_commands) {
if (_converse.muc_disable_moderator_commands) {
return this.sendChatRoomMessage(text);
}
var match = text.replace(/^\s*/, "").match(/^\/(.*?)(?: (.*))?$/) || [false, '', ''],
@ -940,10 +938,10 @@
}]).fail(this.onCommandError.bind(this));
break;
case 'nick':
converse.connection.send($pres({
from: converse.connection.jid,
_converse.connection.send($pres({
from: _converse.connection.jid,
to: this.getRoomJIDAndNick(match[2]),
id: converse.connection.getUniqueId()
id: _converse.connection.getUniqueId()
}).tree());
break;
case 'owner':
@ -968,10 +966,10 @@
break;
case 'topic':
case 'subject':
converse.connection.send(
_converse.connection.send(
$msg({
to: this.model.get('jid'),
from: converse.connection.jid,
from: _converse.connection.jid,
type: "groupchat"
}).c("subject", {xmlns: "jabber:client"}).t(match[2]).tree()
);
@ -1041,12 +1039,12 @@
*/
var room_jid = this.model.get('jid');
this.removeHandlers();
this.presence_handler = converse.connection.addHandler(
this.presence_handler = _converse.connection.addHandler(
this.onChatRoomPresence.bind(this),
Strophe.NS.MUC, 'presence', null, null, room_jid,
{'ignoreNamespaceFragment': true, 'matchBareFromJid': true}
);
this.message_handler = converse.connection.addHandler(
this.message_handler = _converse.connection.addHandler(
this.handleMUCMessage.bind(this),
null, 'message', null, null, room_jid,
{'matchBareFromJid': true}
@ -1058,11 +1056,11 @@
* registered for this chat room.
*/
if (this.message_handler) {
converse.connection.deleteHandler(this.message_handler);
_converse.connection.deleteHandler(this.message_handler);
delete this.message_handler;
}
if (this.presence_handler) {
converse.connection.deleteHandler(this.presence_handler);
_converse.connection.deleteHandler(this.presence_handler);
delete this.presence_handler;
}
return this;
@ -1087,22 +1085,22 @@
return this;
}
var stanza = $pres({
'from': converse.connection.jid,
'from': _converse.connection.jid,
'to': this.getRoomJIDAndNick(nick)
}).c("x", {'xmlns': Strophe.NS.MUC})
.c("history", {'maxstanzas': converse.muc_history_max_stanzas}).up();
.c("history", {'maxstanzas': _converse.muc_history_max_stanzas}).up();
if (password) {
stanza.cnode(Strophe.xmlElement("password", [], password));
}
this.model.save('connection_status', Strophe.Status.CONNECTING);
converse.connection.send(stanza);
_converse.connection.send(stanza);
return this;
},
cleanup: function () {
this.model.save('connection_status', Strophe.Status.DISCONNECTED);
this.removeHandlers();
converse.ChatBoxView.prototype.close.apply(this, arguments);
_converse.ChatBoxView.prototype.close.apply(this, arguments);
},
leave: function(exit_msg) {
@ -1115,7 +1113,7 @@
this.hide();
this.occupantsview.model.reset();
this.occupantsview.model.browserStorage._clear();
if (!converse.connection.connected ||
if (!_converse.connection.connected ||
this.model.get('connection_status') === Strophe.Status.DISCONNECTED) {
// Don't send out a stanza if we're not connected.
this.cleanup();
@ -1123,13 +1121,13 @@
}
var presence = $pres({
type: "unavailable",
from: converse.connection.jid,
from: _converse.connection.jid,
to: this.getRoomJIDAndNick()
});
if (exit_msg !== null) {
presence.c("status", exit_msg);
}
converse.connection.sendPresence(
_converse.connection.sendPresence(
presence,
this.cleanup.bind(this),
this.cleanup.bind(this),
@ -1152,7 +1150,7 @@
$body.children().addClass('hidden');
// Remove any existing forms
$body.find('form.chatroom-form').remove();
$body.append(converse.templates.chatroom_form());
$body.append(_converse.templates.chatroom_form());
var $form = $body.find('form.chatroom-form'),
$fieldset = $form.children('fieldset:first'),
@ -1202,7 +1200,7 @@
_.each(config || [], function (node) { iq.cnode(node).up(); });
onSuccess = _.isUndefined(onSuccess) ? _.noop : _.partial(onSuccess, iq.nodeTree);
onError = _.isUndefined(onError) ? _.noop : _.partial(onError, iq.nodeTree);
return converse.connection.sendIQ(iq, onSuccess, onError);
return _converse.connection.sendIQ(iq, onSuccess, onError);
},
saveConfiguration: function (form) {
@ -1294,7 +1292,7 @@
*/
var that = this;
var deferred = new $.Deferred();
converse.connection.sendIQ(
_converse.connection.sendIQ(
$iq({
'to': this.model.get('jid'),
'type': "get"
@ -1316,7 +1314,7 @@
*/
var deferred = new $.Deferred();
var that = this;
converse.connection.disco.info(this.model.get('jid'), null,
_converse.connection.disco.info(this.model.get('jid'), null,
function (iq) {
/*
* See http://xmpp.org/extensions/xep-0045.html#disco-roominfo
@ -1403,10 +1401,10 @@
* form.
*/
this.showSpinner();
converse.connection.sendIQ(
_converse.connection.sendIQ(
$iq({
'to': this.model.get('jid'),
'from': converse.connection.jid,
'from': _converse.connection.jid,
'type': "get"
}).c("query", {
'xmlns': Strophe.NS.DISCO_INFO,
@ -1439,10 +1437,10 @@
},
onNickNameNotFound: function (message) {
if (converse.muc_nickname_from_jid) {
if (_converse.muc_nickname_from_jid) {
// We try to enter the room with the node part of
// the user's JID.
this.join(Strophe.unescapeNode(Strophe.getNodeFromJid(converse.bare_jid)));
this.join(Strophe.unescapeNode(Strophe.getNodeFromJid(_converse.bare_jid)));
} else {
this.renderNicknameForm(message);
}
@ -1454,7 +1452,7 @@
* We put this in a separate method so that it can be
* overridden by plugins.
*/
return Strophe.unescapeNode(Strophe.getNodeFromJid(converse.bare_jid));
return Strophe.unescapeNode(Strophe.getNodeFromJid(_converse.bare_jid));
},
onNicknameClash: function (presence) {
@ -1466,7 +1464,7 @@
* Which option is take depends on the value of
* muc_nickname_from_jid.
*/
if (converse.muc_nickname_from_jid) {
if (_converse.muc_nickname_from_jid) {
var nick = presence.getAttribute('from').split('/')[1];
if (nick === this.getDefaultNickName()) {
this.join(nick + '-2');
@ -1492,7 +1490,7 @@
message = '';
}
this.$('.chatroom-body').append(
converse.templates.chatroom_nickname_form({
_converse.templates.chatroom_nickname_form({
heading: __('Please choose your nickname'),
label_nickname: __('Nickname'),
label_join: __('Enter room'),
@ -1512,7 +1510,7 @@
this.$('.chatroom-body').children().addClass('hidden');
this.$('span.centered.spinner').remove();
this.$('.chatroom-body').append(
converse.templates.chatroom_password_form({
_converse.templates.chatroom_password_form({
heading: __('This chatroom requires a password'),
label_password: __('Password: '),
label_submit: __('Submit')
@ -1538,17 +1536,17 @@
from_nick;
if (is_self && code === "210") {
from_nick = Strophe.unescapeNode(Strophe.getResourceFromJid(stanza.getAttribute('from')));
return __(converse.muc.new_nickname_messages[code], from_nick);
return __(_converse.muc.new_nickname_messages[code], from_nick);
} else if (is_self && code === "303") {
return __(
converse.muc.new_nickname_messages[code],
_converse.muc.new_nickname_messages[code],
stanza.querySelector('x item').getAttribute('nick')
);
} else if (!is_self && (code in converse.muc.action_info_messages)) {
} else if (!is_self && (code in _converse.muc.action_info_messages)) {
from_nick = Strophe.unescapeNode(Strophe.getResourceFromJid(stanza.getAttribute('from')));
return __(converse.muc.action_info_messages[code], from_nick);
} else if (code in converse.muc.info_messages) {
return converse.muc.info_messages[code];
return __(_converse.muc.action_info_messages[code], from_nick);
} else if (code in _converse.muc.info_messages) {
return _converse.muc.info_messages[code];
} else if (code !== '110') {
if (stat.textContent) {
// Sometimes the status contains human readable text and not a code.
@ -1575,7 +1573,7 @@
var item = $(pres).find('x[xmlns="'+Strophe.NS.MUC_USER+'"] item').get(0);
if (_.isUndefined(item)) { return; }
var jid = item.getAttribute('jid');
if (Strophe.getBareJidFromJid(jid) === converse.bare_jid) {
if (Strophe.getBareJidFromJid(jid) === _converse.bare_jid) {
var affiliation = item.getAttribute('affiliation');
var role = item.getAttribute('role');
if (affiliation) {
@ -1600,11 +1598,11 @@
};
// 2. Get disconnection messages based on the <status> elements
var codes = _.invokeMap(statuses, Element.prototype.getAttribute, 'code');
var disconnection_codes = _.intersection(codes, _.keys(converse.muc.disconnect_messages));
var disconnection_codes = _.intersection(codes, _.keys(_converse.muc.disconnect_messages));
var disconnected = is_self && disconnection_codes.length > 0;
if (disconnected) {
notification.disconnected = true;
notification.disconnection_message = converse.muc.disconnect_messages[disconnection_codes[0]];
notification.disconnection_message = _converse.muc.disconnect_messages[disconnection_codes[0]];
}
// 3. Find the reason and actor from the <item> element
var item = x.querySelector('item');
@ -1643,7 +1641,7 @@
return;
}
_.each(notification.messages, function (message) {
that.$content.append(converse.templates.info({'message': message}));
that.$content.append(_converse.templates.info({'message': message}));
});
if (notification.reason) {
this.showStatusNotification(__('The reason given is: "'+notification.reason+'"'), true);
@ -1764,7 +1762,7 @@
// This is a new room. It will now be configured
// and the configuration cached on the
// Backbone.Model.
if (converse.muc_instant_rooms) {
if (_converse.muc_instant_rooms) {
this.createInstantRoom(); // Accept default configuration
} else {
this.configureChatRoom();
@ -1798,7 +1796,7 @@
// For translators: the %1$s and %2$s parts will get replaced by the user and topic text respectively
// Example: Topic set by JC Brand to: Hello World!
this.$content.append(
converse.templates.info({
_converse.templates.info({
'message': __('Topic set by %1$s to: %2$s', sender, subject)
}));
this.scrollDown();
@ -1842,7 +1840,7 @@
this.model.createMessage(message, delay, original_stanza);
if (sender !== this.model.get('nick')) {
// We only emit an event if it's not our own message
converse.emit('message', msg);
_converse.emit('message', message);
}
return true;
},
@ -1854,12 +1852,12 @@
* so that they are displayed inside it.
*/
var that = this;
if (!converse.features.findWhere({'var': Strophe.NS.MAM})) {
converse.log("Attempted to fetch archived messages but this user's server doesn't support XEP-0313");
if (!_converse.features.findWhere({'var': Strophe.NS.MAM})) {
_converse.log("Attempted to fetch archived messages but this user's server doesn't support XEP-0313");
return;
}
this.addSpinner();
converse.api.archive.query(_.extend(options, {'groupchat': true}),
_converse.api.archive.query(_.extend(options, {'groupchat': true}),
function (messages) {
that.clearSpinner();
if (messages.length) {
@ -1868,21 +1866,21 @@
},
function () {
that.clearSpinner();
converse.log("Error while trying to fetch archived messages", "error");
_converse.log("Error while trying to fetch archived messages", "error");
}
);
}
});
converse.ChatRoomOccupant = Backbone.Model.extend({
_converse.ChatRoomOccupant = Backbone.Model.extend({
initialize: function (attributes) {
this.set(_.extend({
'id': converse.connection.getUniqueId(),
'id': _converse.connection.getUniqueId(),
}, attributes));
}
});
converse.ChatRoomOccupantView = Backbone.View.extend({
_converse.ChatRoomOccupantView = Backbone.View.extend({
tagName: 'li',
initialize: function () {
this.model.on('change', this.render, this);
@ -1890,7 +1888,7 @@
},
render: function () {
var new_el = converse.templates.occupant(
var new_el = _converse.templates.occupant(
_.extend(
this.model.toJSON(), {
'hint_occupant': __('Click to mention this user in your message.'),
@ -1916,11 +1914,11 @@
}
});
converse.ChatRoomOccupants = Backbone.Collection.extend({
model: converse.ChatRoomOccupant
_converse.ChatRoomOccupants = Backbone.Collection.extend({
model: _converse.ChatRoomOccupant
});
converse.ChatRoomOccupantsView = Backbone.Overview.extend({
_converse.ChatRoomOccupantsView = Backbone.Overview.extend({
tagName: 'div',
className: 'occupants',
@ -1930,13 +1928,13 @@
render: function () {
this.$el.html(
converse.templates.chatroom_sidebar({
'allow_muc_invitations': converse.allow_muc_invitations,
_converse.templates.chatroom_sidebar({
'allow_muc_invitations': _converse.allow_muc_invitations,
'label_invitation': __('Invite'),
'label_occupants': __('Occupants')
})
);
if (converse.allow_muc_invitations) {
if (_converse.allow_muc_invitations) {
return this.initInviteWidget();
}
return this;
@ -1945,7 +1943,7 @@
onOccupantAdded: function (item) {
var view = this.get(item.get('id'));
if (!view) {
view = this.add(item.get('id'), new converse.ChatRoomOccupantView({model: item}));
view = this.add(item.get('id'), new _converse.ChatRoomOccupantView({model: item}));
} else {
delete view.model; // Remove ref to old model to help garbage collection
view.model = item;
@ -2046,7 +2044,7 @@
name: 'contacts-dataset',
source: function (q, cb) {
cb(_.map(
converse.roster.filter(utils.contains(['fullname', 'jid'], q)),
_converse.roster.filter(utils.contains(['fullname', 'jid'], q)),
function (n) {
return {value: n.get('fullname'), jid: n.get('jid')};
}
@ -2070,7 +2068,7 @@
}
});
converse.RoomsPanel = Backbone.View.extend({
_converse.RoomsPanel = Backbone.View.extend({
/* Backbone View which renders the "Rooms" tab and accompanying
* panel in the control box.
*
@ -2098,9 +2096,9 @@
render: function () {
this.$parent.append(
this.$el.html(
converse.templates.room_panel({
'server_input_type': converse.hide_muc_server && 'hidden' || 'text',
'server_label_global_attr': converse.hide_muc_server && ' hidden' || '',
_converse.templates.room_panel({
'server_input_type': _converse.hide_muc_server && 'hidden' || 'text',
'server_label_global_attr': _converse.hide_muc_server && ' hidden' || '',
'label_room_name': __('Room name'),
'label_nickname': __('Nickname'),
'label_server': __('Server'),
@ -2110,8 +2108,8 @@
));
this.$tabs = this.$parent.parent().find('#controlbox-tabs');
var controlbox = converse.chatboxes.get('controlbox');
this.$tabs.append(converse.templates.chatrooms_tab({
var controlbox = _converse.chatboxes.get('controlbox');
this.$tabs.append(_converse.templates.chatrooms_tab({
'label_rooms': __('Rooms'),
'is_current': controlbox.get('active-panel') === ROOMS_PANEL_ID
}));
@ -2124,7 +2122,7 @@
onDomainChange: function (model) {
var $server = this.$el.find('input.new-chatroom-server');
$server.val(model.get('muc_domain'));
if (converse.auto_list_rooms) {
if (_converse.auto_list_rooms) {
this.updateRoomsList();
}
},
@ -2157,7 +2155,7 @@
name = Strophe.unescapeNode($(this.rooms[i]).attr('name')||$(this.rooms[i]).attr('jid'));
jid = $(this.rooms[i]).attr('jid');
fragment.appendChild($(
converse.templates.room_item({
_converse.templates.room_item({
'name':name,
'jid':jid,
'open_title': __('Click to open this room'),
@ -2176,10 +2174,10 @@
updateRoomsList: function () {
/* Send and IQ stanza to the server asking for all rooms
*/
converse.connection.sendIQ(
_converse.connection.sendIQ(
$iq({
to: this.model.get('muc_domain'),
from: converse.connection.jid,
from: _converse.connection.jid,
type: "get"
}).c("query", {xmlns: Strophe.NS.DISCO_ITEMS}),
this.onRoomsFound.bind(this),
@ -2215,7 +2213,7 @@
var $stanza = $(stanza);
// All MUC features found here: http://xmpp.org/registrar/disco-features.html
$(el).find('span.spinner').replaceWith(
converse.templates.room_description({
_converse.templates.room_description({
'desc': $stanza.find('field[var="muc#roominfo_description"] value').text(),
'occ': $stanza.find('field[var="muc#roominfo_occupants"] value').text(),
'hidden': $stanza.find('feature[var="muc_hidden"]').length,
@ -2258,7 +2256,7 @@
} else {
$parent.find('span.spinner').remove();
$parent.append('<span class="spinner hor_centered"/>');
converse.connection.disco.info(
_converse.connection.disco.info(
$(target).attr('data-room-jid'), null, _.partial(this.insertRoomInfo, $parent[0])
);
}
@ -2287,7 +2285,7 @@
return;
}
}
converse.createChatRoom({
_converse.createChatRoom({
'id': jid,
'jid': jid,
'name': name || Strophe.unescapeNode(Strophe.getNodeFromJid(jid)),
@ -2307,7 +2305,7 @@
/************************ End of ChatRoomView **********************/
converse.onDirectMUCInvitation = function (message) {
_converse.onDirectMUCInvitation = function (message) {
/* A direct MUC invitation to join a room has been received
* See XEP-0249: Direct MUC invitations.
*
@ -2320,10 +2318,10 @@
from = Strophe.getBareJidFromJid($message.attr('from')),
room_jid = $x.attr('jid'),
reason = $x.attr('reason'),
contact = converse.roster.get(from),
contact = _converse.roster.get(from),
result;
if (converse.auto_join_on_invite) {
if (_converse.auto_join_on_invite) {
result = true;
} else {
// Invite request might come from someone not your roster list
@ -2341,11 +2339,11 @@
}
}
if (result === true) {
var chatroom = converse.createChatRoom({
var chatroom = _converse.createChatRoom({
'id': room_jid,
'jid': room_jid,
'name': Strophe.unescapeNode(Strophe.getNodeFromJid(room_jid)),
'nick': Strophe.unescapeNode(Strophe.getNodeFromJid(converse.connection.jid)),
'nick': Strophe.unescapeNode(Strophe.getNodeFromJid(_converse.connection.jid)),
'type': 'chatroom',
'box_id': b64_sha1(room_jid),
'password': $x.attr('password')
@ -2354,21 +2352,21 @@
[Strophe.Status.CONNECTING, Strophe.Status.CONNECTED],
chatroom.get('connection_status'))
) {
converse.chatboxviews.get(room_jid).join();
_converse.chatboxviews.get(room_jid).join();
}
}
};
if (converse.allow_muc_invitations) {
if (_converse.allow_muc_invitations) {
var registerDirectInvitationHandler = function () {
converse.connection.addHandler(
_converse.connection.addHandler(
function (message) {
converse.onDirectMUCInvitation(message);
_converse.onDirectMUCInvitation(message);
return true;
}, 'jabber:x:conference', 'message');
};
converse.on('connected', registerDirectInvitationHandler);
converse.on('reconnected', registerDirectInvitationHandler);
_converse.on('connected', registerDirectInvitationHandler);
_converse.on('reconnected', registerDirectInvitationHandler);
}
var autoJoinRooms = function () {
@ -2377,21 +2375,21 @@
* of strings (room JIDs) or objects (with room JID and other
* settings).
*/
_.each(converse.auto_join_rooms, function (room) {
_.each(_converse.auto_join_rooms, function (room) {
if (_.isString(room)) {
converse.api.rooms.open(room);
_converse.api.rooms.open(room);
} else if (_.isObject(room)) {
converse_api.rooms.open(room.jid, room.nick);
_converse_api.rooms.open(room.jid, room.nick);
} else {
converse.log('Invalid room criteria specified for "auto_join_rooms"', 'error');
_converse.log('Invalid room criteria specified for "auto_join_rooms"', 'error');
}
});
};
converse.on('chatBoxesFetched', autoJoinRooms);
_converse.on('chatBoxesFetched', autoJoinRooms);
converse.getWrappedChatRoom = function (jid, attrs, fetcher) {
_converse.getWrappedChatRoom = function (jid, attrs, fetcher) {
jid = jid.toLowerCase();
return converse.wrappedChatBox(fetcher(_.extend({
return _converse.wrappedChatBox(fetcher(_.extend({
'id': jid,
'jid': jid,
'name': Strophe.unescapeNode(Strophe.getNodeFromJid(jid)),
@ -2404,21 +2402,21 @@
/* We extend the default converse.js API to add methods specific to MUC
* chat rooms.
*/
_.extend(converse.api, {
_.extend(_converse.api, {
'rooms': {
'close': function (jids) {
if (_.isUndefined(jids)) {
converse.chatboxviews.each(function (view) {
_converse.chatboxviews.each(function (view) {
if (view.is_chatroom && view.model) {
view.close();
}
});
} else if (_.isString(jids)) {
var view = converse.chatboxviews.get(jids);
var view = _converse.chatboxviews.get(jids);
if (view) { view.close(); }
} else {
_.each(jids, function (jid) {
var view = converse.chatboxviews.get(jid);
var view = _converse.chatboxviews.get(jid);
if (view) { view.close(); }
});
}
@ -2432,15 +2430,15 @@
if (_.isUndefined(attrs.maximize)) {
attrs.maximize = false;
}
if (!attrs.nick && converse.muc_nickname_from_jid) {
attrs.nick = Strophe.getNodeFromJid(converse.bare_jid);
if (!attrs.nick && _converse.muc_nickname_from_jid) {
attrs.nick = Strophe.getNodeFromJid(_converse.bare_jid);
}
if (_.isUndefined(jids)) {
throw new TypeError('rooms.open: You need to provide at least one JID');
} else if (_.isString(jids)) {
return converse.getWrappedChatRoom(jids, attrs, converse.createChatRoom);
return _converse.getWrappedChatRoom(jids, attrs, _converse.createChatRoom);
}
return _.map(jids, _.partial(converse.getWrappedChatRoom, _, attrs, converse.createChatRoom));
return _.map(jids, _.partial(_converse.getWrappedChatRoom, _, attrs, _converse.createChatRoom));
},
'get': function (jids, attrs, create) {
if (_.isString(attrs)) {
@ -2450,21 +2448,21 @@
}
if (_.isUndefined(jids)) {
var result = [];
converse.chatboxes.each(function (chatbox) {
_converse.chatboxes.each(function (chatbox) {
if (chatbox.get('type') === 'chatroom') {
result.push(converse.wrappedChatBox(chatbox));
result.push(_converse.wrappedChatBox(chatbox));
}
});
return result;
}
var fetcher = _.partial(converse.chatboxviews.getChatBox.bind(converse.chatboxviews), _, create);
var fetcher = _.partial(_converse.chatboxviews.getChatBox.bind(_converse.chatboxviews), _, create);
if (!attrs.nick) {
attrs.nick = Strophe.getNodeFromJid(converse.bare_jid);
attrs.nick = Strophe.getNodeFromJid(_converse.bare_jid);
}
if (_.isString(jids)) {
return converse.getWrappedChatRoom(jids, attrs, fetcher);
return _converse.getWrappedChatRoom(jids, attrs, fetcher);
}
return _.map(jids, _.partial(converse.getWrappedChatRoom, _, attrs, fetcher));
return _.map(jids, _.partial(_converse.getWrappedChatRoom, _, attrs, fetcher));
}
}
});
@ -2473,28 +2471,28 @@
/* Upon a reconnection event from converse, join again
* all the open chat rooms.
*/
converse.chatboxviews.each(function (view) {
_converse.chatboxviews.each(function (view) {
if (view.model.get('type') === 'chatroom') {
view.model.save('connection_status', Strophe.Status.DISCONNECTED);
view.join();
}
});
};
converse.on('reconnected', reconnectToChatRooms);
_converse.on('reconnected', reconnectToChatRooms);
var disconnectChatRooms = function () {
/* When disconnecting, or reconnecting, mark all chat rooms as
* disconnected, so that they will be properly entered again
* when fetched from session storage.
*/
converse.chatboxes.each(function (model) {
_converse.chatboxes.each(function (model) {
if (model.get('type') === 'chatroom') {
model.save('connection_status', Strophe.Status.DISCONNECTED);
}
});
};
converse.on('reconnecting', disconnectChatRooms);
converse.on('disconnecting', disconnectChatRooms);
_converse.on('reconnecting', disconnectChatRooms);
_converse.on('disconnecting', disconnectChatRooms);
}
});
}));

View File

@ -8,14 +8,14 @@
(function (root, factory) {
define("converse-notification", ["converse-core", "converse-api"], factory);
}(this, function (converse, converse_api) {
}(this, function (_converse, converse_api) {
"use strict";
var $ = converse_api.env.jQuery,
utils = converse_api.env.utils,
Strophe = converse_api.env.Strophe,
_ = converse_api.env._;
// For translations
var __ = utils.__.bind(converse);
var __ = utils.__.bind(_converse);
var ___ = utils.___;
@ -25,8 +25,8 @@
/* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery.
*/
var converse = this.converse;
converse.supports_html5_notification = "Notification" in window;
var _converse = this.converse;
_converse.supports_html5_notification = "Notification" in window;
this.updateSettings({
notify_all_room_messages: false,
@ -38,23 +38,23 @@
notification_icon: '/logo/conversejs128.png'
});
converse.isOnlyChatStateNotification = function ($msg) {
_converse.isOnlyChatStateNotification = function ($msg) {
// See XEP-0085 Chat State Notification
return (
$msg.find('body').length === 0 && (
$msg.find(converse.ACTIVE).length !== 0 ||
$msg.find(converse.COMPOSING).length !== 0 ||
$msg.find(converse.INACTIVE).length !== 0 ||
$msg.find(converse.PAUSED).length !== 0 ||
$msg.find(converse.GONE).length !== 0
$msg.find(_converse.ACTIVE).length !== 0 ||
$msg.find(_converse.COMPOSING).length !== 0 ||
$msg.find(_converse.INACTIVE).length !== 0 ||
$msg.find(_converse.PAUSED).length !== 0 ||
$msg.find(_converse.GONE).length !== 0
)
);
};
converse.shouldNotifyOfGroupMessage = function ($message) {
_converse.shouldNotifyOfGroupMessage = function ($message) {
/* Is this a group message worthy of notification?
*/
var notify_all = converse.notify_all_room_messages,
var notify_all = _converse.notify_all_room_messages,
jid = $message.attr('from'),
resource = Strophe.getResourceFromJid(jid),
room_jid = Strophe.getBareJidFromJid(jid),
@ -62,7 +62,7 @@
if (sender === '' || $message.find('delay').length > 0) {
return false;
}
var room = converse.chatboxes.get(room_jid);
var room = _converse.chatboxes.get(room_jid);
var $body = $message.children('body');
if (!$body.length) {
return false;
@ -75,7 +75,7 @@
return true;
};
converse.shouldNotifyOfMessage = function (message) {
_converse.shouldNotifyOfMessage = function (message) {
/* Is this a message worthy of notification?
*/
if (utils.isOTRMessage(message)) {
@ -86,45 +86,45 @@
if ($forwarded.length) {
return false;
} else if ($message.attr('type') === 'groupchat') {
return converse.shouldNotifyOfGroupMessage($message);
return _converse.shouldNotifyOfGroupMessage($message);
} else if (utils.isHeadlineMessage(message)) {
// We want to show notifications for headline messages.
return true;
}
var is_me = Strophe.getBareJidFromJid($message.attr('from')) === converse.bare_jid;
return !converse.isOnlyChatStateNotification($message) && !is_me;
var is_me = Strophe.getBareJidFromJid($message.attr('from')) === _converse.bare_jid;
return !_converse.isOnlyChatStateNotification($message) && !is_me;
};
converse.playSoundNotification = function ($message) {
_converse.playSoundNotification = function ($message) {
/* Plays a sound to notify that a new message was recieved.
*/
// XXX Eventually this can be refactored to use Notification's sound
// feature, but no browser currently supports it.
// https://developer.mozilla.org/en-US/docs/Web/API/notification/sound
var audio;
if (converse.play_sounds && !_.isUndefined(Audio)) {
audio = new Audio(converse.sounds_path+"msg_received.ogg");
if (_converse.play_sounds && !_.isUndefined(Audio)) {
audio = new Audio(_converse.sounds_path+"msg_received.ogg");
if (audio.canPlayType('/audio/ogg')) {
audio.play();
} else {
audio = new Audio(converse.sounds_path+"msg_received.mp3");
audio = new Audio(_converse.sounds_path+"msg_received.mp3");
audio.play();
}
}
};
converse.areDesktopNotificationsEnabled = function (ignore_hidden) {
var enabled = converse.supports_html5_notification &&
converse.show_desktop_notifications &&
_converse.areDesktopNotificationsEnabled = function (ignore_hidden) {
var enabled = _converse.supports_html5_notification &&
_converse.show_desktop_notifications &&
Notification.permission === "granted";
if (ignore_hidden) {
return enabled;
} else {
return enabled && converse.windowState === 'hidden';
return enabled && _converse.windowState === 'hidden';
}
};
converse.showMessageNotification = function ($message) {
_converse.showMessageNotification = function ($message) {
/* Shows an HTML5 Notification to indicate that a new chat
* message was received.
*/
@ -138,28 +138,28 @@
if ($message.attr('type') === 'groupchat') {
title = __(___("%1$s says"), Strophe.getResourceFromJid(from_jid));
} else {
if (_.isUndefined(converse.roster)) {
converse.log("Could not send notification, because roster is undefined", "error");
if (_.isUndefined(_converse.roster)) {
_converse.log("Could not send notification, because roster is undefined", "error");
return;
}
contact_jid = Strophe.getBareJidFromJid($message.attr('from'));
roster_item = converse.roster.get(contact_jid);
roster_item = _converse.roster.get(contact_jid);
title = __(___("%1$s says"), roster_item.get('fullname'));
}
}
n = new Notification(title, {
body: $message.children('body').text(),
lang: converse.i18n.locale_data.converse[""].lang,
icon: converse.notification_icon
lang: _converse.i18n.locale_data.converse[""].lang,
icon: _converse.notification_icon
});
setTimeout(n.close.bind(n), 5000);
};
converse.showChatStateNotification = function (contact) {
_converse.showChatStateNotification = function (contact) {
/* Creates an HTML5 Notification to inform of a change in a
* contact's chat state.
*/
if (_.includes(converse.chatstate_notification_blacklist, contact.jid)) {
if (_.includes(_converse.chatstate_notification_blacklist, contact.jid)) {
// Don't notify if the user is being ignored.
return;
}
@ -179,85 +179,85 @@
}
var n = new Notification(contact.fullname, {
body: message,
lang: converse.i18n.locale_data.converse[""].lang,
lang: _converse.i18n.locale_data._converse[""].lang,
icon: 'logo/conversejs.png'
});
setTimeout(n.close.bind(n), 5000);
};
converse.showContactRequestNotification = function (contact) {
_converse.showContactRequestNotification = function (contact) {
var n = new Notification(contact.fullname, {
body: __('wants to be your contact'),
lang: converse.i18n.locale_data.converse[""].lang,
lang: _converse.i18n.locale_data._converse[""].lang,
icon: 'logo/conversejs.png'
});
setTimeout(n.close.bind(n), 5000);
};
converse.showFeedbackNotification = function (data) {
_converse.showFeedbackNotification = function (data) {
if (data.klass === 'error' || data.klass === 'warn') {
var n = new Notification(data.subject, {
body: data.message,
lang: converse.i18n.locale_data.converse[""].lang,
lang: _converse.i18n.locale_data._converse[""].lang,
icon: 'logo/conversejs.png'
});
setTimeout(n.close.bind(n), 5000);
}
};
converse.handleChatStateNotification = function (contact) {
_converse.handleChatStateNotification = function (contact) {
/* Event handler for on('contactStatusChanged').
* Will show an HTML5 notification to indicate that the chat
* status has changed.
*/
if (converse.areDesktopNotificationsEnabled()) {
converse.showChatStateNotification(contact);
if (_converse.areDesktopNotificationsEnabled()) {
_converse.showChatStateNotification(contact);
}
};
converse.handleMessageNotification = function (message) {
_converse.handleMessageNotification = function (message) {
/* Event handler for the on('message') event. Will call methods
* to play sounds and show HTML5 notifications.
*/
var $message = $(message);
if (!converse.shouldNotifyOfMessage(message)) {
if (!_converse.shouldNotifyOfMessage(message)) {
return false;
}
converse.playSoundNotification($message);
if (converse.areDesktopNotificationsEnabled()) {
converse.showMessageNotification($message);
_converse.playSoundNotification($message);
if (_converse.areDesktopNotificationsEnabled()) {
_converse.showMessageNotification($message);
}
};
converse.handleContactRequestNotification = function (contact) {
if (converse.areDesktopNotificationsEnabled(true)) {
converse.showContactRequestNotification(contact);
_converse.handleContactRequestNotification = function (contact) {
if (_converse.areDesktopNotificationsEnabled(true)) {
_converse.showContactRequestNotification(contact);
}
};
converse.handleFeedback = function (data) {
if (converse.areDesktopNotificationsEnabled(true)) {
converse.showFeedbackNotification(data);
_converse.handleFeedback = function (data) {
if (_converse.areDesktopNotificationsEnabled(true)) {
_converse.showFeedbackNotification(data);
}
};
converse.requestPermission = function () {
if (converse.supports_html5_notification &&
_converse.requestPermission = function () {
if (_converse.supports_html5_notification &&
! _.includes(['denied', 'granted'], Notification.permission)) {
// Ask user to enable HTML5 notifications
Notification.requestPermission();
}
};
converse.on('pluginsInitialized', function () {
_converse.on('pluginsInitialized', function () {
// We only register event handlers after all plugins are
// registered, because other plugins might override some of our
// handlers.
converse.on('contactRequest', converse.handleContactRequestNotification);
converse.on('contactStatusChanged', converse.handleChatStateNotification);
converse.on('message', converse.handleMessageNotification);
converse.on('feedback', converse.handleFeedback);
converse.on('connected', converse.requestPermission);
_converse.on('contactRequest', _converse.handleContactRequestNotification);
_converse.on('contactStatusChanged', _converse.handleChatStateNotification);
_converse.on('message', _converse.handleMessageNotification);
_converse.on('feedback', _converse.handleFeedback);
_converse.on('connected', _converse.requestPermission);
});
}
});

View File

@ -16,9 +16,9 @@
"converse-api",
"tpl!toolbar_otr"
], factory);
}(this, function (otr, converse, converse_api, tpl_toolbar_otr) {
}(this, function (otr, _converse, converse_api, tpl_toolbar_otr) {
"use strict";
converse.templates.toolbar_otr = tpl_toolbar_otr;
_converse.templates.toolbar_otr = tpl_toolbar_otr;
// Strophe methods for building stanzas
var Strophe = converse_api.env.Strophe,
utils = converse_api.env.utils,
@ -28,7 +28,7 @@
_ = converse_api.env._;
// For translations
var __ = utils.__.bind(converse);
var __ = utils.__.bind(_converse);
var HAS_CSPRNG = ((!_.isUndefined(crypto)) &&
((_.isFunction(crypto.randomBytes)) || (_.isFunction(crypto.getRandomValues))
@ -108,10 +108,10 @@
},
createMessage: function (message, delay, original_stanza) {
var converse = this.__super__.converse,
var _converse = this.__super__.converse,
text = _.propertyOf(message.querySelector('body'))('textContent');
if ((!text) || (!converse.allow_otr)) {
if ((!text) || (!_converse.allow_otr)) {
return this.__super__.createMessage.apply(this, arguments);
}
if (text.match(/^\?OTRv23?/)) {
@ -135,11 +135,11 @@
},
getSession: function (callback) {
var converse = this.__super__.converse;
var _converse = this.__super__.converse;
var cipher = CryptoJS.lib.PasswordBasedCipher;
var pass, instance_tag, saved_key, pass_check;
if (converse.cache_otr_key) {
pass = converse.otr.getSessionPassphrase();
if (_converse.cache_otr_key) {
pass = _converse.otr.getSessionPassphrase();
if (!_.isUndefined(pass)) {
instance_tag = window.sessionStorage[b64_sha1(this.id+'instance_tag')];
saved_key = window.sessionStorage[b64_sha1(this.id+'priv_key')];
@ -169,7 +169,7 @@
window.setTimeout(function () {
var instance_tag = otr.OTR.makeInstanceTag();
callback({
'key': converse.otr.generatePrivateKey.call(this, instance_tag),
'key': _converse.otr.generatePrivateKey.call(this, instance_tag),
'instance_tag': instance_tag
});
}, 500);
@ -226,7 +226,7 @@
// send the query message to them.
this.save({'otr_status': UNENCRYPTED});
this.getSession(function (session) {
var converse = this.__super__.converse;
var _converse = this.__super__.converse;
this.otr = new otr.OTR({
fragment_size: 140,
send_interval: 200,
@ -241,7 +241,7 @@
this.trigger('showReceivedOTRMessage', msg);
}.bind(this));
this.otr.on('io', function (msg) {
this.trigger('sendMessage', new converse.Message({ message: msg }));
this.trigger('sendMessage', new _converse.Message({ message: msg }));
}.bind(this));
this.otr.on('error', function (msg) {
this.trigger('showOTRError', msg);
@ -273,7 +273,7 @@
},
initialize: function () {
var converse = this.__super__.converse;
var _converse = this.__super__.converse;
this.__super__.initialize.apply(this, arguments);
this.model.on('change:otr_status', this.onOTRStatusChanged, this);
this.model.on('showOTRError', this.showOTRError, this);
@ -283,7 +283,7 @@
this.model.on('showReceivedOTRMessage', function (text) {
this.showMessage({'message': text, 'sender': 'them'});
}, this);
if ((_.includes([UNVERIFIED, VERIFIED], this.model.get('otr_status'))) || converse.use_otr_by_default) {
if ((_.contains([UNVERIFIED, VERIFIED], this.model.get('otr_status'))) || _converse.use_otr_by_default) {
this.model.initiateOTR();
}
},
@ -301,8 +301,8 @@
},
onMessageSubmitted: function (text) {
var converse = this.__super__.converse;
if (!converse.connection.authenticated) {
var _converse = this.__super__.converse;
if (!_converse.connection.authenticated) {
return this.showHelpMessages(
['Sorry, the connection has been lost, '+
'and your message could not be sent'],
@ -311,9 +311,9 @@
}
var match = text.replace(/^\s*/, "").match(/^\/(.*)\s*$/);
if (match) {
if ((converse.allow_otr) && (match[1] === "endotr")) {
if ((_converse.allow_otr) && (match[1] === "endotr")) {
return this.endOTR();
} else if ((converse.allow_otr) && (match[1] === "otr")) {
} else if ((_converse.allow_otr) && (match[1] === "otr")) {
return this.model.initiateOTR();
}
}
@ -346,7 +346,7 @@
},
showOTRError: function (msg) {
var converse = this.__super__.converse;
var _converse = this.__super__.converse;
if (msg === 'Message cannot be sent at this time.') {
this.showHelpMessages(
[__('Your message could not be sent')], 'error');
@ -360,7 +360,7 @@
} else {
this.showHelpMessages(['Encryption error occured: '+msg], 'error');
}
converse.log("OTR ERROR:"+msg);
_converse.log("OTR ERROR:"+msg);
},
startOTRFromToolbar: function (ev) {
@ -378,13 +378,13 @@
},
authOTR: function (ev) {
var converse = this.__super__.converse;
var _converse = this.__super__.converse;
var scheme = $(ev.target).data().scheme;
var result, question, answer;
if (scheme === 'fingerprint') {
result = confirm(__('Here are the fingerprints, please confirm them with %1$s, outside of this chat.\n\nFingerprint for you, %2$s: %3$s\n\nFingerprint for %1$s: %4$s\n\nIf you have confirmed that the fingerprints match, click OK, otherwise click Cancel.', [
this.model.get('fullname'),
converse.xmppstatus.get('fullname')||converse.bare_jid,
_converse.xmppstatus.get('fullname')||_converse.bare_jid,
this.model.otr.priv.fingerprint(),
this.model.otr.their_priv_pk.fingerprint()
]
@ -425,8 +425,8 @@
},
renderToolbar: function (toolbar, options) {
var converse = this.__super__.converse;
if (!converse.show_toolbar) {
var _converse = this.__super__.converse;
if (!_converse.show_toolbar) {
return;
}
var data = this.model.toJSON();
@ -436,7 +436,7 @@
UNVERIFIED: UNVERIFIED,
VERIFIED: VERIFIED,
// FIXME: Leaky abstraction MUC
allow_otr: converse.allow_otr && !this.is_chatroom,
allow_otr: _converse.allow_otr && !this.is_chatroom,
label_end_encrypted_conversation: __('End encrypted conversation'),
label_refresh_encrypted_conversation: __('Refresh encrypted conversation'),
label_start_encrypted_conversation: __('Start encrypted conversation'),
@ -449,7 +449,7 @@
});
this.__super__.renderToolbar.apply(this, arguments);
this.$el.find('.chat-toolbar').append(
converse.templates.toolbar_otr(
_converse.templates.toolbar_otr(
_.extend(this.model.toJSON(), options || {})
));
return this;
@ -461,7 +461,7 @@
/* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery.
*/
var converse = this.converse;
var _converse = this.converse;
// Translation aware constants
// ---------------------------
// We can only call the __ translation method *after* converse.js
@ -474,29 +474,29 @@
OTR_TRANSLATED_MAPPING[FINISHED] = __('finished');
// For translations
__ = utils.__.bind(converse);
__ = utils.__.bind(_converse);
// Configuration values for this plugin
var settings = {
allow_otr: true,
cache_otr_key: false,
use_otr_by_default: false
};
_.extend(converse.default_settings, settings);
_.extend(converse, settings);
_.extend(converse, _.pick(converse.user_settings, _.keys(settings)));
_.extend(_converse.default_settings, settings);
_.extend(_converse, settings);
_.extend(_converse, _.pick(_converse.user_settings, _.keys(settings)));
// Only allow OTR if we have the capability
converse.allow_otr = converse.allow_otr && HAS_CRYPTO;
_converse.allow_otr = _converse.allow_otr && HAS_CRYPTO;
// Only use OTR by default if allow OTR is enabled to begin with
converse.use_otr_by_default = converse.use_otr_by_default && converse.allow_otr;
_converse.use_otr_by_default = _converse.use_otr_by_default && _converse.allow_otr;
// Backbone Models and Views
// -------------------------
converse.OTR = Backbone.Model.extend({
_converse.OTR = Backbone.Model.extend({
// A model for managing OTR settings.
getSessionPassphrase: function () {
if (converse.authentication === 'prebind') {
var key = b64_sha1(converse.connection.jid),
if (_converse.authentication === 'prebind') {
var key = b64_sha1(_converse.connection.jid),
pass = window.sessionStorage[key];
if (_.isUndefined(pass)) {
pass = Math.floor(Math.random()*4294967295).toString();
@ -504,14 +504,14 @@
}
return pass;
} else {
return converse.connection.pass;
return _converse.connection.pass;
}
},
generatePrivateKey: function (instance_tag) {
var key = new otr.DSA();
var jid = converse.connection.jid;
if (converse.cache_otr_key) {
var jid = _converse.connection.jid;
if (_converse.cache_otr_key) {
var cipher = CryptoJS.lib.PasswordBasedCipher;
var pass = this.getSessionPassphrase();
if (!_.isUndefined(pass)) {

View File

@ -15,7 +15,7 @@
"converse-api",
"strophe.ping"
], factory);
}(this, function (converse, converse_api) {
}(this, function (_converse, converse_api) {
"use strict";
// Strophe methods for building stanzas
var Strophe = converse_api.env.Strophe;
@ -26,61 +26,61 @@
/* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery.
*/
var converse = this.converse;
var _converse = this.converse;
this.updateSettings({
ping_interval: 180 //in seconds
});
converse.ping = function (jid, success, error, timeout) {
_converse.ping = function (jid, success, error, timeout) {
// XXX: We could first check here if the server advertised that
// it supports PING.
// However, some servers don't advertise while still keeping the
// connection option due to pings.
//
// var feature = converse.features.findWhere({'var': Strophe.NS.PING});
converse.lastStanzaDate = new Date();
// var feature = _converse.features.findWhere({'var': Strophe.NS.PING});
_converse.lastStanzaDate = new Date();
if (_.isNil(jid)) {
jid = Strophe.getDomainFromJid(converse.bare_jid);
jid = Strophe.getDomainFromJid(_converse.bare_jid);
}
if (_.isUndefined(timeout) ) { timeout = null; }
if (_.isUndefined(success) ) { success = null; }
if (_.isUndefined(error) ) { error = null; }
if (converse.connection) {
converse.connection.ping.ping(jid, success, error, timeout);
if (_converse.connection) {
_converse.connection.ping.ping(jid, success, error, timeout);
return true;
}
return false;
};
converse.pong = function (ping) {
converse.lastStanzaDate = new Date();
converse.connection.ping.pong(ping);
_converse.pong = function (ping) {
_converse.lastStanzaDate = new Date();
_converse.connection.ping.pong(ping);
return true;
};
converse.registerPongHandler = function () {
converse.connection.disco.addFeature(Strophe.NS.PING);
converse.connection.ping.addPingHandler(converse.pong);
_converse.registerPongHandler = function () {
_converse.connection.disco.addFeature(Strophe.NS.PING);
_converse.connection.ping.addPingHandler(_converse.pong);
};
converse.registerPingHandler = function () {
converse.registerPongHandler();
if (converse.ping_interval > 0) {
converse.connection.addHandler(function () {
_converse.registerPingHandler = function () {
_converse.registerPongHandler();
if (_converse.ping_interval > 0) {
_converse.connection.addHandler(function () {
/* Handler on each stanza, saves the received date
* in order to ping only when needed.
*/
converse.lastStanzaDate = new Date();
_converse.lastStanzaDate = new Date();
return true;
});
converse.connection.addTimedHandler(1000, function () {
_converse.connection.addTimedHandler(1000, function () {
var now = new Date();
if (!converse.lastStanzaDate) {
converse.lastStanzaDate = now;
if (!_converse.lastStanzaDate) {
_converse.lastStanzaDate = now;
}
if ((now - converse.lastStanzaDate)/1000 > converse.ping_interval) {
return converse.ping();
if ((now - _converse.lastStanzaDate)/1000 > _converse.ping_interval) {
return _converse.ping();
}
return true;
});
@ -89,10 +89,10 @@
var onConnected = function () {
// Wrapper so that we can spy on registerPingHandler in tests
converse.registerPingHandler();
_converse.registerPingHandler();
};
converse.on('connected', onConnected);
converse.on('reconnected', onConnected);
_converse.on('connected', onConnected);
_converse.on('reconnected', onConnected);
}
});
}));

View File

@ -21,7 +21,7 @@
"converse-controlbox"
], factory);
}(this, function (
converse,
_converse,
converse_api,
tpl_form_username,
tpl_register_panel,
@ -30,11 +30,11 @@
tpl_registration_request) {
"use strict";
converse.templates.form_username = tpl_form_username;
converse.templates.register_panel = tpl_register_panel;
converse.templates.register_tab = tpl_register_tab;
converse.templates.registration_form = tpl_registration_form;
converse.templates.registration_request = tpl_registration_request;
_converse.templates.form_username = tpl_form_username;
_converse.templates.register_panel = tpl_register_panel;
_converse.templates.register_tab = tpl_register_tab;
_converse.templates.registration_form = tpl_registration_form;
_converse.templates.registration_request = tpl_registration_request;
// Strophe methods for building stanzas
var Strophe = converse_api.env.Strophe,
@ -44,7 +44,7 @@
var $ = converse_api.env.jQuery,
_ = converse_api.env._;
// For translations
var __ = utils.__.bind(converse);
var __ = utils.__.bind(_converse);
// Add Strophe Namespaces
Strophe.addNamespace('REGISTER', 'jabber:iq:register');
@ -75,9 +75,9 @@
* login panel.
*/
this.__super__.renderLoginPanel.apply(this, arguments);
var converse = this.__super__.converse;
if (converse.allow_registration) {
this.registerpanel = new converse.RegisterPanel({
var _converse = this.__super__.converse;
if (_converse.allow_registration) {
this.registerpanel = new _converse.RegisterPanel({
'$parent': this.$el.find('.controlbox-panes'),
'model': this
});
@ -92,7 +92,7 @@
/* The initialize function gets called as soon as the plugin is
* loaded by converse.js's plugin machinery.
*/
var converse = this.converse;
var _converse = this.converse;
this.updateSettings({
allow_registration: true,
@ -101,7 +101,7 @@
});
converse.RegisterPanel = Backbone.View.extend({
_converse.RegisterPanel = Backbone.View.extend({
tagName: 'div',
id: "register",
className: 'controlbox-pane',
@ -118,16 +118,16 @@
render: function () {
this.$parent.append(this.$el.html(
converse.templates.register_panel({
_converse.templates.register_panel({
'label_domain': __("Your XMPP provider's domain name:"),
'label_register': __('Fetch registration form'),
'help_providers': __('Tip: A list of public XMPP providers is available'),
'help_providers_link': __('here'),
'href_providers': converse.providers_link,
'domain_placeholder': converse.domain_placeholder
'href_providers': _converse.providers_link,
'domain_placeholder': _converse.domain_placeholder
})
));
this.$tabs.append(converse.templates.register_tab({label_register: __('Register')}));
this.$tabs.append(_converse.templates.register_tab({label_register: __('Register')}));
return this;
},
@ -135,7 +135,7 @@
/* Hook into Strophe's _connect_cb, so that we can send an IQ
* requesting the registration fields.
*/
var conn = converse.connection;
var conn = _converse.connection;
var connect_cb = conn._connect_cb.bind(conn);
conn._connect_cb = function (req, callback, raw) {
if (!this._registering) {
@ -155,8 +155,8 @@
* (Strophe.Request) req - The current request
* (Function) callback
*/
converse.log("sendQueryStanza was called");
var conn = converse.connection;
_converse.log("sendQueryStanza was called");
var conn = _converse.connection;
conn.connected = true;
var body = conn._proto._reqToData(req);
@ -190,7 +190,7 @@
* (XMLElement) elem - The query stanza.
*/
if (stanza.getElementsByTagName("query").length !== 1) {
converse.connection._changeConnectStatus(Strophe.Status.REGIFAIL, "unknown");
_converse.connection._changeConnectStatus(Strophe.Status.REGIFAIL, "unknown");
return false;
}
this.setFields(stanza);
@ -231,7 +231,7 @@
return;
}
$form.find('input[type=submit]').hide()
.after(converse.templates.registration_request({
.after(_converse.templates.registration_request({
cancel: __('Cancel'),
info_message: __('Requesting a registration form from the XMPP server')
}));
@ -240,7 +240,7 @@
domain: Strophe.getDomainFromJid(domain),
_registering: true
});
converse.connection.connect(this.domain, "", this.onRegistering.bind(this));
_converse.connection.connect(this.domain, "", this.onRegistering.bind(this));
return false;
},
@ -253,7 +253,7 @@
onRegistering: function (status, error) {
var that;
converse.log('onRegistering');
_converse.log('onRegistering');
if (_.includes([
Strophe.Status.DISCONNECTED,
Strophe.Status.CONNFAIL,
@ -262,7 +262,7 @@
Strophe.Status.CONFLICT
], status)) {
converse.log('Problem during registration: Strophe.Status is: '+status);
_converse.log('Problem during registration: Strophe.Status is: '+status);
this.cancelRegistration();
if (error) {
this.giveFeedback(error, 'error');
@ -273,24 +273,24 @@
), 'error');
}
} else if (status === Strophe.Status.REGISTERED) {
converse.log("Registered successfully.");
converse.connection.reset();
_converse.log("Registered successfully.");
_converse.connection.reset();
that = this;
this.$('form').hide(function () {
$(this).replaceWith('<span class="spinner centered"/>');
if (that.fields.password && that.fields.username) {
// automatically log the user in
converse.connection.connect(
_converse.connection.connect(
that.fields.username.toLowerCase()+'@'+that.domain.toLowerCase(),
that.fields.password,
converse.onConnectStatusChanged
_converse.onConnectStatusChanged
);
converse.chatboxviews.get('controlbox')
_converse.chatboxviews.get('controlbox')
.switchTab({'target': that.$tabs.find('.current')});
converse.giveFeedback(__('Now logging you in'));
_converse.giveFeedback(__('Now logging you in'));
} else {
converse.chatboxviews.get('controlbox').renderLoginPanel();
converse.giveFeedback(__('Registered successfully'));
_converse.chatboxviews.get('controlbox').renderLoginPanel();
_converse.giveFeedback(__('Registered successfully'));
}
that.reset();
});
@ -307,7 +307,7 @@
var $form= this.$('form'),
$stanza = $(stanza),
$fields, $input;
$form.empty().append(converse.templates.registration_form({
$form.empty().append(_converse.templates.registration_form({
'domain': this.domain,
'title': this.title,
'instructions': this.instructions
@ -321,7 +321,7 @@
// Show fields
_.each(_.keys(this.fields), function (key) {
if (key === "username") {
$input = converse.templates.form_username({
$input = _converse.templates.form_username({
domain: ' @'+this.domain,
name: key,
type: "text",
@ -391,7 +391,7 @@
/* Handler, when the user cancels the registration form.
*/
if (ev && ev.preventDefault) { ev.preventDefault(); }
converse.connection.reset();
_converse.connection.reset();
this.render();
},
@ -423,8 +423,8 @@
iq.c($input.attr('name'), {}, $input.val());
});
}
converse.connection._addSysHandler(this._onRegisterIQ.bind(this), null, "iq", null, null);
converse.connection.send(iq);
_converse.connection._addSysHandler(this._onRegisterIQ.bind(this), null, "iq", null, null);
_converse.connection.send(iq);
this.setFields(iq.tree());
},
@ -474,7 +474,7 @@
this.fields[_var.toLowerCase()] = $(field).children('value').text();
} else {
// TODO: other option seems to be type="fixed"
converse.log("WARNING: Found field we couldn't parse");
_converse.log("WARNING: Found field we couldn't parse");
}
}.bind(this));
this.form_type = 'xform';
@ -494,23 +494,23 @@
query = query[0];
}
if (stanza.getAttribute("type") === "error") {
converse.log("Registration failed.");
_converse.log("Registration failed.");
error = stanza.getElementsByTagName("error");
if (error.length !== 1) {
converse.connection._changeConnectStatus(Strophe.Status.REGIFAIL, "unknown");
_converse.connection._changeConnectStatus(Strophe.Status.REGIFAIL, "unknown");
return false;
}
error = error[0].firstChild.tagName.toLowerCase();
if (error === 'conflict') {
converse.connection._changeConnectStatus(Strophe.Status.CONFLICT, error);
_converse.connection._changeConnectStatus(Strophe.Status.CONFLICT, error);
} else if (error === 'not-acceptable') {
converse.connection._changeConnectStatus(Strophe.Status.NOTACCEPTABLE, error);
_converse.connection._changeConnectStatus(Strophe.Status.NOTACCEPTABLE, error);
} else {
converse.connection._changeConnectStatus(Strophe.Status.REGIFAIL, error);
_converse.connection._changeConnectStatus(Strophe.Status.REGIFAIL, error);
}
this.reportErrors(stanza);
} else {
converse.connection._changeConnectStatus(Strophe.Status.REGISTERED, null);
_converse.connection._changeConnectStatus(Strophe.Status.REGISTERED, null);
}
return false;
},

View File

@ -17,7 +17,7 @@
"tpl!roster_item"
], factory);
}(this, function (
converse,
_converse,
converse_api,
tpl_group_header,
tpl_pending_contact,
@ -25,11 +25,11 @@
tpl_roster,
tpl_roster_item) {
"use strict";
converse.templates.group_header = tpl_group_header;
converse.templates.pending_contact = tpl_pending_contact;
converse.templates.requesting_contact = tpl_requesting_contact;
converse.templates.roster = tpl_roster;
converse.templates.roster_item = tpl_roster_item;
_converse.templates.group_header = tpl_group_header;
_converse.templates.pending_contact = tpl_pending_contact;
_converse.templates.requesting_contact = tpl_requesting_contact;
_converse.templates.roster = tpl_roster;
_converse.templates.roster_item = tpl_roster_item;
var $ = converse_api.env.jQuery,
utils = converse_api.env.utils,
@ -37,7 +37,7 @@
$iq = converse_api.env.$iq,
b64_sha1 = converse_api.env.b64_sha1,
_ = converse_api.env._,
__ = utils.__.bind(converse);
__ = utils.__.bind(_converse);
converse_api.plugins.add('rosterview', {
@ -66,7 +66,7 @@
comparator: function () {
// RosterGroupsComparator only gets set later (once i18n is
// set up), so we need to wrap it in this nameless function.
return converse.RosterGroupsComparator.apply(this, arguments);
return _converse.RosterGroupsComparator.apply(this, arguments);
}
}
},
@ -102,7 +102,7 @@
HEADER_WEIGHTS[HEADER_UNGROUPED] = 2;
HEADER_WEIGHTS[HEADER_PENDING_CONTACTS] = 3;
converse.RosterGroupsComparator = function (a, b) {
_converse.RosterGroupsComparator = function (a, b) {
/* Groups are sorted alphabetically, ignoring case.
* However, Ungrouped, Requesting Contacts and Pending Contacts
* appear last and in that order.
@ -124,7 +124,7 @@
};
converse.RosterFilter = Backbone.Model.extend({
_converse.RosterFilter = Backbone.Model.extend({
initialize: function () {
this.set({
'filter_text': '',
@ -134,7 +134,7 @@
},
});
converse.RosterFilterView = Backbone.View.extend({
_converse.RosterFilterView = Backbone.View.extend({
tagName: 'span',
events: {
"keydown .roster-filter": "liveFilter",
@ -149,7 +149,7 @@
},
render: function () {
this.$el.html(converse.templates.roster(
this.$el.html(_converse.templates.roster(
_.extend(this.model.toJSON(), {
placeholder: __('Filter'),
label_contacts: LABEL_CONTACTS,
@ -252,28 +252,28 @@
}
});
converse.RosterView = Backbone.Overview.extend({
_converse.RosterView = Backbone.Overview.extend({
tagName: 'div',
id: 'converse-roster',
initialize: function () {
this.roster_handler_ref = this.registerRosterHandler();
this.rosterx_handler_ref = this.registerRosterXHandler();
converse.roster.on("add", this.onContactAdd, this);
converse.roster.on('change', this.onContactChange, this);
converse.roster.on("destroy", this.update, this);
converse.roster.on("remove", this.update, this);
_converse.roster.on("add", this.onContactAdd, this);
_converse.roster.on('change', this.onContactChange, this);
_converse.roster.on("destroy", this.update, this);
_converse.roster.on("remove", this.update, this);
this.model.on("add", this.onGroupAdd, this);
this.model.on("reset", this.reset, this);
converse.on('rosterGroupsFetched', this.positionFetchedGroups, this);
converse.on('rosterContactsFetched', this.update, this);
_converse.on('rosterGroupsFetched', this.positionFetchedGroups, this);
_converse.on('rosterContactsFetched', this.update, this);
this.createRosterFilter();
},
render: function () {
this.$roster = $('<dl class="roster-contacts" style="display: none;"></dl>');
this.$el.html(this.filter_view.render());
if (!converse.allow_contact_requests) {
if (!_converse.allow_contact_requests) {
// XXX: if we ever support live editing of config then
// we'll need to be able to remove this class on the fly.
this.$el.addClass('no-contact-requests');
@ -283,10 +283,10 @@
createRosterFilter: function () {
// Create a model on which we can store filter properties
var model = new converse.RosterFilter();
model.id = b64_sha1('converse.rosterfilter'+converse.bare_jid);
var model = new _converse.RosterFilter();
model.id = b64_sha1('_converse.rosterfilter'+_converse.bare_jid);
model.browserStorage = new Backbone.BrowserStorage.local(this.filter.id);
this.filter_view = new converse.RosterFilterView({'model': model});
this.filter_view = new _converse.RosterFilterView({'model': model});
this.filter_view.model.on('change', this.updateFilter, this);
this.filter_view.model.fetch();
},
@ -308,9 +308,9 @@
}, 100),
unregisterHandlers: function () {
converse.connection.deleteHandler(this.roster_handler_ref);
_converse.connection.deleteHandler(this.roster_handler_ref);
delete this.roster_handler_ref;
converse.connection.deleteHandler(this.rosterx_handler_ref);
_converse.connection.deleteHandler(this.rosterx_handler_ref);
delete this.rosterx_handler_ref;
},
@ -319,7 +319,7 @@
this.$el.append(this.$roster.show());
}
return this.showHideFilter();
}, converse.animate ? 100 : 0),
}, _converse.animate ? 100 : 0),
showHideFilter: function () {
if (!this.$el.is(':visible')) {
@ -359,7 +359,7 @@
},
reset: function () {
converse.roster.reset();
_converse.roster.reset();
this.removeAll();
this.$roster = $('<dl class="roster-contacts" style="display: none;"></dl>');
this.render().update();
@ -367,20 +367,20 @@
},
registerRosterHandler: function () {
converse.connection.addHandler(
converse.roster.onRosterPush.bind(converse.roster),
_converse.connection.addHandler(
_converse.roster.onRosterPush.bind(_converse.roster),
Strophe.NS.ROSTER, 'iq', "set"
);
},
registerRosterXHandler: function () {
var t = 0;
converse.connection.addHandler(
_converse.connection.addHandler(
function (msg) {
window.setTimeout(
function () {
converse.connection.flush();
converse.roster.subscribeToSuggestedItems.bind(converse.roster)(msg);
_converse.connection.flush();
_converse.roster.subscribeToSuggestedItems.bind(_converse.roster)(msg);
},
t
);
@ -392,7 +392,7 @@
},
onGroupAdd: function (group) {
var view = new converse.RosterGroupView({model: group});
var view = new _converse.RosterGroupView({model: group});
this.add(group.get('name'), view.render());
this.positionGroup(view);
},
@ -421,7 +421,7 @@
},
updateChatBox: function (contact) {
var chatbox = converse.chatboxes.get(contact.get('jid')),
var chatbox = _converse.chatboxes.get(contact.get('jid')),
changes = {};
if (!chatbox) {
return this;
@ -450,7 +450,7 @@
this.model.each(function (group, idx) {
var view = that.get(group.get('name'));
if (!view) {
view = new converse.RosterGroupView({model: group});
view = new _converse.RosterGroupView({model: group});
that.add(group.get('name'), view.render());
}
if (idx === 0) {
@ -507,7 +507,7 @@
addExistingContact: function (contact) {
var groups;
if (converse.roster_groups) {
if (_converse.roster_groups) {
groups = contact.get('groups');
if (groups.length === 0) {
groups = [HEADER_UNGROUPED];
@ -533,7 +533,7 @@
});
converse.RosterContactView = Backbone.View.extend({
_converse.RosterContactView = Backbone.View.extend({
tagName: 'dd',
events: {
@ -589,31 +589,31 @@
* So in both cases the user is a "pending" contact.
*/
this.$el.addClass('pending-xmpp-contact');
this.$el.html(converse.templates.pending_contact(
this.$el.html(_converse.templates.pending_contact(
_.extend(item.toJSON(), {
'desc_remove': __('Click to remove this contact'),
'allow_chat_pending_contacts': converse.allow_chat_pending_contacts
'allow_chat_pending_contacts': _converse.allow_chat_pending_contacts
})
));
} else if (requesting === true) {
this.$el.addClass('requesting-xmpp-contact');
this.$el.html(converse.templates.requesting_contact(
this.$el.html(_converse.templates.requesting_contact(
_.extend(item.toJSON(), {
'desc_accept': __("Click to accept this contact request"),
'desc_decline': __("Click to decline this contact request"),
'allow_chat_pending_contacts': converse.allow_chat_pending_contacts
'allow_chat_pending_contacts': _converse.allow_chat_pending_contacts
})
));
} else if (subscription === 'both' || subscription === 'to') {
this.$el.addClass('current-xmpp-contact');
this.$el.removeClass(_.without(['both', 'to'], subscription)[0]).addClass(subscription);
this.$el.html(converse.templates.roster_item(
this.$el.html(_converse.templates.roster_item(
_.extend(item.toJSON(), {
'desc_status': STATUSES[chat_status||'offline'],
'desc_chat': __('Click to chat with this contact'),
'desc_remove': __('Click to remove this contact'),
'title_fullname': __('Name'),
'allow_contact_removal': converse.allow_contact_removal
'allow_contact_removal': _converse.allow_contact_removal
})
));
}
@ -631,8 +631,8 @@
// would simplify things by not having to check whether the
// group is collapsed or not.
var name = this.$el.prevAll('dt:first').data('group');
var group = converse.rosterview.model.where({'name': name})[0];
if (group.get('state') === converse.CLOSED) {
var group = _converse.rosterview.model.where({'name': name})[0];
if (group.get('state') === _converse.CLOSED) {
return true;
}
return false;
@ -646,8 +646,8 @@
* the group it's in is collapsed (see isGroupCollapsed).
*/
var chatStatus = this.model.get('chat_status');
if ((converse.show_only_online_users && chatStatus !== 'online') ||
(converse.hide_offline_users && chatStatus === 'offline')) {
if ((_converse.show_only_online_users && chatStatus !== 'online') ||
(_converse.hide_offline_users && chatStatus === 'offline')) {
// If pending or requesting, show
if ((this.model.get('ask') === 'subscribe') ||
(this.model.get('subscription') === 'from') ||
@ -661,25 +661,25 @@
openChat: function (ev) {
if (ev && ev.preventDefault) { ev.preventDefault(); }
return converse.chatboxviews.showChat(this.model.attributes);
return _converse.chatboxviews.showChat(this.model.attributes);
},
removeContact: function (ev) {
if (ev && ev.preventDefault) { ev.preventDefault(); }
if (!converse.allow_contact_removal) { return; }
if (!_converse.allow_contact_removal) { return; }
var result = confirm(__("Are you sure you want to remove this contact?"));
if (result === true) {
var iq = $iq({type: 'set'})
.c('query', {xmlns: Strophe.NS.ROSTER})
.c('item', {jid: this.model.get('jid'), subscription: "remove"});
converse.connection.sendIQ(iq,
_converse.connection.sendIQ(iq,
function (iq) {
this.model.destroy();
this.remove();
}.bind(this),
function (err) {
alert(__("Sorry, there was an error while trying to remove "+name+" as a contact."));
converse.log(err);
_converse.log(err);
}
);
}
@ -687,7 +687,7 @@
acceptRequest: function (ev) {
if (ev && ev.preventDefault) { ev.preventDefault(); }
converse.roster.sendContactAddIQ(
_converse.roster.sendContactAddIQ(
this.model.get('jid'),
this.model.get('fullname'),
[],
@ -706,7 +706,7 @@
});
converse.RosterGroupView = Backbone.Overview.extend({
_converse.RosterGroupView = Backbone.Overview.extend({
tagName: 'dt',
className: 'roster-group',
events: {
@ -725,13 +725,13 @@
}, this);
this.model.contacts.on("destroy", this.onRemove, this);
this.model.contacts.on("remove", this.onRemove, this);
converse.roster.on('change:groups', this.onContactGroupChange, this);
_converse.roster.on('change:groups', this.onContactGroupChange, this);
},
render: function () {
this.$el.attr('data-group', this.model.get('name'));
this.$el.html(
$(converse.templates.group_header({
$(_converse.templates.group_header({
label_group: this.model.get('name'),
desc_group_toggle: this.model.get('description'),
toggle_state: this.model.get('state')
@ -741,11 +741,11 @@
},
addContact: function (contact) {
var view = new converse.RosterContactView({model: contact});
var view = new _converse.RosterContactView({model: contact});
this.add(contact.get('id'), view);
view = this.positionContact(contact).render();
if (view.mayBeShown()) {
if (this.model.get('state') === converse.CLOSED) {
if (this.model.get('state') === _converse.CLOSED) {
if (view.$el[0].style.display !== "none") { view.$el.hide(); }
if (!this.$el.is(':visible')) { this.$el.show(); }
} else {
@ -793,7 +793,7 @@
*/
var matches;
if (q.length === 0) {
if (this.model.get('state') === converse.OPENED) {
if (this.model.get('state') === _converse.OPENED) {
this.model.contacts.each(function (item) {
var view = this.get(item.get('id'));
if (view.mayBeShown() && !view.isGroupCollapsed()) {
@ -850,14 +850,14 @@
var $el = $(ev.target);
if ($el.hasClass("icon-opened")) {
this.$el.nextUntil('dt').slideUp();
this.model.save({state: converse.CLOSED});
this.model.save({state: _converse.CLOSED});
$el.removeClass("icon-opened").addClass("icon-closed");
} else {
$el.removeClass("icon-closed").addClass("icon-opened");
this.model.save({state: converse.OPENED});
this.model.save({state: _converse.OPENED});
this.filter(
converse.rosterview.$('.roster-filter').val() || '',
converse.rosterview.$('.filter-type').val()
_converse.rosterview.$('.roster-filter').val() || '',
_converse.rosterview.$('.filter-type').val()
);
}
},
@ -907,13 +907,13 @@
/* Create an instance of RosterView once the RosterGroups
* collection has been created (in converse-core.js)
*/
converse.rosterview = new converse.RosterView({
'model': converse.rostergroups
_converse.rosterview = new _converse.RosterView({
'model': _converse.rostergroups
});
converse.rosterview.render();
_converse.rosterview.render();
};
converse.on('rosterInitialized', initRoster);
converse.on('rosterReadyAfterReconnection', initRoster);
_converse.on('rosterInitialized', initRoster);
_converse.on('rosterReadyAfterReconnection', initRoster);
}
});
}));

View File

@ -12,7 +12,7 @@
"converse-api",
"strophe.vcard",
], factory);
}(this, function (converse, converse_api) {
}(this, function (_converse, converse_api) {
"use strict";
var Strophe = converse_api.env.Strophe,
$ = converse_api.env.jQuery,
@ -31,8 +31,8 @@
Features: {
addClientFeatures: function () {
this.__super__.addClientFeatures.apply(this, arguments);
if (converse.use_vcards) {
converse.connection.disco.addFeature(Strophe.NS.VCARD);
if (_converse.use_vcards) {
_converse.connection.disco.addFeature(Strophe.NS.VCARD);
}
}
},
@ -40,12 +40,12 @@
RosterContacts: {
createRequestingContact: function (presence) {
var bare_jid = Strophe.getBareJidFromJid(presence.getAttribute('from'));
converse.getVCard(
_converse.getVCard(
bare_jid,
_.partial(converse.createRequestingContactFromVCard, presence),
_.partial(_converse.createRequestingContactFromVCard, presence),
function (iq, jid) {
converse.log("Error while retrieving vcard for "+jid);
converse.createRequestingContactFromVCard(presence, iq, jid);
_converse.log("Error while retrieving vcard for "+jid);
_converse.createRequestingContactFromVCard(presence, iq, jid);
}
);
}
@ -61,7 +61,7 @@
use_vcards: true,
});
converse.createRequestingContactFromVCard = function (presence, iq, jid, fullname, img, img_type, url) {
_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 = {
@ -75,26 +75,26 @@
url: url,
vcard_updated: moment().format()
};
converse.roster.create(user_data);
converse.emit('contactRequest', user_data);
_converse.roster.create(user_data);
_converse.emit('contactRequest', user_data);
};
converse.onVCardError = function (jid, iq, errback) {
var contact = converse.roster.get(jid);
_converse.onVCardError = function (jid, iq, errback) {
var contact = _converse.roster.get(jid);
if (contact) {
contact.save({ 'vcard_updated': moment().format() });
}
if (errback) { errback(iq, jid); }
};
converse.onVCardData = function (jid, iq, callback) {
_converse.onVCardData = function (jid, iq, callback) {
var $vcard = $(iq).find('vCard'),
fullname = $vcard.find('FN').text(),
img = $vcard.find('BINVAL').text(),
img_type = $vcard.find('TYPE').text(),
url = $vcard.find('URL').text();
if (jid) {
var contact = converse.roster.get(jid);
var contact = _converse.roster.get(jid);
if (contact) {
fullname = _.isEmpty(fullname)? contact.get('fullname') || jid: fullname;
contact.save({
@ -111,7 +111,7 @@
}
};
converse.getVCard = function (jid, callback, errback) {
_converse.getVCard = function (jid, callback, errback) {
/* Request the VCard of another user.
*
* Parameters:
@ -122,22 +122,22 @@
* (Function) errback - A function to call if an error occured
* while trying to fetch the VCard.
*/
if (!converse.use_vcards) {
if (!_converse.use_vcards) {
if (callback) { callback(null, jid); }
} else {
converse.connection.vcard.get(
_.partial(converse.onVCardData, jid, _, callback),
_converse.connection.vcard.get(
_.partial(_converse.onVCardData, jid, _, callback),
jid,
_.partial(converse.onVCardError, jid, _, errback));
_.partial(_converse.onVCardError, jid, _, errback));
}
};
var updateVCardForChatBox = function (chatbox) {
if (!converse.use_vcards) { return; }
if (!_converse.use_vcards) { return; }
var jid = chatbox.model.get('jid'),
contact = converse.roster.get(jid);
contact = _converse.roster.get(jid);
if ((contact) && (!contact.get('vcard_updated'))) {
converse.getVCard(
_converse.getVCard(
jid,
function (iq, jid, fullname, image, image_type, url) {
chatbox.model.save({
@ -148,38 +148,38 @@
});
},
function () {
converse.log(
_converse.log(
"updateVCardForChatBox: Error occured while fetching vcard"
);
}
);
}
};
converse.on('chatBoxInitialized', updateVCardForChatBox);
_converse.on('chatBoxInitialized', updateVCardForChatBox);
var onContactAdd = function (contact) {
if (!contact.get('vcard_updated')) {
// This will update the vcard, which triggers a change
// request which will rerender the roster contact.
converse.getVCard(contact.get('jid'));
_converse.getVCard(contact.get('jid'));
}
};
converse.on('initialized', function () {
converse.roster.on("add", onContactAdd);
_converse.on('initialized', function () {
_converse.roster.on("add", onContactAdd);
});
var fetchOwnVCard = function () {
if (converse.xmppstatus.get('fullname') === undefined) {
converse.getVCard(
if (_converse.xmppstatus.get('fullname') === undefined) {
_converse.getVCard(
null, // No 'to' attr when getting one's own vCard
function (iq, jid, fullname) {
converse.xmppstatus.save({'fullname': fullname});
_converse.xmppstatus.save({'fullname': fullname});
}
);
}
};
converse.on('statusInitialized', fetchOwnVCard);
_converse.on('statusInitialized', fetchOwnVCard);
}
});
}));