Otherwise, I might have a possible solution for your problem which I will briefly outline below. Maybe there is a better way of doing it, but I have none for the moment :
When a new user is added to a project, you create for every user and every other user of the project a new document with content
{
delete : false
When you create this document, the sync function will give userId1 access to the channel of userId2:
function(doc) {
case 'user-doc':
channel('user_'+doc.userId1); //add the user-doc to the channel of the first user
access(doc.userId1,[ 'user_'+doc.userId2 ]); //give the user access to the channel of the other user
}
}
This means that the user-doc decides which user has access to which other user profiles. So if there are 3 user in a project, you need to create 3x2=6 user-docs in total.
Now, when you remove a user from a project, you update the corresponding delete-property in all user-docs which are concerned:
{
type : 'user-doc'
userId2 : 'yyy',
The Sync function will now remove the channel containing the profile of user 2 from the list of user1's channels.
However, you still have the profile of user2 in user1's CBLite instance. Therefore, you will need to listen for this document change in your app and manually remove the profile from CBLite,
In other words, you use the user-doc to signal to your app that a profile should be deleted.
However, a problem with this solution is that (i) the user-doc gets replicated although it is not needed anymore and (ii) the solution does not work when a user is logged in on multiple devices. To solve (i) you could let the app or (your server) delete the user-doc after the user profile was deleted. Solving (ii) requires some more effort.
Rather than just having a delete property in the document, you could have an array describing which Sync Gateway Session of a user has deleted the profile already, e.g.
{
type : 'user-doc'
userId2 : 'yyy',
delete : true,
{ sessionId : '1', removed : true}, { sessionId : '2', removed : false}
When an app removes a user profile, it will validate the sessions entry corresponding to its sessionId (e.g., its Sync Gateway Session Cookie). Only when all sessionIds in the array are validated. Sync Gateway will remove the user-doc from the user channel and you could deleted it from the data base.
I know this is a bit complicated but it should work. Let me know if anything is unclear with this solution or if you have an idea of how to improve it.
Another option could be to have document for every user which simply contains a list of all user profiles to which the user access. The Sync function would then use this document to give a user access to the channels containing the profiles. When a user is deleted from the list, the sync function revokes access to the channel. However, to delete it from CBLite, you needed to listen do changes in this document and remove the profile locally.
Cheers,
Jakob