Tony Tony - 1 year ago 139
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

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 Source

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

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

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:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download