Search and Query Users
Search User
Query for users by their display name, receiving a collection of AmityUser matching your search. It requires two parameters: the display name you're searching for, and a 'sort option' from the AmityUserSortOption enum. If no keyword is supplied, the list of users will be organized alphabetically by display name.
Users also have the option to sort by lastCreated, firstCreated, or displayName. When a keyword is provided, the list will be arranged based on search rank. The displayName sort option will be specified by default if it isn't specified.
If the collection is sorted by displayName, the results will be alphabetically and case-sensitively ordered (aA-zZ). For example: adam, arthur, Alice, Andre, charlie, Kristen.
Note: If the user ID or display name you’re searching for contains special characters, you’ll need to enter the whole keyword in order for it to appear in the search results.
The code above will provide you with the list of users which matches with display name "Brian".
userRepo.searchUserByDisplayName('Test User 1')The above example searches for all users whose display names start with "Test User 1".
The queryUsers provides a way to search for users by their display name.
Query Users
Query for users to receive a collection of AmityUser based on a single parameter: a 'sort option' from the AmityUserSortOption enum. Sort the list by options such as displayName, firstCreated, or lastCreated. The displayName sort option will be specified by default if it isn't specified.
const liveUserCollection = UserRepository.queryUsers({
keyword?: string,
filter?: 'all' | 'flagged',
sortBy?: 'lastCreated' | 'firstCreated' | 'displayName'
})
// filter if flagCount is > 0
// lastCreated: sort: createdAt desc
// firstCreated: sort: createdAt asc
// displayName: sort: alphanumerical asc
liveUserCollection.on(“dataUpdated”, models => {
models.map(model => console.log(model.userId))
})If you wish to observe for changes to a collection of users, you can use liveUsers
Last updated
Was this helpful?