For your partition key, I’d suggest creating a String attribute called partition. User partition as the partion key. partition will be set to <key>=<value>, and <key> can be different for different collections.
For the User collection, docs would include partition: "user=878275838475834".
For the PublicUser collection, docs would include partition: "manyUsers=all-the-users".
For the FriendUser collection, docs would include partition: "friendlyUser=878275838475834".
Your sync permissions can then call a Realm function that will make different checks, depending on the “type” of key and the value:
If key == "user" then check that this is the correct user asking (by comparing with the value)
If key == "manyUsers" && value == "all-the-users" then return true
If key == "friendlyUser" then check if the current user is allowed to access data for the user represented by value (e.g. by checking that user’s data to see if the current user has been added as a friend).
This will work! I think I got it from a different perspective, I was trying to have a value of “friends-only” and got super confused how I am going to check this. Your suggestion solves everything!
I am facing another problem because of the partition strategy. It’s related to accepting, declining and canceling the friend request but I will open another thread because it’s Swift related.