0

I have to query the messages for the current user . I am using the same format(flat structure) as suggested by firebase documents.

messages structure

the only difference is i am using room id combination generated from parse for the room which i can access(not one,two given in the link above) me

Now this is the code I have written to get the messages for sender :

messagesRef.childByAppendingPath(roomid).queryOrderedByChild("sender").queryEqualToValue(senderuserName)
    .observeEventType(.Value, withBlock: { messageTextsnapshot in

print("messageTextsnapshot test is \(messageTextsnapshot.key) , \(messageTextsnapshot.value)")
    })

this prints

messageTextsnapshot test is B8qLq7esr0L4Ezen0owHQ7PfdpD077lLfCswolf , {
    "-K8v2sM7VL_xvfbmWMom" =     {
        message = Hmm;
        sender = B8qLq7esr0L4Ezen0owHQ7Pfd;
        timestamp = "[.sv: timestamp]";
    };
    "-K8v3cv9EGqZlXSF4fGB" =     {
        message = Up;
        sender = B8qLq7esr0L4Ezen0owHQ7Pfd;
        timestamp = "[.sv: timestamp]";
    };
}

which are the correct messages. but how do i access them. I have been stuck since last 3 hours. I have this problem since i dont know how to query when auto ID's are involved. What should be the query to drill down to the messages.

subodh1989
  • 696
  • 6
  • 13
  • 40

0 Answers0