Amity SDKs do not store or manage any user data. This means that you do not have to import or migrate existing user profiles into the system, user management should be handled by your application code. Instead, every user is simply represented by a unique userID, which can be any string that uniquely identifies the user and is immutable throughout its lifetime.
A database primary key would make an ideal userID. Conversely, something like username or emails is not recommended as those values may change over time.
If you wish to assign additional permissions for a user, for example, moderation privileges or different sending limits, you can provide an array of roles to assign to this user. Roles are defined in the admin panel and can be tied to an unlimited number of users. Once again, Amity does not store or manage any user data, which means you do not have to import or migrate existing users into the system. It also means that Amity cannot provide user management functionalities like lists of users, or limit actions of certain users (e.g. user permissions). Instead, these functionalities should be handled by the rest of your application's capabilities and your server.

Descriptions of User

Data Type
The id of this user
A list of user's roles
The display name of the user
Flag that indicates if the user is globally banned. True means the user is globally banned.
The number of users that have flagged this user
The metadata of the user
The date/time the user was created at
The date/time the user was updated at
Avatar associated with this User
Custom Url provided for this user avatar
Flag that indicates if the user is deleted
Though the SDK does not store and should not be responsible for the handling of User profile data for your application, we do provide tools to make some surface-level queries and searches for existing user accounts. With the help of our AmityUserRepository class, you would be able to list all the users, search for list of users whose display name matches your search query and get AmityUser object from user id.

User Repository

Create AmityUserRepository

Create User

You can create a new user into the system by logging in as shown below.
  1. 1.
    If user doesn’t exist, it will be created upon calling this method.
  2. 2.
    If displayName is passed, it will update the user directly.
  3. 3.
    if displayName is passed, but secured mode is enabled, the values will be ignored.

Ban User

You can ban a user globally. When users are globally banned, they can no longer access Amity's network and will be forcibly removed from all their existing channels.
Refer to our global ban documentation for the instructions on how to global-ban a user.

Delete User

We now support GDPR data erasure requests from customers via the Amity Help Center. When a user is deleted, the account cannot be reactivated in any case, and there is way to retrieve the data as it will be permanently deleted.
Refer to our data erasure documentation for more information on what happens when a user is deleted.

User Details

Each User consists of a userId and displayName. The userId is immutable once the account is created. However, the displayName can be updated at all times. AmityUserRepository provides a convenient method getUser(_:) which maps user id to a particular AmityUser object. It returns a live AmityObject<AmityUser> which you can observe too. It accepts one parameter userId which is the ID of the user.
Observe a user

Query Users

AmityUserRepository provides a convenient method getUsers(_:) to fetch all users. This method will return AmityCollection<AmityUser>. You can observe changes in collection, similar to message or channel. The method accepts AmityUserSortOption enum as a parameter. The list can be sorted by displayName, firstCreated or lastCreated.
Query users
The code above will provide you with list of users which are sorted by displayName.

Search User

AmityUserRepository contains another convenient method searchUser(_:_:) which allows you to query for any particular user using their display name. It provides you with a collection of AmityUser whose display name matches with your search query. It accepts two parameters. The first one is the display name that you want to search for and the second one is sort option which is AmityUserSortOption enum.
Search users by display name
The code above will provide you with the list of users which matches with display name "abc".

Update User Information

You can also update information related to current user such as display name, avatar, user description, metadata, etc. AmityClient class contains updateUser: method which allows you to update information about current user.
Update the current user data

User Avatar

You can upload an image and set it as an avatar for the current user. First, you need to upload image using AmityFileRepository and then update the image info.
Step 1 — Upload an image:
Create AmityFileRepository
Upload an image with AmityFileRepository
Step 2 — Passing AmityImageData from step 1 into the builder, and call user update API.
Update the current user avatar
If you have an avatar present in your current system/server and just want to integrate that existing avatar to AmitySDK, you can just set the URL for the avatar directly.
Update user custom avatar

User Permission

AmityClient class provides a method hasPermission(_:) which allows you to check if the current logged in user has permission to do stuffs.
Check the current user permissions