1

I am making an app that should include chat. I would like to display conversations of the current user. I am not sure how to get only chats of the current user. This is my structure of database.

"chats" : {
"-KWYiJiFwE6miPNkKPe0" : {
  "chatPartner1" : {
    "id" : "rtg3ru7zNYQQp9LA484VIG5rItl1",
    "name" : "ghjg",
    "photo" : ""
  },
  "chatPartner2" : {
    "id" : "rtg3ru7bzwwewNYQwwewetegb",
    "name" : "petra",
    "photo" : ""
  },
  "id" : "-KWYiJiFwE6miPNkKPe0",
  "lastMessage" : "dhjcd",
  "timestamp" : 1479141836276
}

This json represents storing message for specified chats according to its id.

"messages" : {
"-KWYiJiFwE6miPNkKPe0" : {
  "-KWYiJiPWR3n_YcvokCm" : {
    "senderId" : "rtg3ru7zNYQQp9LA484VIG5rItl1",
    "text" : "dhjcd",
    "timestamp" : 1479141836276
  }
}

I would need to check if the chatPartner 1 or 2 contains id of the current user. Or do you know about better way to store chats?

Thanks

Community
  • 1
  • 1
user3637775
  • 499
  • 4
  • 20
  • create node "users" and put chat keys for each user, why not? – Dmytro Rostopira Nov 14 '16 at 20:19
  • do you mean inside chats? or at the same level as chats? Not sure if i will help me. I need to get information from chats such as name, photo of the chat partner – user3637775 Nov 14 '16 at 22:03
  • see https://github.com/firebase/friendlypix – Kato Nov 14 '16 at 23:57
  • For 1:1 chats I normally recommend modeling the room ID after the UIDs of the participants. See http://stackoverflow.com/questions/33540479/best-way-to-manage-chat-channels-in-firebase. – Frank van Puffelen Nov 15 '16 at 04:00
  • inside the room would be messages? how can I get information about the user such as photo and name without accesing node users or could I put the information about them inside chat_id1_id2? isnt it problem that I will have too many nodes with chats? – user3637775 Nov 15 '16 at 09:31

0 Answers0