Make sure the time attribute for MAM message is parsed through moment

Messages (received directly or via MAM) are stored in a backbone
collection that's kept sorted by the message's "time" attribute.
Various parts of the codebase rely on this behavior.

For regular messages, the time attribute is generated by
`moment().format()`, which generates a timestamp in the browser's
local timezone, for example "...+02:00".

For MAM messages, we would previously copy the "delay.stamp" value
into the "time" attribute verbatim. However, that value is generated
by the server and is unlikely to be in the same timezone locale.

ISO timestamps expressed in different timezones cannot be sorted
lexicographically, breaking the premise of keeping the messages
collection sorted by time.
This commit is contained in:
laszlovl 2019-05-02 00:33:21 +02:00 committed by JC Brand
parent 15b2273631
commit 565f7d9f74
3 changed files with 3 additions and 3 deletions

2
dist/converse.js vendored
View File

@ -62855,7 +62855,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 ? delay.getAttribute('stamp') : moment().format(),
'time': delay ? moment(delay.getAttribute('stamp')).format() : moment().format(),
'type': stanza.getAttribute('type')
}, this.getStanzaIDs(original_stanza));

View File

@ -747,7 +747,7 @@ converse.plugins.add('converse-chatboxes', {
'references': this.getReferencesFromStanza(stanza),
'subject': _.propertyOf(stanza.querySelector('subject'))('textContent'),
'thread': _.propertyOf(stanza.querySelector('thread'))('textContent'),
'time': delay ? delay.getAttribute('stamp') : moment().format(),
'time': delay ? moment(delay.getAttribute('stamp')).format() : moment().format(),
'type': stanza.getAttribute('type')
}, this.getStanzaIDs(original_stanza));

View File

@ -41102,7 +41102,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 ? delay.getAttribute('stamp') : moment().format(),
'time': delay ? moment(delay.getAttribute('stamp')).format() : moment().format(),
'type': stanza.getAttribute('type')
}, this.getStanzaIDs(original_stanza));