I am currently trying to develop an app with which users can track their location. It is important that other users must not see the location of others not being in the group.
In order to listen to location updates from all users in the group I was wandering if attaching a ChildEventListener to each location is the most efficient way. It feels a bit strange to add so many listeners to the reference. (I think of storing the uid's in a list and applying a listener to the location child with the uid). As far as I know I can't set a Listener to the parent for security reason.
Is there any better way or is this the way to go?
{
locations:{
yY6qmwJLj69JGzgG:{
"accuracy" : 23.429000854492188,
"altitude" : 57,
"latitude" : 3.4386667,
"longitude" : 10.024,
"speed" : 0,
"time" : 1531114956000
},
msVYdaTy2DWcjuJ7:{
...
},
...
},
groups:{
users:{
msVYdaTy2DWcjuJ7:true,
yY6qmwJLj69JGzgG:true,
...
},
...
},
...
}
I have currently following rules applied:
{
"rules": {
"groups" : {
".read" : false,
".write" : false,
"$gid" : {
".read" : "auth != null",
".write" : "auth != null"
}
},
"locations" : {
".read" : false,
".write" : false,
"$uid" : {
".read" : "auth != null",
".write" : "auth.uid === $uid"
}
}
}
}
My idea:
for(String uid : mUserList) {
mDatabaseReference.child("locations").child(uid).addValueEventListener(myListener);
}
I solved the problem by saving the structure to the following model
locations:{
$groupID:{
$userid:{
...
},
...
},
...
}
By doing so, I can listen to all locations with a single listener