How to get timestamp of incoming xmpp message?

后端 未结 6 1922
梦谈多话
梦谈多话 2021-02-04 05:05

I am using aSmack library to communicate with remote xmpp server. I am able to send/receive messages, but I want to get timestamp of incoming message.

Could you tell me

6条回答
  •  梦如初夏
    2021-02-04 05:57

    Due to specs time is required attribute for XMPP message:

    http://xmpp.org/extensions/xep-0203.html#protocol

    Check the item of :

    
    Offline Storage
     
    

    But getting it looks a bit tricky. As soon as aSmack is recompiled Smack with some replaced stuff, so try to get it the way like here:

    http://edwin.baculsoft.com/2011/06/how-to-get-offline-messages-timestamp-on-openfire/

    DelayInformation inf = null;
    try {
        inf = (DelayInformation)packet.getExtension("x","jabber:x:delay");
    } catch (Exception e) {
        log.error(e);
    }
    // get offline message timestamp
    if(inf!=null)
        Date date = inf.getStamp();
    

    Problably, you will need to check what server sends with message as extension value and replace "jabber:x:delay" with 'urn:xmpp:delay' as it is shown in XMPP specs example.

    But not sure if it works.

提交回复
热议问题