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