I have two fire object "chats" and "messages" like below. Each chat has list id of message.
"chats" : {
"13dc0865-616b-4963-bfdf-6c9b5d2011ef" : {
"buyer_id" : "dcf20b88-0612-4c13-933d-8b4f3d1838cb",
"created_at" : 1500676108229,
"item_id" : "fdab7447-e16d-4dac-8318-43f376ab3107",
"key1" : "fdab7447-e16d-4dac-8318-43f376ab3107_7060e0b7-420b-48fd-bc02-2e4868c6c2bb_dcf20b88-0612-4c13-933d-8b4f3d1838cb",
"key2" : "fdab7447-e16d-4dac-8318-43f376ab3107_dcf20b88-0612-4c13-933d-8b4f3d1838cb_7060e0b7-420b-48fd-bc02-2e4868c6c2bb",
"message_ids" : [ "-KpbG1tnCItaKykzEjaN", "-KpbG3cvMwitf_yzdYb6", "-KpbG9UhiOBJFR8GPE2x" ],
"seller_id" : "7060e0b7-420b-48fd-bc02-2e4868c6c2bb"
},
"25d667a3-6fe3-477d-b076-ac8d7b389133" : {
"buyer_id" : "dcf20b88-0612-4c13-933d-8b4f3d1838cb",
"created_at" : 1500674927785,
"item_id" : "b3985467-4e4e-4ecf-a914-48fb66fc5225",
"key1" : "b3985467-4e4e-4ecf-a914-48fb66fc5225_e68cf8f4-7470-45bf-8852-709d84fdae7f_dcf20b88-0612-4c13-933d-8b4f3d1838cb",
"key2" : "b3985467-4e4e-4ecf-a914-48fb66fc5225_dcf20b88-0612-4c13-933d-8b4f3d1838cb_e68cf8f4-7470-45bf-8852-709d84fdae7f",
"message_ids" : [ "-KpbBXhF5jjpspKgHPiV", "-KpbBpww9CcXL9n73J9j", "-KpbFgedT6RH2WZ6vjCV", "-KpbFxERv2adSRQHLnc2" ],
"seller_id" : "e68cf8f4-7470-45bf-8852-709d84fdae7f"
},
"messages" : {
"-KpbBXhF5jjpspKgHPiV" : {
"content" : "Tôi muốn mua Sua ban phim của bạn với giá 123.456 đ",
"created_at" : 1500674927777,
"sender_id" : "dcf20b88-0612-4c13-933d-8b4f3d1838cb"
},
"-KpbBpww9CcXL9n73J9j" : {
"content" : "Tôi muốn mua Sua ban phim của bạn với giá 123.456 đ",
"created_at" : 1500675006605,
"sender_id" : "dcf20b88-0612-4c13-933d-8b4f3d1838cb"
},
I am going to use FirebaseRecyclerAdapter to show messages for a chat conversation. My problem is on "chat" node, it only include the list message_id, the real data in inside node "messages".
How can I handle this case to work with FirebaseRecyclerAdapter ? (Sorry for my bad English)
From the chat node 13dc0865-616b-4963-bfdf-6c9b5d2011ef, you can access message_ids corresponding to it which are -KpbG1tnCItaKykzEjaN, -KpbG3cvMwitf_yzdYb6, -KpbG9UhiOBJFR8GPE2x.
Now you can get message data corresponding to the id as
(messages -> -KpbG1tnCItaKykzEjaN = your message). You can repeat this for remaining message ids.
Related
I have very big problem. I have this structure in my Firebase:
I would like to save this structure in JSON file/String no matter. I would get such a result:
{
"-Ka8_NYNxaFCcZQ3eaTp" : {
"Persons" : {
"-KaHUTUan-l06OVjsUlu" : {
"birthDay" : "13.01.2017",
"deathDay" : "06.01.2017",
"lastName" : "LastName1",
"latitude" : "54.2039383",
"longitude" : "16.1930868",
"name" : "name1"
},
"-KaHU_nPOE2NlqTbhLxT" : {
"birthDay" : "11.01.2017",
"deathDay" : "03.01.2017",
"lastName" : "LastName2",
"latitude" : "54.2039383",
"longitude" : "16.1930868",
"name" : "name2"
}
},
"city" : "Wroclaw",
"county" : "county1",
"nameCemetery" : "nameCemetery1",
"province" : "province1",
"street" : "street1"
}
I tried through DataSnaphot but the result was not in the format JSON, e.g:
{-Ka8_NYNxaFCcZQ3eaTp={nameCemetery=nameCemetery1, street=street1, county=county1, province=province1, Persons={-KaHU_nPOE2NlqTbhLxT={name=Damian, latitude=54.2039383, lastName=Szeeczyk, birthDay=11.01.2017, longitude=16.1930868, deathDay=03.01.2017}, -KaHUTUan-l06OVjsUlu={name=name1, latitude=54.2039383, lastName=LastName1, birthDay=13.01.2017, longitude=16.1930868, deathDay=06.01.2017}}, city=Wroclaw}}
The most important for me is not to create JSONArray Persons, because then my application will run incorrectly.
In short, I would like to make a copy node (in my example key -"Ka8_NYNxaFCcZQ3eaTp"
{
"Events" : {
"events" : {
"-KT5UMQAhDHs1bB8bKLc" : {
"activity" : "biking",
"address" : "54°05'45.8\"N 28°19'02.9\"E, просп. Мира 9, Жодино, Беларусь",
"category" : "sport",
"creatorID" : "m11EvlP19OSbEz8XYl2MsNCwGXX2",
"date" : 1475431200689,
"forFriends" : true,
"info" : "вттчтвт",
"name" : "ьаьатвтвтт",
"uid" : "-KT5UMQAhDHs1bB8bKLc"
},
"-KUSsl7RaL-dVoDCoSYT" : {
"activity" : "picnic",
"address" : "Узденский район, Узденский район, Беларусь",
"category" : "entertainment",
"creatorID" : "1RXDSJzSEXakxvNdM41Ae3nbHN72",
"date" : 1477328400000,
"forFriends" : false,
"info" : "45",
"name" : "Test of date",
"uid" : "-KUSsl7RaL-dVoDCoSYT"
}
},
"FriendsOF" : {
"NuKweeGv8zTgt1Vi9RcU3i1u86U2" : {
"1RXDSJzSEXakxvNdM41Ae3nbHN72" : true
},
"m11EvlP19OSbEz8XYl2MsNCwGXX2" : {
"1RXDSJzSEXakxvNdM41Ae3nbHN72" : true
}
},
"Users" : {
"1RXDSJzSEXakxvNdM41Ae3nbHN72" : {
"email" : "*#gmail.com",
"name" : "Алексей Гвоздицкий",
"picture" : "*.jpg"
},
"NuKweeGv8zTgt1Vi9RcU3i1u86U2" : {
"email" : "*#gmail.com",
"name" : "Ольга Гвоздицкая",
"picture" : "*.jpg"
},
"m11EvlP19OSbEz8XYl2MsNCwGXX2" : {
"email" : "*#gmail.com",
"name" : "Егор Александров",
"picture" : "*.jpg"
}
}
}
I have a list of "events". Every "event" can be "forFiends" only (only if current user is in event creators "FriendsOF" list, then he can see this event. FriendsOF it's a whitelist). All availiable for current user events i want to represent in RecyclerView.
I am stucked. I can get all data snapshot and then filter on client side it. But it is not way of Jedi, because i load tonns of unnecessary data. Another solution is to deny acces to event if user should not see it. But i don't understand how to do it. My ref is mEventsRef = FirebaseDatabase.getInstance().getReference().child("Events").child("events"); And rule i can make for
"events":{
"$eventId":{".read":....}
}
So according to this guide i'll get empty recyclerView because of "error callback triggered with PERMISSION_DENIED"
Help me to solve my problem please!
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
I have a child node that looks like this:
and I want to get the data and put the userID in the from of array. So that I can iterate and write data in those userID. However currently I am unable to figure out how to read from the database and get the userID into an array.
I only want the userID in the array. Where the node is like (friends/"key"/userID).
here is the json -
"friends" : {
"-KVFPNlR76oIsnvdeuEr" : {
"userID" : "QbfjBiy7yhTT9Bi9H8dLNv7h0A02",
"userName" : "michael s speed",
"userPhoto" : ""
},
"-KVFPNmS42zrefrGKM2L" : {
"userID" : "QbfjBiy7yhTT9Bi9H8dLNv7h0A02",
"userName" : "michael s speed",
"userPhoto" : ""
},
"-KVQWEH4xY1-88vyUmKd" : {
"userID" : "ZEBXY8WmQaWIza4L2ptSPpKUQGY2",
"userName" : "michael dinesh",
"userPhoto" : ""
},
"-KVVeqLtEji4b1ZW3gcj" : {
"userID" : "Hvf69rGDTsgQgBLdnUcg5uGZSgB2",
"userName" : "rina bora",
"userPhoto" : ""
}
},
So I have the Json in following format on firebase:
{
"30000000549656652" : {
"cast" : [ {
"src" : "https://encrypted-tbn1.gstatic.com/images",
"title" : "Hilary Duff (Samantha \"Sam\" Montgomery)"
}],
"channel_name" : "HBO",
"desc" : "After her .....",
"extras" : {
"initial" : "July 10, 2004 (Hollywood)",
"director" : "Mark Rosman",
"screenplay" : "Leigh Dunlap"
},
"genre" : "Thriller",
"lang" : "English",
"movie" : 1,
"prog_id" : 30000000549656652,
"prog_img" : "http://images."
"ratings" : {
"IMDb" : "5.9/10",
"Metacritic" : "25%",
"Rotten Tomatoes" : "11%"
},
"start" : 201607141800,
"stop" : 201607141700,
"title" : "Thrill A Cinderella Story",
"year" : "2004"
},
.....
}
I want to do the following in activity on my android app-
Query the node in which these JSON exist, then filter them such that i get all the results which have movies of one specific genre(e.g., Thriller) and the year is within five yrs less or five yrs more of the one i would pass in the query.
Like i would want to query to get all thriller movies whose "year" are between 2000 and 2009.
Can someone please help me to build such query for a json like this. Thanks!