Monday, June 17, 2013

Private Chat packets(reversal)

While it makes sense, it's worth noting that when A sends a private chat to B, the 'from' variable = A and 'room' variable = B. This also happens vice-versa. The issue here is that since ALL messages are broadcasted across the users, then 'room' value keeps changing. Sample this

1. Broadcast message from me

processPacket...{"ref":"chat","mod":"chat","status":200,"err":null,"result":{"type":"p","ctype":"t","id":"2E3QW1AW34ay7y410wfQ","msg":"Hey, please send another message","from":"254712249559","room":"233200238442","coord":null,"ts":"1371461833"}}
Reading data...

2. Broadcast message from friend with reply
processPacket...{"ref":"3_faaa586c9aa38f01968715d762e3c995","mod":"chat","status":200,"err":null,"result":{"type":"p","ctype":"t","id":"2E3QWagtWQM0RYWluxOK","msg":"another message","from":"233200238442","room":"254712249559","coord":"5.645256:-0.151525","ts":"1371461857"}}
Reading data...

As seen, the 'room' variable keeps changing. To handle this change:
1. Check if chat is private
2. Check that chat is not from me
3. Apply room reversal


/*
             * Handle reversal for private chat--arghh!!!!
             *
             */
            if(json.getJSONObject("result").getString("type").equals("p")){
                //Check if message is not from me and reverse roomid
                if(!json.getJSONObject("result").getString("from").equals(phone)){
                    roomid = json.getJSONObject("result").getString("from");
                }
            }
            

No comments:

Post a Comment