Tony Tony - 1 month ago 15
Javascript Question

Getting message time in chat history pubnub

I'm working on Titanium mobile project which contain a chat section

and i'm using

pubnub
js sdk to accomplish this

every things works great for me but the problem is the the i can't get the time for each message when i'm loading the chat history i've checked the detailed chat history example on the Github repository but there is no info on how to do this

also in the in the Docs the value returned in the history callback is an array like this

[["message1", "message2", "message3",... ],"Start Time Token","End Time Token"]


with with start time and end time and each message object

any help?

Answer

A couple ways to do it! First way is to set include_tokens to true on your history request:

{'include_token': true, ....}

https://github.com/pubnub/javascript/blob/master/titanium/pubnub.js#L809

This will give you a PN timetoken accompanying each history message response.

You could also, at publish time, just include your own timestamp as well. Both methods are fine if you need the timetoken.

If using the PN provided timetoken, to convert the timetoken to UNIXTIME, follow this guide:

http://www.pubnub.com/knowledge-base/discussion/425/how-do-i-convert-the-pubnub-timetoken

Comments