In the Amity SDK, a user is represented by an AmityUser object, which contains the user's unique userId and displayName. The userId is an immutable value that is assigned to a user when their account is created, and cannot be changed afterwards. This value serves as a unique identifier for the user within the SDK, and is used to perform actions such as sending messages or creating connections between users.
To retrieve an AmityUser object for a specific userId, you can use the getUser method provided by the UserRepository. This method accepts the userId as a parameter and returns a Live Object of AmityUser. The live object allows developers to observe changes to the user's properties in real-time, ensuring that their app remains up-to-date with the latest user information.
Follow the below code to retrieve a user object:
import { UserRepository } from'@amityco/js-sdk';constliveObject=UserRepository.getUser('userId');liveObject.on('dataUpdated', user => {// user is successfully fetched});
Get Single User
The User Repository provides a method to get a single user. It returns a LiveObject which you can observe.
userRepo.userForId('user123')
You can also use the code below to get one user:
let liveUser =UserRepository.getUser("some-user-id")userObject.on(“dataUpdated”, model => {// you can access user object as model hereconsole.log(model.userId,model.displayName)})
Get All Users
The User Repository provides a method to get a list of all users, which will be returned as a LiveCollection:
userRepo.getAllUsers()
This method takes an optional sortBy parameter which must be a UserSortingMethod - these include displayName, firstCreated, and lastCreated:
The functionality isn't currently supported by this SDK.
To retrieve multiple users, you can use getUserByIds method provided by UserRepository. This method accepts a collection of userId as a parameter and returns a Live Collection ofAmityUser.
The functionality isn't currently supported by this SDK.
The functionality isn't currently supported by this SDK.
The functionality isn't currently supported by this SDK.