Sign In Register

How can we help you today?

Start a new topic

getting timestamp from responses


I have a lot of trouble getting the timestamp from chat messages.

For once, I use ListTeamChatRequest() to get some previous messages and as the documentation promises there is a "When" field in the message object which always gives null although the messages have their timestamp according to the NoSQL search.

GSEnumerable<GameSparks.Api.Responses.ListTeamChatResponse._ChatMessage> messages = response.Messages;
foreach(GameSparks.Api.Responses.ListTeamChatResponse._ChatMessage msg in messages) {
    Debug.Log(msg.When);    // this is always Null

Second. I tried to get it directly from the JSON String and it has the timestamp but I can't get it to convert to current time. (UTC)  

DateTime when = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
object ts = null;
msg.JSONData.TryGetValue("when", out ts);    // always has it
if(ts != null) {
    long t1 = Convert.ToInt64(ts);    // got something like 1493387388498
    w.AddMilliseconds(t1);    // this doesn't affect it somehow
} else
    Debug.LogWarning("ListTeamChatRequest warning: got Null for When"); 

Third - actually is a question. I need the timestamp from the server in the TeamChatMessage.Listener too - can't guess why this isn't built in by default. I tried to put it in the message in Cloud Code but there is two place to choose from - namely the Global and the User. Which one is for what?
I see when I'm trying to send from my app the UserMessages will count. I get the value from the GSData as a long but I also have to be able to get a DateTime from this. 

Spark.setScriptData("When", new Date().getTime());


Can someone somehow clarify what am I doing wrong? Also an in-depth usage tutorial on using GSData and GSEnumerable<T> in the responses and also a comparison with the JSONData would be a lot of help.

Also I can't understand why all the responses has their own implementation of the _Player and _ChatMessage classes. They are all the same but can't write GSEnumerable<GSTypedResponse> or at least GSEnumerable<ChatMessage>.


Sorry for my miserable life but I have to ask these things somewhere. :)
Thanks for the help in advance!

User Message will run on a per user basis (ie customizing cloud code based on user). IE: if a message is sent to 5 people, the Cloud code will run 5 times under the context of that user (Spark.getPlayer()). Global will run once for everyone, and is not under a player's context. Global is good for processing/adding data to a message before it gets sent to a player.

As to the rest, I'd need to do a little testing.

Thank you Christopher, that's valuable information!

As for the time conversion, I've found my problem. w.AddMiliseconds(t1) will create a new DateTime object and not modifies the old as would be expected how the syntax reads - it's something like a builder concept I assume.

This leaves us with my first problem and the lack of usage examples on GSData and GSEnumarable<T> - also with the question on why all responses have their own implementation of _Player and _ChatMessage while they could be handled generally the same.

Thanks for further helps!

Can't help you there, never used GSData or GSEnumerable (although I loop through stuff all the time, I must have figured an alternative way lol).

Login to post a comment