Fixed the following:
- Added missing var statements for variable declarations - Added TODO entries for code that needs to be used or further tested - Removed unused variables - Removed check of length > 0 as it's enought to check just item.length as a boolean - Renamed scrolldown to scrollDown to keep a consitent style of method naming - Removed extra jQuery wrapping for many objects and instead define it once and use it in the other places - Use jQuery chaining for modifying connecting message in jarn.disconnect - Define wrapped message in messageReceived from line 342 instead of expecting it to be received from the other messageReceived function
This commit is contained in:
parent
8b84ce346e
commit
fdddecbeb2
75
converse.js
75
converse.js
@ -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 {
|
||||||
@ -318,6 +319,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 +343,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 +352,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;
|
||||||
}
|
}
|
||||||
@ -399,7 +401,7 @@
|
|||||||
insertClientStoredMessages: function () {
|
insertClientStoredMessages: function () {
|
||||||
var msgs = xmppchat.storage.getMessages(this.model.get('jid')),
|
var msgs = xmppchat.storage.getMessages(this.model.get('jid')),
|
||||||
$content = this.$el.find('.chat-content'),
|
$content = this.$el.find('.chat-content'),
|
||||||
prev_date, this_date, now, separator, i;
|
prev_date, this_date, i;
|
||||||
|
|
||||||
for (i=0; i<_.size(msgs); i++) {
|
for (i=0; i<_.size(msgs); i++) {
|
||||||
var msg = msgs[i],
|
var msg = msgs[i],
|
||||||
@ -411,7 +413,7 @@
|
|||||||
if (this.isDifferentDay(this_date, new Date())) {
|
if (this.isDifferentDay(this_date, new Date())) {
|
||||||
$content.append($('<div class="chat-date"></div>').text(this_date.toString().substring(0,15)));
|
$content.append($('<div class="chat-date"></div>').text(this_date.toString().substring(0,15)));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
prev_date = this_date;
|
prev_date = this_date;
|
||||||
this_date = new Date(Date(date));
|
this_date = new Date(Date(date));
|
||||||
if (this.isDifferentDay(prev_date, this_date)) {
|
if (this.isDifferentDay(prev_date, this_date)) {
|
||||||
@ -447,7 +449,7 @@
|
|||||||
for (i=0; i<msgs.length; i++) {
|
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 +458,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 +498,7 @@
|
|||||||
var $textarea = $(ev.target),
|
var $textarea = $(ev.target),
|
||||||
message,
|
message,
|
||||||
notify,
|
notify,
|
||||||
composing,
|
composing;
|
||||||
that = this;
|
|
||||||
|
|
||||||
if(ev.keyCode == 13) {
|
if(ev.keyCode == 13) {
|
||||||
message = $textarea.val();
|
message = $textarea.val();
|
||||||
@ -603,7 +604,7 @@
|
|||||||
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);
|
||||||
}
|
}
|
||||||
@ -726,7 +727,7 @@
|
|||||||
|
|
||||||
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,
|
var name, jid, i,
|
||||||
rooms = $(iq).find('query').find('item');
|
rooms = $(iq).find('query').find('item');
|
||||||
this.$el.find('#available-chatrooms').find('dd.available-chatroom').remove();
|
this.$el.find('#available-chatrooms').find('dd.available-chatroom').remove();
|
||||||
if (rooms.length) {
|
if (rooms.length) {
|
||||||
@ -862,10 +863,7 @@
|
|||||||
|
|
||||||
keyPressed: function (ev) {
|
keyPressed: function (ev) {
|
||||||
var $textarea = $(ev.target),
|
var $textarea = $(ev.target),
|
||||||
message,
|
message;
|
||||||
notify,
|
|
||||||
composing,
|
|
||||||
that = this;
|
|
||||||
|
|
||||||
if(ev.keyCode == 13) {
|
if(ev.keyCode == 13) {
|
||||||
message = $textarea.val();
|
message = $textarea.val();
|
||||||
@ -879,7 +877,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
|
||||||
@ -909,9 +908,10 @@
|
|||||||
$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 +939,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,6 +956,7 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
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');
|
from = $(presence).attr('from');
|
||||||
if ($(presence).attr('type') !== 'error') {
|
if ($(presence).attr('type') !== 'error') {
|
||||||
@ -970,18 +972,20 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
onChatRoomMessage: function (message) {
|
onChatRoomMessage: function (message) {
|
||||||
var body = $(message).children('body').text(),
|
var $message = $(message),
|
||||||
jid = $(message).attr('from'),
|
body = $message.children('body').text(),
|
||||||
composing = $(message).find('composing'),
|
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;
|
||||||
}
|
}
|
||||||
@ -1053,8 +1057,7 @@
|
|||||||
el: '#collective-xmpp-chat-data',
|
el: '#collective-xmpp-chat-data',
|
||||||
|
|
||||||
restoreOpenChats: function () {
|
restoreOpenChats: function () {
|
||||||
var open_chats = xmppchat.storage.getOpenChats(),
|
var open_chats = xmppchat.storage.getOpenChats();
|
||||||
that = this;
|
|
||||||
|
|
||||||
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 +1131,7 @@
|
|||||||
} else {
|
} else {
|
||||||
view.show();
|
view.show();
|
||||||
if (jid !== 'controlbox') {
|
if (jid !== 'controlbox') {
|
||||||
view.scrolldown();
|
view.scrollDown();
|
||||||
view.focus();
|
view.focus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1137,15 +1140,14 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
messageReceived: function (message) {
|
messageReceived: function (message) {
|
||||||
if ($(message).attr('from') == xmppchat.connection.jid) {
|
var partner_jid, $message = $(message);
|
||||||
|
if ($message.attr('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');
|
var $forwarded = $message.children('forwarded');
|
||||||
if ($forwarded.length > 0) {
|
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.attr('from')),
|
||||||
@ -1315,7 +1317,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'));
|
||||||
|
|
||||||
@ -1496,6 +1497,7 @@
|
|||||||
// 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;
|
||||||
@ -1551,6 +1553,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);
|
||||||
@ -1629,7 +1632,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'),
|
||||||
@ -1864,9 +1868,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.html('Unable to communicate with chat server');
|
.css('background-image', "url(images/error_icon.png)")
|
||||||
$connecting.css('background-image', "url(images/error_icon.png)");
|
.show();
|
||||||
console.log("Connection Failed :(");
|
console.log("Connection Failed :(");
|
||||||
}, this));
|
}, this));
|
||||||
|
|
||||||
@ -1886,7 +1890,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);
|
||||||
|
Loading…
Reference in New Issue
Block a user