Commit 9528276b authored by JC Brand's avatar JC Brand

Use native Date methods instead of moment

- Use native `getTime` method instead of moment's `valueOf`
- Use toISOString() instead of moment().format()
  This makes the code timezone independent since we're now globally using UTC.
parent 565f7d9f
This diff is collapsed.
...@@ -338,10 +338,10 @@ ...@@ -338,10 +338,10 @@
`<value>urn:xmpp:mam:2</value>`+ `<value>urn:xmpp:mam:2</value>`+
`</field>`+ `</field>`+
`<field var="start">`+ `<field var="start">`+
`<value>${moment(start).format()}</value>`+ `<value>${moment(start).toISOString()}</value>`+
`</field>`+ `</field>`+
`<field var="end">`+ `<field var="end">`+
`<value>${moment(end).format()}</value>`+ `<value>${moment(end).toISOString()}</value>`+
`</field>`+ `</field>`+
`</x>`+ `</x>`+
`</query>`+ `</query>`+
...@@ -391,7 +391,7 @@ ...@@ -391,7 +391,7 @@
`<value>urn:xmpp:mam:2</value>`+ `<value>urn:xmpp:mam:2</value>`+
`</field>`+ `</field>`+
`<field var="start">`+ `<field var="start">`+
`<value>${moment(start).format()}</value>`+ `<value>${moment(start).toISOString()}</value>`+
`</field>`+ `</field>`+
`</x>`+ `</x>`+
`</query>`+ `</query>`+
...@@ -424,7 +424,7 @@ ...@@ -424,7 +424,7 @@
`<value>urn:xmpp:mam:2</value>`+ `<value>urn:xmpp:mam:2</value>`+
`</field>`+ `</field>`+
`<field var="start">`+ `<field var="start">`+
`<value>${moment(start).format()}</value>`+ `<value>${moment(start).toISOString()}</value>`+
`</field>`+ `</field>`+
`</x>`+ `</x>`+
`<set xmlns="http://jabber.org/protocol/rsm">`+ `<set xmlns="http://jabber.org/protocol/rsm">`+
...@@ -464,7 +464,7 @@ ...@@ -464,7 +464,7 @@
`<value>urn:xmpp:mam:2</value>`+ `<value>urn:xmpp:mam:2</value>`+
`</field>`+ `</field>`+
`<field var="start">`+ `<field var="start">`+
`<value>${moment(start).format()}</value>`+ `<value>${moment(start).toISOString()}</value>`+
`</field>`+ `</field>`+
`</x>`+ `</x>`+
`<set xmlns="http://jabber.org/protocol/rsm">`+ `<set xmlns="http://jabber.org/protocol/rsm">`+
...@@ -541,7 +541,7 @@ ...@@ -541,7 +541,7 @@
`<value>romeo@montague.lit</value>`+ `<value>romeo@montague.lit</value>`+
`</field>`+ `</field>`+
`<field var="start">`+ `<field var="start">`+
`<value>${moment(rsm.start).format()}</value>`+ `<value>${moment(rsm.start).toISOString()}</value>`+
`</field>`+ `</field>`+
`</x>`+ `</x>`+
`<set xmlns="http://jabber.org/protocol/rsm">`+ `<set xmlns="http://jabber.org/protocol/rsm">`+
......
...@@ -408,7 +408,7 @@ ...@@ -408,7 +408,7 @@
expect(chat_content.querySelectorAll('.date-separator').length).toEqual(4); expect(chat_content.querySelectorAll('.date-separator').length).toEqual(4);
let day = sizzle('.date-separator:first', chat_content).pop(); let day = sizzle('.date-separator:first', chat_content).pop();
expect(day.getAttribute('data-isodate')).toEqual(moment('2017-12-31T00:00:00').format()); expect(day.getAttribute('data-isodate')).toEqual(moment('2017-12-31T00:00:00').toISOString());
let time = sizzle('time:first', chat_content).pop(); let time = sizzle('time:first', chat_content).pop();
expect(time.textContent).toEqual('Sunday Dec 31st 2017') expect(time.textContent).toEqual('Sunday Dec 31st 2017')
...@@ -424,7 +424,7 @@ ...@@ -424,7 +424,7 @@
expect(time.textContent).toEqual("Monday Jan 1st 2018"); expect(time.textContent).toEqual("Monday Jan 1st 2018");
day = sizzle('.date-separator:eq(1)', chat_content).pop(); day = sizzle('.date-separator:eq(1)', chat_content).pop();
expect(day.getAttribute('data-isodate')).toEqual(moment('2018-01-01T00:00:00').format()); expect(day.getAttribute('data-isodate')).toEqual(moment('2018-01-01T00:00:00').toISOString());
expect(day.nextElementSibling.querySelector('.chat-msg__text').textContent).toBe('Inbetween message'); expect(day.nextElementSibling.querySelector('.chat-msg__text').textContent).toBe('Inbetween message');
el = sizzle('.chat-msg:eq(1)', chat_content).pop(); el = sizzle('.chat-msg:eq(1)', chat_content).pop();
...@@ -439,7 +439,7 @@ ...@@ -439,7 +439,7 @@
expect(time.textContent).toEqual("Tuesday Jan 2nd 2018"); expect(time.textContent).toEqual("Tuesday Jan 2nd 2018");
day = sizzle('.date-separator:nth(2)', chat_content).pop(); day = sizzle('.date-separator:nth(2)', chat_content).pop();
expect(day.getAttribute('data-isodate')).toEqual(moment('2018-01-02T00:00:00').format()); expect(day.getAttribute('data-isodate')).toEqual(moment('2018-01-02T00:00:00').toISOString());
expect(day.nextElementSibling.querySelector('.chat-msg__text').textContent).toBe('An earlier message on the next day'); expect(day.nextElementSibling.querySelector('.chat-msg__text').textContent).toBe('An earlier message on the next day');
el = sizzle('.chat-msg:eq(3)', chat_content).pop(); el = sizzle('.chat-msg:eq(3)', chat_content).pop();
...@@ -452,7 +452,7 @@ ...@@ -452,7 +452,7 @@
expect(u.hasClass('chat-msg--followup', el)).toBe(false); expect(u.hasClass('chat-msg--followup', el)).toBe(false);
day = sizzle('.date-separator:last', chat_content).pop(); day = sizzle('.date-separator:last', chat_content).pop();
expect(day.getAttribute('data-isodate')).toEqual(moment().startOf('day').format()); expect(day.getAttribute('data-isodate')).toEqual(moment().startOf('day').toISOString());
expect(day.nextElementSibling.querySelector('.chat-msg__text').textContent).toBe('latest message'); expect(day.nextElementSibling.querySelector('.chat-msg__text').textContent).toBe('latest message');
expect(u.hasClass('chat-msg--followup', el)).toBe(false); expect(u.hasClass('chat-msg--followup', el)).toBe(false);
done(); done();
...@@ -731,7 +731,7 @@ ...@@ -731,7 +731,7 @@
type: 'chat', type: 'chat',
id: one_day_ago.unix() id: one_day_ago.unix()
}).c('body').t(message).up() }).c('body').t(message).up()
.c('delay', { xmlns:'urn:xmpp:delay', from: 'localhost', stamp: one_day_ago.format() }) .c('delay', { xmlns:'urn:xmpp:delay', from: 'localhost', stamp: one_day_ago.toISOString() })
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree(); .c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
await _converse.chatboxes.onMessage(msg); await _converse.chatboxes.onMessage(msg);
await new Promise((resolve, reject) => view.once('messageInserted', resolve)); await new Promise((resolve, reject) => view.once('messageInserted', resolve));
...@@ -753,7 +753,7 @@ ...@@ -753,7 +753,7 @@
expect(chat_content.querySelectorAll('.date-separator').length).toEqual(1); expect(chat_content.querySelectorAll('.date-separator').length).toEqual(1);
let day = chat_content.querySelector('.date-separator'); let day = chat_content.querySelector('.date-separator');
expect(day.getAttribute('class')).toEqual('message date-separator'); expect(day.getAttribute('class')).toEqual('message date-separator');
expect(day.getAttribute('data-isodate')).toEqual(moment(one_day_ago.startOf('day')).format()); expect(day.getAttribute('data-isodate')).toEqual(moment(one_day_ago.startOf('day')).toISOString());
let time = chat_content.querySelector('time.separator-text'); let time = chat_content.querySelector('time.separator-text');
expect(time.textContent).toEqual(moment(one_day_ago.startOf('day')).format("dddd MMM Do YYYY")); expect(time.textContent).toEqual(moment(one_day_ago.startOf('day')).format("dddd MMM Do YYYY"));
...@@ -778,7 +778,7 @@ ...@@ -778,7 +778,7 @@
day = sizzle('.date-separator:last', chat_content); day = sizzle('.date-separator:last', chat_content);
expect(day.length).toEqual(1); expect(day.length).toEqual(1);
expect(day[0].getAttribute('class')).toEqual('message date-separator'); expect(day[0].getAttribute('class')).toEqual('message date-separator');
expect(day[0].getAttribute('data-isodate')).toEqual(moment(message_date).startOf('day').format()); expect(day[0].getAttribute('data-isodate')).toEqual(moment(message_date).startOf('day').toISOString());
time = sizzle('time.separator-text:last', chat_content).pop(); time = sizzle('time.separator-text:last', chat_content).pop();
expect(time.textContent).toEqual(moment(message_date).startOf('day').format("dddd MMM Do YYYY")); expect(time.textContent).toEqual(moment(message_date).startOf('day').format("dddd MMM Do YYYY"));
...@@ -1159,7 +1159,7 @@ ...@@ -1159,7 +1159,7 @@
_converse.chatboxes.onMessage($msg({'id': 'aeb218', 'to': _converse.bare_jid}) _converse.chatboxes.onMessage($msg({'id': 'aeb218', 'to': _converse.bare_jid})
.c('forwarded', {'xmlns': 'urn:xmpp:forward:0'}) .c('forwarded', {'xmlns': 'urn:xmpp:forward:0'})
.c('delay', {'xmlns': 'urn:xmpp:delay', .c('delay', {'xmlns': 'urn:xmpp:delay',
'stamp': moment(base_time).add(5, 'minutes').format() 'stamp': moment(base_time).add(5, 'minutes').toISOString()
}).up() }).up()
.c('message', { .c('message', {
'xmlns': 'jabber:client', 'xmlns': 'jabber:client',
...@@ -1190,7 +1190,7 @@ ...@@ -1190,7 +1190,7 @@
_converse.chatboxes.onMessage($msg({'id': 'aeb213', 'to': _converse.bare_jid}) _converse.chatboxes.onMessage($msg({'id': 'aeb213', 'to': _converse.bare_jid})
.c('forwarded', {'xmlns': 'urn:xmpp:forward:0'}) .c('forwarded', {'xmlns': 'urn:xmpp:forward:0'})
.c('delay', {'xmlns': 'urn:xmpp:delay', 'stamp':moment(base_time).add(4, 'minutes').format()}).up() .c('delay', {'xmlns': 'urn:xmpp:delay', 'stamp':moment(base_time).add(4, 'minutes').toISOString()}).up()
.c('message', { .c('message', {
'xmlns': 'jabber:client', 'xmlns': 'jabber:client',
'to': sender_jid, 'to': sender_jid,
...@@ -1497,7 +1497,7 @@ ...@@ -1497,7 +1497,7 @@
vcard_fetched = true; vcard_fetched = true;
return Promise.resolve({ return Promise.resolve({
'fullname': mock.cur_names[0], 'fullname': mock.cur_names[0],
'vcard_updated': moment().format(), 'vcard_updated': (new Date()).toISOString(),
'jid': sender_jid 'jid': sender_jid
}); });
}); });
...@@ -1636,7 +1636,7 @@ ...@@ -1636,7 +1636,7 @@
'msgid': '82bc02ce-9651-4336-baf0-fa04762ed8d2', 'msgid': '82bc02ce-9651-4336-baf0-fa04762ed8d2',
'fullname': fullname, 'fullname': fullname,
'sender': 'me', 'sender': 'me',
'time': moment().format(), 'time': (new Date()).toISOString(),
'message': msg_text 'message': msg_text
}); });
view.model.sendMessage(msg_text); view.model.sendMessage(msg_text);
...@@ -1653,7 +1653,7 @@ ...@@ -1653,7 +1653,7 @@
'msgid': '6fcdeee3-000f-4ce8-a17e-9ce28f0ae104', 'msgid': '6fcdeee3-000f-4ce8-a17e-9ce28f0ae104',
'fullname': fullname, 'fullname': fullname,
'sender': 'me', 'sender': 'me',
'time': moment().format(), 'time': (new Date()).toISOString(),
'message': msg_text 'message': msg_text
}); });
view.model.sendMessage(msg_text); view.model.sendMessage(msg_text);
...@@ -1721,7 +1721,7 @@ ...@@ -1721,7 +1721,7 @@
'msgid': 'another-id', 'msgid': 'another-id',
'fullname': fullname, 'fullname': fullname,
'sender': 'me', 'sender': 'me',
'time': moment().format(), 'time': (new Date()).toISOString(),
'message': msg_text 'message': msg_text
}); });
view.model.sendMessage(msg_text); view.model.sendMessage(msg_text);
......
...@@ -969,7 +969,7 @@ ...@@ -969,7 +969,7 @@
let indicator = chat_content.querySelector('.date-separator'); let indicator = chat_content.querySelector('.date-separator');
expect(indicator).not.toBe(null); expect(indicator).not.toBe(null);
expect(indicator.getAttribute('class')).toEqual('message date-separator'); expect(indicator.getAttribute('class')).toEqual('message date-separator');
expect(indicator.getAttribute('data-isodate')).toEqual(moment().startOf('day').format()); expect(indicator.getAttribute('data-isodate')).toEqual(moment().startOf('day').toISOString());
expect(indicator.querySelector('time').textContent).toEqual(moment().startOf('day').format("dddd MMM Do YYYY")); expect(indicator.querySelector('time').textContent).toEqual(moment().startOf('day').format("dddd MMM Do YYYY"));
expect(chat_content.querySelectorAll('div.chat-info').length).toBe(1); expect(chat_content.querySelectorAll('div.chat-info').length).toBe(1);
expect(chat_content.querySelector('div.chat-info').textContent).toBe("dummy has entered the groupchat"); expect(chat_content.querySelector('div.chat-info').textContent).toBe("dummy has entered the groupchat");
...@@ -999,11 +999,11 @@ ...@@ -999,11 +999,11 @@
}); });
_converse.connection._dataRecv(test_utils.createRequest(presence)); _converse.connection._dataRecv(test_utils.createRequest(presence));
indicator = chat_content.querySelector('.date-separator[data-isodate="'+moment().startOf('day').format()+'"]'); indicator = chat_content.querySelector('.date-separator[data-isodate="'+moment().startOf('day').toISOString()+'"]');
expect(indicator).not.toBe(null); expect(indicator).not.toBe(null);
expect(indicator.getAttribute('class')).toEqual('message date-separator'); expect(indicator.getAttribute('class')).toEqual('message date-separator');
expect(indicator.getAttribute('data-isodate')).toEqual(moment().startOf('day').format()); expect(indicator.getAttribute('data-isodate')).toEqual(moment().startOf('day').toISOString());
expect(indicator.querySelector('time').getAttribute('class')).toEqual('separator-text'); expect(indicator.querySelector('time').getAttribute('class')).toEqual('separator-text');
expect(indicator.querySelector('time').textContent).toEqual(moment().startOf('day').format("dddd MMM Do YYYY")); expect(indicator.querySelector('time').textContent).toEqual(moment().startOf('day').format("dddd MMM Do YYYY"));
expect(chat_content.querySelectorAll('div.chat-info').length).toBe(2); expect(chat_content.querySelectorAll('div.chat-info').length).toBe(2);
...@@ -1028,11 +1028,11 @@ ...@@ -1028,11 +1028,11 @@
}); });
_converse.connection._dataRecv(test_utils.createRequest(presence)); _converse.connection._dataRecv(test_utils.createRequest(presence));
indicator = chat_content.querySelector('.date-separator[data-isodate="'+moment().startOf('day').format()+'"]'); indicator = chat_content.querySelector('.date-separator[data-isodate="'+moment().startOf('day').toISOString()+'"]');
expect(indicator).not.toBe(null); expect(indicator).not.toBe(null);
expect(indicator.getAttribute('class')).toEqual('message date-separator'); expect(indicator.getAttribute('class')).toEqual('message date-separator');
expect(indicator.getAttribute('data-isodate')).toEqual(moment().startOf('day').format()); expect(indicator.getAttribute('data-isodate')).toEqual(moment().startOf('day').toISOString());
expect(indicator.querySelector('time').textContent).toEqual(moment().startOf('day').format("dddd MMM Do YYYY")); expect(indicator.querySelector('time').textContent).toEqual(moment().startOf('day').format("dddd MMM Do YYYY"));
expect(chat_content.querySelectorAll('div.chat-info').length).toBe(3); expect(chat_content.querySelectorAll('div.chat-info').length).toBe(3);
...@@ -1048,7 +1048,7 @@ ...@@ -1048,7 +1048,7 @@
type="groupchat" type="groupchat"
from="coven@chat.shakespeare.lit/some1"> from="coven@chat.shakespeare.lit/some1">
<body>hello world</body> <body>hello world</body>
<delay xmlns="urn:xmpp:delay" stamp="${moment().format()}" from="some1@localhost"/> <delay xmlns="urn:xmpp:delay" stamp="${(new Date()).toISOString()}" from="some1@localhost"/>
</message>`); </message>`);
_converse.connection._dataRecv(test_utils.createRequest(stanza)); _converse.connection._dataRecv(test_utils.createRequest(stanza));
await new Promise((resolve, reject) => view.once('messageInserted', resolve)); await new Promise((resolve, reject) => view.once('messageInserted', resolve));
...@@ -1069,7 +1069,7 @@ ...@@ -1069,7 +1069,7 @@
indicator = sizzle('.date-separator:eq(3)', chat_content).pop(); indicator = sizzle('.date-separator:eq(3)', chat_content).pop();
expect(indicator.getAttribute('class')).toEqual('message date-separator'); expect(indicator.getAttribute('class')).toEqual('message date-separator');
expect(indicator.getAttribute('data-isodate')).toEqual(moment().startOf('day').format()); expect(indicator.getAttribute('data-isodate')).toEqual(moment().startOf('day').toISOString());
expect(indicator.querySelector('time').textContent).toEqual(moment().startOf('day').format("dddd MMM Do YYYY")); expect(indicator.querySelector('time').textContent).toEqual(moment().startOf('day').format("dddd MMM Do YYYY"));
expect(chat_content.querySelectorAll('div.chat-info').length).toBe(4); expect(chat_content.querySelectorAll('div.chat-info').length).toBe(4);
expect(sizzle('div.chat-info:last', chat_content).pop().textContent) expect(sizzle('div.chat-info:last', chat_content).pop().textContent)
...@@ -1083,7 +1083,7 @@ ...@@ -1083,7 +1083,7 @@
type="groupchat" type="groupchat"
from="coven@chat.shakespeare.lit/some1">"+ from="coven@chat.shakespeare.lit/some1">"+
<body>hello world</body>"+ <body>hello world</body>"+
<delay xmlns="urn:xmpp:delay" stamp="${moment().format()}" from="some1@localhost"/>"+ <delay xmlns="urn:xmpp:delay" stamp="${(new Date()).toISOString()}" from="some1@localhost"/>"+
</message>`); </message>`);
_converse.connection._dataRecv(test_utils.createRequest(stanza)); _converse.connection._dataRecv(test_utils.createRequest(stanza));
await new Promise((resolve, reject) => view.once('messageInserted', resolve)); await new Promise((resolve, reject) => view.once('messageInserted', resolve));
...@@ -1109,7 +1109,7 @@ ...@@ -1109,7 +1109,7 @@
indicator = sizzle('.date-separator:eq(5)', chat_content).pop(); indicator = sizzle('.date-separator:eq(5)', chat_content).pop();
expect(indicator.getAttribute('class')).toEqual('message date-separator'); expect(indicator.getAttribute('class')).toEqual('message date-separator');
expect(indicator.getAttribute('data-isodate')).toEqual(moment().startOf('day').format()); expect(indicator.getAttribute('data-isodate')).toEqual(moment().startOf('day').toISOString());
expect(indicator.querySelector('time').textContent).toEqual(moment().startOf('day').format("dddd MMM Do YYYY")); expect(indicator.querySelector('time').textContent).toEqual(moment().startOf('day').format("dddd MMM Do YYYY"));
expect(chat_content.querySelectorAll('div.chat-info').length).toBe(5); expect(chat_content.querySelectorAll('div.chat-info').length).toBe(5);
expect(sizzle('div.chat-info:last', chat_content).pop().textContent).toBe( expect(sizzle('div.chat-info:last', chat_content).pop().textContent).toBe(
...@@ -4428,9 +4428,7 @@ ...@@ -4428,9 +4428,7 @@
expect(notifications[0].textContent).toEqual('newguy is typing'); expect(notifications[0].textContent).toEqual('newguy is typing');
const timeout_functions = []; const timeout_functions = [];
spyOn(window, 'setTimeout').and.callFake(function (func, delay) { spyOn(window, 'setTimeout').and.callFake(f => timeout_functions.push(f));
timeout_functions.push(func);
});
// Check that it doesn't appear twice // Check that it doesn't appear twice
msg = $msg({ msg = $msg({
...@@ -4450,7 +4448,6 @@ ...@@ -4450,7 +4448,6 @@
notifications = view.el.querySelectorAll('.chat-state-notification'); notifications = view.el.querySelectorAll('.chat-state-notification');
expect(notifications.length).toBe(1); expect(notifications.length).toBe(1);
expect(notifications[0].textContent).toEqual('newguy is typing'); expect(notifications[0].textContent).toEqual('newguy is typing');
expect(timeout_functions.length).toBe(1); expect(timeout_functions.length).toBe(1);
// <composing> state for a different occupant // <composing> state for a different occupant
...@@ -4470,8 +4467,8 @@ ...@@ -4470,8 +4467,8 @@
await test_utils.waitUntil(() => (view.el.querySelectorAll('.chat-state-notification').length === 2)); await test_utils.waitUntil(() => (view.el.querySelectorAll('.chat-state-notification').length === 2));
notifications = view.el.querySelectorAll('.chat-state-notification'); notifications = view.el.querySelectorAll('.chat-state-notification');
expect(notifications.length).toBe(2); expect(notifications.length).toBe(2);
expect(notifications[0].textContent).toEqual('newguy is typing'); expect(notifications[0].textContent).toEqual('nomorenicks is typing');
expect(notifications[1].textContent).toEqual('nomorenicks is typing'); expect(notifications[1].textContent).toEqual('newguy is typing');
// Check that new messages appear under the chat state notifications // Check that new messages appear under the chat state notifications
msg = $msg({ msg = $msg({
......
...@@ -560,7 +560,7 @@ converse.plugins.add('converse-chatview', { ...@@ -560,7 +560,7 @@ converse.plugins.add('converse-chatview', {
}, },
showChatEvent (message) { showChatEvent (message) {
const isodate = moment().format(); const isodate = (new Date()).toISOString();
this.content.insertAdjacentHTML( this.content.insertAdjacentHTML(
'beforeend', 'beforeend',
tpl_info({ tpl_info({
...@@ -576,7 +576,7 @@ converse.plugins.add('converse-chatview', { ...@@ -576,7 +576,7 @@ converse.plugins.add('converse-chatview', {
showErrorMessage (message) { showErrorMessage (message) {
this.content.insertAdjacentHTML( this.content.insertAdjacentHTML(
'beforeend', 'beforeend',
tpl_error_message({'message': message, 'isodate': moment().format() }) tpl_error_message({'message': message, 'isodate': (new Date()).toISOString() })
); );
this.scrollDown(); this.scrollDown();
}, },
...@@ -622,7 +622,7 @@ converse.plugins.add('converse-chatview', { ...@@ -622,7 +622,7 @@ converse.plugins.add('converse-chatview', {
const day_date = moment(next_msg_date).startOf('day'); const day_date = moment(next_msg_date).startOf('day');
next_msg_el.insertAdjacentHTML('beforeBegin', next_msg_el.insertAdjacentHTML('beforeBegin',
tpl_new_day({ tpl_new_day({
'isodate': day_date.format(), 'isodate': day_date.toISOString(),
'datestring': day_date.format("dddd MMM Do YYYY") 'datestring': day_date.format("dddd MMM Do YYYY")
}) })
); );
...@@ -633,19 +633,23 @@ converse.plugins.add('converse-chatview', { ...@@ -633,19 +633,23 @@ converse.plugins.add('converse-chatview', {
* Return the ISO8601 format date of the latest message. * Return the ISO8601 format date of the latest message.
* @private * @private
* @method _converse.ChatBoxView#getLastMessageDate * @method _converse.ChatBoxView#getLastMessageDate
* @param { object } cutoff - Moment Date cutoff date. The last * @param { Date } cutoff - Moment Date cutoff date. The last
* message received cutoff this date will be returned. * message received cutoff this date will be returned.
* @returns { Date }
*/ */
getLastMessageDate (cutoff) { getLastMessageDate (cutoff) {
const first_msg = u.getFirstChildElement(this.content, '.message:not(.chat-state-notification)'), const first_msg = u.getFirstChildElement(this.content, '.message:not(.chat-state-notification)');
oldest_date = first_msg ? first_msg.getAttribute('data-isodate') : null; const oldest_date = first_msg ? first_msg.getAttribute('data-isodate') : null;
if (!_.isNull(oldest_date) && moment(oldest_date).isAfter(cutoff)) { if (!_.isNull(oldest_date) && moment(oldest_date).isAfter(cutoff)) {
return null; return null;
} }
const last_msg = u.getLastChildElement(this.content, '.message:not(.chat-state-notification)'), const last_msg = u.getLastChildElement(this.content, '.message:not(.chat-state-notification)');
most_recent_date = last_msg ? last_msg.getAttribute('data-isodate') : null; const most_recent_date = last_msg ? last_msg.getAttribute('data-isodate') : null;
if (_.isNull(most_recent_date) || moment(most_recent_date).isBefore(cutoff)) { if (_.isNull(most_recent_date)) {
return most_recent_date; return null;
}
if (moment(most_recent_date).isBefore(cutoff)) {
return moment(most_recent_date).toDate();
} }
/* XXX: We avoid .chat-state-notification messages, since they are /* XXX: We avoid .chat-state-notification messages, since they are
* temporary and get removed once a new element is * temporary and get removed once a new element is
...@@ -656,17 +660,15 @@ converse.plugins.add('converse-chatview', { ...@@ -656,17 +660,15 @@ converse.plugins.add('converse-chatview', {
const msg_dates = _.invokeMap( const msg_dates = _.invokeMap(
sizzle('.message:not(.chat-state-notification)', this.content), sizzle('.message:not(.chat-state-notification)', this.content),
Element.prototype.getAttribute, 'data-isodate' Element.prototype.getAttribute, 'data-isodate'
) );
if (_.isObject(cutoff)) { const cutoff_iso = cutoff.toISOString();
cutoff = cutoff.format(); msg_dates.push(cutoff_iso);
}
msg_dates.push(cutoff);
msg_dates.sort(); msg_dates.sort();
const idx = msg_dates.lastIndexOf(cutoff); const idx = msg_dates.lastIndexOf(cutoff_iso);
if (idx === 0) { if (idx === 0) {
return null; return null;
} else { } else {
return msg_dates[idx-1]; return moment(msg_dates[idx-1]).toDate();
} }
}, },
...@@ -698,7 +700,7 @@ converse.plugins.add('converse-chatview', { ...@@ -698,7 +700,7 @@ converse.plugins.add('converse-chatview', {
this.content.insertAdjacentHTML( this.content.insertAdjacentHTML(
'beforeend', 'beforeend',
tpl_help_message({ tpl_help_message({
'isodate': moment().format(), 'isodate': (new Date()).toISOString(),
'type': type, 'type': type,
'message': xss.filterXSS(msg, {'whiteList': {'strong': []}}) 'message': xss.filterXSS(msg, {'whiteList': {'strong': []}})
}) })
...@@ -712,17 +714,6 @@ converse.plugins.add('converse-chatview', { ...@@ -712,17 +714,6 @@ converse.plugins.add('converse-chatview', {
return this.scrollDown(); return this.scrollDown();
}, },
clearChatStateNotification (message, isodate) {
if (isodate) {
_.each(
sizzle(`.chat-state-notification[data-csn="${message.get('from')}"][data-isodate="${isodate}"]`, this.content),
u.removeElement
);
} else {
_.each(sizzle(`.chat-state-notification[data-csn="${message.get('from')}"]`, this.content), u.removeElement);
}
},
shouldShowOnTextMessage () { shouldShowOnTextMessage () {
return !u.isVisible(this.el); return !u.isVisible(this.el);
}, },
...@@ -742,13 +733,13 @@ converse.plugins.add('converse-chatview', { ...@@ -742,13 +733,13 @@ converse.plugins.add('converse-chatview', {
return this.trigger('messageInserted', view.el); return this.trigger('messageInserted', view.el);
} }
} }
const current_msg_date = moment(view.model.get('time')) || moment, const current_msg_date = moment(view.model.get('time')).toDate() || new Date(),
previous_msg_date = this.getLastMessageDate(current_msg_date); previous_msg_date = this.getLastMessageDate(current_msg_date);
if (_.isNull(previous_msg_date)) { if (_.isNull(previous_msg_date)) {
this.content.insertAdjacentElement('afterbegin', view.el); this.content.insertAdjacentElement('afterbegin', view.el);
} else { } else {
const previous_msg_el = sizzle(`[data-isodate="${previous_msg_date}"]:last`, this.content).pop(); const previous_msg_el = sizzle(`[data-isodate="${previous_msg_date.toISOString()}"]:last`, this.content).pop();
if (view.model.get('type') === 'error' && if (view.model.get('type') === 'error' &&
u.hasClass('chat-error', previous_msg_el) && u.hasClass('chat-error', previous_msg_el) &&
previous_msg_el.textContent === view.model.get('message')) { previous_msg_el.textContent === view.model.get('message')) {
...@@ -815,7 +806,10 @@ converse.plugins.add('converse-chatview', { ...@@ -815,7 +806,10 @@ converse.plugins.add('converse-chatview', {
} }
const view = new _converse.MessageView({'model': message}); const view = new _converse.MessageView({'model': message});
await view.render(); await view.render();
this.clearChatStateNotification(message);
// Clear chat state notifications
sizzle(`.chat-state-notification[data-csn="${message.get('from')}"]`, this.content).forEach(u.removeElement);
this.insertMessage(view); this.insertMessage(view);
this.insertDayIndicator(view.el); this.insertDayIndicator(view.el);
this.setScrollPosition(view.el); this.setScrollPosition(view.el);
...@@ -1219,7 +1213,7 @@ converse.plugins.add('converse-chatview', { ...@@ -1219,7 +1213,7 @@ converse.plugins.add('converse-chatview', {
'beforeend', 'beforeend',
tpl_status_message({ tpl_status_message({
'message': text, 'message': text,
'isodate': moment().format(), 'isodate': (new Date()).toISOString(),
})); }));
this.scrollDown(); this.scrollDown();
} }
......
...@@ -196,7 +196,7 @@ converse.plugins.add('converse-controlbox', { ...@@ -196,7 +196,7 @@ converse.plugins.add('converse-controlbox', {
'chat_state': undefined, 'chat_state': undefined,
'closed': !_converse.show_controlbox_by_default, 'closed': !_converse.show_controlbox_by_default,
'num_unread': 0, 'num_unread': 0,
'time_opened': this.get('time_opened') || moment().valueOf(), 'time_opened': this.get('time_opened') || (new Date()).getTime(),
'type': _converse.CONTROLBOX_TYPE, 'type': _converse.CONTROLBOX_TYPE,
'url': '' 'url': ''
} }
......
...@@ -58,7 +58,7 @@ converse.plugins.add('converse-headline', { ...@@ -58,7 +58,7 @@ converse.plugins.add('converse-headline', {
'hidden': _.includes(['mobile', 'fullscreen'], _converse.view_mode), 'hidden': _.includes(['mobile', 'fullscreen'], _converse.view_mode),
'message_type': 'headline', 'message_type': 'headline',
'num_unread': 0, 'num_unread': 0,
'time_opened': this.get('time_opened') || moment().valueOf(), 'time_opened': this.get('time_opened') || (new Date()).getTime(),
'type': _converse.HEADLINES_TYPE 'type': _converse.HEADLINES_TYPE
} }
}, },
......
...@@ -149,7 +149,7 @@ converse.plugins.add('converse-message-view', { ...@@ -149,7 +149,7 @@ converse.plugins.add('converse-message-view', {
async renderChatMessage () { async renderChatMessage () {
const is_me_message = this.isMeCommand(), const is_me_message = this.isMeCommand(),
moment_time = moment(this.model.get('time')), time = moment(this.model.get('time')),
role = this.model.vcard ? this.model.vcard.get('role') : null, role = this.model.vcard ? this.model.vcard.get('role') : null,
roles = role ? role.split(',') : []; roles = role ? role.split(',') : [];
...@@ -159,8 +159,8 @@ converse.plugins.add('converse-message-view', { ...@@ -159,8 +159,8 @@ converse.plugins.add('converse-message-view', {
'__': __, '__': __,
'is_me_message': is_me_message, 'is_me_message': is_me_message,
'roles': roles, 'roles': roles,
'pretty_time': moment_time.format(_converse.time_format), 'pretty_time': time.format(_converse.time_format),
'time': moment_time.format(), 'time': time.toISOString(),
'extra_classes': this.getExtraMessageClasses(), 'extra_classes': this.getExtraMessageClasses(),
'label_show': __('Show more'), 'label_show': __('Show more'),
'username': this.model.getDisplayName() 'username': this.model.getDisplayName()
...@@ -201,12 +201,12 @@ converse.plugins.add('converse-message-view', { ...@@ -201,12 +201,12 @@ converse.plugins.add('converse-message-view', {
}, },
renderErrorMessage () { renderErrorMessage () {
const moment_time = moment(this.model.get('time')), const msg = u.stringToElement(
msg = u.stringToElement( tpl_info(Object.assign(this.model.toJSON(), {
tpl_info(Object.assign(this.model.toJSON(), { 'extra_classes': 'chat-error',
'extra_classes': 'chat-error', 'isodate': moment(this.model.get('time')).toISOString()
'isodate': moment_time.format() }))
}))); );
return this.replaceElement(msg); return this.replaceElement(msg);
}, },
...@@ -232,7 +232,7 @@ converse.plugins.add('converse-message-view', { ...@@ -232,7 +232,7 @@ converse.plugins.add('converse-message-view', {
} else { } else {
return; return;
} }
const isodate = moment().format(); const isodate = (new Date()).toISOString();
this.replaceElement( this.replaceElement(
u.stringToElement( u.stringToElement(
tpl_csn({ tpl_csn({
......
...@@ -58,14 +58,14 @@ converse.plugins.add('converse-minimize', { ...@@ -58,14 +58,14 @@ converse.plugins.add('converse-minimize', {
maximize () { maximize () {
u.safeSave(this, { u.safeSave(this, {
'minimized': false, 'minimized': false,
'time_opened': moment().valueOf() 'time_opened': (new Date()).getTime()
}); });
}, },
minimize () { minimize () {
u.safeSave(this, { u.safeSave(this, {
'minimized': true, 'minimized': true,
'time_minimized': moment().format() 'time_minimized': (new Date()).toISOString()
}); });
}, },
......
...@@ -1528,7 +1528,7 @@ converse.plugins.add('converse-muc-views', { ...@@ -1528,7 +1528,7 @@ converse.plugins.add('converse-muc-views', {
this.content.insertAdjacentHTML( this.content.insertAdjacentHTML(
'beforeend', 'beforeend',
tpl_info({ tpl_info({
'isodate': moment().format(), 'isodate': (new Date()).toISOString(),
'extra_classes': 'chat-event', 'extra_classes': 'chat-event',
'message': message 'message': message
})); }));
...@@ -1608,7 +1608,7 @@ converse.plugins.add('converse-muc-views', { ...@@ -1608,7 +1608,7 @@ converse.plugins.add('converse-muc-views', {
const data = { const data = {
'data_name': 'leavejoin', 'data_name': 'leavejoin',
'data_value': nick, 'data_value': nick,
'isodate': moment().format(), 'isodate': (new Date()).toISOString(),
'extra_classes': 'chat-event', 'extra_classes': 'chat-event',
'message': message 'message': message
}; };
...@@ -1627,7 +1627,7 @@ converse.plugins.add('converse-muc-views', { ...@@ -1627,7 +1627,7 @@ converse.plugins.add('converse-muc-views', {
const data = { const data = {
'data_name': 'join', 'data_name': 'join',
'data_value': nick, 'data_value': nick,
'isodate': moment().format(), 'isodate': (new Date()).toISOString(),
'extra_classes': 'chat-event', 'extra_classes': 'chat-event',
'message': message 'message': message
}; };
...@@ -1663,7 +1663,7 @@ converse.plugins.add('converse-muc-views', { ...@@ -1663,7 +1663,7 @@ converse.plugins.add('converse-muc-views', {
const data = { const data = {
'data_name': 'joinleave', 'data_name': 'joinleave',
'data_value': nick, 'data_value': nick,
'isodate': moment().format(), 'isodate': (new Date()).toISOString(),
'extra_classes': 'chat-event', 'extra_classes': 'chat-event',
'message': message 'message': message
}; };
...@@ -1681,7 +1681,7 @@ converse.plugins.add('converse-muc-views', { ...@@ -1681,7 +1681,7 @@ converse.plugins.add('converse-muc-views', {
} }
const data = { const data = {
'message': message, 'message': message,
'isodate': moment().format(), 'isodate': (new Date()).toISOString(),
'extra_classes': 'chat-event', 'extra_classes': 'chat-event',
'data_name': 'leave', 'data_name': 'leave',
'data_value': nick 'data_value': nick
...@@ -1794,7 +1794,7 @@ converse.plugins.add('converse-muc-views', { ...@@ -1794,7 +1794,7 @@ converse.plugins.add('converse-muc-views', {
const subject = this.model.get('subject'), const subject = this.model.get('subject'),
message = subject.text ? __('Topic set by %1$s', subject.author) : message = subject.text ? __('Topic set by %1$s', subject.author) :
__('Topic cleared by %1$s', subject.author), __('Topic cleared by %1$s', subject.author),
date = moment().format(); date = (new Date()).toISOString();
this.content.insertAdjacentHTML( this.content.insertAdjacentHTML(
'beforeend', 'beforeend',
tpl_info({ tpl_info({
......
...@@ -74,7 +74,7 @@ converse.plugins.add('converse-chatboxes', { ...@@ -74,7 +74,7 @@ converse.plugins.add('converse-chatboxes', {
defaults () { defaults () {
return { return {
'msgid': _converse.connection.getUniqueId(), 'msgid': _converse.connection.getUniqueId(),
'time': moment().format() 'time': (new Date()).toISOString()
}; };
}, },
...@@ -259,7 +259,7 @@ converse.plugins.add('converse-chatboxes', { ...@@ -259,7 +259,7 @@ converse.plugins.add('converse-chatboxes', {
'message_type': 'chat', 'message_type': 'chat',
'nickname': undefined, 'nickname': undefined,
'num_unread': 0, 'num_unread': 0,
'time_opened': this.get('time_opened') || moment().valueOf(), 'time_opened': this.get('time_opened') || (new Date()).getTime(),
'type': _converse.PRIVATE_CHAT_TYPE, 'type': _converse.PRIVATE_CHAT_TYPE,
'url': '' 'url': ''
} }
...@@ -353,7 +353,7 @@ converse.plugins.add('converse-chatboxes', { ...@@ -353,7 +353,7 @@ converse.plugins.add('converse-chatboxes', {
'message': this.getMessageBody(stanza), 'message': this.getMessageBody(stanza),
'references': this.getReferencesFromStanza(stanza), 'references': this.getReferencesFromStanza(stanza),
'older_versions': older_versions, 'older_versions': older_versions,
'edited': moment().format() 'edited': (new Date()).toISOString()
}); });
return true; return true;
} }
...@@ -442,7 +442,7 @@ converse.plugins.add('converse-chatboxes', { ...@@ -442,7 +442,7 @@ converse.plugins.add('converse-chatboxes', {
field_name = `marker_${marker.nodeName}`; field_name = `marker_${marker.nodeName}`;
if (message && !message.get(field_name)) { if (message && !message.get(field_name)) {
message.save({field_name: moment().format()}); message.save({field_name: (new Date()).toISOString()});
} }
return true; return true;
} }
...@@ -472,7 +472,7 @@ converse.plugins.add('converse-chatboxes', { ...@@ -472,7 +472,7 @@ converse.plugins.add('converse-chatboxes', {
const msgid = receipt && receipt.getAttribute('id'), const msgid = receipt && receipt.getAttribute('id'),
message = msgid && this.messages.findWhere({msgid}); message = msgid && this.messages.findWhere({msgid});
if (message && !message.get('received')) { if (message && !message.get('received')) {
message.save({'received': moment().format()}); message.save({'received': (new Date()).toISOString()});
} }
return true; return true;
} }
...@@ -534,9 +534,8 @@ converse.plugins.add('converse-chatboxes', { ...@@ -534,9 +534,8 @@ converse.plugins.add('converse-chatboxes', {
}, },
getOutgoingMessageAttributes (text, spoiler_hint) { getOutgoingMessageAttributes (text, spoiler_hint) {
const is_spoiler = this.get('composing_spoiler'), const is_spoiler = this.get('composing_spoiler');
origin_id = _converse.connection.getUniqueId(); const origin_id = _converse.connection.getUniqueId();
return { return {
'jid': this.get('jid'), 'jid': this.get('jid'),
'nickname': this.get('nickname'), 'nickname': this.get('nickname'),
...@@ -546,7 +545,7 @@ converse.plugins.add('converse-chatboxes', { ...@@ -546,7 +545,7 @@ converse.plugins.add('converse-chatboxes', {
'from': _converse.bare_jid, 'from': _converse.bare_jid,
'is_single_emoji': text ? u.isSingleEmoji(text) : false, 'is_single_emoji': text ? u.isSingleEmoji(text) : false,
'sender': 'me', 'sender': 'me',
'time': moment().format(), 'time': (new Date()).toISOString(),
'message': text ? u.httpToGeoUri(u.shortnameToUnicode(text), _converse) : undefined, 'message': text ? u.httpToGeoUri(u.shortnameToUnicode(text), _converse) : undefined,
'is_spoiler': is_spoiler, 'is_spoiler': is_spoiler,
'spoiler_hint': is_spoiler ? spoiler_hint : undefined, 'spoiler_hint': is_spoiler ? spoiler_hint : undefined,
...@@ -576,7 +575,7 @@ converse.plugins.add('converse-chatboxes', { ...@@ -576,7 +575,7 @@ converse.plugins.add('converse-chatboxes', {
older_versions.push(message.get('message')); older_versions.push(message.get('message'));
message.save({ message.save({
'correcting': false, 'correcting': false,
'edited': moment().format(), 'edited': (new Date()).toISOString(),
'message': attrs.message, 'message': attrs.message,
'older_versions': older_versions, 'older_versions': older_versions,
'references': attrs.references 'references': attrs.references
...@@ -747,7 +746,7 @@ converse.plugins.add('converse-chatboxes', { ...@@ -747,7 +746,7 @@ converse.plugins.add('converse-chatboxes', {
'references': this.getReferencesFromStanza(stanza), 'references': this.getReferencesFromStanza(stanza),
'subject': _.propertyOf(stanza.querySelector('subject'))('textContent'), 'subject': _.propertyOf(stanza.querySelector('subject'))('textContent'),
'thread': _.propertyOf(stanza.querySelector('thread'))('textContent'), 'thread': _.propertyOf(stanza.querySelector('thread'))('textContent'),
'time': delay ? moment(delay.getAttribute('stamp')).format() : moment().format(), 'time': delay ? moment(delay.getAttribute('stamp')).toISOString() : (new Date()).toISOString(),
'type': stanza.getAttribute('type') 'type': stanza.getAttribute('type')
}, this.getStanzaIDs(original_stanza)); }, this.getStanzaIDs(original_stanza));
......
...@@ -259,15 +259,15 @@ _converse.log = function (message, level, style='') { ...@@ -259,15 +259,15 @@ _converse.log = function (message, level, style='') {
logger.error(`${prefix} ERROR: ${message}`, style); logger.error(`${prefix} ERROR: ${message}`, style);
} else if (level === Strophe.LogLevel.WARN) { } else if (level === Strophe.LogLevel.WARN) {
if (_converse.debug) { if (_converse.debug) {
logger.warn(`${prefix} ${moment().format()} WARNING: ${message}`, style); logger.warn(`${prefix} ${(new Date()).toISOString()} WARNING: ${message}`, style);
} }
} else if (level === Strophe.LogLevel.FATAL) { } else if (level === Strophe.LogLevel.FATAL) {
logger.error(`${prefix} FATAL: ${message}`, style); logger.error(`${prefix} FATAL: ${message}`, style);
} else if (_converse.debug) { } else if (_converse.debug) {
if (level === Strophe.LogLevel.DEBUG) { if (level === Strophe.LogLevel.DEBUG) {
logger.debug(`${prefix} ${moment().format()} DEBUG: ${message}`, style); logger.debug(`${prefix} ${(new Date()).toISOString()} DEBUG: ${message}`, style);
} else { } else {
logger.info(`${prefix} ${moment().format()} INFO: ${message}`, style); logger.info(`${prefix} ${(new Date()).toISOString()} INFO: ${message}`, style);
} }
} }
}; };
...@@ -1793,7 +1793,7 @@ _converse.api = { ...@@ -1793,7 +1793,7 @@ _converse.api = {
}).c('forwarded', {'xmlns': Strophe.NS.FORWARD}) }).c('forwarded', {'xmlns': Strophe.NS.FORWARD})
.c('delay', { .c('delay', {
'xmns': Strophe.NS.DELAY, 'xmns': Strophe.NS.DELAY,
'stamp': moment().format() 'stamp': (new Date()).toISOString()
}).up() }).up()
.cnode(stanza.tree()) .cnode(stanza.tree())
); );
......
...@@ -363,7 +363,7 @@ converse.plugins.add('converse-mam', { ...@@ -363,7 +363,7 @@ converse.plugins.add('converse-mam', {
if (options[t]) { if (options[t]) {
const date = moment(options[t]); const date = moment(options[t]);
if (date.isValid()) { if (date.isValid()) {
stanza.c('field', {'var':t}).c('value').t(date.format()).up().up(); stanza.c('field', {'var':t}).c('value').t(date.toISOString()).up().up();
} else { } else {
throw new TypeError(`archive.query: invalid date provided for: ${t}`); throw new TypeError(`archive.query: invalid date provided for: ${t}`);
} }
......
...@@ -199,7 +199,7 @@ converse.plugins.add('converse-muc', { ...@@ -199,7 +199,7 @@ converse.plugins.add('converse-muc', {
'nick': _converse.xmppstatus.get('nickname') || _converse.nickname, 'nick': _converse.xmppstatus.get('nickname') || _converse.nickname,
'num_unread': 0, 'num_unread': 0,
'roomconfig': {}, 'roomconfig': {},
'time_opened': this.get('time_opened') || moment().valueOf(), 'time_opened': this.get('time_opened') || (new Date()).getTime(),
'type': _converse.CHATROOMS_TYPE 'type': _converse.CHATROOMS_TYPE
} }
}, },
...@@ -561,7 +561,7 @@ converse.plugins.add('converse-muc', { ...@@ -561,7 +561,7 @@ converse.plugins.add('converse-muc', {
const features = await _converse.api.disco.getFeatures(this.get('jid')); const features = await _converse.api.disco.getFeatures(this.get('jid'));
const attrs = Object.assign( const attrs = Object.assign(
_.zipObject(converse.ROOM_FEATURES, _.map(converse.ROOM_FEATURES, _.stubFalse)), _.zipObject(converse.ROOM_FEATURES, _.map(converse.ROOM_FEATURES, _.stubFalse)),
{'fetched': moment().format()} {'fetched': (new Date()).toISOString()}
); );
features.each(feature => { features.each(feature => {
const fieldname = feature.get('var'); const fieldname = feature.get('var');
...@@ -1055,7 +1055,7 @@ converse.plugins.add('converse-muc', { ...@@ -1055,7 +1055,7 @@ converse.plugins.add('converse-muc', {
attrs[key] = stanza_id.getAttribute('id'); attrs[key] = stanza_id.getAttribute('id');
} }
if (!message.get('received')) { if (!message.get('received')) {
attrs.received = moment().format(); attrs.received = (new Date()).toISOString();
} }
} }
return attrs; return attrs;
...@@ -1103,7 +1103,7 @@ converse.plugins.add('converse-muc', { ...@@ -1103,7 +1103,7 @@ converse.plugins.add('converse-muc', {
const msg = this.messages.create(attrs); const msg = this.messages.create(attrs);
this.incrementUnreadMsgCounter(msg); this.incrementUnreadMsgCounter(msg);
if (forwarded && msg && msg.get('sender') === 'me') { if (forwarded && msg && msg.get('sender') === 'me') {
msg.save({'received': moment().format()}); msg.save({'received': (new Date()).toISOString()});
} }
} }
_converse.api.trigger('message', {'stanza': original_stanza, 'chatbox': this}); _converse.api.trigger('message', {'stanza': original_stanza, 'chatbox': this});
......
...@@ -175,7 +175,7 @@ converse.plugins.add('converse-roster', { ...@@ -175,7 +175,7 @@ converse.plugins.add('converse-roster', {
'name': name, 'name': name,
'priority': _.isNaN(parseInt(priority, 10)) ? 0 : parseInt(priority, 10), 'priority': _.isNaN(parseInt(priority, 10)) ? 0 : parseInt(priority, 10),
'show': _.propertyOf(presence.querySelector('show'))('textContent') || 'online', 'show': _.propertyOf(presence.querySelector('show'))('textContent') || 'online',
'timestamp': _.isNil(delay) ? moment().format() : moment(delay.getAttribute('stamp')).format() 'timestamp': _.isNil(delay) ? (new Date()).toISOString() : moment(delay.getAttribute('stamp')).toISOString()
}; };
if (resource) { if (resource) {
resource.save(settings); resource.save(settings);
......
...@@ -73,7 +73,7 @@ converse.plugins.add('converse-vcard', { ...@@ -73,7 +73,7 @@ converse.plugins.add('converse-vcard', {
'url': _.get(vcard.querySelector('URL'), 'textContent'), 'url': _.get(vcard.querySelector('URL'), 'textContent'),
'role': _.get(vcard.querySelector('ROLE'), 'textContent'), 'role': _.get(vcard.querySelector('ROLE'), 'textContent'),
'email': _.get(vcard.querySelector('EMAIL USERID'), 'textContent'), 'email': _.get(vcard.querySelector('EMAIL USERID'), 'textContent'),
'vcard_updated': moment().format(), 'vcard_updated': (new Date()).toISOString(),
'vcard_error': undefined 'vcard_error': undefined
}; };
} }
...@@ -112,7 +112,7 @@ converse.plugins.add('converse-vcard', { ...@@ -112,7 +112,7 @@ converse.plugins.add('converse-vcard', {
return { return {
'stanza': iq, 'stanza': iq,
'jid': jid, 'jid': jid,
'vcard_error': moment().format() 'vcard_error': (new Date()).toISOString()
} }
} }
return onVCardData(jid, iq); return onVCardData(jid, iq);
......
...@@ -40304,7 +40304,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha ...@@ -40304,7 +40304,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
defaults() { defaults() {
return { return {
'msgid': _converse.connection.getUniqueId(), 'msgid': _converse.connection.getUniqueId(),
'time': moment().format() 'time': new Date().toISOString()
}; };
}, },
...@@ -40522,7 +40522,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha ...@@ -40522,7 +40522,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
'message_type': 'chat', 'message_type': 'chat',
'nickname': undefined, 'nickname': undefined,
'num_unread': 0, 'num_unread': 0,
'time_opened': this.get('time_opened') || moment().valueOf(), 'time_opened': this.get('time_opened') || new Date().getTime(),
'type': _converse.PRIVATE_CHAT_TYPE, 'type': _converse.PRIVATE_CHAT_TYPE,
'url': '' 'url': ''
}; };
...@@ -40638,7 +40638,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha ...@@ -40638,7 +40638,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
'message': this.getMessageBody(stanza), 'message': this.getMessageBody(stanza),
'references': this.getReferencesFromStanza(stanza), 'references': this.getReferencesFromStanza(stanza),
'older_versions': older_versions, 'older_versions': older_versions,
'edited': moment().format() 'edited': new Date().toISOString()
}); });
return true; return true;
} }
...@@ -40751,7 +40751,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha ...@@ -40751,7 +40751,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
if (message && !message.get(field_name)) { if (message && !message.get(field_name)) {
message.save({ message.save({
field_name: moment().format() field_name: new Date().toISOString()
}); });
} }
...@@ -40796,7 +40796,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha ...@@ -40796,7 +40796,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
if (message && !message.get('received')) { if (message && !message.get('received')) {
message.save({ message.save({
'received': moment().format() 'received': new Date().toISOString()
}); });
} }
...@@ -40880,8 +40880,9 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha ...@@ -40880,8 +40880,9 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
}, },
getOutgoingMessageAttributes(text, spoiler_hint) { getOutgoingMessageAttributes(text, spoiler_hint) {
const is_spoiler = this.get('composing_spoiler'), const is_spoiler = this.get('composing_spoiler');
origin_id = _converse.connection.getUniqueId();
const origin_id = _converse.connection.getUniqueId();
return { return {
'jid': this.get('jid'), 'jid': this.get('jid'),
...@@ -40892,7 +40893,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha ...@@ -40892,7 +40893,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
'from': _converse.bare_jid, 'from': _converse.bare_jid,
'is_single_emoji': text ? u.isSingleEmoji(text) : false, 'is_single_emoji': text ? u.isSingleEmoji(text) : false,
'sender': 'me', 'sender': 'me',
'time': moment().format(), 'time': new Date().toISOString(),
'message': text ? u.httpToGeoUri(u.shortnameToUnicode(text), _converse) : undefined, 'message': text ? u.httpToGeoUri(u.shortnameToUnicode(text), _converse) : undefined,
'is_spoiler': is_spoiler, 'is_spoiler': is_spoiler,
'spoiler_hint': is_spoiler ? spoiler_hint : undefined, 'spoiler_hint': is_spoiler ? spoiler_hint : undefined,
...@@ -40923,7 +40924,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha ...@@ -40923,7 +40924,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
older_versions.push(message.get('message')); older_versions.push(message.get('message'));
message.save({ message.save({
'correcting': false, 'correcting': false,
'edited': moment().format(), 'edited': new Date().toISOString(),
'message': attrs.message, 'message': attrs.message,
'older_versions': older_versions, 'older_versions': older_versions,
'references': attrs.references 'references': attrs.references
...@@ -41102,7 +41103,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha ...@@ -41102,7 +41103,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-cha
'references': this.getReferencesFromStanza(stanza), 'references': this.getReferencesFromStanza(stanza),
'subject': _.propertyOf(stanza.querySelector('subject'))('textContent'), 'subject': _.propertyOf(stanza.querySelector('subject'))('textContent'),
'thread': _.propertyOf(stanza.querySelector('thread'))('textContent'), 'thread': _.propertyOf(stanza.querySelector('thread'))('textContent'),
'time': delay ? moment(delay.getAttribute('stamp')).format() : moment().format(), 'time': delay ? moment(delay.getAttribute('stamp')).toISOString() : new Date().toISOString(),
'type': stanza.getAttribute('type') 'type': stanza.getAttribute('type')
}, this.getStanzaIDs(original_stanza)); }, this.getStanzaIDs(original_stanza));
...@@ -41904,15 +41905,15 @@ _converse.log = function (message, level) { ...@@ -41904,15 +41905,15 @@ _converse.log = function (message, level) {
logger.error(`${prefix} ERROR: ${message}`, style); logger.error(`${prefix} ERROR: ${message}`, style);
} else if (level === strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].LogLevel.WARN) { } else if (level === strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].LogLevel.WARN) {
if (_converse.debug) { if (_converse.debug) {
logger.warn(`${prefix} ${moment__WEBPACK_IMPORTED_MODULE_7___default()().format()} WARNING: ${message}`, style); logger.warn(`${prefix} ${new Date().toISOString()} WARNING: ${message}`, style);
} }
} else if (level === strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].LogLevel.FATAL) { } else if (level === strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].LogLevel.FATAL) {
logger.error(`${prefix} FATAL: ${message}`, style); logger.error(`${prefix} FATAL: ${message}`, style);
} else if (_converse.debug) { } else if (_converse.debug) {
if (level === strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].LogLevel.DEBUG) { if (level === strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].LogLevel.DEBUG) {
logger.debug(`${prefix} ${moment__WEBPACK_IMPORTED_MODULE_7___default()().format()} DEBUG: ${message}`, style); logger.debug(`${prefix} ${new Date().toISOString()} DEBUG: ${message}`, style);
} else { } else {
logger.info(`${prefix} ${moment__WEBPACK_IMPORTED_MODULE_7___default()().format()} INFO: ${message}`, style); logger.info(`${prefix} ${new Date().toISOString()} INFO: ${message}`, style);
} }
} }
}; };
...@@ -43589,7 +43590,7 @@ _converse.api = { ...@@ -43589,7 +43590,7 @@ _converse.api = {
'xmlns': strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].NS.FORWARD 'xmlns': strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].NS.FORWARD
}).c('delay', { }).c('delay', {
'xmns': strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].NS.DELAY, 'xmns': strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].NS.DELAY,
'stamp': moment__WEBPACK_IMPORTED_MODULE_7___default()().format() 'stamp': new Date().toISOString()
}).up().cnode(stanza.tree())); }).up().cnode(stanza.tree()));
} }
...@@ -44952,7 +44953,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-mam ...@@ -44952,7 +44953,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_2__["default"].plugins.add('converse-mam
if (date.isValid()) { if (date.isValid()) {
stanza.c('field', { stanza.c('field', {
'var': t 'var': t
}).c('value').t(date.format()).up().up(); }).c('value').t(date.toISOString()).up().up();
} else { } else {
throw new TypeError(`archive.query: invalid date provided for: ${t}`); throw new TypeError(`archive.query: invalid date provided for: ${t}`);
} }
...@@ -45246,7 +45247,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].plugins.add('converse-muc ...@@ -45246,7 +45247,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].plugins.add('converse-muc
'nick': _converse.xmppstatus.get('nickname') || _converse.nickname, 'nick': _converse.xmppstatus.get('nickname') || _converse.nickname,
'num_unread': 0, 'num_unread': 0,
'roomconfig': {}, 'roomconfig': {},
'time_opened': this.get('time_opened') || moment().valueOf(), 'time_opened': this.get('time_opened') || new Date().getTime(),
'type': _converse.CHATROOMS_TYPE 'type': _converse.CHATROOMS_TYPE
}; };
}, },
...@@ -45678,7 +45679,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].plugins.add('converse-muc ...@@ -45678,7 +45679,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].plugins.add('converse-muc
}); });
const features = await _converse.api.disco.getFeatures(this.get('jid')); const features = await _converse.api.disco.getFeatures(this.get('jid'));
const attrs = Object.assign(_.zipObject(_converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].ROOM_FEATURES, _.map(_converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].ROOM_FEATURES, _.stubFalse)), { const attrs = Object.assign(_.zipObject(_converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].ROOM_FEATURES, _.map(_converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].ROOM_FEATURES, _.stubFalse)), {
'fetched': moment().format() 'fetched': new Date().toISOString()
}); });
features.each(feature => { features.each(feature => {
const fieldname = feature.get('var'); const fieldname = feature.get('var');
...@@ -46242,7 +46243,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].plugins.add('converse-muc ...@@ -46242,7 +46243,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].plugins.add('converse-muc
} }
if (!message.get('received')) { if (!message.get('received')) {
attrs.received = moment().format(); attrs.received = new Date().toISOString();
} }
} }
...@@ -46292,7 +46293,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].plugins.add('converse-muc ...@@ -46292,7 +46293,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].plugins.add('converse-muc
if (forwarded && msg && msg.get('sender') === 'me') { if (forwarded && msg && msg.get('sender') === 'me') {
msg.save({ msg.save({
'received': moment().format() 'received': new Date().toISOString()
}); });
} }
} }
...@@ -47388,7 +47389,7 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins ...@@ -47388,7 +47389,7 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins
'name': name, 'name': name,
'priority': _.isNaN(parseInt(priority, 10)) ? 0 : parseInt(priority, 10), 'priority': _.isNaN(parseInt(priority, 10)) ? 0 : parseInt(priority, 10),
'show': _.propertyOf(presence.querySelector('show'))('textContent') || 'online', 'show': _.propertyOf(presence.querySelector('show'))('textContent') || 'online',
'timestamp': _.isNil(delay) ? moment().format() : moment(delay.getAttribute('stamp')).format() 'timestamp': _.isNil(delay) ? new Date().toISOString() : moment(delay.getAttribute('stamp')).toISOString()
}; };
if (resource) { if (resource) {
...@@ -48467,7 +48468,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins.add('converse-vca ...@@ -48467,7 +48468,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins.add('converse-vca
'url': _.get(vcard.querySelector('URL'), 'textContent'), 'url': _.get(vcard.querySelector('URL'), 'textContent'),
'role': _.get(vcard.querySelector('ROLE'), 'textContent'), 'role': _.get(vcard.querySelector('ROLE'), 'textContent'),
'email': _.get(vcard.querySelector('EMAIL USERID'), 'textContent'), 'email': _.get(vcard.querySelector('EMAIL USERID'), 'textContent'),
'vcard_updated': moment().format(), 'vcard_updated': new Date().toISOString(),
'vcard_error': undefined 'vcard_error': undefined
}; };
} }
...@@ -48519,7 +48520,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins.add('converse-vca ...@@ -48519,7 +48520,7 @@ _converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins.add('converse-vca
return { return {
'stanza': iq, 'stanza': iq,
'jid': jid, 'jid': jid,
'vcard_error': moment().format() 'vcard_error': new Date().toISOString()
}; };
} }
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