mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 10:33:45 +00:00
Improve user search using the GET profile (#754)
* Add getProfile in ClientProxyProtocol * Add fetchProfileIfNeeded * Refactor search * Update StartChatSuggestedUserCell UI * Add showProfilePopover action * Remove popover code * Add UTs in StartChatViewModelTests * Add UI tests * Cleanup code * Refine design * Fix design * Localise StartChatSuggestedUserCell * Update localisations * Update StartChatSuggestedUserCell design * Fix UT * Fix PR comments * Apply suggestions * Fix typo
This commit is contained in:
@@ -258,6 +258,16 @@ class ClientProxy: ClientProxyProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
func getProfile(for userID: String) async -> Result<UserProfile, ClientProxyError> {
|
||||
await Task.dispatch(on: clientQueue) {
|
||||
do {
|
||||
return try .success(.init(sdkUserProfile: self.client.getProfile(userId: userID)))
|
||||
} catch {
|
||||
return .failure(.failedGettingUserProfile)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Private
|
||||
|
||||
private func loadUserAvatarURLFromCache() {
|
||||
|
||||
@@ -32,6 +32,7 @@ enum ClientProxyError: Error {
|
||||
case failedRetrievingSessionVerificationController
|
||||
case failedLoadingMedia
|
||||
case failedSearchingUsers
|
||||
case failedGettingUserProfile
|
||||
}
|
||||
|
||||
enum SlidingSyncConstants {
|
||||
@@ -94,4 +95,6 @@ protocol ClientProxyProtocol: AnyObject, MediaLoaderProtocol {
|
||||
func setPusher(with configuration: PusherConfiguration) async throws
|
||||
|
||||
func searchUsers(searchTerm: String, limit: UInt) async -> Result<SearchUsersResults, ClientProxyError>
|
||||
|
||||
func getProfile(for userID: String) async -> Result<UserProfile, ClientProxyError>
|
||||
}
|
||||
|
||||
@@ -115,4 +115,11 @@ class MockClientProxy: ClientProxyProtocol {
|
||||
func searchUsers(searchTerm: String, limit: UInt) async -> Result<SearchUsersResults, ClientProxyError> {
|
||||
searchUsersResult
|
||||
}
|
||||
|
||||
var getProfileResult: Result<UserProfile, ClientProxyError> = .success(.init(userID: "@a:b.com", displayName: "Some user"))
|
||||
private(set) var getProfileCalled = false
|
||||
func getProfile(for userID: String) async -> Result<UserProfile, ClientProxyError> {
|
||||
getProfileCalled = true
|
||||
return getProfileResult
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,12 @@ struct UserProfile {
|
||||
displayName = sdkUserProfile.displayName
|
||||
avatarURL = sdkUserProfile.avatarUrl.flatMap(URL.init(string:))
|
||||
}
|
||||
|
||||
/// A user is meant to be "verified" when the GET profile returns back either the display name or the avatar
|
||||
/// If isn't we aren't sure that the related matrix id really exists.
|
||||
var isVerified: Bool {
|
||||
displayName != nil || avatarURL != nil
|
||||
}
|
||||
}
|
||||
|
||||
struct SearchUsersResults {
|
||||
|
||||
Reference in New Issue
Block a user