ClickCease
Flagging user in a iOS app

How to flag & unflag users in your social iOS app

Italo Orihuela
Italo Orihuela
Engineer
iOS
Aug 28, 2023

Nowadays, creating a safe and engaging community within your social app is of utmost importance. One way to ensure this is by implementing a user flagging feature. This feature allows administrators and moderators to monitor and manage inappropriate behaviour within a chat channel effectively. In this tutorial, we will guide you on how to add a user flagging feature to your iOS social app using the Amity Social Cloud SDK.

Pre-requisites:

Before we begin, make sure you have the following:

  • The Amity Social Cloud SDK installed in your iOS project.
  • A valid instance of `AmityUserRepository` and `AmityUserFlagger`.
  • The user ID of the user you want to flag or unflag.

Initialization and Authentication:

Before you can start flagging or unflagging users, you need to initialize and authenticate your Amity client. Here’s how you can do it:

To authenticate your client, you need to call the `login(…)` method with the current user. Here’s how you can do it:

Use Cases for the Flag/Unflag User Feature

The flag/unflag user feature can be used in various scenarios to maintain a safe and engaging community. Here are a few examples:

  • Content Moderation: If a user posts inappropriate content, other users can flag them. The flagged user can then be reviewed by the administrators or moderators.
  • User Reporting: Users can flag other users who are behaving inappropriately or violating the community guidelines. This helps in maintaining a respectful environment.
  • User Management: Administrators can use the flag/unflag feature to manage users effectively. They can unflag users who were flagged mistakenly or have improved their behaviour.

Step 1: Create an Instance of AmityUserRepository

First, you need to create an instance of `AmityUserRepository`. This repository is responsible for all user-related operations.

Step 2: Get the User Object

Next, get the user object for the user you want to flag. You can do this by calling the `user(forId:)` method on the `userRepository` instance.

Step 3: Validate the User Object

Before proceeding, ensure that the user object is valid.

Step 4: Create an Instance of AmityUserFlagger

Now, create an instance of `AmityUserFlagger`. This instance will be used to flag and unflag the user.

Step 5: Flag a User

To flag a user, call the `flagUser(withId:)` method on the `userRepository` instance.

Step 6: Unflag a User

Similarly, to unflag a user, call the `unflagUser(withId:)` method on the `userRepository` instance.

Step 7: Check if a User has been Flagged

Finally, to check if a user has been flagged by the current user, call the `isUserFlaggedByMe(withId:)` method on the `userRepository` instance.

Final Thoughts

By following these steps, you can easily add a user flagging feature to your iOS social app using the Amity Social Cloud SDK. This feature not only helps in maintaining a safe and engaging community but also enhances the overall user experience. Remember, a safe and respectful environment is key to the success of any social app.

Amity Social Cloud Analytics & Moderation Panel