Commit 75b9a35e authored by JC Brand's avatar JC Brand

Bugfix. Time on old messages shown incorrectly.

Also other backports from production.
parent 3224a8c5
...@@ -44,7 +44,6 @@ ...@@ -44,7 +44,6 @@
define([ define([
"Libraries/burry.js/burry", "Libraries/burry.js/burry",
"Libraries/underscore.string",
"Libraries/jquery.tinysort", "Libraries/jquery.tinysort",
"Libraries/jquery-ui-1.9.1.custom", "Libraries/jquery-ui-1.9.1.custom",
"Libraries/sjcl", "Libraries/sjcl",
...@@ -94,6 +93,29 @@ ...@@ -94,6 +93,29 @@
} }
}; };
xmppchat.parseISO8601 = function (datestr) {
/* Parses string formatted as 2013-02-14T11:27:08.268Z to a Date obj.
*/
    var numericKeys = [1, 4, 5, 6, 7, 10, 11],
struct = /^\s*(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}\.?\d*)Z\s*$/.exec(datestr),
minutesOffset = 0;
for (var i = 0, k; (k = numericKeys[i]); ++i) {
struct[k] = +struct[k] || 0;
}
// allow undefined days and months
struct[2] = (+struct[2] || 1) - 1;
struct[3] = +struct[3] || 1;
if (struct[8] !== 'Z' && struct[9] !== undefined) {
minutesOffset = struct[10] * 60 + struct[11];
if (struct[9] === '+') {
minutesOffset = 0 - minutesOffset;
}
}
return new Date(Date.UTC(struct[1], struct[2], struct[3], struct[4], struct[5] + minutesOffset, struct[6], struct[7]));
};
xmppchat.updateMsgCounter = function () { xmppchat.updateMsgCounter = function () {
this.msg_counter += 1; this.msg_counter += 1;
if (this.msg_counter > 0) { if (this.msg_counter > 0) {
...@@ -278,7 +300,7 @@ ...@@ -278,7 +300,7 @@
var now = new Date(), var now = new Date(),
time = now.toLocaleTimeString().substring(0,5), time = now.toLocaleTimeString().substring(0,5),
minutes = now.getMinutes().toString(), minutes = now.getMinutes().toString(),
$chat_content = $(this.el).find('.chat-content'); $chat_content = this.$el.find('.chat-content');
var msg = xmppchat.storage.getLastMessage(this.model.get('jid')); var msg = xmppchat.storage.getLastMessage(this.model.get('jid'));
if (typeof msg !== 'undefined') { if (typeof msg !== 'undefined') {
...@@ -316,7 +338,7 @@ ...@@ -316,7 +338,7 @@
from = Strophe.getBareJidFromJid($message.attr('from')), from = Strophe.getBareJidFromJid($message.attr('from')),
to = $message.attr('to'), to = $message.attr('to'),
composing = $message.find('composing'), composing = $message.find('composing'),
$chat_content = $(this.el).find('.chat-content'), $chat_content = this.$el.find('.chat-content'),
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;
...@@ -413,25 +435,35 @@ ...@@ -413,25 +435,35 @@
} }
}, },
addHelpMessages: function (msgs) {
var $chat_content = this.$el.find('.chat-content'), i;
for (i=0; i<msgs.length; i++) {
$chat_content.append($('<div class="chat-help">'+msgs[i]+'</div>'));
}
this.scrolldown();
},
sendMessage: function (text) { sendMessage: function (text) {
// TODO: Look in ChatPartners to see what resources we have for the recipient. // TODO: Look in ChatPartners to see what resources we have for the recipient.
// if we have one resource, we sent to only that resources, if we have multiple // if we have one resource, we sent to only that resources, if we have multiple
// 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*$/), el, $chat_content,
msgs;
if (match) { if (match) {
if (match[1] === "clear") { if (match[1] === "clear") {
$(this.el).find('.chat-content').empty(); this.$el.find('.chat-content').empty();
xmppchat.storage.clearMessages(bare_jid); xmppchat.storage.clearMessages(bare_jid);
return; return;
} }
else if (match[1] === "help") { else if (match[1] === "help") {
$chat_content = $(this.el).find('.chat-content'); msgs = [
$chat_content.append($('<div class="chat-help"><strong>/help</strong>: Show this menu</div>')); '<strong>/help</strong>: Show this menu',
$chat_content.append($('<div class="chat-help"><strong>/clear</strong>: Remove messages</div>')); '<strong>/clear</strong>: Remove messages'
this.scrolldown(); ];
this.addHelpMessages(msgs);
return; return;
} }
} }
...@@ -466,14 +498,19 @@ ...@@ -466,14 +498,19 @@
if (message !== '') { if (message !== '') {
this.sendMessage(message); this.sendMessage(message);
} }
$(this.el).data('composing', false); this.$el.data('composing', false);
} else { } else {
composing = $(this.el).data('composing'); composing = this.$el.data('composing');
if (!composing) { if (!composing) {
notify = $msg({'to':this.model.get('jid'), 'type': 'chat'}) if (ev.keyCode != 47) {
.c('composing', {'xmlns':'http://jabber.org/protocol/chatstates'}); // We don't send composing messages if the message
xmppchat.connection.send(notify); // starts with forward-slash.
$(this.el).data('composing', true); notify = $msg({'to':this.model.get('jid'), 'type': 'chat'})
.c('composing', {'xmlns':'http://jabber.org/protocol/chatstates'});
xmppchat.connection.send(notify);
this.$el.data('composing', true);
}
this.$el.data('composing', true);
} }
} }
}, },
...@@ -535,18 +572,18 @@ ...@@ -535,18 +572,18 @@
'</form>'), '</form>'),
render: function () { render: function () {
$(this.el).attr('id', this.model.get('box_id')); this.$el.attr('id', this.model.get('box_id'));
$(this.el).html(this.template(this.model.toJSON())); this.$el.html(this.template(this.model.toJSON()));
this.insertClientStoredMessages(); this.insertClientStoredMessages();
return this; return this;
}, },
isVisible: function () { isVisible: function () {
return $(this.el).is(':visible'); return this.$el.is(':visible');
}, },
focus: function () { focus: function () {
$(this.el).find('.chat-textarea').focus(); this.$el.find('.chat-textarea').focus();
return this; return this;
}, },
...@@ -703,7 +740,7 @@ ...@@ -703,7 +740,7 @@
if (ev.type === 'click') { if (ev.type === 'click') {
jid = $(ev.target).attr('room-jid'); jid = $(ev.target).attr('room-jid');
} else { } else {
name = _.str.strip($(ev.target).find('input.new-chatroom-name').val()).toLowerCase(); name = $(ev.target).find('input.new-chatroom-name').val().trim().toLowerCase();
if (name) { if (name) {
jid = Strophe.escapeNode(name) + '@' + xmppchat.connection.muc_domain; jid = Strophe.escapeNode(name) + '@' + xmppchat.connection.muc_domain;
} else { } else {
...@@ -766,6 +803,11 @@ ...@@ -766,6 +803,11 @@
}); });
}, },
addHelpMessages: function (msgs) {
// Override addHelpMessages in ChatBoxView, for now do nothing.
return;
},
render: function () { render: function () {
var that = this; var that = this;
this.$el.hide('fast', function () { this.$el.hide('fast', function () {
...@@ -821,12 +863,13 @@ ...@@ -821,12 +863,13 @@
message = message.replace(/^\s+|\s+jQuery/g,""); message = message.replace(/^\s+|\s+jQuery/g,"");
$textarea.val('').focus(); $textarea.val('').focus();
if (message !== '') { if (message !== '') {
this.sendGroupMessage(message); this.sendChatRoomMessage(message);
} }
} }
}, },
sendGroupMessage: function (body) { sendChatRoomMessage: function (body) {
this.appendMessage(body);
var match = body.replace(/^\s*/, "").match(/^\/(.*?)(?: (.*))?$/) || [false]; var match = body.replace(/^\s*/, "").match(/^\/(.*?)(?: (.*))?$/) || [false];
switch (match[1]) { switch (match[1]) {
case 'msg': case 'msg':
...@@ -848,7 +891,7 @@ ...@@ -848,7 +891,7 @@
xmppchat.connection.muc.deop(this.model.get('jid'), match[2]); xmppchat.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');
$chat_content.append($('<div class="chat-help"><strong>/help</strong>: Show this menu</div>')); $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>/topic</strong>: Set chatroom topic</div>'));
/* TODO: /* TODO:
...@@ -890,9 +933,9 @@ ...@@ -890,9 +933,9 @@
xmppchat.connection.muc.join( xmppchat.connection.muc.join(
this.model.get('jid'), this.model.get('jid'),
this.model.get('nick'), this.model.get('nick'),
$.proxy(this.onMessage, this), $.proxy(this.onChatRoomMessage, this),
$.proxy(this.onPresence, this), $.proxy(this.onChatRoomPresence, this),
$.proxy(this.onRoster, this)); $.proxy(this.onChatRoomRoster, this));
}, },
onLeave: function () { onLeave: function () {
...@@ -902,7 +945,7 @@ ...@@ -902,7 +945,7 @@
} }
}, },
onPresence: function (presence, room) { onChatRoomPresence: function (presence, room) {
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') {
...@@ -917,11 +960,11 @@ ...@@ -917,11 +960,11 @@
return true; return true;
}, },
onMessage: function (message) { onChatRoomMessage: function (message) {
var body = $(message).children('body').text(), var body = $(message).children('body').text(),
jid = $(message).attr('from'), jid = $(message).attr('from'),
composing = $(message).find('composing'), 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();
...@@ -935,7 +978,8 @@ ...@@ -935,7 +978,8 @@
} }
} else { } else {
if (sender === this.model.get('nick')) { if (sender === this.model.get('nick')) {
this.appendMessage(body); // Our own message which is already appended
return true;
} else { } else {
$chat_content.find('div.chat-event').remove(); $chat_content.find('div.chat-event').remove();
...@@ -966,7 +1010,7 @@ ...@@ -966,7 +1010,7 @@
return true; return true;
}, },
onRoster: function (roster, room) { onChatRoomRoster: function (roster, room) {
var controlboxview = xmppchat.chatboxesview.views.controlbox, var controlboxview = xmppchat.chatboxesview.views.controlbox,
i; i;
...@@ -988,8 +1032,8 @@ ...@@ -988,8 +1032,8 @@
}, },
render: function () { render: function () {
$(this.el).attr('id', this.model.get('box_id')); this.$el.attr('id', this.model.get('box_id'));
$(this.el).html(this.template(this.model.toJSON())); this.$el.html(this.template(this.model.toJSON()));
return this; return this;
} }
}); });
...@@ -1009,7 +1053,7 @@ ...@@ -1009,7 +1053,7 @@
} }
_.each(open_chats, $.proxy(function (jid) { _.each(open_chats, $.proxy(function (jid) {
if (jid != 'controlbox') { if (jid != 'controlbox') {
if (_.str.include(jid, xmppchat.connection.muc_domain)) { if (strinclude(jid, xmppchat.connection.muc_domain)) {
this.createChatBox(jid); this.createChatBox(jid);
} else { } else {
this.openChat(jid); this.openChat(jid);
...@@ -1078,8 +1122,8 @@ ...@@ -1078,8 +1122,8 @@
view.scrolldown(); view.scrolldown();
view.focus(); view.focus();
} }
view.saveChatToStorage();
} }
view.saveChatToStorage();
return view; return view;
}, },
...@@ -1248,14 +1292,14 @@ ...@@ -1248,14 +1292,14 @@
that = this, that = this,
subscription = item.get('subscription'); subscription = item.get('subscription');
$(this.el).addClass(item.get('presence_type')); this.$el.addClass(item.get('presence_type'));
if (ask === 'subscribe') { if (ask === 'subscribe') {
this.$el.addClass('pending-xmpp-contact'); this.$el.addClass('pending-xmpp-contact');
$(this.el).html(this.pending_template(item.toJSON())); this.$el.html(this.pending_template(item.toJSON()));
} 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()));
this.$el.delegate('button.accept-xmpp-request', 'click', function (ev) { this.$el.delegate('button.accept-xmpp-request', 'click', function (ev) {
ev.preventDefault(); ev.preventDefault();
that.acceptRequest(); that.acceptRequest();
...@@ -1285,7 +1329,7 @@ ...@@ -1285,7 +1329,7 @@
initialize: function () { initialize: function () {
this.options.model.on('change', function (item, changed) { this.options.model.on('change', function (item, changed) {
if (_.has(changed.changes, 'presence_type')) { if (_.has(changed.changes, 'presence_type')) {
$(this.el).attr('class', item.changed.presence_type); this.$el.attr('class', item.changed.presence_type);
} }
}, this); }, this);
} }
...@@ -1557,7 +1601,7 @@ ...@@ -1557,7 +1601,7 @@
render: function () { render: function () {
this.$el.empty().html(this.template()); this.$el.empty().html(this.template());
var models = this.model.sort().models, var models = this.model.sort().models,
children = $(this.el).children(), children = this.$el.children(),
$my_contacts = this.$el.find('#xmpp-contacts').hide(), $my_contacts = this.$el.find('#xmpp-contacts').hide(),
$contact_requests = this.$el.find('#xmpp-contact-requests').hide(), $contact_requests = this.$el.find('#xmpp-contact-requests').hide(),
$pending_contacts = this.$el.find('#pending-xmpp-contacts').hide(), $pending_contacts = this.$el.find('#pending-xmpp-contacts').hide(),
...@@ -1704,7 +1748,7 @@ ...@@ -1704,7 +1748,7 @@
updateStatusUI: function (ev) { updateStatusUI: function (ev) {
var stat = ev.get('status'), var stat = ev.get('status'),
status_message = ev.get('status_message') || "I am " + stat; status_message = ev.get('status_message') || "I am " + stat;
$(this.el).find('#fancy-xmpp-status-select').html( this.$el.find('#fancy-xmpp-status-select').html(
this.status_template({ this.status_template({
'presence_type': stat, 'presence_type': stat,
'status_message': status_message 'status_message': status_message
...@@ -1729,12 +1773,12 @@ ...@@ -1729,12 +1773,12 @@
initialize: function () { initialize: function () {
// Replace the default dropdown with something nicer // Replace the default dropdown with something nicer
// ------------------------------------------------- // -------------------------------------------------
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),
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')
.html(this.status_template({ .html(this.status_template({
'status_message': "I am " + presence_type, 'status_message': "I am " + presence_type,
'presence_type': presence_type 'presence_type': presence_type
...@@ -1758,7 +1802,7 @@ ...@@ -1758,7 +1802,7 @@
// Event handlers // Event handlers
// -------------- // --------------
$(document).ready($.proxy(function () { $(document).ready($.proxy(function () {
var chatdata = jQuery('div#collective-xmpp-chat-data'), var chatdata = $('div#collective-xmpp-chat-data'),
$toggle = $('a#toggle-online-users'); $toggle = $('a#toggle-online-users');
$toggle.unbind('click'); $toggle.unbind('click');
...@@ -1787,7 +1831,6 @@ ...@@ -1787,7 +1831,6 @@
this.chatboxes = new this.ChatBoxes(); this.chatboxes = new this.ChatBoxes();
this.chatboxesview = new this.ChatBoxesView({'model': this.chatboxes}); this.chatboxesview = new this.ChatBoxesView({'model': this.chatboxes});
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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment