Commit 7d472eb2 authored by JC Brand's avatar JC Brand

Add new dependency moment.js

Use it to better compare dates when trying to determine whether a message falls
on a different day.

Also upgraded some dependencies' versions.
parent 2a83d557
...@@ -3,12 +3,12 @@ ...@@ -3,12 +3,12 @@
"version": "0.8.0", "version": "0.8.0",
"devDependencies": { "devDependencies": {
"jasmine": "https://github.com/jcbrand/jasmine.git#1_3_x", "jasmine": "https://github.com/jcbrand/jasmine.git#1_3_x",
"otr": "0.2.7", "otr": "0.2.12",
"requirejs-text": "~2.0.10", "requirejs-text": "~2.0.10",
"requirejs-tpl-jcbrand": "*" "requirejs-tpl-jcbrand": "*"
}, },
"dependencies": { "dependencies": {
"requirejs": "2.1.8", "requirejs": "2.1.11",
"jquery": "1.8.3", "jquery": "1.8.3",
"jed": "0.5.4", "jed": "0.5.4",
"tinysort": "git://github.com/Sjeiti/TinySort.git", "tinysort": "git://github.com/Sjeiti/TinySort.git",
...@@ -20,11 +20,12 @@ ...@@ -20,11 +20,12 @@
"strophe.vcard": "https://raw.github.com/jcbrand/strophejs-plugins/75c8693992bc357c699b6d615eeb396e799f5c02/vcard/strophe.vcard.js", "strophe.vcard": "https://raw.github.com/jcbrand/strophejs-plugins/75c8693992bc357c699b6d615eeb396e799f5c02/vcard/strophe.vcard.js",
"strophe.disco": "https://raw.github.com/jcbrand/strophejs-plugins/75c8693992bc357c699b6d615eeb396e799f5c02/disco/strophe.disco.js", "strophe.disco": "https://raw.github.com/jcbrand/strophejs-plugins/75c8693992bc357c699b6d615eeb396e799f5c02/disco/strophe.disco.js",
"strophe.muc": "https://raw.github.com/strophe/strophejs-plugins/02310ad1b8da2962cd05b0f4bceaecca134efed4/muc/strophe.muc.js", "strophe.muc": "https://raw.github.com/strophe/strophejs-plugins/02310ad1b8da2962cd05b0f4bceaecca134efed4/muc/strophe.muc.js",
"otr": "0.2.7", "otr": "0.2.12",
"crypto-js-evanvosberg": "~3.1.2", "crypto-js-evanvosberg": "~3.1.2",
"almond": "~0.2.6", "almond": "~0.2.6",
"requirejs-text": "~2.0.10", "requirejs-text": "~2.0.10",
"requirejs-tpl-jcbrand": "*" "requirejs-tpl-jcbrand": "*",
"momentjs": "~2.6.0"
}, },
"exportsOverride": {} "exportsOverride": {}
} }
...@@ -12,11 +12,12 @@ ...@@ -12,11 +12,12 @@
define("converse", define("converse",
["converse-dependencies", "converse-templates"], ["converse-dependencies", "converse-templates"],
function(dependencies, templates) { function(dependencies, templates) {
var otr = dependencies[0]; var otr = dependencies.otr,
moment = dependencies.moment;
if (typeof otr !== "undefined") { if (typeof otr !== "undefined") {
return factory(jQuery, _, otr.OTR, otr.DSA, templates); return factory(jQuery, _, otr.OTR, otr.DSA, templates, moment);
} else { } else {
return factory(jQuery, _, undefined, undefined, templates); return factory(jQuery, _, undefined, undefined, templates, moment);
} }
} }
); );
...@@ -30,7 +31,7 @@ ...@@ -30,7 +31,7 @@
// TODO Templates not defined // TODO Templates not defined
root.converse = factory(jQuery, _, OTR, DSA, templates); root.converse = factory(jQuery, _, OTR, DSA, templates);
} }
}(this, function ($, _, OTR, DSA, templates) { }(this, function ($, _, OTR, DSA, templates, moment) {
if (typeof console === "undefined" || typeof console.log === "undefined") { if (typeof console === "undefined" || typeof console.log === "undefined") {
console = { log: function () {}, error: function () {} }; console = { log: function () {}, error: function () {} };
} }
...@@ -998,22 +999,19 @@ ...@@ -998,22 +999,19 @@
onMessageAdded: function (message) { onMessageAdded: 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 = converse.parseISO8601(time), previous_message, idx, this_date, prev_date, text, match;
previous_message, idx, prev_date, isodate, text, match;
// If this message is on a different day than the one received // If this message is on a different day than the one received
// prior, then indicate it on the chatbox. // prior, then indicate it on the chatbox.
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 = converse.parseISO8601(previous_message.get('time')); prev_date = moment(previous_message.get('time'));
isodate = new Date(this_date.getTime()); if (prev_date.isBefore(time, 'day')) {
isodate.setUTCHours(0,0,0,0); this_date = moment(time);
isodate = converse.toISOString(isodate);
if (this.isDifferentDay(prev_date, this_date)) {
this.$el.find('.chat-content').append(converse.templates.new_day({ this.$el.find('.chat-content').append(converse.templates.new_day({
isodate: isodate, isodate: this_date.format("YYYY-MM-DD"),
datestring: this_date.toString().substring(0,15) datestring: this_date.format("dddd, MMMM Do YYYY")
})); }));
} }
} }
...@@ -1029,13 +1027,6 @@ ...@@ -1029,13 +1027,6 @@
return this.scrollDown(); return this.scrollDown();
}, },
isDifferentDay: function (prev_date, next_date) {
return (
(next_date.getDate() != prev_date.getDate()) ||
(next_date.getFullYear() != prev_date.getFullYear()) ||
(next_date.getMonth() != prev_date.getMonth()));
},
sendMessageStanza: function (text) { sendMessageStanza: function (text) {
/* /*
* Sends the actual XML stanza to the XMPP server. * Sends the actual XML stanza to the XMPP server.
......
...@@ -29,6 +29,7 @@ config = { ...@@ -29,6 +29,7 @@ config = {
"crypto.mode-ctr": "components/otr/vendor/cryptojs/mode-ctr", "crypto.mode-ctr": "components/otr/vendor/cryptojs/mode-ctr",
"crypto": "src/crypto", "crypto": "src/crypto",
"eventemitter": "components/otr/build/dep/eventemitter", "eventemitter": "components/otr/build/dep/eventemitter",
"moment": "components/momentjs/moment",
"otr": "components/otr/build/otr", "otr": "components/otr/build/otr",
"converse-dependencies": "src/deps-full" "converse-dependencies": "src/deps-full"
}, },
......
...@@ -412,15 +412,11 @@ ...@@ -412,15 +412,11 @@
}, converse)); }, converse));
it("will indicate when it has a time difference of more than a day between it and its predecessor", $.proxy(function () { it("will indicate when it has a time difference of more than a day between it and its predecessor", $.proxy(function () {
// FIXME: there are issues where with timezones (when
// the browser is in a new day but the XMPP server is in
// the previous day).
spyOn(converse, 'emit'); spyOn(converse, 'emit');
var contact_name = mock.cur_names[1]; var contact_name = mock.cur_names[1];
var contact_jid = contact_name.replace(' ','.').toLowerCase() + '@localhost'; var contact_jid = contact_name.replace(' ','.').toLowerCase() + '@localhost';
utils.openChatBoxFor(contact_jid); utils.openChatBoxFor(contact_jid);
utils.clearChatBoxMessages(contact_jid); utils.clearChatBoxMessages(contact_jid);
var one_day_ago = new Date(new Date().setDate(new Date().getDate()-1)); var one_day_ago = new Date(new Date().setDate(new Date().getDate()-1));
var message = 'This is a day old message'; var message = 'This is a day old message';
var chatbox = this.chatboxes.get(contact_jid); var chatbox = this.chatboxes.get(contact_jid);
...@@ -465,11 +461,10 @@ ...@@ -465,11 +461,10 @@
// props. // props.
var $time = $chat_content.find('time'); var $time = $chat_content.find('time');
var message_date = new Date(); var message_date = new Date();
message_date.setUTCHours(0,0,0,0);
expect($time.length).toEqual(1); expect($time.length).toEqual(1);
expect($time.attr('class')).toEqual('chat-date'); expect($time.attr('class')).toEqual('chat-date');
expect($time.attr('datetime')).toEqual(converse.toISOString(message_date)); expect($time.attr('datetime')).toEqual(moment(message_date).format("YYYY-MM-DD"));
expect($time.text()).toEqual(message_date.toString().substring(0,15)); expect($time.text()).toEqual(moment(message_date).format("dddd, MMMM Do YYYY"));
// Normal checks for the 2nd message // Normal checks for the 2nd message
expect(chatbox.messages.length).toEqual(2); expect(chatbox.messages.length).toEqual(2);
...@@ -633,6 +628,7 @@ ...@@ -633,6 +628,7 @@
it("is cleared when the window is focused", $.proxy(function () { it("is cleared when the window is focused", $.proxy(function () {
spyOn(converse, 'clearMsgCounter').andCallThrough(); spyOn(converse, 'clearMsgCounter').andCallThrough();
runs(function () { runs(function () {
$(window).trigger('blur');
$(window).trigger('focus'); $(window).trigger('focus');
}); });
waits(50); waits(50);
......
define("converse-dependencies", [ define("converse-dependencies", [
"otr", "otr",
"moment",
"locales", "locales",
"backbone.localStorage", "backbone.localStorage",
"jquery.tinysort", "jquery.tinysort",
...@@ -8,6 +9,9 @@ define("converse-dependencies", [ ...@@ -8,6 +9,9 @@ define("converse-dependencies", [
"strophe.roster", "strophe.roster",
"strophe.vcard", "strophe.vcard",
"strophe.disco" "strophe.disco"
], function() { ], function(otr, moment) {
return arguments; return {
'otr': otr,
'moment': moment
};
}); });
define("converse-dependencies", [ define("converse-dependencies", [
"moment",
"locales", "locales",
"backbone.localStorage", "backbone.localStorage",
"jquery.tinysort", "jquery.tinysort",
...@@ -7,6 +8,9 @@ define("converse-dependencies", [ ...@@ -7,6 +8,9 @@ define("converse-dependencies", [
"strophe.roster", "strophe.roster",
"strophe.vcard", "strophe.vcard",
"strophe.disco" "strophe.disco"
], function() { ], function(moment) {
return undefined; return {
'otr': undefined,
'moment': moment
};
}); });
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