Hi, I'm making a facebook chat and I'm already receiving the list of online friends, and connected to the XMPP server through sockets.... when the XMPP connects instead of requesting the roster I use Ti.Facebook to request the online friends via FQL.. at that point I need to store the users in a global variable, as the chat window is not opened....
so I have defined Ti.App.onlineFriends={};
and then later on I have this:
Titanium.Facebook.query(query, function(r){ if(r.success){ var jp=r.data; var olf={}; for (var c=0;c<jp.length;c++){ olf[jp[c].uid]={"name":jp[c].name.toString(),"img":jp[c].pic_square_with_logo.toString(),"messages":[]};//jp[c]); } Ti.App.onlineFriends=olf; Ti.App.fireEvent("gotFriends"); }else{ alert(r.error); } });Note I had to create the olf variable to make the Ti.App.onlineFriends array as it won't be written directly.... for some reason... Everything is fine up to this point.... I can call for example:
Ti.App.onlineFriends[12345678].img and it returns the friend's image with logo....
Now..... when a message is received by the socket.... I'm already getting the user ID and the message...
so I made this function...
function getChat(msg,to){ var myMessage={"time":new Date(),"msg":msg.toString()}; Ti.App.onlineFriends[to].messages.push(msg.toString()); alert(Ti.App.onlineFriends[to.toString()]["messages"]); Ti.App.fireEvent("gotMessage",myMessage); }Well.... guess what is the alert displaying?
().... Empty array! But no error code! Is this a bug or a lack of rest on my part which makes me miss something?
I'm not using Ti.App.properties as I want to store an object, not an integer, string or boolean... also I don't need that data to be persistent.... Same applies for databases etc.... but I guess I'll end up using a database! :S
Help greatly appreciated! Thanks!