ClickCease
Follow features and user profiles made with TypeScript

Beginner’s guide to implement Follow/Unfollow Requests and User Profile Customization in TypeScript

Italo Orihuela
Italo Orihuela
Engineer
Android
iOS
Web
Apr 8, 2024

For social media applications, the ability to follow and unfollow users is a fundamental feature. It allows users to customize their feeds and engage with content that interests them. Additionally, the ability to customize user profiles while a follow request is pending adds another layer of personalization and privacy. In this tutorial, we will explore how to implement follow and unfollow requests in TypeScript using the Amity Social Cloud SDK, as well as how to customize user profiles using the user’s object metadata. This SDK provides methods to accept and decline follow requests, promoting a more personalized and engaging user experience. Whether you’re a seasoned developer or a beginner in TypeScript, this guide will provide you with step-by-step instructions and code snippets to help you implement these features in your application.

Pre-requisites

  • Basic knowledge of TypeScript
  • The Amity Social Cloud SDK installed in your project.
  • An Amity Social Cloud Portal account
  • An Amity Social Cloud Console Account

Note: If you haven’t already registered for an Amity account, we recommend following our comprehensive step-by-step guide in the Amity Portal to create your new network

Step 1: Understanding the Follow/Unfollow Feature and User Profile Customization

The follow/unfollow feature is a key aspect of user interaction in social media apps. It allows users to follow other users, receive their updates, and engage with their content. Conversely, users can also unfollow others if they no longer wish to see their updates.

The Amity Social Cloud SDK provides two methods for managing these requests: acceptMyFollower and declineMyFollower. Additionally, while a follow request is pending, user profiles can be customized using the user's object metadata. This allows users to set their profile as public or private, providing an additional layer of privacy.

Step 2: Accepting Follow Requests

To accept a follow request, users can call the acceptMyFollower method and provide the userId of the user whose follow request they wish to accept. This will add the user to the list of followers and allow them to receive updates. Here's how you can do this in TypeScript:

Step 3: Declining Follow Requests

Similarly, to decline a follow request, users can call the declineMyFollower method and provide the userId of the user whose follow request they wish to decline. This will remove the user's request to follow. Here's the TypeScript code for this:

Step 4: Customizing User Profiles

While a follow request is pending, you can customize the user’s profile by adding a field such as status to the user's object metadata. Depending on the status (public or private), your frontend logic can decide whether to display the user's timeline or not. Here's how you can do this in TypeScript:

Step 5: Handling Errors

It’s important to note that if the follow request is no longer available (either the follower request sender has withdrawn the request or the request has been accepted or declined before), the SDK will return an error message. Therefore, it’s crucial to handle these potential errors in your code.

Final Thoughts

Implementing follow/unfollow requests and user profile customization in TypeScript using the Amity Social Cloud SDK is a straightforward process. By understanding the acceptMyFollower, declineMyFollower methods, and user object metadata, you can provide your users with a more personalized and engaging experience.