Back

Creating following/follower feature in a social app - Database structure and feature implementation

  • 0
  • Databases
  • Apple
fofopuff
12 Aug, 2023, 23:17

Hi! I’m working on a social media app. I’m planning on using Appwrite to sign-up users. I would like to implement a following/follower/friend feature; a friend would be someone you follow that also follows you.

What would be the ideal way to structure this in an Appwrite database?

Should the following/followers be: array attributes on a user document, in it's own collection, or another way?

Also, how best to get the friends from a user's followers/following?

TL;DR
To implement the following/follower feature in a social app: 1. Create a separate collection called "following" or similar, with attributes for the ID of the follower and the ID of the person being followed. 2. Use an Appwrite function to automatically populate the "following" collection when someone follows or unfollows another user. 3. To get the followers, retrieve all documents where the user is the followee (person being followed). 4. To get the following, retrieve all documents where the user is the follower. 5. To get the friends, on the client side, get the UUIDs from the following and followers,
Drake
13 Aug, 2023, 04:14

I would create a collection called following or something with two attributes: the id of the follower and the id of the person that follower is following

fofopuff
13 Aug, 2023, 14:42

Thanks so much. So to get the followers, following, and friends would it involve doing the following:

Following: get all documents for which the user is the follower.

Followers: get all documents for which the user is the followee (person that someone is following).

Friends: on the client side, get the uuids from following and followers then use a set operation (intersection) to get the friends.

Is there a better way to do this? In particular for getting the friends?

Drake
13 Aug, 2023, 20:18

You can have another collection for friends that is auto populated based on the following collection by an Appwrite function that executed automatically when someone follows or unfollows

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more