User

Though the SDK does not store and should not be responsible for the handling 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 EkoUserRepository class, you would be able to list all the users, search for list of users whose display name matches your search query and get EkoUser object from user id.

User Respository

let userRepository = EkoUserRepository(client: client)

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. EkoUserRepository provides a convenient method userForId(_:) which map user id to particular EkoUser object. It returns a live EkoObject<EkoUser> which you can observe too. It accepts one parameter userId which is the userId of the user.

let userObject = userRepository.user(forId: "some-user-id")
userObject.observe { (user, error) in
// you can access EkoUser object as user.object here
}

Query User

EkoUserRepository provides a convenient method getAllUsersSortedBy(_:) to fetch all users. This method will return EkoCollection<EkoUser>. You can observe for changes in collection, similar to message or channel. The method accepts EkoUserSortOption enum as a parameter. The list can be sorted by displayName, firstCreated or lastCreated.

var userCollectionToken: EkoNotificationToken?
...
let userCollection = userRepository.getAllUsersSorted(by: .displayName)
userCollectionToken = userCollection?.observe({ (collection, change, error) in
// React to changes here
})

The code above will provide you with list of users which are sorted by displayName.

Search User

EkoUserRepository 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 EkoUser 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 EkoUserSortOption enum.

var userSearchToken: EkoNotificationToken?
...
searchCollection = userRepository.searchUser("abc", sortBy: .displayName)
searchCollectionToken = searchCollection?.observe({ (collection, change, error) in
// React to changes here
})

The code above will provide you with the list of users which matches with display name "abc".

User Permission

EkoClient class provides a method hasPermission(_:) which allows to check if the current logged in user has permission to do stuffs in given channel.