Globally rename xmppchat to converse

This commit is contained in:
JC Brand 2013-04-20 10:41:10 +02:00
parent 71f4cdb931
commit 1cae33b06b
3 changed files with 215 additions and 217 deletions

View File

@ -340,42 +340,42 @@ form.search-xmpp-contact input {
padding-top: 0.5em; padding-top: 0.5em;
} }
#xmppchat-roster dd.odd { #converse-roster dd.odd {
background-color: #DCEAC5; /* Make this difference */ background-color: #DCEAC5; /* Make this difference */
} }
#xmppchat-roster dd.current-xmpp-contact { #converse-roster dd.current-xmpp-contact {
clear: both; clear: both;
} }
#xmppchat-roster dd.current-xmpp-contact, #converse-roster dd.current-xmpp-contact,
#xmppchat-roster dd.current-xmpp-contact:hover { #converse-roster dd.current-xmpp-contact:hover {
background: url(images/user_online_panel.png) no-repeat 5px 2px; background: url(images/user_online_panel.png) no-repeat 5px 2px;
} }
#xmppchat-roster dd.current-xmpp-contact.offline:hover, #converse-roster dd.current-xmpp-contact.offline:hover,
#xmppchat-roster dd.current-xmpp-contact.unavailable:hover, #converse-roster dd.current-xmpp-contact.unavailable:hover,
#xmppchat-roster dd.current-xmpp-contact.offline, #converse-roster dd.current-xmpp-contact.offline,
#xmppchat-roster dd.current-xmpp-contact.unavailable { #converse-roster dd.current-xmpp-contact.unavailable {
background: url(images/user_offline_panel.png) no-repeat 5px 2px; background: url(images/user_offline_panel.png) no-repeat 5px 2px;
} }
#xmppchat-roster dd.current-xmpp-contact.dnd, #converse-roster dd.current-xmpp-contact.dnd,
#xmppchat-roster dd.current-xmpp-contact.dnd:hover { #converse-roster dd.current-xmpp-contact.dnd:hover {
background: url(images/user_busy_panel.png) no-repeat 5px 2px; background: url(images/user_busy_panel.png) no-repeat 5px 2px;
} }
#xmppchat-roster dd.current-xmpp-contact.away, #converse-roster dd.current-xmpp-contact.away,
#xmppchat-roster dd.current-xmpp-contact.away:hover { #converse-roster dd.current-xmpp-contact.away:hover {
background: url(images/user_away_panel.png) no-repeat 5px 2px; background: url(images/user_away_panel.png) no-repeat 5px 2px;
} }
#xmppchat-roster dd.requesting-xmpp-contact button{ #converse-roster dd.requesting-xmpp-contact button{
margin-left: 0.5em; margin-left: 0.5em;
} }
#xmppchat-roster dd a, #converse-roster dd a,
#xmppchat-roster dd span { #converse-roster dd span {
text-shadow: 0 1px 0 rgba(250, 250, 250, 1); text-shadow: 0 1px 0 rgba(250, 250, 250, 1);
display: inline-block; display: inline-block;
overflow: hidden; overflow: hidden;
@ -383,12 +383,12 @@ form.search-xmpp-contact input {
text-overflow: ellipsis; text-overflow: ellipsis;
} }
#xmppchat-roster dd a { #converse-roster dd a {
margin-left: 1.5em; margin-left: 1.5em;
width: 113px; width: 113px;
} }
#xmppchat-roster dd span { #converse-roster dd span {
width: 125px; width: 125px;
} }
@ -396,7 +396,7 @@ form.search-xmpp-contact input {
border: none; border: none;
} }
#xmppchat-roster { #converse-roster {
height: 200px; height: 200px;
overflow-y: scroll; overflow-y: scroll;
width: 100%; width: 100%;
@ -408,7 +408,7 @@ form.search-xmpp-contact input {
} }
#available-chatrooms dt, #available-chatrooms dt,
#xmppchat-roster dt { #converse-roster dt {
font-weight: normal; font-weight: normal;
display: none; display: none;
font-size: 13px; font-size: 13px;
@ -428,7 +428,7 @@ form.search-xmpp-contact input {
dd.available-chatroom, dd.available-chatroom,
#xmppchat-roster dd { #converse-roster dd {
font-weight: bold; font-weight: bold;
border: none; border: none;
display: block; display: block;
@ -437,7 +437,7 @@ dd.available-chatroom,
text-shadow: 0 1px 0 rgba(250, 250, 250, 1); text-shadow: 0 1px 0 rgba(250, 250, 250, 1);
} }
#xmppchat-roster dd a.remove-xmpp-contact { #converse-roster dd a.remove-xmpp-contact {
background: url('images/delete_icon.png') no-repeat right top; background: url('images/delete_icon.png') no-repeat right top;
padding: 0 1em 1em 0; padding: 0 1em 1em 0;
float: right; float: right;
@ -494,12 +494,12 @@ div#controlbox-panes {
width: 199px; width: 199px;
} }
form#xmppchat-login { form#converse-login {
background: white; background: white;
padding: 2em 0 0.3em 0.5em; padding: 2em 0 0.3em 0.5em;
} }
form#xmppchat-login input { form#converse-login input {
display: block; display: block;
} }

View File

