mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Rename UserProfileProxy to UserProfile. It's a pure struct and proxies nothing.
Also remove the redundant `userID` property given `id` already exists (for Identifiable conformance).
This commit is contained in:
@@ -10,7 +10,7 @@ import Foundation
|
||||
|
||||
struct UserDiscoverySection {
|
||||
let type: UserDiscoverySectionType
|
||||
let users: [UserProfileProxy]
|
||||
let users: [UserProfile]
|
||||
|
||||
var title: String? {
|
||||
switch type {
|
||||
|
||||
@@ -15,7 +15,7 @@ final class UserDiscoveryService: UserDiscoveryServiceProtocol {
|
||||
self.clientProxy = clientProxy
|
||||
}
|
||||
|
||||
func searchProfiles(with searchQuery: String) async -> Result<[UserProfileProxy], UserDiscoveryErrorType> {
|
||||
func searchProfiles(with searchQuery: String) async -> Result<[UserProfile], UserDiscoveryErrorType> {
|
||||
async let queriedProfile = profileIfPossible(with: searchQuery)
|
||||
|
||||
do {
|
||||
@@ -32,7 +32,7 @@ final class UserDiscoveryService: UserDiscoveryServiceProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
private func merge(queriedProfile: UserProfileProxy?, searchResults: SearchUsersResultsProxy) -> [UserProfileProxy] {
|
||||
private func merge(queriedProfile: UserProfile?, searchResults: SearchUsersResultsProxy) -> [UserProfile] {
|
||||
let searchResults = searchResults.results
|
||||
|
||||
guard let queriedProfile else {
|
||||
@@ -40,13 +40,13 @@ final class UserDiscoveryService: UserDiscoveryServiceProtocol {
|
||||
}
|
||||
|
||||
let filteredSearchResult = searchResults.filter {
|
||||
$0.userID != queriedProfile.userID
|
||||
$0.id != queriedProfile.id
|
||||
}
|
||||
|
||||
return [queriedProfile] + filteredSearchResult
|
||||
}
|
||||
|
||||
private func profileIfPossible(with searchQuery: String) async -> UserProfileProxy? {
|
||||
private func profileIfPossible(with searchQuery: String) async -> UserProfile? {
|
||||
guard searchQuery.isMatrixIdentifier, searchQuery != clientProxy.userID else {
|
||||
return nil
|
||||
}
|
||||
@@ -57,9 +57,9 @@ final class UserDiscoveryService: UserDiscoveryServiceProtocol {
|
||||
return getProfileResult ?? .init(userID: searchQuery)
|
||||
}
|
||||
|
||||
private func filterAccountOwner(_ profiles: [UserProfileProxy]) -> [UserProfileProxy] {
|
||||
private func filterAccountOwner(_ profiles: [UserProfile]) -> [UserProfile] {
|
||||
let accountOwnerID = clientProxy.userID
|
||||
return profiles.filter { $0.userID != accountOwnerID }
|
||||
return profiles.filter { $0.id != accountOwnerID }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,5 +14,5 @@ enum UserDiscoveryErrorType: Error {
|
||||
|
||||
// sourcery: AutoMockable
|
||||
protocol UserDiscoveryServiceProtocol {
|
||||
func searchProfiles(with searchQuery: String) async -> Result<[UserProfileProxy], UserDiscoveryErrorType>
|
||||
func searchProfiles(with searchQuery: String) async -> Result<[UserProfile], UserDiscoveryErrorType>
|
||||
}
|
||||
|
||||
+9
-15
@@ -9,37 +9,37 @@
|
||||
import Foundation
|
||||
import MatrixRustSDK
|
||||
|
||||
nonisolated struct UserProfileProxy: Equatable, Hashable {
|
||||
let userID: String
|
||||
nonisolated struct UserProfile: Hashable, Identifiable {
|
||||
let id: String
|
||||
let displayName: String?
|
||||
let avatarURL: URL?
|
||||
|
||||
init(userID: String, displayName: String? = nil, avatarURL: URL? = nil) {
|
||||
self.userID = userID
|
||||
id = userID
|
||||
self.displayName = displayName
|
||||
self.avatarURL = avatarURL
|
||||
}
|
||||
|
||||
init(member: RoomMemberDetails) {
|
||||
userID = member.id
|
||||
id = member.id
|
||||
displayName = member.isBanned ? nil : member.name
|
||||
avatarURL = member.isBanned ? nil : member.avatarURL
|
||||
}
|
||||
|
||||
init(sender: TimelineItemSender) {
|
||||
userID = sender.id
|
||||
id = sender.id
|
||||
displayName = sender.displayName
|
||||
avatarURL = sender.avatarURL
|
||||
}
|
||||
|
||||
init(sdkUserProfile: MatrixRustSDK.UserProfile) {
|
||||
userID = sdkUserProfile.userId
|
||||
id = sdkUserProfile.userId
|
||||
displayName = sdkUserProfile.displayName
|
||||
avatarURL = sdkUserProfile.avatarUrl.flatMap(URL.init(string:))
|
||||
}
|
||||
|
||||
init(sdkRoomHero: MatrixRustSDK.RoomHero) {
|
||||
userID = sdkRoomHero.userId
|
||||
id = sdkRoomHero.userId
|
||||
displayName = sdkRoomHero.displayName
|
||||
avatarURL = sdkRoomHero.avatarUrl.flatMap(URL.init(string:))
|
||||
}
|
||||
@@ -56,19 +56,13 @@ nonisolated struct UserProfileProxy: Equatable, Hashable {
|
||||
}
|
||||
|
||||
struct SearchUsersResultsProxy {
|
||||
let results: [UserProfileProxy]
|
||||
let results: [UserProfile]
|
||||
let limited: Bool
|
||||
}
|
||||
|
||||
extension SearchUsersResultsProxy {
|
||||
init(sdkResults: MatrixRustSDK.SearchUsersResults) {
|
||||
results = sdkResults.results.map(UserProfileProxy.init)
|
||||
results = sdkResults.results.map(UserProfile.init)
|
||||
limited = sdkResults.limited
|
||||
}
|
||||
}
|
||||
|
||||
extension UserProfileProxy: Identifiable {
|
||||
var id: String {
|
||||
userID
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user