How to manage subscriptions/follows

So I am working on a community application (similar to this forum itself) which will have subscription/follower functionality. I need help to validate what I am planning is the optimum approach or is there a better way to do it. Please read and suggest.

What can be subscribed:

  • Communities
  • Users
  • Posts

How can it be subscribed:

  • Community - Join button on the community
  • Users - Follow button on the users
  • Posts - Subscribe button on post OR Reply on post

How will it get updated:

  • Community - Create doc on subscription collection (user: RefUser, subscription: RefCommunity)
  • Users - Create doc on subscription collection (user: RefUser, subscription: RefUser)
  • Posts - Create doc on subscription collection (user: RefUser, subscription: RefPost)

How will subscribed feed update:

  1. Fetch all docs in subscription collection with user = currentUser
  2. Map over subscription Refs
  3. Query post collection for each ref depending on the Ref Type (community, user, post)
  4. Combines results in one set of posts (to remove duplicates)
  5. Sort combined posts array by last updated date
  6. Return result
1 Like

Thats probably how I would do it too. Are you going to make a subscription with fauna too? So that the UI updates automatically when a subscription gets updated? I wonder how that would work on a larger community. When you are done can you show us the implementation you did? Thank you!

1 Like

No I am not planning on setting up a subscription stream. At least for now I am taking one step at a time and open to refactoring.

This approach really highlights how powerful a flexible schema can be! This is a good use of storing different kinds of documents or references in a single Collection.

I suspect there are several ways to map the subscriptions into Posts, and the most optimal way will probably depend on your mix of data.

One tip I can share that you might find helpful: You can retrieve the Collection Ref or just the Collection’s name from a Ref. This might help you add some logic to do different things depending on what type the subscription ref is.

Let(
  {
    ref: Ref(Collection("user"), "310623304708784192")
  },
  Select(["collection", "id"], Var("ref"))
)

=> "user"
1 Like