fix search model
This commit is contained in:
parent
c81337646a
commit
2baf7ae2cb
@ -6,10 +6,10 @@ struct SearchDataPayload: Decodable {
|
||||
|
||||
struct UserSearchResult: Decodable, Identifiable {
|
||||
let userId: UUID
|
||||
let login: String
|
||||
let fullName: String?
|
||||
let customName: String?
|
||||
let createdAt: Date?
|
||||
// let login: String
|
||||
// let fullName: String?
|
||||
// let customName: String?
|
||||
// let createdAt: Date?
|
||||
let profile: SearchProfile?
|
||||
|
||||
var id: UUID { userId }
|
||||
@ -17,25 +17,36 @@ struct UserSearchResult: Decodable, Identifiable {
|
||||
|
||||
struct SearchProfile: Decodable {
|
||||
let userId: UUID
|
||||
let login: String?
|
||||
let login: String
|
||||
let fullName: String?
|
||||
let customName: String?
|
||||
let bio: String?
|
||||
|
||||
let isVerified: Bool
|
||||
let isSystem: Bool
|
||||
|
||||
let lastSeen: Int?
|
||||
let createdAt: Date?
|
||||
}
|
||||
|
||||
extension UserSearchResult {
|
||||
var officialFullName: String? {
|
||||
trimmed(fullName) ?? trimmed(profile?.fullName)
|
||||
trimmed(profile?.fullName)
|
||||
}
|
||||
|
||||
var preferredCustomName: String? {
|
||||
trimmed(customName) ?? trimmed(profile?.customName)
|
||||
trimmed(profile?.customName)
|
||||
}
|
||||
|
||||
var login: String? {
|
||||
trimmed(profile?.login)
|
||||
}
|
||||
|
||||
var loginHandle: String {
|
||||
"@\(login)"
|
||||
if let login {
|
||||
return "@\(login)"
|
||||
}
|
||||
return "@\(userId.uuidString)"
|
||||
}
|
||||
|
||||
var displayName: String {
|
||||
@ -45,20 +56,17 @@ extension UserSearchResult {
|
||||
if let custom = preferredCustomName {
|
||||
return custom
|
||||
}
|
||||
if let profileFull = trimmed(profile?.fullName) {
|
||||
return profileFull
|
||||
if let login = login {
|
||||
return "@\(login)"
|
||||
}
|
||||
if let profileCustom = trimmed(profile?.customName) {
|
||||
return profileCustom
|
||||
}
|
||||
return loginHandle
|
||||
return "@\(userId.uuidString)"
|
||||
}
|
||||
|
||||
var avatarInitial: String {
|
||||
let source = officialFullName
|
||||
?? preferredCustomName
|
||||
?? trimmed(profile?.login)
|
||||
?? login
|
||||
?? userId.uuidString
|
||||
|
||||
if let character = source.first(where: { !$0.isWhitespace && $0 != "@" }) {
|
||||
return String(character).uppercased()
|
||||
@ -67,7 +75,11 @@ extension UserSearchResult {
|
||||
}
|
||||
|
||||
var isOfficial: Bool {
|
||||
officialFullName != nil
|
||||
profile?.isVerified ?? false
|
||||
}
|
||||
|
||||
var createdAt: Date? {
|
||||
profile?.createdAt
|
||||
}
|
||||
|
||||
private func trimmed(_ value: String?) -> String? {
|
||||
|
||||
@ -583,7 +583,7 @@ private extension ChatsTab {
|
||||
return custom
|
||||
}
|
||||
|
||||
if let profileLogin = user.profile?.login?.trimmingCharacters(in: .whitespacesAndNewlines), !profileLogin.isEmpty {
|
||||
if let profileLogin = user.profile?.login.trimmingCharacters(in: .whitespacesAndNewlines), !profileLogin.isEmpty {
|
||||
let handle = "@\(profileLogin)"
|
||||
if handle != user.loginHandle {
|
||||
return handle
|
||||
@ -630,9 +630,9 @@ private extension ChatsTab {
|
||||
|
||||
func chatProfile(from user: UserSearchResult) -> ChatProfile {
|
||||
let profile = user.profile
|
||||
let login = profile?.login ?? user.login
|
||||
let fullName = user.officialFullName ?? user.fullName ?? profile?.fullName
|
||||
let customName = user.preferredCustomName ?? user.customName ?? profile?.customName
|
||||
let login = user.login ?? profile?.login
|
||||
let fullName = user.officialFullName ?? profile?.fullName
|
||||
let customName = user.preferredCustomName ?? profile?.customName
|
||||
|
||||
return ChatProfile(
|
||||
userId: user.userId.uuidString,
|
||||
@ -641,7 +641,7 @@ private extension ChatsTab {
|
||||
customName: customName,
|
||||
bio: profile?.bio,
|
||||
lastSeen: profile?.lastSeen,
|
||||
createdAt: profile?.createdAt
|
||||
createdAt: user.createdAt ?? profile?.createdAt
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user