You can specify which posts may be read and written using security rules. For example, if I have this data set:
{
"users": {
"me": {
"friends" { "jack", "mary" }
},
},
"posts": {
"post1": {
"owner": "me",
...
}
}
}
I could use a security rule like the following:
{
"posts": {
"$post_id": {
// any friend can read my post
".read": "auth.uid === data.child('owner').val() || root.child('users/'+data.child.owner.val()+'/friends/'+auth.uid).exists()",
// only I can write it
".write": "auth.uid === data.child('owner').val()"
}
}
}
Keep in mind, however, that security rules can't be used as a filter. You can't iterate a list of posts and only expect to get back the ones friends are allowed to see--if it encounters items in the list that aren't readable, then the operation will fail to return results.