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