|
@@ -83,6 +83,7 @@
|
|
};
|
|
};
|
|
|
|
|
|
xmppchat.toISOString = function (date) {
|
|
xmppchat.toISOString = function (date) {
|
|
|
|
+ var pad;
|
|
if (typeof date.toISOString !== 'undefined') {
|
|
if (typeof date.toISOString !== 'undefined') {
|
|
return date.toISOString();
|
|
return date.toISOString();
|
|
} else {
|
|
} else {
|
|
@@ -202,8 +203,9 @@
|
|
getMessages: function (jid) {
|
|
getMessages: function (jid) {
|
|
var bare_jid = Strophe.getBareJidFromJid(jid),
|
|
var bare_jid = Strophe.getBareJidFromJid(jid),
|
|
decrypted_msgs = [], i;
|
|
decrypted_msgs = [], i;
|
|
- var msgs = store.get(hex_sha1(this.get('own_jid')+bare_jid)) || [];
|
|
|
|
- for (i=0; i<msgs.length; i++) {
|
|
|
|
|
|
+ var msgs = store.get(hex_sha1(this.get('own_jid')+bare_jid)) || [],
|
|
|
|
+ msgs_length = msgs.length;
|
|
|
|
+ for (i=0; i<msgs_length; i++) {
|
|
decrypted_msgs.push(sjcl.decrypt(hex_sha1(this.get('own_jid')), msgs[i]));
|
|
decrypted_msgs.push(sjcl.decrypt(hex_sha1(this.get('own_jid')), msgs[i]));
|
|
}
|
|
}
|
|
return decrypted_msgs;
|
|
return decrypted_msgs;
|
|
@@ -226,10 +228,11 @@
|
|
getOpenChats: function () {
|
|
getOpenChats: function () {
|
|
var key = hex_sha1(this.get('own_jid')+'-open-chats'),
|
|
var key = hex_sha1(this.get('own_jid')+'-open-chats'),
|
|
chats = store.get(key) || [],
|
|
chats = store.get(key) || [],
|
|
|
|
+ chats_length = chats.length,
|
|
decrypted_chats = [],
|
|
decrypted_chats = [],
|
|
i;
|
|
i;
|
|
|
|
|
|
- for (i=0; i<chats.length; i++) {
|
|
|
|
|
|
+ for (i=0; i<chats_length; i++) {
|
|
decrypted_chats.push(chats[i]);
|
|
decrypted_chats.push(chats[i]);
|
|
}
|
|
}
|
|
return decrypted_chats;
|
|
return decrypted_chats;
|
|
@@ -318,6 +321,7 @@
|
|
}
|
|
}
|
|
}
|
|
}
|
|
message = this.autoLink(message);
|
|
message = this.autoLink(message);
|
|
|
|
+ // TODO use minutes logic or remove it
|
|
if (minutes.length==1) {minutes = '0'+minutes;}
|
|
if (minutes.length==1) {minutes = '0'+minutes;}
|
|
$chat_content.find('div.chat-event').remove();
|
|
$chat_content.find('div.chat-event').remove();
|
|
$chat_content.append(this.message_template({
|
|
$chat_content.append(this.message_template({
|
|
@@ -341,6 +345,7 @@
|
|
/* XXX: event.mtype should be 'xhtml' for XHTML-IM messages,
|
|
/* XXX: event.mtype should be 'xhtml' for XHTML-IM messages,
|
|
but I only seem to get 'text'.
|
|
but I only seem to get 'text'.
|
|
*/
|
|
*/
|
|
|
|
+ var $message = $(message);
|
|
var body = this.autoLink($message.children('body').text()),
|
|
var body = this.autoLink($message.children('body').text()),
|
|
from = Strophe.getBareJidFromJid($message.attr('from')),
|
|
from = Strophe.getBareJidFromJid($message.attr('from')),
|
|
to = $message.attr('to'),
|
|
to = $message.attr('to'),
|
|
@@ -349,13 +354,12 @@
|
|
delayed = $message.find('delay').length > 0,
|
|
delayed = $message.find('delay').length > 0,
|
|
fullname = this.model.get('fullname'),
|
|
fullname = this.model.get('fullname'),
|
|
time, stamp, username, sender;
|
|
time, stamp, username, sender;
|
|
-
|
|
|
|
if (xmppchat.xmppstatus.getStatus() === 'offline') {
|
|
if (xmppchat.xmppstatus.getStatus() === 'offline') {
|
|
// only update the UI if the user is not offline
|
|
// only update the UI if the user is not offline
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
if (!body) {
|
|
if (!body) {
|
|
- if (composing.length > 0) {
|
|
|
|
|
|
+ if (composing.length) {
|
|
this.insertStatusNotification(fullname+' '+'is typing');
|
|
this.insertStatusNotification(fullname+' '+'is typing');
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -398,10 +402,10 @@
|
|
|
|
|
|
insertClientStoredMessages: function () {
|
|
insertClientStoredMessages: function () {
|
|
var msgs = xmppchat.storage.getMessages(this.model.get('jid')),
|
|
var msgs = xmppchat.storage.getMessages(this.model.get('jid')),
|
|
|
|
+ msgs_length = msgs.length,
|
|
$content = this.$el.find('.chat-content'),
|
|
$content = this.$el.find('.chat-content'),
|
|
- prev_date, this_date, now, separator, i;
|
|
|
|
-
|
|
|
|
- for (i=0; i<_.size(msgs); i++) {
|
|
|
|
|
|
+ prev_date, this_date, i;
|
|
|
|
+ for (i=0; i<msgs_length; i++) {
|
|
var msg = msgs[i],
|
|
var msg = msgs[i],
|
|
msg_array = msg.split(' ', 2),
|
|
msg_array = msg.split(' ', 2),
|
|
date = msg_array[0];
|
|
date = msg_array[0];
|
|
@@ -443,11 +447,12 @@
|
|
},
|
|
},
|
|
|
|
|
|
addHelpMessages: function (msgs) {
|
|
addHelpMessages: function (msgs) {
|
|
- var $chat_content = this.$el.find('.chat-content'), i;
|
|
|
|
- for (i=0; i<msgs.length; i++) {
|
|
|
|
|
|
+ var $chat_content = this.$el.find('.chat-content'), i,
|
|
|
|
+ msgs_length = msgs.length;
|
|
|
|
+ for (i=0; i<msgs_length; i++) {
|
|
$chat_content.append($('<div class="chat-help">'+msgs[i]+'</div>'));
|
|
$chat_content.append($('<div class="chat-help">'+msgs[i]+'</div>'));
|
|
}
|
|
}
|
|
- this.scrolldown();
|
|
|
|
|
|
+ this.scrollDown();
|
|
},
|
|
},
|
|
|
|
|
|
sendMessage: function (text) {
|
|
sendMessage: function (text) {
|
|
@@ -456,7 +461,7 @@
|
|
// we send to the bare jid.
|
|
// we send to the bare jid.
|
|
var timestamp = (new Date()).getTime(),
|
|
var timestamp = (new Date()).getTime(),
|
|
bare_jid = this.model.get('jid'),
|
|
bare_jid = this.model.get('jid'),
|
|
- match = text.replace(/^\s*/, "").match(/^\/(.*)\s*$/), el, $chat_content,
|
|
|
|
|
|
+ match = text.replace(/^\s*/, "").match(/^\/(.*)\s*$/),
|
|
msgs;
|
|
msgs;
|
|
|
|
|
|
if (match) {
|
|
if (match) {
|
|
@@ -496,8 +501,7 @@
|
|
var $textarea = $(ev.target),
|
|
var $textarea = $(ev.target),
|
|
message,
|
|
message,
|
|
notify,
|
|
notify,
|
|
- composing,
|
|
|
|
- that = this;
|
|
|
|
|
|
+ composing;
|
|
|
|
|
|
if(ev.keyCode == 13) {
|
|
if(ev.keyCode == 13) {
|
|
message = $textarea.val();
|
|
message = $textarea.val();
|
|
@@ -515,7 +519,6 @@
|
|
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);
|
|
xmppchat.connection.send(notify);
|
|
- this.$el.data('composing', true);
|
|
|
|
}
|
|
}
|
|
this.$el.data('composing', true);
|
|
this.$el.data('composing', true);
|
|
}
|
|
}
|
|
@@ -538,19 +541,21 @@
|
|
},
|
|
},
|
|
|
|
|
|
initialize: function (){
|
|
initialize: function (){
|
|
- $('body').append($(this.el).hide());
|
|
|
|
|
|
+ $('body').append(this.$el.hide());
|
|
|
|
|
|
xmppchat.roster.on('change', function (item, changed) {
|
|
xmppchat.roster.on('change', function (item, changed) {
|
|
|
|
+ var fullname = this.model.get('fullname'),
|
|
|
|
+ presence_type = item.get('presence_type');
|
|
if (item.get('jid') === this.model.get('jid')) {
|
|
if (item.get('jid') === this.model.get('jid')) {
|
|
if (_.has(changed.changes, 'presence_type')) {
|
|
if (_.has(changed.changes, 'presence_type')) {
|
|
if (this.$el.is(':visible')) {
|
|
if (this.$el.is(':visible')) {
|
|
- if (item.get('presence_type') === 'offline') {
|
|
|
|
- this.insertStatusNotification(this.model.get('fullname')+' '+'has gone offline');
|
|
|
|
- } else if (item.get('presence_type') === 'away') {
|
|
|
|
- this.insertStatusNotification(this.model.get('fullname')+' '+'has gone away');
|
|
|
|
- } else if ((item.get('presence_type') === 'busy') || (item.get('presence_type') === 'dnd')) {
|
|
|
|
- this.insertStatusNotification(this.model.get('fullname')+' '+'is busy');
|
|
|
|
- } else if (item.get('presence_type') === 'online') {
|
|
|
|
|
|
+ if (presence_type === 'offline') {
|
|
|
|
+ this.insertStatusNotification(fullname+' '+'has gone offline');
|
|
|
|
+ } else if (presence_type === 'away') {
|
|
|
|
+ this.insertStatusNotification(fullname+' '+'has gone away');
|
|
|
|
+ } else if ((presence_type === 'busy') || (presence_type === 'dnd')) {
|
|
|
|
+ this.insertStatusNotification(fullname+' '+'is busy');
|
|
|
|
+ } else if (presence_type === 'online') {
|
|
this.$el.find('div.chat-event').remove();
|
|
this.$el.find('div.chat-event').remove();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -579,8 +584,8 @@
|
|
'</form>'),
|
|
'</form>'),
|
|
|
|
|
|
render: function () {
|
|
render: function () {
|
|
- this.$el.attr('id', this.model.get('box_id'));
|
|
|
|
- this.$el.html(this.template(this.model.toJSON()));
|
|
|
|
|
|
+ this.$el.attr('id', this.model.get('box_id'))
|
|
|
|
+ .html(this.template(this.model.toJSON()));
|
|
this.insertClientStoredMessages();
|
|
this.insertClientStoredMessages();
|
|
return this;
|
|
return this;
|
|
},
|
|
},
|
|
@@ -595,15 +600,13 @@
|
|
},
|
|
},
|
|
|
|
|
|
show: function () {
|
|
show: function () {
|
|
- this.$el.css({'opacity': 0});
|
|
|
|
- this.$el.css({'display': 'inline'});
|
|
|
|
- this.$el.animate({
|
|
|
|
- opacity: '1'
|
|
|
|
- }, 200);
|
|
|
|
|
|
+ this.$el.css({'opacity': 0,
|
|
|
|
+ 'display': 'inline'})
|
|
|
|
+ .animate({opacity: '1'}, 200);
|
|
return this;
|
|
return this;
|
|
},
|
|
},
|
|
|
|
|
|
- scrolldown: function () {
|
|
|
|
|
|
+ scrollDown: function () {
|
|
var $content = this.$el.find('.chat-content');
|
|
var $content = this.$el.find('.chat-content');
|
|
$content.scrollTop($content[0].scrollHeight);
|
|
$content.scrollTop($content[0].scrollHeight);
|
|
}
|
|
}
|
|
@@ -657,7 +660,7 @@
|
|
$.getJSON(portal_url + "/search-users?q=" + $(ev.target).find('input.username').val(), function (data) {
|
|
$.getJSON(portal_url + "/search-users?q=" + $(ev.target).find('input.username').val(), function (data) {
|
|
var $results_el = $('#found-users');
|
|
var $results_el = $('#found-users');
|
|
$(data).each(function (idx, obj) {
|
|
$(data).each(function (idx, obj) {
|
|
- if ($results_el.children().length > 0) {
|
|
|
|
|
|
+ if ($results_el.children().length) {
|
|
$results_el.empty();
|
|
$results_el.empty();
|
|
}
|
|
}
|
|
$results_el.append(
|
|
$results_el.append(
|
|
@@ -675,12 +678,13 @@
|
|
|
|
|
|
subscribeToContact: function (ev) {
|
|
subscribeToContact: function (ev) {
|
|
ev.preventDefault();
|
|
ev.preventDefault();
|
|
- var jid = $(ev.target).attr('data-recipient'),
|
|
|
|
- name = $(ev.target).text();
|
|
|
|
|
|
+ var $target = $(ev.target),
|
|
|
|
+ jid = $target.attr('data-recipient'),
|
|
|
|
+ name = $target.text();
|
|
xmppchat.connection.roster.add(jid, name, [], function (iq) {
|
|
xmppchat.connection.roster.add(jid, name, [], function (iq) {
|
|
xmppchat.connection.roster.subscribe(jid);
|
|
xmppchat.connection.roster.subscribe(jid);
|
|
});
|
|
});
|
|
- $(ev.target).parent().remove();
|
|
|
|
|
|
+ $target.parent().remove();
|
|
$('form.search-xmpp-contact').hide();
|
|
$('form.search-xmpp-contact').hide();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -726,18 +730,20 @@
|
|
|
|
|
|
updateRoomsList: function () {
|
|
updateRoomsList: function () {
|
|
xmppchat.connection.muc.listRooms(xmppchat.connection.muc_domain, $.proxy(function (iq) {
|
|
xmppchat.connection.muc.listRooms(xmppchat.connection.muc_domain, $.proxy(function (iq) {
|
|
- var room, name, jid, i,
|
|
|
|
- rooms = $(iq).find('query').find('item');
|
|
|
|
- this.$el.find('#available-chatrooms').find('dd.available-chatroom').remove();
|
|
|
|
|
|
+ var name, jid, i,
|
|
|
|
+ rooms = $(iq).find('query').find('item'),
|
|
|
|
+ rooms_length = rooms.length,
|
|
|
|
+ $available_chatrooms = this.$el.find('#available-chatrooms');
|
|
|
|
+ $available_chatrooms.find('dd.available-chatroom').remove();
|
|
if (rooms.length) {
|
|
if (rooms.length) {
|
|
- this.$el.find('#available-chatrooms dt').show();
|
|
|
|
|
|
+ $available_chatrooms.find('dt').show();
|
|
} else {
|
|
} else {
|
|
- this.$el.find('#available-chatrooms dt').hide();
|
|
|
|
|
|
+ $available_chatrooms.find('dt').hide();
|
|
}
|
|
}
|
|
- for (i=0; i<rooms.length; i++) {
|
|
|
|
|
|
+ for (i=0; i<rooms_length; i++) {
|
|
name = Strophe.unescapeNode($(rooms[i]).attr('name'));
|
|
name = Strophe.unescapeNode($(rooms[i]).attr('name'));
|
|
jid = $(rooms[i]).attr('jid');
|
|
jid = $(rooms[i]).attr('jid');
|
|
- this.$el.find('#available-chatrooms').append(this.room_template({'name':name, 'jid':jid}));
|
|
|
|
|
|
+ $available_chatrooms.append(this.room_template({'name':name, 'jid':jid}));
|
|
}
|
|
}
|
|
return true;
|
|
return true;
|
|
}, this));
|
|
}, this));
|
|
@@ -786,7 +792,7 @@
|
|
},
|
|
},
|
|
|
|
|
|
initialize: function () {
|
|
initialize: function () {
|
|
- $('body').append($(this.el).hide());
|
|
|
|
|
|
+ $('body').append(this.$el.hide());
|
|
},
|
|
},
|
|
|
|
|
|
template: _.template(
|
|
template: _.template(
|
|
@@ -862,10 +868,7 @@
|
|
|
|
|
|
keyPressed: function (ev) {
|
|
keyPressed: function (ev) {
|
|
var $textarea = $(ev.target),
|
|
var $textarea = $(ev.target),
|
|
- message,
|
|
|
|
- notify,
|
|
|
|
- composing,
|
|
|
|
- that = this;
|
|
|
|
|
|
+ message;
|
|
|
|
|
|
if(ev.keyCode == 13) {
|
|
if(ev.keyCode == 13) {
|
|
message = $textarea.val();
|
|
message = $textarea.val();
|
|
@@ -879,7 +882,8 @@
|
|
|
|
|
|
sendChatRoomMessage: function (body) {
|
|
sendChatRoomMessage: function (body) {
|
|
this.appendMessage(body);
|
|
this.appendMessage(body);
|
|
- var match = body.replace(/^\s*/, "").match(/^\/(.*?)(?: (.*))?$/) || [false];
|
|
|
|
|
|
+ var match = body.replace(/^\s*/, "").match(/^\/(.*?)(?: (.*))?$/) || [false],
|
|
|
|
+ $chat_content;
|
|
switch (match[1]) {
|
|
switch (match[1]) {
|
|
case 'msg':
|
|
case 'msg':
|
|
// TODO: Private messages
|
|
// TODO: Private messages
|
|
@@ -901,17 +905,18 @@
|
|
break;
|
|
break;
|
|
case 'help':
|
|
case 'help':
|
|
$chat_content = this.$el.find('.chat-content');
|
|
$chat_content = this.$el.find('.chat-content');
|
|
- $chat_content.append($('<div class="chat-help"><strong>/help</strong>: Show this menu</div>'));
|
|
|
|
- $chat_content.append($('<div class="chat-help"><strong>/topic</strong>: Set chatroom topic</div>'));
|
|
|
|
|
|
+ $chat_content.append('<div class="chat-help"><strong>/help</strong>: Show this menu</div>' +
|
|
|
|
+ '<div class="chat-help"><strong>/topic</strong>: Set chatroom topic</div>');
|
|
/* TODO:
|
|
/* TODO:
|
|
$chat_content.append($('<div class="chat-help"><strong>/kick</strong>: Kick out user</div>'));
|
|
$chat_content.append($('<div class="chat-help"><strong>/kick</strong>: Kick out user</div>'));
|
|
$chat_content.append($('<div class="chat-help"><strong>/ban</strong>: Ban user</div>'));
|
|
$chat_content.append($('<div class="chat-help"><strong>/ban</strong>: Ban user</div>'));
|
|
$chat_content.append($('<div class="chat-help"><strong>/op $user</strong>: Remove messages</div>'));
|
|
$chat_content.append($('<div class="chat-help"><strong>/op $user</strong>: Remove messages</div>'));
|
|
$chat_content.append($('<div class="chat-help"><strong>/deop $user</strong>: Remove messages</div>'));
|
|
$chat_content.append($('<div class="chat-help"><strong>/deop $user</strong>: Remove messages</div>'));
|
|
*/
|
|
*/
|
|
- this.scrolldown();
|
|
|
|
|
|
+ this.scrollDown();
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
|
|
+ // TODO see why muc is flagged as unresolved variable
|
|
this.last_msgid = xmppchat.connection.muc.groupchat(this.model.get('jid'), body);
|
|
this.last_msgid = xmppchat.connection.muc.groupchat(this.model.get('jid'), body);
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
@@ -939,6 +944,7 @@
|
|
'</div>'),
|
|
'</div>'),
|
|
|
|
|
|
initialize: function () {
|
|
initialize: function () {
|
|
|
|
+ // TODO see why muc is flagged as unresolved variable
|
|
xmppchat.connection.muc.join(
|
|
xmppchat.connection.muc.join(
|
|
this.model.get('jid'),
|
|
this.model.get('jid'),
|
|
this.model.get('nick'),
|
|
this.model.get('nick'),
|
|
@@ -955,13 +961,15 @@
|
|
},
|
|
},
|
|
|
|
|
|
onChatRoomPresence: function (presence, room) {
|
|
onChatRoomPresence: function (presence, room) {
|
|
|
|
+ // TODO see if nick is useful
|
|
var nick = room.nick,
|
|
var nick = room.nick,
|
|
- from = $(presence).attr('from');
|
|
|
|
- if ($(presence).attr('type') !== 'error') {
|
|
|
|
|
|
+ $presence = $(presence),
|
|
|
|
+ from = $presence.attr('from');
|
|
|
|
+ if ($presence.attr('type') !== 'error') {
|
|
// check for status 110 to see if it's our own presence
|
|
// check for status 110 to see if it's our own presence
|
|
- if ($(presence).find("status[code='110']").length > 0) {
|
|
|
|
|
|
+ if ($presence.find("status[code='110']").length) {
|
|
// check if server changed our nick
|
|
// check if server changed our nick
|
|
- if ($(presence).find("status[code='210']").length > 0) {
|
|
|
|
|
|
+ if ($presence.find("status[code='210']").length) {
|
|
this.model.set({'nick': Strophe.getResourceFromJid(from)});
|
|
this.model.set({'nick': Strophe.getResourceFromJid(from)});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -970,18 +978,20 @@
|
|
},
|
|
},
|
|
|
|
|
|
onChatRoomMessage: function (message) {
|
|
onChatRoomMessage: function (message) {
|
|
- var body = $(message).children('body').text(),
|
|
|
|
- jid = $(message).attr('from'),
|
|
|
|
- composing = $(message).find('composing'),
|
|
|
|
|
|
+ var $message = $(message),
|
|
|
|
+ body = $message.children('body').text(),
|
|
|
|
+ jid = $message.attr('from'),
|
|
|
|
+ composing = $message.find('composing'),
|
|
$chat_content = this.$el.find('.chat-content'),
|
|
$chat_content = this.$el.find('.chat-content'),
|
|
sender = Strophe.unescapeNode(Strophe.getResourceFromJid(jid)),
|
|
sender = Strophe.unescapeNode(Strophe.getResourceFromJid(jid)),
|
|
- subject = $(message).children('subject').text();
|
|
|
|
|
|
+ subject = $message.children('subject').text(),
|
|
|
|
+ match;
|
|
|
|
|
|
if (subject) {
|
|
if (subject) {
|
|
this.$el.find('.chatroom-topic').text(subject).attr('title', subject);
|
|
this.$el.find('.chatroom-topic').text(subject).attr('title', subject);
|
|
}
|
|
}
|
|
if (!body) {
|
|
if (!body) {
|
|
- if (composing.length > 0) {
|
|
|
|
|
|
+ if (composing.length) {
|
|
this.insertStatusNotification(sender+' '+'is typing');
|
|
this.insertStatusNotification(sender+' '+'is typing');
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
@@ -1001,7 +1011,7 @@
|
|
'time': (new Date()).toLocaleTimeString().substring(0,5),
|
|
'time': (new Date()).toLocaleTimeString().substring(0,5),
|
|
'message': body,
|
|
'message': body,
|
|
'username': sender,
|
|
'username': sender,
|
|
- 'extra_classes': ($(message).find('delay').length > 0) && 'delayed' || ''
|
|
|
|
|
|
+ 'extra_classes': ($message.find('delay').length > 0) && 'delayed' || ''
|
|
}));
|
|
}));
|
|
} else {
|
|
} else {
|
|
$chat_content.append(
|
|
$chat_content.append(
|
|
@@ -1010,7 +1020,7 @@
|
|
'time': (new Date()).toLocaleTimeString().substring(0,5),
|
|
'time': (new Date()).toLocaleTimeString().substring(0,5),
|
|
'message': body,
|
|
'message': body,
|
|
'username': sender,
|
|
'username': sender,
|
|
- 'extra_classes': ($(message).find('delay').length > 0) && 'delayed' || ''
|
|
|
|
|
|
+ 'extra_classes': ($message.find('delay').length > 0) && 'delayed' || ''
|
|
}));
|
|
}));
|
|
}
|
|
}
|
|
$chat_content.scrollTop($chat_content[0].scrollHeight);
|
|
$chat_content.scrollTop($chat_content[0].scrollHeight);
|
|
@@ -1020,29 +1030,34 @@
|
|
},
|
|
},
|
|
|
|
|
|
onChatRoomRoster: function (roster, room) {
|
|
onChatRoomRoster: function (roster, room) {
|
|
|
|
+ // underscore size is needed because roster is on object
|
|
var controlboxview = xmppchat.chatboxesview.views.controlbox,
|
|
var controlboxview = xmppchat.chatboxesview.views.controlbox,
|
|
|
|
+ roster_size = _.size(roster),
|
|
|
|
+ $participant_list = this.$el.find('.participant-list'),
|
|
|
|
+ participants = [],
|
|
i;
|
|
i;
|
|
|
|
|
|
if (controlboxview) {
|
|
if (controlboxview) {
|
|
controlboxview.roomspanel.trigger('update-rooms-list');
|
|
controlboxview.roomspanel.trigger('update-rooms-list');
|
|
}
|
|
}
|
|
this.$el.find('.participant-list').empty();
|
|
this.$el.find('.participant-list').empty();
|
|
- for (i=0; i<_.size(roster); i++) {
|
|
|
|
- this.$el.find('.participant-list').append('<li>' + Strophe.unescapeNode(_.keys(roster)[i]) + '</li>');
|
|
|
|
|
|
+ for (i=0; i<roster_size; i++) {
|
|
|
|
+ participants.push('<li>' + Strophe.unescapeNode(_.keys(roster)[i]) + '</li>');
|
|
}
|
|
}
|
|
|
|
+ $participant_list.append(participants.join(""));
|
|
return true;
|
|
return true;
|
|
},
|
|
},
|
|
|
|
|
|
show: function () {
|
|
show: function () {
|
|
- this.$el.css({'opacity': 0});
|
|
|
|
- this.$el.css({'display': 'inline'});
|
|
|
|
- this.$el.animate({opacity: '1'}, 200);
|
|
|
|
|
|
+ this.$el.css({'opacity': 0,
|
|
|
|
+ 'display': 'inline'})
|
|
|
|
+ .animate({opacity: '1'}, 200);
|
|
return this;
|
|
return this;
|
|
},
|
|
},
|
|
|
|
|
|
render: function () {
|
|
render: function () {
|
|
- this.$el.attr('id', this.model.get('box_id'));
|
|
|
|
- this.$el.html(this.template(this.model.toJSON()));
|
|
|
|
|
|
+ this.$el.attr('id', this.model.get('box_id'))
|
|
|
|
+ .html(this.template(this.model.toJSON()));
|
|
return this;
|
|
return this;
|
|
}
|
|
}
|
|
});
|
|
});
|
|
@@ -1053,8 +1068,7 @@
|
|
el: '#collective-xmpp-chat-data',
|
|
el: '#collective-xmpp-chat-data',
|
|
|
|
|
|
restoreOpenChats: function () {
|
|
restoreOpenChats: function () {
|
|
- var open_chats = xmppchat.storage.getOpenChats(),
|
|
|
|
- that = this;
|
|
|
|
|
|
+ var open_chats = xmppchat.storage.getOpenChats();
|
|
|
|
|
|
if (_.indexOf(open_chats, 'controlbox') != -1) {
|
|
if (_.indexOf(open_chats, 'controlbox') != -1) {
|
|
// Controlbox already exists, we just need to show it.
|
|
// Controlbox already exists, we just need to show it.
|
|
@@ -1128,7 +1142,7 @@
|
|
} else {
|
|
} else {
|
|
view.show();
|
|
view.show();
|
|
if (jid !== 'controlbox') {
|
|
if (jid !== 'controlbox') {
|
|
- view.scrolldown();
|
|
|
|
|
|
+ view.scrollDown();
|
|
view.focus();
|
|
view.focus();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1137,18 +1151,18 @@
|
|
},
|
|
},
|
|
|
|
|
|
messageReceived: function (message) {
|
|
messageReceived: function (message) {
|
|
- if ($(message).attr('from') == xmppchat.connection.jid) {
|
|
|
|
|
|
+ var partner_jid, $message = $(message),
|
|
|
|
+ message_from = $message.attr('from');
|
|
|
|
+ if ( message_from == xmppchat.connection.jid) {
|
|
// FIXME: Forwarded messages should be sent to specific resources, not broadcasted
|
|
// FIXME: Forwarded messages should be sent to specific resources, not broadcasted
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
- var $forwarded = $(message).children('forwarded');
|
|
|
|
- if ($forwarded.length > 0) {
|
|
|
|
|
|
+ var $forwarded = $message.children('forwarded');
|
|
|
|
+ if ($forwarded.length) {
|
|
$message = $forwarded.children('message');
|
|
$message = $forwarded.children('message');
|
|
- } else {
|
|
|
|
- $message = $(message);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- var from = Strophe.getBareJidFromJid($message.attr('from')),
|
|
|
|
|
|
+ var from = Strophe.getBareJidFromJid(message_from),
|
|
to = Strophe.getBareJidFromJid($message.attr('to')),
|
|
to = Strophe.getBareJidFromJid($message.attr('to')),
|
|
view, resource;
|
|
view, resource;
|
|
|
|
|
|
@@ -1158,7 +1172,7 @@
|
|
resource = Strophe.getResourceFromJid($message.attr('to'));
|
|
resource = Strophe.getResourceFromJid($message.attr('to'));
|
|
} else {
|
|
} else {
|
|
partner_jid = from;
|
|
partner_jid = from;
|
|
- resource = Strophe.getResourceFromJid($message.attr('from'));
|
|
|
|
|
|
+ resource = Strophe.getResourceFromJid(message_from);
|
|
}
|
|
}
|
|
|
|
|
|
view = this.views[partner_jid];
|
|
view = this.views[partner_jid];
|
|
@@ -1315,7 +1329,6 @@
|
|
render: function () {
|
|
render: function () {
|
|
var item = this.model,
|
|
var item = this.model,
|
|
ask = item.get('ask'),
|
|
ask = item.get('ask'),
|
|
- that = this,
|
|
|
|
subscription = item.get('subscription');
|
|
subscription = item.get('subscription');
|
|
this.$el.addClass(item.get('presence_type'));
|
|
this.$el.addClass(item.get('presence_type'));
|
|
|
|
|
|
@@ -1377,9 +1390,10 @@
|
|
|
|
|
|
subscribeToSuggestedItems: function (msg) {
|
|
subscribeToSuggestedItems: function (msg) {
|
|
$(msg).find('item').each(function () {
|
|
$(msg).find('item').each(function () {
|
|
- var jid = $(this).attr('jid'),
|
|
|
|
- action = $(this).attr('action'),
|
|
|
|
- fullname = $(this).attr('name');
|
|
|
|
|
|
+ var $this = $(this),
|
|
|
|
+ jid = $this.attr('jid'),
|
|
|
|
+ action = $this.attr('action'),
|
|
|
|
+ fullname = $this.attr('name');
|
|
if (action === 'add') {
|
|
if (action === 'add') {
|
|
xmppchat.connection.roster.add(jid, fullname, [], function (iq) {
|
|
xmppchat.connection.roster.add(jid, fullname, [], function (iq) {
|
|
xmppchat.connection.roster.subscribe(jid);
|
|
xmppchat.connection.roster.subscribe(jid);
|
|
@@ -1451,9 +1465,11 @@
|
|
},
|
|
},
|
|
|
|
|
|
getNumOnlineContacts: function () {
|
|
getNumOnlineContacts: function () {
|
|
- var count = 0;
|
|
|
|
- for (var i=0; i<this.models.length; i++) {
|
|
|
|
- if (_.indexOf(['offline', 'unavailable'], this.models[i].get('presence_type')) === -1) {
|
|
|
|
|
|
+ var count = 0,
|
|
|
|
+ models = this.models,
|
|
|
|
+ models_length = models.length;
|
|
|
|
+ for (var i=0; i<models_length; i++) {
|
|
|
|
+ if (_.indexOf(['offline', 'unavailable'], models[i].get('presence_type')) === -1) {
|
|
count++;
|
|
count++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1483,12 +1499,13 @@
|
|
},
|
|
},
|
|
|
|
|
|
presenceHandler: function (presence) {
|
|
presenceHandler: function (presence) {
|
|
- var jid = $(presence).attr('from'),
|
|
|
|
|
|
+ var $presence = $(presence),
|
|
|
|
+ jid = $presence.attr('from'),
|
|
bare_jid = Strophe.getBareJidFromJid(jid),
|
|
bare_jid = Strophe.getBareJidFromJid(jid),
|
|
resource = Strophe.getResourceFromJid(jid),
|
|
resource = Strophe.getResourceFromJid(jid),
|
|
- presence_type = $(presence).attr('type'),
|
|
|
|
- show = $(presence).find('show'),
|
|
|
|
- status_message = $(presence).find('status'),
|
|
|
|
|
|
+ presence_type = $presence.attr('type'),
|
|
|
|
+ show = $presence.find('show'),
|
|
|
|
+ status_message = $presence.find('status'),
|
|
item, model;
|
|
item, model;
|
|
|
|
|
|
if (this.isSelf(bare_jid)) {
|
|
if (this.isSelf(bare_jid)) {
|
|
@@ -1496,14 +1513,15 @@
|
|
// 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.)
|
|
|
|
+ // TODO see if xmppstatus is truly unresolved
|
|
xmppchat.xmppstatus.set({'status': presence_type});
|
|
xmppchat.xmppstatus.set({'status': presence_type});
|
|
}
|
|
}
|
|
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) {
|
|
return true; // Ignore MUC
|
|
return true; // Ignore MUC
|
|
}
|
|
}
|
|
|
|
|
|
- if ((status_message.length > 0) && (status_message.text() && (presence_type !== 'unavailable'))) {
|
|
|
|
|
|
+ if ((status_message.length) && (status_message.text() && (presence_type !== 'unavailable'))) {
|
|
model = this.getItem(bare_jid);
|
|
model = this.getItem(bare_jid);
|
|
model.set({'status': status_message.text()});
|
|
model.set({'status': status_message.text()});
|
|
}
|
|
}
|
|
@@ -1513,7 +1531,7 @@
|
|
|
|
|
|
} else if (presence_type === 'subscribe') {
|
|
} else if (presence_type === 'subscribe') {
|
|
item = this.getItem(bare_jid);
|
|
item = this.getItem(bare_jid);
|
|
-
|
|
|
|
|
|
+ // TODO see if auto_subscribe is truly an unresolved variable
|
|
if (xmppchat.auto_subscribe) {
|
|
if (xmppchat.auto_subscribe) {
|
|
if ((!item) || (item.get('subscription') != 'to')) {
|
|
if ((!item) || (item.get('subscription') != 'to')) {
|
|
if (xmppchat.connection.roster.findItem(bare_jid)) {
|
|
if (xmppchat.connection.roster.findItem(bare_jid)) {
|
|
@@ -1551,6 +1569,7 @@
|
|
* 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.
|
|
*/
|
|
*/
|
|
|
|
+ // TODO see if xmppstatus is truly unresolved
|
|
xmppchat.xmppstatus.sendPresence('unsubscribe');
|
|
xmppchat.xmppstatus.sendPresence('unsubscribe');
|
|
if (xmppchat.connection.roster.findItem(bare_jid)) {
|
|
if (xmppchat.connection.roster.findItem(bare_jid)) {
|
|
xmppchat.chatboxesview.controlbox.roster.remove(bare_jid);
|
|
xmppchat.chatboxesview.controlbox.roster.remove(bare_jid);
|
|
@@ -1614,8 +1633,8 @@
|
|
delete this.rosteritemviews[item.id];
|
|
delete this.rosteritemviews[item.id];
|
|
}, this);
|
|
}, this);
|
|
|
|
|
|
- this.$el.hide();
|
|
|
|
- this.$el.html(this.template());
|
|
|
|
|
|
+ this.$el.hide()
|
|
|
|
+ .html(this.template());
|
|
},
|
|
},
|
|
|
|
|
|
template: _.template('<dt id="xmpp-contact-requests">Contact requests</dt>' +
|
|
template: _.template('<dt id="xmpp-contact-requests">Contact requests</dt>' +
|
|
@@ -1629,7 +1648,8 @@
|
|
var $my_contacts = this.$el.find('#xmpp-contacts'),
|
|
var $my_contacts = this.$el.find('#xmpp-contacts'),
|
|
$contact_requests = this.$el.find('#xmpp-contact-requests'),
|
|
$contact_requests = this.$el.find('#xmpp-contact-requests'),
|
|
$pending_contacts = this.$el.find('#pending-xmpp-contacts'),
|
|
$pending_contacts = this.$el.find('#pending-xmpp-contacts'),
|
|
- $count, num, presence_change;
|
|
|
|
|
|
+ $count, presence_change;
|
|
|
|
+ // TODO see if user_id would be useful
|
|
var user_id = Strophe.getNodeFromJid(item.id),
|
|
var user_id = Strophe.getNodeFromJid(item.id),
|
|
view = this.rosteritemviews[item.id],
|
|
view = this.rosteritemviews[item.id],
|
|
ask = item.get('ask'),
|
|
ask = item.get('ask'),
|
|
@@ -1823,6 +1843,8 @@
|
|
var $select = this.$el.find('select#select-xmpp-status'),
|
|
var $select = this.$el.find('select#select-xmpp-status'),
|
|
presence_type = this.model.getStatus() || 'offline',
|
|
presence_type = this.model.getStatus() || 'offline',
|
|
options = $('option', $select),
|
|
options = $('option', $select),
|
|
|
|
+ $options_target,
|
|
|
|
+ options_list = [],
|
|
that = this;
|
|
that = this;
|
|
this.$el.html(this.choose_template());
|
|
this.$el.html(this.choose_template());
|
|
this.$el.find('#fancy-xmpp-status-select')
|
|
this.$el.find('#fancy-xmpp-status-select')
|
|
@@ -1830,13 +1852,15 @@
|
|
'status_message': "I am " + presence_type,
|
|
'status_message': "I am " + presence_type,
|
|
'presence_type': presence_type
|
|
'presence_type': presence_type
|
|
}));
|
|
}));
|
|
- // iterate through all the <option> elements and create UL
|
|
|
|
|
|
+ // iterate through all the <option> elements and add option values
|
|
options.each(function(){
|
|
options.each(function(){
|
|
- $(that.el).find("#target dd ul").append(that.option_template({
|
|
|
|
- 'value': $(this).val(),
|
|
|
|
- 'text': $(this).text()
|
|
|
|
- })).hide();
|
|
|
|
|
|
+ options_list.push(that.option_template({
|
|
|
|
+ 'value': $(this).val(),
|
|
|
|
+ 'text': $(this).text()
|
|
|
|
+ }));
|
|
});
|
|
});
|
|
|
|
+ $options_target = this.$el.find("#target dd ul").hide();
|
|
|
|
+ $options_target.append(options_list.join(''));
|
|
$select.remove();
|
|
$select.remove();
|
|
|
|
|
|
// Listen for status change on the model and initialize
|
|
// Listen for status change on the model and initialize
|
|
@@ -1864,9 +1888,9 @@
|
|
|
|
|
|
$(document).bind('jarnxmpp.disconnected', $.proxy(function (ev, conn) {
|
|
$(document).bind('jarnxmpp.disconnected', $.proxy(function (ev, conn) {
|
|
$toggle.hide();
|
|
$toggle.hide();
|
|
- $connecting.show();
|
|
|
|
- $connecting.html('Unable to communicate with chat server');
|
|
|
|
- $connecting.css('background-image', "url(images/error_icon.png)");
|
|
|
|
|
|
+ $connecting.html('Unable to communicate with chat server')
|
|
|
|
+ .css('background-image', "url(images/error_icon.png)")
|
|
|
|
+ .show();
|
|
console.log("Connection Failed :(");
|
|
console.log("Connection Failed :(");
|
|
}, this));
|
|
}, this));
|
|
|
|
|
|
@@ -1886,7 +1910,8 @@
|
|
this.connection.addHandler(
|
|
this.connection.addHandler(
|
|
$.proxy(this.roster.subscribeToSuggestedItems, this.roster),
|
|
$.proxy(this.roster.subscribeToSuggestedItems, this.roster),
|
|
'http://jabber.org/protocol/rosterx', 'message', null);
|
|
'http://jabber.org/protocol/rosterx', 'message', null);
|
|
-
|
|
|
|
|
|
+ // TODO check this callback as pycharm returns a warning of invalid number
|
|
|
|
+ // of parameters
|
|
this.connection.roster.registerCallback(
|
|
this.connection.roster.registerCallback(
|
|
$.proxy(this.roster.rosterHandler, this.roster),
|
|
$.proxy(this.roster.rosterHandler, this.roster),
|
|
null, 'presence', null);
|
|
null, 'presence', null);
|