@ -79,12 +79,12 @@
evaluate : /\{\[([\s\S]+?)\]\}/g, evaluate : /\{\[([\s\S]+?)\]\}/g,
interpolate : /\{\{([\s\S]+?)\}\}/g interpolate : /\{\{([\s\S]+?)\}\}/g
}; };
root.xmppchat = factory(jQuery, _, console || {log: function(){}}); root.converse = factory(jQuery, _, console || {log: function(){}});
} }
}(this, function ($, _, console) { }(this, function ($, _, console) {
var xmppchat = {}; var converse = {};
xmppchat.msg_counter = 0; converse.msg_counter = 0;
var strinclude = function(str, needle){ var strinclude = function(str, needle){
if (needle === '') { return true; } if (needle === '') { return true; }
@ -92,13 +92,13 @@
return String(str).indexOf(needle) !== -1; return String(str).indexOf(needle) !== -1;
}; };
xmppchat.autoLink = function (text) { converse.autoLink = function (text) {
// Convert URLs into hyperlinks // Convert URLs into hyperlinks
var re = /((http|https|ftp):\/\/[\w?=&.\/\-;#~%\-]+(?![\w\s?&.\/;#~%"=\-]*>))/g; var re = /((http|https|ftp):\/\/[\w?=&.\/\-;#~%\-]+(?![\w\s?&.\/;#~%"=\-]*>))/g;
return text.replace(re, '<a target="_blank" href="$1">$1</a>'); return text.replace(re, '<a target="_blank" href="$1">$1</a>');
}; };
xmppchat.toISOString = function (date) { converse.toISOString = function (date) {
var pad; var pad;
if (typeof date.toISOString !== 'undefined') { if (typeof date.toISOString !== 'undefined') {
return date.toISOString(); return date.toISOString();
@ -116,7 +116,7 @@
} }
}; };
xmppchat.parseISO8601 = function (datestr) { converse.parseISO8601 = function (datestr) {
/* Parses string formatted as 2013-02-14T11:27:08.268Z to a Date obj. /* Parses string formatted as 2013-02-14T11:27:08.268Z to a Date obj.
*/ */
    var numericKeys = [1, 4, 5, 6, 7, 10, 11],     var numericKeys = [1, 4, 5, 6, 7, 10, 11],
@ -140,7 +140,7 @@
return new Date(Date.UTC(struct[1], struct[2], struct[3], struct[4], struct[5] + minutesOffset, struct[6], struct[7])); return new Date(Date.UTC(struct[1], struct[2], struct[3], struct[4], struct[5] + minutesOffset, struct[6], struct[7]));
}; };
xmppchat.updateMsgCounter = function () { converse.updateMsgCounter = function () {
if (this.msg_counter > 0) { if (this.msg_counter > 0) {
if (document.title.search(/^Messages \(\d+\) /) == -1) { if (document.title.search(/^Messages \(\d+\) /) == -1) {
document.title = "Messages (" + this.msg_counter + ") " + document.title; document.title = "Messages (" + this.msg_counter + ") " + document.title;
@ -154,17 +154,17 @@
} }
}; };
xmppchat.incrementMsgCounter = function () { converse.incrementMsgCounter = function () {
this.msg_counter += 1; this.msg_counter += 1;
this.updateMsgCounter(); this.updateMsgCounter();
}; };
xmppchat.clearMsgCounter = function () { converse.clearMsgCounter = function () {
this.msg_counter = 0; this.msg_counter = 0;
this.updateMsgCounter(); this.updateMsgCounter();
}; };
xmppchat.collections = { converse.collections = {
/* FIXME: XEP-0136 specifies 'urn:xmpp:archive' but the mod_archive_odbc /* FIXME: XEP-0136 specifies 'urn:xmpp:archive' but the mod_archive_odbc
* add-on for ejabberd wants the URL below. This might break for other * add-on for ejabberd wants the URL below. This might break for other
* Jabber servers. * Jabber servers.
@ -172,7 +172,7 @@
'URI': 'http://www.xmpp.org/extensions/xep-0136.html#ns' 'URI': 'http://www.xmpp.org/extensions/xep-0136.html#ns'
}; };
xmppchat.collections.getLastCollection = function (jid, callback) { converse.collections.getLastCollection = function (jid, callback) {
var bare_jid = Strophe.getBareJidFromJid(jid), var bare_jid = Strophe.getBareJidFromJid(jid),
iq = $iq({'type':'get'}) iq = $iq({'type':'get'})
.c('list', {'xmlns': this.URI, .c('list', {'xmlns': this.URI,
@ -183,14 +183,14 @@
.c('max') .c('max')
.t('1'); .t('1');
xmppchat.connection.sendIQ(iq, converse.connection.sendIQ(iq,
callback, callback,
function () { function () {
console.log('Error while retrieving collections'); console.log('Error while retrieving collections');
}); });
}; };
xmppchat.collections.getLastMessages = function (jid, callback) { converse.collections.getLastMessages = function (jid, callback) {
var that = this; var that = this;
this.getLastCollection(jid, function (result) { this.getLastCollection(jid, function (result) {
// Retrieve the last page of a collection (max 30 elements). // Retrieve the last page of a collection (max 30 elements).
@ -205,20 +205,20 @@
.c('set', {'xmlns': 'http://jabber.org/protocol/rsm'}) .c('set', {'xmlns': 'http://jabber.org/protocol/rsm'})
.c('max') .c('max')
.t('30'); .t('30');
xmppchat.connection.sendIQ(iq, callback); converse.connection.sendIQ(iq, callback);
}); });
}; };
xmppchat.Message = Backbone.Model.extend(); converse.Message = Backbone.Model.extend();
xmppchat.Messages = Backbone.Collection.extend({ converse.Messages = Backbone.Collection.extend({
model: xmppchat.Message model: converse.Message
}); });
xmppchat.ChatBox = Backbone.Model.extend({ converse.ChatBox = Backbone.Model.extend({
initialize: function () { initialize: function () {
if (this.get('box_id') !== 'controlbox') { if (this.get('box_id') !== 'controlbox') {
this.messages = new xmppchat.Messages(); this.messages = new converse.Messages();
this.messages.localStorage = new Backbone.LocalStorage( this.messages.localStorage = new Backbone.LocalStorage(
hex_sha1('converse.messages'+this.get('jid'))); hex_sha1('converse.messages'+this.get('jid')));
this.set({ this.set({
@ -234,7 +234,7 @@
messageReceived: function (message) { messageReceived: function (message) {
var $message = $(message), var $message = $(message),
body = xmppchat.autoLink($message.children('body').text()), body = converse.autoLink($message.children('body').text()),
from = Strophe.getBareJidFromJid($message.attr('from')), from = Strophe.getBareJidFromJid($message.attr('from')),
composing = $message.find('composing'), composing = $message.find('composing'),
delayed = $message.find('delay').length > 0, delayed = $message.find('delay').length > 0,
@ -247,7 +247,7 @@
fullname: fullname, fullname: fullname,
sender: 'them', sender: 'them',
delayed: delayed, delayed: delayed,
time: xmppchat.toISOString(new Date()), time: converse.toISOString(new Date()),
composing: composing.length composing: composing.length
}); });
} }
@ -256,9 +256,9 @@
stamp = $message.find('delay').attr('stamp'); stamp = $message.find('delay').attr('stamp');
time = stamp; time = stamp;
} else { } else {
time = xmppchat.toISOString(new Date()); time = converse.toISOString(new Date());
} }
if (from == xmppchat.bare_jid) { if (from == converse.bare_jid) {
fullname = 'me'; fullname = 'me';
sender = 'me'; sender = 'me';
} else { } else {
@ -275,7 +275,7 @@
} }
}); });
xmppchat.ChatBoxView = Backbone.View.extend({ converse.ChatBoxView = Backbone.View.extend({
length: 200, length: 200,
tagName: 'div', tagName: 'div',
className: 'chatbox', className: 'chatbox',
@ -311,7 +311,7 @@
showMessage: function (message) { showMessage: function (message) {
var time = message.get('time'), var time = message.get('time'),
times = this.model.messages.pluck('time'), times = this.model.messages.pluck('time'),
this_date = xmppchat.parseISO8601(time), this_date = converse.parseISO8601(time),
$chat_content = this.$el.find('.chat-content'), $chat_content = this.$el.find('.chat-content'),
previous_message, idx, prev_date, isodate; previous_message, idx, prev_date, isodate;
@ -320,10 +320,10 @@
idx = _.indexOf(times, time)-1; idx = _.indexOf(times, time)-1;
if (idx >= 0) { if (idx >= 0) {
previous_message = this.model.messages.at(idx); previous_message = this.model.messages.at(idx);
prev_date = xmppchat.parseISO8601(previous_message.get('time')); prev_date = converse.parseISO8601(previous_message.get('time'));
isodate = new Date(this_date.getTime()); isodate = new Date(this_date.getTime());
isodate.setUTCHours(0,0,0,0); isodate.setUTCHours(0,0,0,0);
isodate = xmppchat.toISOString(isodate); isodate = converse.toISOString(isodate);
if (this.isDifferentDay(prev_date, this_date)) { if (this.isDifferentDay(prev_date, this_date)) {
$chat_content.append(this.new_day_template({ $chat_content.append(this.new_day_template({
isodate: isodate, isodate: isodate,
@ -331,7 +331,7 @@
})); }));
} }
} }
if (xmppchat.xmppstatus.get('status') === 'offline') { if (converse.xmppstatus.get('status') === 'offline') {
// only update the UI if the user is not offline // only update the UI if the user is not offline
return; return;
} }
@ -350,7 +350,7 @@
})); }));
} }
if (message.get('sender') != 'me') { if (message.get('sender') != 'me') {
xmppchat.incrementMsgCounter(); converse.incrementMsgCounter();
} }
this.scrollDown(); this.scrollDown();
}, },
@ -396,22 +396,22 @@
} }
} }
var message = $msg({from: xmppchat.bare_jid, to: bare_jid, type: 'chat', id: timestamp}) var message = $msg({from: converse.bare_jid, to: bare_jid, type: 'chat', id: timestamp})
.c('body').t(text).up() .c('body').t(text).up()
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}); .c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'});
// Forward the message, so that other connected resources are also aware of it. // Forward the message, so that other connected resources are also aware of it.
// TODO: Forward the message only to other connected resources (inside the browser) // TODO: Forward the message only to other connected resources (inside the browser)
var forwarded = $msg({to:xmppchat.bare_jid, type:'chat', id:timestamp}) var forwarded = $msg({to:converse.bare_jid, type:'chat', id:timestamp})
.c('forwarded', {xmlns:'urn:xmpp:forward:0'}) .c('forwarded', {xmlns:'urn:xmpp:forward:0'})
.c('delay', {xmns:'urn:xmpp:delay',stamp:timestamp}).up() .c('delay', {xmns:'urn:xmpp:delay',stamp:timestamp}).up()
.cnode(message.tree()); .cnode(message.tree());
xmppchat.connection.send(message); converse.connection.send(message);
xmppchat.connection.send(forwarded); converse.connection.send(forwarded);
// Add the new message // Add the new message
this.model.messages.create({ this.model.messages.create({
fullname: 'me', fullname: 'me',
sender: 'me', sender: 'me',
time: xmppchat.toISOString(new Date()), time: converse.toISOString(new Date()),
message: text message: text
}); });
}, },
@ -444,7 +444,7 @@
// starts with forward-slash. // starts with forward-slash.
notify = $msg({'to':this.model.get('jid'), 'type': 'chat'}) notify = $msg({'to':this.model.get('jid'), 'type': 'chat'})
.c('composing', {'xmlns':'http://jabber.org/protocol/chatstates'}); .c('composing', {'xmlns':'http://jabber.org/protocol/chatstates'});
xmppchat.connection.send(notify); converse.connection.send(notify);
} }
this.$el.data('composing', true); this.$el.data('composing', true);
} }
@ -476,7 +476,7 @@
}, },
closeChat: function () { closeChat: function () {
if (xmppchat.connection) { if (converse.connection) {
this.model.destroy(); this.model.destroy();
} else { } else {
this.model.trigger('hide'); this.model.trigger('hide');
@ -489,12 +489,12 @@
this.model.on('destroy', this.hide, this); this.model.on('destroy', this.hide, this);
this.model.on('change', this.onChange, this); this.model.on('change', this.onChange, this);
this.$el.appendTo(xmppchat.chatboxesview.$el); this.$el.appendTo(converse.chatboxesview.$el);
this.render().show().model.messages.fetch({add: true}); this.render().show().model.messages.fetch({add: true});
if (this.model.get('status')) { if (this.model.get('status')) {
this.showStatusMessage(this.model.get('status')); this.showStatusMessage(this.model.get('status'));
} }
xmppchat.clearMsgCounter(); converse.clearMsgCounter();
}, },
template: _.template( template: _.template(
@ -537,7 +537,7 @@
}, },
hide: function () { hide: function () {
if (xmppchat.animate) { if (converse.animate) {
this.$el.hide('fast'); this.$el.hide('fast');
} else { } else {
this.$el.hide(); this.$el.hide();
@ -548,12 +548,12 @@
if (this.$el.is(':visible') && this.$el.css('opacity') == "1") { if (this.$el.is(':visible') && this.$el.css('opacity') == "1") {
return this.focus(); return this.focus();
} }
if (xmppchat.animate) { if (converse.animate) {
this.$el.css({'opacity': 0, 'display': 'inline'}).animate({opacity: '1'}, 200); this.$el.css({'opacity': 0, 'display': 'inline'}).animate({opacity: '1'}, 200);
} else { } else {
this.$el.css({'opacity': 1, 'display': 'inline'}); this.$el.css({'opacity': 1, 'display': 'inline'});
} }
if (xmppchat.connection) { if (converse.connection) {
// Without a connection, we haven't yet initialized // Without a connection, we haven't yet initialized
// localstorage // localstorage
this.model.save(); this.model.save();
@ -568,7 +568,7 @@
} }
}); });
xmppchat.ContactsPanel = Backbone.View.extend({ converse.ContactsPanel = Backbone.View.extend({
tagName: 'div', tagName: 'div',
className: 'oc-chat-content', className: 'oc-chat-content',
id: 'users', id: 'users',
@ -617,7 +617,7 @@
var markup; var markup;
this.$parent.find('#controlbox-tabs').append(this.tab_template()); this.$parent.find('#controlbox-tabs').append(this.tab_template());
this.$parent.find('#controlbox-panes').append(this.$el.html(this.template())); this.$parent.find('#controlbox-panes').append(this.$el.html(this.template()));
if (xmppchat.xhr_user_search) { if (converse.xhr_user_search) {
markup = this.search_contact_template(); markup = this.search_contact_template();
} else { } else {
markup = this.add_contact_template(); markup = this.add_contact_template();
@ -644,7 +644,7 @@
.attr('id', 'found-users-'+obj.id) .attr('id', 'found-users-'+obj.id)
.append( .append(
$('<a class="subscribe-to-user" href="#" title="Click to add as a chat contact"></a>') $('<a class="subscribe-to-user" href="#" title="Click to add as a chat contact"></a>')
.attr('data-recipient', Strophe.escapeNode(obj.id)+'@'+xmppchat.domain) .attr('data-recipient', Strophe.escapeNode(obj.id)+'@'+converse.domain)
.text(obj.fullname) .text(obj.fullname)
) )
); );
@ -669,13 +669,13 @@
}, },
addContact: function (jid, name) { addContact: function (jid, name) {
xmppchat.connection.roster.add(jid, name, [], function (iq) { converse.connection.roster.add(jid, name, [], function (iq) {
xmppchat.connection.roster.subscribe(jid, null, xmppchat.fullname); converse.connection.roster.subscribe(jid, null, converse.fullname);
}); });
} }
}); });
xmppchat.RoomsPanel = Backbone.View.extend({ converse.RoomsPanel = Backbone.View.extend({
tagName: 'div', tagName: 'div',
id: 'chatrooms', id: 'chatrooms',
events: { events: {
@ -714,7 +714,7 @@
}, },
updateRoomsList: function () { updateRoomsList: function () {
xmppchat.connection.muc.listRooms(xmppchat.muc_domain, $.proxy(function (iq) { converse.connection.muc.listRooms(converse.muc_domain, $.proxy(function (iq) {
var name, jid, i, var name, jid, i,
rooms = $(iq).find('query').find('item'), rooms = $(iq).find('query').find('item'),
rooms_length = rooms.length, rooms_length = rooms.length,
@ -744,23 +744,23 @@
name = input.val().trim().toLowerCase(); name = input.val().trim().toLowerCase();
input.val(''); // Clear the input input.val(''); // Clear the input
if (name) { if (name) {
jid = Strophe.escapeNode(name) + '@' + xmppchat.muc_domain; jid = Strophe.escapeNode(name) + '@' + converse.muc_domain;
} else { } else {
return; return;
} }
} }
xmppchat.chatboxes.create({ converse.chatboxes.create({
'id': jid, 'id': jid,
'jid': jid, 'jid': jid,
'name': Strophe.unescapeNode(Strophe.getNodeFromJid(jid)), 'name': Strophe.unescapeNode(Strophe.getNodeFromJid(jid)),
'nick': xmppchat.xmppstatus.get('fullname')||xmppchat.bare_jid, 'nick': converse.xmppstatus.get('fullname')||converse.bare_jid,
'chatroom': true, 'chatroom': true,
'box_id' : hex_sha1(jid) 'box_id' : hex_sha1(jid)
}); });
} }
}); });
xmppchat.ControlBoxView = xmppchat.ChatBoxView.extend({ converse.ControlBoxView = converse.ChatBoxView.extend({
tagName: 'div', tagName: 'div',
className: 'chatbox', className: 'chatbox',
id: 'controlbox', id: 'controlbox',
@ -770,7 +770,7 @@
}, },
initialize: function () { initialize: function () {
this.$el.appendTo(xmppchat.chatboxesview.$el); this.$el.appendTo(converse.chatboxesview.$el);
this.model.on('change', $.proxy(function (item, changed) { this.model.on('change', $.proxy(function (item, changed) {
if (_.has(item.changed, 'connected')) { if (_.has(item.changed, 'connected')) {
this.render(); this.render();
@ -820,17 +820,17 @@
render: function () { render: function () {
this.$el.html(this.template(this.model.toJSON())); this.$el.html(this.template(this.model.toJSON()));
if ((!xmppchat.prebind) && (!xmppchat.connection)) { if ((!converse.prebind) && (!converse.connection)) {
// Add login panel if the user still has to authenticate // Add login panel if the user still has to authenticate
this.loginpanel = new xmppchat.LoginPanel(); this.loginpanel = new converse.LoginPanel();
this.loginpanel.$parent = this.$el; this.loginpanel.$parent = this.$el;
this.loginpanel.render(); this.loginpanel.render();
} else { } else {
this.contactspanel = new xmppchat.ContactsPanel(); this.contactspanel = new converse.ContactsPanel();
this.contactspanel.$parent = this.$el; this.contactspanel.$parent = this.$el;
this.contactspanel.render(); this.contactspanel.render();
// TODO: Only add the rooms panel if the server supports MUC // TODO: Only add the rooms panel if the server supports MUC
this.roomspanel = new xmppchat.RoomsPanel(); this.roomspanel = new converse.RoomsPanel();
this.roomspanel.$parent = this.$el; this.roomspanel.$parent = this.$el;
this.roomspanel.render(); this.roomspanel.render();
} }
@ -838,7 +838,7 @@
} }
}); });
xmppchat.ChatRoomView = xmppchat.ChatBoxView.extend({ converse.ChatRoomView = converse.ChatBoxView.extend({
length: 300, length: 300,
tagName: 'div', tagName: 'div',
className: 'chatroom', className: 'chatroom',
@ -855,19 +855,19 @@
// TODO: Private messages // TODO: Private messages
break; break;
case 'topic': case 'topic':
xmppchat.connection.muc.setTopic(this.model.get('jid'), match[2]); converse.connection.muc.setTopic(this.model.get('jid'), match[2]);
break; break;
case 'kick': case 'kick':
xmppchat.connection.muc.kick(this.model.get('jid'), match[2]); converse.connection.muc.kick(this.model.get('jid'), match[2]);
break; break;
case 'ban': case 'ban':
xmppchat.connection.muc.ban(this.model.get('jid'), match[2]); converse.connection.muc.ban(this.model.get('jid'), match[2]);
break; break;
case 'op': case 'op':
xmppchat.connection.muc.op(this.model.get('jid'), match[2]); converse.connection.muc.op(this.model.get('jid'), match[2]);
break; break;
case 'deop': case 'deop':
xmppchat.connection.muc.deop(this.model.get('jid'), match[2]); converse.connection.muc.deop(this.model.get('jid'), match[2]);
break; break;
case 'help': case 'help':
$chat_content = this.$el.find('.chat-content'); $chat_content = this.$el.find('.chat-content');
@ -882,7 +882,7 @@
this.scrollDown(); this.scrollDown();
break; break;
default: default:
this.last_msgid = xmppchat.connection.muc.groupchat(this.model.get('jid'), body); this.last_msgid = converse.connection.muc.groupchat(this.model.get('jid'), body);
break; break;
} }
}, },
@ -909,7 +909,7 @@
'</div>'), '</div>'),
initialize: function () { initialize: function () {
xmppchat.connection.muc.join( converse.connection.muc.join(
this.model.get('jid'), this.model.get('jid'),
this.model.get('nick'), this.model.get('nick'),
$.proxy(this.onChatRoomMessage, this), $.proxy(this.onChatRoomMessage, this),
@ -920,20 +920,20 @@
this.model.messages.on('add', this.showMessage, this); this.model.messages.on('add', this.showMessage, this);
this.model.on('destroy', function (model, response, options) { this.model.on('destroy', function (model, response, options) {
this.$el.hide('fast'); this.$el.hide('fast');
xmppchat.connection.muc.leave( converse.connection.muc.leave(
this.model.get('jid'), this.model.get('jid'),
this.model.get('nick'), this.model.get('nick'),
this.onLeave, this.onLeave,
undefined); undefined);
}, },
this); this);
this.$el.appendTo(xmppchat.chatboxesview.$el); this.$el.appendTo(converse.chatboxesview.$el);
this.render().show().model.messages.fetch({add: true}); this.render().show().model.messages.fetch({add: true});
xmppchat.clearMsgCounter(); converse.clearMsgCounter();
}, },
onLeave: function () { onLeave: function () {
var controlboxview = xmppchat.chatboxesview.views.controlbox; var controlboxview = converse.chatboxesview.views.controlbox;
if (controlboxview) { if (controlboxview) {
controlboxview.roomspanel.trigger('update-rooms-list'); controlboxview.roomspanel.trigger('update-rooms-list');
} }
@ -970,7 +970,7 @@
} }
if (delayed) { if (delayed) {
stamp = $message.find('delay').attr('stamp'); stamp = $message.find('delay').attr('stamp');
message_datetime = xmppchat.parseISO8601(stamp); message_datetime = converse.parseISO8601(stamp);
} else { } else {
message_datetime = new Date(); message_datetime = new Date();
} }
@ -979,7 +979,7 @@
dates = $chat_content.find("time").map(function(){return $(this).attr("datetime");}).get(); dates = $chat_content.find("time").map(function(){return $(this).attr("datetime");}).get();
message_date = message_datetime; message_date = message_datetime;
message_date.setUTCHours(0,0,0,0); message_date.setUTCHours(0,0,0,0);
isodate = xmppchat.toISOString(message_date); isodate = converse.toISOString(message_date);
if (_.indexOf(dates, isodate) == -1) { if (_.indexOf(dates, isodate) == -1) {
$chat_content.append(this.new_day_template({ $chat_content.append(this.new_day_template({
isodate: isodate, isodate: isodate,
@ -1012,7 +1012,7 @@
onChatRoomRoster: function (roster, room) { onChatRoomRoster: function (roster, room) {
// underscore size is needed because roster is an object // underscore size is needed because roster is an object
var controlboxview = xmppchat.chatboxesview.views.controlbox, var controlboxview = converse.chatboxesview.views.controlbox,
roster_size = _.size(roster), roster_size = _.size(roster),
$participant_list = this.$el.find('.participant-list'), $participant_list = this.$el.find('.participant-list'),
participants = [], participants = [],
@ -1036,12 +1036,12 @@
} }
}); });
xmppchat.ChatBoxes = Backbone.Collection.extend({ converse.ChatBoxes = Backbone.Collection.extend({
model: xmppchat.ChatBox, model: converse.ChatBox,
onConnected: function () { onConnected: function () {
this.localStorage = new Backbone.LocalStorage( this.localStorage = new Backbone.LocalStorage(
hex_sha1('converse.chatboxes-'+xmppchat.bare_jid)); hex_sha1('converse.chatboxes-'+converse.bare_jid));
if (!this.get('controlbox')) { if (!this.get('controlbox')) {
this.add({ this.add({
id: 'controlbox', id: 'controlbox',
@ -1067,7 +1067,7 @@
messageReceived: function (message) { messageReceived: function (message) {
var partner_jid, $message = $(message), var partner_jid, $message = $(message),
message_from = $message.attr('from'); message_from = $message.attr('from');
if (message_from == xmppchat.connection.jid) { if (message_from == converse.connection.jid) {
// FIXME: Forwarded messages should be sent to specific resources, // FIXME: Forwarded messages should be sent to specific resources,
// not broadcasted // not broadcasted
return true; return true;
@ -1079,7 +1079,7 @@
var from = Strophe.getBareJidFromJid(message_from), var from = Strophe.getBareJidFromJid(message_from),
to = Strophe.getBareJidFromJid($message.attr('to')), to = Strophe.getBareJidFromJid($message.attr('to')),
resource, chatbox; resource, chatbox;
if (from == xmppchat.bare_jid) { if (from == converse.bare_jid) {
// I am the sender, so this must be a forwarded message... // I am the sender, so this must be a forwarded message...
partner_jid = to; partner_jid = to;
resource = Strophe.getResourceFromJid($message.attr('to')); resource = Strophe.getResourceFromJid($message.attr('to'));
@ -1089,7 +1089,7 @@
} }
chatbox = this.get(partner_jid); chatbox = this.get(partner_jid);
if (!chatbox) { if (!chatbox) {
xmppchat.getVCard( converse.getVCard(
partner_jid, partner_jid,
$.proxy(function (jid, fullname, image, image_type, url) { $.proxy(function (jid, fullname, image, image_type, url) {
var chatbox = this.create({ var chatbox = this.create({
@ -1101,7 +1101,7 @@
'url': url 'url': url
}); });
chatbox.messageReceived(message); chatbox.messageReceived(message);
xmppchat.roster.addResource(partner_jid, resource); converse.roster.addResource(partner_jid, resource);
}, this), }, this),
$.proxy(function () { $.proxy(function () {
// # FIXME // # FIXME
@ -1110,12 +1110,12 @@
return true; return true;
} }
chatbox.messageReceived(message); chatbox.messageReceived(message);
xmppchat.roster.addResource(partner_jid, resource); converse.roster.addResource(partner_jid, resource);
return true; return true;
} }
}); });
xmppchat.ChatBoxesView = Backbone.View.extend({ converse.ChatBoxesView = Backbone.View.extend({
el: '#collective-xmpp-chat-data', el: '#collective-xmpp-chat-data',
initialize: function () { initialize: function () {
@ -1125,12 +1125,12 @@
var view = this.views[item.get('id')]; var view = this.views[item.get('id')];
if (!view) { if (!view) {
if (item.get('chatroom')) { if (item.get('chatroom')) {
view = new xmppchat.ChatRoomView({'model': item}); view = new converse.ChatRoomView({'model': item});
} else if (item.get('box_id') === 'controlbox') { } else if (item.get('box_id') === 'controlbox') {
view = new xmppchat.ControlBoxView({model: item}); view = new converse.ControlBoxView({model: item});
view.render(); view.render();
} else { } else {
view = new xmppchat.ChatBoxView({model: item}); view = new converse.ChatBoxView({model: item});
} }
this.views[item.get('id')] = view; this.views[item.get('id')] = view;
} else { } else {
@ -1145,7 +1145,7 @@
} }
}); });
xmppchat.RosterItem = Backbone.Model.extend({ converse.RosterItem = Backbone.Model.extend({
initialize: function (attributes, options) { initialize: function (attributes, options) {
var jid = attributes.jid; var jid = attributes.jid;
if (!attributes.fullname) { if (!attributes.fullname) {
@ -1163,7 +1163,7 @@
} }
}); });
xmppchat.RosterItemView = Backbone.View.extend({ converse.RosterItemView = Backbone.View.extend({
tagName: 'dd', tagName: 'dd',
events: { events: {
@ -1176,11 +1176,11 @@
openChat: function (ev) { openChat: function (ev) {
ev.preventDefault(); ev.preventDefault();
var jid = Strophe.getBareJidFromJid(this.model.get('jid')), var jid = Strophe.getBareJidFromJid(this.model.get('jid')),
chatbox = xmppchat.chatboxes.get(jid); chatbox = converse.chatboxes.get(jid);
if (chatbox) { if (chatbox) {
chatbox.trigger('show'); chatbox.trigger('show');
} else { } else {
xmppchat.chatboxes.create({ converse.chatboxes.create({
'id': this.model.get('jid'), 'id': this.model.get('jid'),
'jid': this.model.get('jid'), 'jid': this.model.get('jid'),
'fullname': this.model.get('fullname'), 'fullname': this.model.get('fullname'),
@ -1196,25 +1196,25 @@
var result = confirm("Are you sure you want to remove this contact?"); var result = confirm("Are you sure you want to remove this contact?");
if (result === true) { if (result === true) {
var bare_jid = this.model.get('jid'); var bare_jid = this.model.get('jid');
xmppchat.connection.roster.remove(bare_jid, function (iq) { converse.connection.roster.remove(bare_jid, function (iq) {
xmppchat.connection.roster.unauthorize(bare_jid); converse.connection.roster.unauthorize(bare_jid);
xmppchat.rosterview.model.remove(bare_jid); converse.rosterview.model.remove(bare_jid);
}); });
} }
}, },
acceptRequest: function (ev) { acceptRequest: function (ev) {
var jid = this.model.get('jid'); var jid = this.model.get('jid');
xmppchat.connection.roster.authorize(jid); converse.connection.roster.authorize(jid);
xmppchat.connection.roster.add(jid, this.model.get('fullname'), [], function (iq) { converse.connection.roster.add(jid, this.model.get('fullname'), [], function (iq) {
xmppchat.connection.roster.subscribe(jid, null, xmppchat.fullname); converse.connection.roster.subscribe(jid, null, converse.fullname);
}); });
ev.preventDefault(); ev.preventDefault();
}, },
declineRequest: function (ev) { declineRequest: function (ev) {
ev.preventDefault(); ev.preventDefault();
xmppchat.connection.roster.unauthorize(this.model.get('jid')); converse.connection.roster.unauthorize(this.model.get('jid'));
this.model.destroy(); this.model.destroy();
}, },
@ -1245,7 +1245,7 @@
} else if (ask === 'request') { } else if (ask === 'request') {
this.$el.addClass('requesting-xmpp-contact'); this.$el.addClass('requesting-xmpp-contact');
this.$el.html(this.request_template(item.toJSON())); this.$el.html(this.request_template(item.toJSON()));
xmppchat.showControlBox(); converse.showControlBox();
} else if (subscription === 'both' || subscription === 'to') { } else if (subscription === 'both' || subscription === 'to') {
this.$el.addClass('current-xmpp-contact'); this.$el.addClass('current-xmpp-contact');
this.$el.html(this.template(item.toJSON())); this.$el.html(this.template(item.toJSON()));
@ -1263,8 +1263,8 @@
} }
}); });
xmppchat.getVCard = function (jid, callback, errback) { converse.getVCard = function (jid, callback, errback) {
xmppchat.connection.vcard.get($.proxy(function (iq) { converse.connection.vcard.get($.proxy(function (iq) {
$vcard = $(iq).find('vCard'); $vcard = $(iq).find('vCard');
var fullname = $vcard.find('FN').text(), var fullname = $vcard.find('FN').text(),
img = $vcard.find('BINVAL').text(), img = $vcard.find('BINVAL').text(),
@ -1274,8 +1274,8 @@
}, this), jid, errback); }, this), jid, errback);
} }
xmppchat.RosterItems = Backbone.Collection.extend({ converse.RosterItems = Backbone.Collection.extend({
model: xmppchat.RosterItem, model: converse.RosterItem,
comparator : function (rosteritem) { comparator : function (rosteritem) {
var chat_status = rosteritem.get('chat_status'), var chat_status = rosteritem.get('chat_status'),
rank = 4; rank = 4;
@ -1309,8 +1309,8 @@
action = $this.attr('action'), action = $this.attr('action'),
fullname = $this.attr('name'); fullname = $this.attr('name');
if (action === 'add') { if (action === 'add') {
xmppchat.connection.roster.add(jid, fullname, [], function (iq) { converse.connection.roster.add(jid, fullname, [], function (iq) {
xmppchat.connection.roster.subscribe(jid, null, xmppchat.fullname); converse.connection.roster.subscribe(jid, null, converse.fullname);
}); });
} }
}); });
@ -1318,7 +1318,7 @@
}, },
isSelf: function (jid) { isSelf: function (jid) {
return (Strophe.getBareJidFromJid(jid) === Strophe.getBareJidFromJid(xmppchat.connection.jid)); return (Strophe.getBareJidFromJid(jid) === Strophe.getBareJidFromJid(converse.connection.jid));
}, },
getItem: function (id) { getItem: function (id) {
@ -1359,13 +1359,13 @@
subscribeBack: function (jid) { subscribeBack: function (jid) {
var bare_jid = Strophe.getBareJidFromJid(jid); var bare_jid = Strophe.getBareJidFromJid(jid);
if (xmppchat.connection.roster.findItem(bare_jid)) { if (converse.connection.roster.findItem(bare_jid)) {
xmppchat.connection.roster.authorize(bare_jid); converse.connection.roster.authorize(bare_jid);
xmppchat.connection.roster.subscribe(jid, null, xmppchat.fullname); converse.connection.roster.subscribe(jid, null, converse.fullname);
} else { } else {
xmppchat.connection.roster.add(jid, '', [], function (iq) { converse.connection.roster.add(jid, '', [], function (iq) {
xmppchat.connection.roster.authorize(bare_jid); converse.connection.roster.authorize(bare_jid);
xmppchat.connection.roster.subscribe(jid, null, xmppchat.fullname); converse.connection.roster.subscribe(jid, null, converse.fullname);
}); });
} }
}, },
@ -1377,10 +1377,10 @@
* this step lets the user's server know that it MUST no longer * this step lets the user's server know that it MUST no longer
* send notification of the subscription state change to the user. * send notification of the subscription state change to the user.
*/ */
xmppchat.xmppstatus.sendPresence('unsubscribe'); converse.xmppstatus.sendPresence('unsubscribe');
if (xmppchat.connection.roster.findItem(jid)) { if (converse.connection.roster.findItem(jid)) {
xmppchat.connection.roster.remove(jid, function (iq) { converse.connection.roster.remove(jid, function (iq) {
xmppchat.rosterview.model.remove(jid); converse.rosterview.model.remove(jid);
}); });
} }
}, },
@ -1457,11 +1457,11 @@
item; item;
if (this.isSelf(bare_jid)) { if (this.isSelf(bare_jid)) {
if ((xmppchat.connection.jid !== jid)&&(presence_type !== 'unavailabe')) { if ((converse.connection.jid !== jid)&&(presence_type !== 'unavailabe')) {
// Another resource has changed it's status, we'll update ours as well. // Another resource has changed it's status, we'll update ours as well.
// FIXME: We should ideally differentiate between converse.js using // FIXME: We should ideally differentiate between converse.js using
// resources and other resources (i.e Pidgin etc.) // resources and other resources (i.e Pidgin etc.)
xmppchat.xmppstatus.set({'status': chat_status}); converse.xmppstatus.set({'status': chat_status});
} }
return true; return true;
} else if (($presence.find('x').attr('xmlns') || '').indexOf(Strophe.NS.MUC) === 0) { } else if (($presence.find('x').attr('xmlns') || '').indexOf(Strophe.NS.MUC) === 0) {
@ -1476,17 +1476,17 @@
if ((presence_type === 'error') || (presence_type === 'subscribed') || (presence_type === 'unsubscribe')) { if ((presence_type === 'error') || (presence_type === 'subscribed') || (presence_type === 'unsubscribe')) {
return true; return true;
} else if (presence_type === 'subscribe') { } else if (presence_type === 'subscribe') {
if (xmppchat.auto_subscribe) { if (converse.auto_subscribe) {
if ((!item) || (item.get('subscription') != 'to')) { if ((!item) || (item.get('subscription') != 'to')) {
this.subscribeBack(jid); this.subscribeBack(jid);
} else { } else {
xmppchat.connection.roster.authorize(bare_jid); converse.connection.roster.authorize(bare_jid);
} }
} else { } else {
if ((item) && (item.get('subscription') != 'none')) { if ((item) && (item.get('subscription') != 'none')) {
xmppchat.connection.roster.authorize(bare_jid); converse.connection.roster.authorize(bare_jid);
} else { } else {
xmppchat.getVCard( converse.getVCard(
bare_jid, bare_jid,
$.proxy(function (jid, fullname, img, img_type, url) { $.proxy(function (jid, fullname, img, img_type, url) {
this.add({ this.add({
@ -1524,9 +1524,9 @@
} }
}); });
xmppchat.RosterView = Backbone.View.extend({ converse.RosterView = Backbone.View.extend({
tagName: 'dl', tagName: 'dl',
id: 'xmppchat-roster', id: 'converse-roster',
rosteritemviews: {}, rosteritemviews: {},
removeRosterItem: function (item) { removeRosterItem: function (item) {
@ -1540,7 +1540,7 @@
initialize: function () { initialize: function () {
this.model.on("add", function (item) { this.model.on("add", function (item) {
var view = new xmppchat.RosterItemView({model: item}); var view = new converse.RosterItemView({model: item});
this.rosteritemviews[item.id] = view; this.rosteritemviews[item.id] = view;
this.render(item); this.render(item);
}, this); }, this);
@ -1560,11 +1560,11 @@
this.$el.hide().html(this.template()); this.$el.hide().html(this.template());
this.model.fetch({add: true}); // Get the cached roster items from localstorage this.model.fetch({add: true}); // Get the cached roster items from localstorage
this.initialSort(); this.initialSort();
this.$el.appendTo(xmppchat.chatboxesview.views.controlbox.contactspanel.$el); this.$el.appendTo(converse.chatboxesview.views.controlbox.contactspanel.$el);
}, },
updateChatBox: function (item, changed) { updateChatBox: function (item, changed) {
var chatbox = xmppchat.chatboxes.get(item.get('jid')), var chatbox = converse.chatboxes.get(item.get('jid')),
changes = {}; changes = {};
if (!chatbox) { return; } if (!chatbox) { return; }
if (_.has(item.changed, 'chat_status')) { if (_.has(item.changed, 'chat_status')) {
@ -1656,7 +1656,7 @@
}); });
xmppchat.XMPPStatus = Backbone.Model.extend({ converse.XMPPStatus = Backbone.Model.extend({
initialize: function () { initialize: function () {
this.set({ this.set({
'status' : this.get('status'), 'status' : this.get('status'),
@ -1696,7 +1696,7 @@
presence.c('status').t(status_message); presence.c('status').t(status_message);
} }
} }
xmppchat.connection.send(presence); converse.connection.send(presence);
}, },
setStatus: function (value) { setStatus: function (value) {
@ -1705,13 +1705,13 @@
}, },
setStatusMessage: function (status_message) { setStatusMessage: function (status_message) {
xmppchat.connection.send($pres().c('show').t(this.get('status')).up().c('status').t(status_message)); converse.connection.send($pres().c('show').t(this.get('status')).up().c('status').t(status_message));
this.save({'status_message': status_message}); this.save({'status_message': status_message});
} }
}); });
xmppchat.XMPPStatusView = Backbone.View.extend({ converse.XMPPStatusView = Backbone.View.extend({
el: "span#xmpp-status-holder", el: "span#xmpp-status-holder",
events: { events: {
@ -1837,16 +1837,16 @@
} }
}); });
xmppchat.LoginPanel = Backbone.View.extend({ converse.LoginPanel = Backbone.View.extend({
tagName: 'div', tagName: 'div',
id: "login-dialog", id: "login-dialog",
events: { events: {
'submit form#xmppchat-login': 'authenticate' 'submit form#converse-login': 'authenticate'
}, },
tab_template: _.template( tab_template: _.template(
'<li><a class="current" href="#login">Sign in</a></li>'), '<li><a class="current" href="#login">Sign in</a></li>'),
template: _.template( template: _.template(
'<form id="xmppchat-login">' + '<form id="converse-login">' +
'<label>XMPP ID:</label>' + '<label>XMPP ID:</label>' +
'<input type="text" id="jid">' + '<input type="text" id="jid">' +
'<label>Password:</label>' + '<label>Password:</label>' +
@ -1879,10 +1879,10 @@
console.log('Connection Failed'); console.log('Connection Failed');
} else if (status === Strophe.Status.AUTHENTICATING) { } else if (status === Strophe.Status.AUTHENTICATING) {
console.log('Authenticating'); console.log('Authenticating');
xmppchat.giveFeedback('Authenticating'); converse.giveFeedback('Authenticating');
} else if (status === Strophe.Status.AUTHFAIL) { } else if (status === Strophe.Status.AUTHFAIL) {
console.log('Authenticating Failed'); console.log('Authenticating Failed');
xmppchat.giveFeedback('Authentication failed'); converse.giveFeedback('Authentication failed');
} else if (status === Strophe.Status.DISCONNECTING) { } else if (status === Strophe.Status.DISCONNECTING) {
console.log('Disconnecting'); console.log('Disconnecting');
} else if (status === Strophe.Status.ATTACHED) { } else if (status === Strophe.Status.ATTACHED) {
@ -1903,7 +1903,7 @@
} }
}); });
xmppchat.showControlBox = function () { converse.showControlBox = function () {
var controlbox = this.chatboxes.get('controlbox'); var controlbox = this.chatboxes.get('controlbox');
if (!controlbox) { if (!controlbox) {
this.chatboxes.add({ this.chatboxes.add({
@ -1919,7 +1919,7 @@
} }
} }
xmppchat.toggleControlBox = function () { converse.toggleControlBox = function () {
if ($("div#controlbox").is(':visible')) { if ($("div#controlbox").is(':visible')) {
var controlbox = this.chatboxes.get('controlbox'); var controlbox = this.chatboxes.get('controlbox');
if (this.connection) { if (this.connection) {
@ -1932,11 +1932,11 @@
} }
}; };
xmppchat.giveFeedback = function (message) { converse.giveFeedback = function (message) {
$('.conn-feedback').text(message); $('.conn-feedback').text(message);
} }
xmppchat.initialize = function (data) { converse.initialize = function (data) {
this.prebind = data.attr('prebind'); this.prebind = data.attr('prebind');
this.fullname = data.attr('fullname'); this.fullname = data.attr('fullname');
this.xhr_user_search = data.attr('xhr_user_search'); this.xhr_user_search = data.attr('xhr_user_search');
@ -1952,7 +1952,7 @@
); );
}, },
xmppchat.onConnected = function (connection) { converse.onConnected = function (connection) {
this.animate = true; // Use animations this.animate = true; // Use animations
this.connection = connection; this.connection = connection;
this.connection.xmlInput = function (body) { console.log(body); }; this.connection.xmlInput = function (body) { console.log(body); };
@ -2019,7 +2019,7 @@
$(document).bind('jarnxmpp.connected', $.proxy(function (ev, connection) { $(document).bind('jarnxmpp.connected', $.proxy(function (ev, connection) {
this.onConnected(connection); this.onConnected(connection);
}, this)); }, this));
}, xmppchat)); }, converse));
return xmppchat; return converse;
})); }));

View File

@ -1,11 +1,11 @@
(function (root, factory) { (function (root, factory) {
define([ define([
"converse" "converse"
], function (xmppchat) { ], function (converse) {
return factory(xmppchat); return factory(converse);
} }
); );
} (this, function (xmppchat) { } (this, function (converse) {
return describe("Converse.js", $.proxy(function() { return describe("Converse.js", $.proxy(function() {
// Names from http://www.fakenamegenerator.com/ // Names from http://www.fakenamegenerator.com/
@ -64,7 +64,7 @@
describe("The Control Box", $.proxy(function () { describe("The Control Box", $.proxy(function () {
it("is not shown by default", $.proxy(function () { it("is not shown by default", $.proxy(function () {
expect(this.rosterview.$el.is(':visible')).toEqual(false); expect(this.rosterview.$el.is(':visible')).toEqual(false);
}, xmppchat)); }, converse));
open_controlbox = $.proxy(function () { open_controlbox = $.proxy(function () {
// This spec will only pass if the controlbox is not currently // This spec will only pass if the controlbox is not currently
@ -74,7 +74,7 @@
$('.toggle-online-users').click(); $('.toggle-online-users').click();
expect(this.toggleControlBox).toHaveBeenCalled(); expect(this.toggleControlBox).toHaveBeenCalled();
expect($("div#controlbox").is(':visible')).toBe(true); expect($("div#controlbox").is(':visible')).toBe(true);
}, xmppchat); }, converse);
it("can be opened by clicking a DOM element with class 'toggle-online-users'", open_controlbox); it("can be opened by clicking a DOM element with class 'toggle-online-users'", open_controlbox);
describe("The Status Widget", $.proxy(function () { describe("The Status Widget", $.proxy(function () {
@ -100,8 +100,8 @@
expect(view.updateStatusUI).toHaveBeenCalled(); expect(view.updateStatusUI).toHaveBeenCalled();
expect(view.$el.find('a.choose-xmpp-status').hasClass('online')).toBe(true); expect(view.$el.find('a.choose-xmpp-status').hasClass('online')).toBe(true);
expect(view.$el.find('a.choose-xmpp-status span.value').text()).toBe('I am online'); expect(view.$el.find('a.choose-xmpp-status span.value').text()).toBe('I am online');
}, xmppchat)); }, converse));
}, xmppchat)); }, converse));
it("can be used to set a custom status message", $.proxy(function () { it("can be used to set a custom status message", $.proxy(function () {
var view = this.xmppstatusview; var view = this.xmppstatusview;
@ -123,17 +123,17 @@
expect(view.$el.find('a.choose-xmpp-status').hasClass('online')).toBe(true); expect(view.$el.find('a.choose-xmpp-status').hasClass('online')).toBe(true);
expect(view.$el.find('a.choose-xmpp-status span.value').text()).toBe(msg); expect(view.$el.find('a.choose-xmpp-status span.value').text()).toBe(msg);
}); });
}, xmppchat)); }, converse));
}, xmppchat)); }, converse));
}, xmppchat)); }, converse));
describe("The Contacts Roster", $.proxy(function () { describe("The Contacts Roster", $.proxy(function () {
describe("Pending Contacts", $.proxy(function () { describe("Pending Contacts", $.proxy(function () {
it("do not have a heading if there aren't any", $.proxy(function () { it("do not have a heading if there aren't any", $.proxy(function () {
expect(this.rosterview.$el.find('dt#pending-xmpp-contacts').css('display')).toEqual('none'); expect(this.rosterview.$el.find('dt#pending-xmpp-contacts').css('display')).toEqual('none');
}, xmppchat)); }, converse));
it("can be added to the roster and they will be sorted alphabetically", $.proxy(function () { it("can be added to the roster and they will be sorted alphabetically", $.proxy(function () {
var i, t, is_last; var i, t, is_last;
@ -159,17 +159,17 @@
t = this.rosterview.$el.find('dt#pending-xmpp-contacts').siblings('dd.pending-xmpp-contact').text(); t = this.rosterview.$el.find('dt#pending-xmpp-contacts').siblings('dd.pending-xmpp-contact').text();
expect(t).toEqual(pend_names.slice(0,i+1).sort().join('')); expect(t).toEqual(pend_names.slice(0,i+1).sort().join(''));
} }
}, xmppchat)); }, converse));
it("will have their own heading once they have been added", $.proxy(function () { it("will have their own heading once they have been added", $.proxy(function () {
expect(this.rosterview.$el.find('dt#pending-xmpp-contacts').css('display')).toEqual('block'); expect(this.rosterview.$el.find('dt#pending-xmpp-contacts').css('display')).toEqual('block');
}, xmppchat)); }, converse));
}, xmppchat)); }, converse));
describe("Existing Contacts", $.proxy(function () { describe("Existing Contacts", $.proxy(function () {
it("do not have a heading if there aren't any", $.proxy(function () { it("do not have a heading if there aren't any", $.proxy(function () {
expect(this.rosterview.$el.find('dt#xmpp-contacts').css('display')).toEqual('none'); expect(this.rosterview.$el.find('dt#xmpp-contacts').css('display')).toEqual('none');
}, xmppchat)); }, converse));
it("can be added to the roster and they will be sorted alphabetically", $.proxy(function () { it("can be added to the roster and they will be sorted alphabetically", $.proxy(function () {
var i, t; var i, t;
@ -187,11 +187,11 @@
t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.offline').find('a.open-chat').text(); t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.offline').find('a.open-chat').text();
expect(t).toEqual(cur_names.slice(0,i+1).sort().join('')); expect(t).toEqual(cur_names.slice(0,i+1).sort().join(''));
} }
}, xmppchat)); }, converse));
it("will have their own heading once they have been added", $.proxy(function () { it("will have their own heading once they have been added", $.proxy(function () {
expect(this.rosterview.$el.find('dt#xmpp-contacts').css('display')).toEqual('block'); expect(this.rosterview.$el.find('dt#xmpp-contacts').css('display')).toEqual('block');
}, xmppchat)); }, converse));
it("can change their status to online and be sorted alphabetically", $.proxy(function () { it("can change their status to online and be sorted alphabetically", $.proxy(function () {
var item, view, jid, t; var item, view, jid, t;
@ -209,7 +209,7 @@
t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.online').find('a.open-chat').text(); t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.online').find('a.open-chat').text();
expect(t).toEqual(cur_names.slice(0,i+1).sort().join('')); expect(t).toEqual(cur_names.slice(0,i+1).sort().join(''));
} }
}, xmppchat)); }, converse));
it("can change their status to busy and be sorted alphabetically", $.proxy(function () { it("can change their status to busy and be sorted alphabetically", $.proxy(function () {
var item, view, jid, t; var item, view, jid, t;
@ -226,7 +226,7 @@
t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.dnd').find('a.open-chat').text(); t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.dnd').find('a.open-chat').text();
expect(t).toEqual(cur_names.slice(3,i+1).sort().join('')); expect(t).toEqual(cur_names.slice(3,i+1).sort().join(''));
} }
}, xmppchat)); }, converse));
it("can change their status to away and be sorted alphabetically", $.proxy(function () { it("can change their status to away and be sorted alphabetically", $.proxy(function () {
var item, view, jid, t; var item, view, jid, t;
@ -244,7 +244,7 @@
t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.away').find('a.open-chat').text(); t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.away').find('a.open-chat').text();
expect(t).toEqual(cur_names.slice(6,i+1).sort().join('')); expect(t).toEqual(cur_names.slice(6,i+1).sort().join(''));
} }
}, xmppchat)); }, converse));
it("can change their status to unavailable and be sorted alphabetically", $.proxy(function () { it("can change their status to unavailable and be sorted alphabetically", $.proxy(function () {
var item, view, jid, t; var item, view, jid, t;
@ -262,7 +262,7 @@
t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.unavailable').find('a.open-chat').text(); t = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact.unavailable').find('a.open-chat').text();
expect(t).toEqual(cur_names.slice(9, i+1).sort().join('')); expect(t).toEqual(cur_names.slice(9, i+1).sort().join(''));
} }
}, xmppchat)); }, converse));
it("are ordered according to status: online, busy, away, unavailable, offline", $.proxy(function () { it("are ordered according to status: online, busy, away, unavailable, offline", $.proxy(function () {
var contacts = this.rosterview.$el.find('dd.current-xmpp-contact'); var contacts = this.rosterview.$el.find('dd.current-xmpp-contact');
@ -287,17 +287,17 @@
for (i=12; i<cur_names.length; i++) { for (i=12; i<cur_names.length; i++) {
expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('offline'); expect($(contacts[i]).attr('class').split(' ',1)[0]).toEqual('offline');
} }
}, xmppchat)); }, converse));
}, xmppchat)); }, converse));
describe("Requesting Contacts", $.proxy(function () { describe("Requesting Contacts", $.proxy(function () {
// by default the dts are hidden from css class and only later they will be hidden // by default the dts are hidden from css class and only later they will be hidden
// by jQuery therefore for the first check we will see if visible instead of none // by jQuery therefore for the first check we will see if visible instead of none
it("do not have a heading if there aren't any", $.proxy(function () { it("do not have a heading if there aren't any", $.proxy(function () {
expect(this.rosterview.$el.find('dt#xmpp-contact-requests').is(':visible')).toEqual(false); expect(this.rosterview.$el.find('dt#xmpp-contact-requests').is(':visible')).toEqual(false);
}, xmppchat)); }, converse));
it("can be added to the roster and they will be sorted alphabetically", $.proxy(function () { it("can be added to the roster and they will be sorted alphabetically", $.proxy(function () {
var i, t; var i, t;
@ -319,11 +319,11 @@
// be opened. // be opened.
expect(this.showControlBox).toHaveBeenCalled(); expect(this.showControlBox).toHaveBeenCalled();
} }
}, xmppchat)); }, converse));
it("will have their own heading once they have been added", $.proxy(function () { it("will have their own heading once they have been added", $.proxy(function () {
expect(this.rosterview.$el.find('dt#xmpp-contact-requests').css('display')).toEqual('block'); expect(this.rosterview.$el.find('dt#xmpp-contact-requests').css('display')).toEqual('block');
}, xmppchat)); }, converse));
it("can have their requests accepted by the user", $.proxy(function () { it("can have their requests accepted by the user", $.proxy(function () {
// TODO: Testing can be more thorough here, the user is // TODO: Testing can be more thorough here, the user is
@ -338,7 +338,7 @@
accept_button.click(); accept_button.click();
expect(view.acceptRequest).toHaveBeenCalled(); expect(view.acceptRequest).toHaveBeenCalled();
expect(this.connection.roster.authorize).toHaveBeenCalled(); expect(this.connection.roster.authorize).toHaveBeenCalled();
}, xmppchat)); }, converse));
it("can have their requests denied by the user", $.proxy(function () { it("can have their requests denied by the user", $.proxy(function () {
var jid = req_names.sort()[1].replace(' ','.').toLowerCase() + '@localhost'; var jid = req_names.sort()[1].replace(' ','.').toLowerCase() + '@localhost';
@ -354,8 +354,8 @@
expect(this.connection.roster.unauthorize).toHaveBeenCalled(); expect(this.connection.roster.unauthorize).toHaveBeenCalled();
// There should now be one less contact // There should now be one less contact
expect(this.roster.length).toEqual(num_contacts-1); expect(this.roster.length).toEqual(num_contacts-1);
}, xmppchat)); }, converse));
}, xmppchat)); }, converse));
describe("All Contacts", $.proxy(function () { describe("All Contacts", $.proxy(function () {
@ -384,7 +384,7 @@
expect(_.isEqual(new_attrs.sort(), old_attrs.sort())).toEqual(true); expect(_.isEqual(new_attrs.sort(), old_attrs.sort())).toEqual(true);
} }
this.rosterview.render(); this.rosterview.render();
}, xmppchat)); }, converse));
afterEach($.proxy(function () { afterEach($.proxy(function () {
// Contacts retrieved from localStorage have chat_status of // Contacts retrieved from localStorage have chat_status of
@ -396,9 +396,9 @@
view = this.rosterview.rosteritemviews[jid]; view = this.rosterview.rosteritemviews[jid];
view.model.set('chat_status', 'online'); view.model.set('chat_status', 'online');
} }
}, xmppchat)); }, converse));
}, xmppchat)); }, converse));
}, xmppchat)); }, converse));
describe("The 'Add Contact' widget", $.proxy(function () { describe("The 'Add Contact' widget", $.proxy(function () {
it("opens up an add form when you click on it", $.proxy(function () { it("opens up an add form when you click on it", $.proxy(function () {
@ -409,9 +409,9 @@
expect(panel.toggleContactForm).toHaveBeenCalled(); expect(panel.toggleContactForm).toHaveBeenCalled();
// XXX: Awaiting more tests, close it again for now... // XXX: Awaiting more tests, close it again for now...
panel.$el.find('a.toggle-xmpp-contact-form').click(); panel.$el.find('a.toggle-xmpp-contact-form').click();
}, xmppchat)); }, converse));
}, xmppchat)); }, converse));
describe("A Chatbox", $.proxy(function () { describe("A Chatbox", $.proxy(function () {
it("is created when you click on a roster item", $.proxy(function () { it("is created when you click on a roster item", $.proxy(function () {
@ -431,7 +431,7 @@
expect(view.openChat).toHaveBeenCalled(); expect(view.openChat).toHaveBeenCalled();
expect(this.chatboxes.length).toEqual(i+2); expect(this.chatboxes.length).toEqual(i+2);
} }
}, xmppchat)); }, converse));
it("can be saved to, and retrieved from, localStorage", $.proxy(function () { it("can be saved to, and retrieved from, localStorage", $.proxy(function () {
// We instantiate a new ChatBoxes collection, which by default // We instantiate a new ChatBoxes collection, which by default
@ -451,7 +451,7 @@
expect(_.isEqual(new_attrs, old_attrs)).toEqual(true); expect(_.isEqual(new_attrs, old_attrs)).toEqual(true);
} }
this.rosterview.render(); this.rosterview.render();
}, xmppchat)); }, converse));
it("can be closed again by clicking a DOM element with class 'close-chatbox-button'", $.proxy(function () { it("can be closed again by clicking a DOM element with class 'close-chatbox-button'", $.proxy(function () {
var chatbox, view, $el, var chatbox, view, $el,
@ -464,7 +464,7 @@
view.$el.find('.close-chatbox-button').click(); view.$el.find('.close-chatbox-button').click();
expect(view.closeChat).toHaveBeenCalled(); expect(view.closeChat).toHaveBeenCalled();
} }
}, xmppchat)); }, converse));
it("will be removed from localStorage when closed", $.proxy(function () { it("will be removed from localStorage when closed", $.proxy(function () {
var newchatboxes = new this.ChatBoxes(); var newchatboxes = new this.ChatBoxes();
@ -477,7 +477,7 @@
// Lets open the controlbox again, purely for visual feedback // Lets open the controlbox again, purely for visual feedback
open_controlbox(); open_controlbox();
}, xmppchat)); }, converse));
describe("A Chat Message", $.proxy(function () { describe("A Chat Message", $.proxy(function () {
it("can be received which will open a chatbox and be displayed inside it", $.proxy(function () { it("can be received which will open a chatbox and be displayed inside it", $.proxy(function () {
@ -500,7 +500,7 @@
// messageReceived is a handler for received XMPP // messageReceived is a handler for received XMPP
// messages // messages
this.chatboxes.messageReceived(msg); this.chatboxes.messageReceived(msg);
}, xmppchat)); }, converse));
waits(500); waits(500);
runs($.proxy(function () { runs($.proxy(function () {
// Since we didn't already have an open chatbox, one // Since we didn't already have an open chatbox, one
@ -526,8 +526,8 @@
// chatbox in the DOM // chatbox in the DOM
var txt = chatboxview.$el.find('.chat-content').find('.chat-message').find('.chat-message-content').text(); var txt = chatboxview.$el.find('.chat-content').find('.chat-message').find('.chat-message-content').text();
expect(txt).toEqual(message); expect(txt).toEqual(message);
}, xmppchat)); }, converse));
}, xmppchat)); }, converse));
it("can be sent from a chatbox, and will appear inside it", $.proxy(function () { it("can be sent from a chatbox, and will appear inside it", $.proxy(function () {
var contact_jid = cur_names[0].replace(' ','.').toLowerCase() + '@localhost'; var contact_jid = cur_names[0].replace(' ','.').toLowerCase() + '@localhost';
@ -540,9 +540,9 @@
expect(view.model.messages.length, 2); expect(view.model.messages.length, 2);
var txt = view.$el.find('.chat-content').find('.chat-message').last().find('.chat-message-content').text(); var txt = view.$el.find('.chat-content').find('.chat-message').last().find('.chat-message-content').text();
expect(txt).toEqual(message); expect(txt).toEqual(message);
}, xmppchat)); }, converse));
}, xmppchat)); }, converse));
}, xmppchat)); }, converse));
describe("The Controlbox Tabs", $.proxy(function () { describe("The Controlbox Tabs", $.proxy(function () {
it("consist of two tabs, 'Contacts' and 'ChatRooms', of which 'Contacts' is by default visible", $.proxy(function () { it("consist of two tabs, 'Contacts' and 'ChatRooms', of which 'Contacts' is by default visible", $.proxy(function () {
@ -553,7 +553,7 @@
expect($panels.children().first().is(':visible')).toBe(true); expect($panels.children().first().is(':visible')).toBe(true);
expect($panels.children().last().attr('id')).toBe('chatrooms'); expect($panels.children().last().attr('id')).toBe('chatrooms');
expect($panels.children().last().is(':visible')).toBe(false); expect($panels.children().last().is(':visible')).toBe(false);
}, xmppchat)); }, converse));
describe("The Chatrooms Panel", $.proxy(function () { describe("The Chatrooms Panel", $.proxy(function () {
@ -574,7 +574,7 @@
expect($chatrooms.is(':visible')).toBe(true); expect($chatrooms.is(':visible')).toBe(true);
expect(cbview.switchTab).toHaveBeenCalled(); expect(cbview.switchTab).toHaveBeenCalled();
}); });
}, xmppchat)); }, converse));
it("contains a form through which a new chatroom can be created", $.proxy(function () { it("contains a form through which a new chatroom can be created", $.proxy(function () {
var roomspanel = this.chatboxesview.views.controlbox.roomspanel; var roomspanel = this.chatboxesview.views.controlbox.roomspanel;
@ -594,11 +594,9 @@
waits('250'); waits('250');
runs($.proxy(function () { runs($.proxy(function () {
expect($('.chatroom').length).toBe(1); // There should now be an open chatroom expect($('.chatroom').length).toBe(1); // There should now be an open chatroom
}, xmppchat)); }, converse));
}, xmppchat)); }, converse));
}, converse));
}, xmppchat)); }, converse));
}, xmppchat)); }, converse));
}, xmppchat));
})); }));