powered by Jive Software

Retrieve the timestamp for offline and Archived messages

am using Smack version 4.3 and I would like to get the timestamp for messages. I have checked the Message class and it contains no clue about time. Not being XMPP expert myself and having read almost everything I could find, am at loss as to how do I retrieve the timestamp for offline messages and MAM archived messages.

Any pointer or help is appreciated.
TIA

1 Like

From XEP-0313 § 4.2:

The <result/> element contains a <forwarded/> element which SHOULD contain the original message as it was received, and SHOULD also contain a <delay/> element qualified by the ‘urn:xmpp:delay’ namespace specified in Delayed Delivery (XEP-0203) [9]. The value of the ‘stamp’ attribute MUST be the time the message was originally received by the forwarding entity.

For offline message:
You will receive message as below:
<message xml:lang='en' to='<TO>' from='<FROM>' type='chat' id='3SE7n-39'><delay xmlns='urn:xmpp:delay' from='lakshitnagar.com' stamp='2020-09-05T18:01:01.854690Z'>Offline Storage</delay><offline xmlns='http://jabber.org/protocol/offline'><item node='335'/></offline><body>Hello</body></message>

You can parse this XML to get stamp attribute under delay tag. This will give you the time on which it is sent from the sender.

For MAM archived message:
You will receive something as below:
<message xmlns='jabber:client' to='<TO>' from='<FROM>' id='NzVV5-84' xml:lang='en' type='chat'><archived xmlns='urn:xmpp:mam:tmp' xmlns:stream='http://etherx.jabber.org/streams' by='lakshitnagar@lakshitnagar.com' id='1599328757912003'></archived><body>hello</body></message>

You can parse this XML to get id attribute under archived tag. This will give you the epoch time in microseconds when this message was sent from the sender.

Hello @Flow, The mentioned solution is working fine for version 4.2 but when I trying with version 4.3, I am using MAMQuery query = mamManager.queryArchive(mamQueryArgs); method to get the history filtered by some criteria(in my case date filter), the query returns me the List of Messages, I could not find any way to get timestamp from that list of messages returned. Thanks in advance.