Question

I have problem when send a message via smack. I handled xml from sender device, it is:

<message id="qOP8c-14" to="52812" from="59271" type="chat"><body>dgggxhhhd</body><thread>52812</thread><datestamp xmlns="jabber:client">2013-08-28T03:59:41Z</datestamp></message>

and xml in receiver device is:

<message id="zqy34-12" to="59271@xmpp.gopaktor.com" from="59270" type="chat"><body>rmhxmxt,jxtj,dtj,</body><thread>59271</thread><datestamp xmlns="jabber:client"></datestamp></message>

You can see datestamp is empty. I'm using Asmack Library of Flowdalic (https://github.com/flowdalic/asmack).
Please help me. Is it the issue of library?

Was it helpful?

Solution

As this thread explains (https://stackoverflow.com/a/11141819/474002): Timestamp is not part of the regular messages. Therefore you cannot extract it.

I think you could send a custom packet (use PacketExtension) to extend your message packet to include the timestamp information.

Message message = new Message();
DefaultPacketExtension yourExt = new DefaultPacketExtension("your_ext", "com:your:ext");
yourExt.setValue("timestamp", YOUR_TIMESTAMP);
messgae.addExtension(yourExt);

OTHER TIPS

A simple solution I implemented (only works if your users are all utilizing your client) is to incorporate the time stamp in the packet ID (also include some other string to mitigate clashes) at the front of the ID.

Java time in millis will be 13 characters long until 2200 something so you can just get the first 13 characters or even to future-proof;

int timeLength String.valueOf(System.currentTimeMillis()).length()

Will give you the length of the timestamp in your packet ID

Then in Smack

packet.getPacketID.subString(0, timeLength)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top