fix search model

This commit is contained in:
cheykrym 2025-10-21 01:04:28 +03:00
parent c81337646a
commit 2baf7ae2cb
2 changed files with 33 additions and 21 deletions

View File

@ -6,10 +6,10 @@ struct SearchDataPayload: Decodable {
struct UserSearchResult: Decodable, Identifiable { struct UserSearchResult: Decodable, Identifiable {
let userId: UUID let userId: UUID
let login: String // let login: String
let fullName: String? // let fullName: String?
let customName: String? // let customName: String?
let createdAt: Date? // let createdAt: Date?
let profile: SearchProfile? let profile: SearchProfile?
var id: UUID { userId } var id: UUID { userId }
@ -17,25 +17,36 @@ struct UserSearchResult: Decodable, Identifiable {
struct SearchProfile: Decodable { struct SearchProfile: Decodable {
let userId: UUID let userId: UUID
let login: String? let login: String
let fullName: String? let fullName: String?
let customName: String? let customName: String?
let bio: String? let bio: String?
let isVerified: Bool
let isSystem: Bool
let lastSeen: Int? let lastSeen: Int?
let createdAt: Date? let createdAt: Date?
} }
extension UserSearchResult { extension UserSearchResult {
var officialFullName: String? { var officialFullName: String? {
trimmed(fullName) ?? trimmed(profile?.fullName) trimmed(profile?.fullName)
} }
var preferredCustomName: String? { var preferredCustomName: String? {
trimmed(customName) ?? trimmed(profile?.customName) trimmed(profile?.customName)
}
var login: String? {
trimmed(profile?.login)
} }
var loginHandle: String { var loginHandle: String {
"@\(login)" if let login {
return "@\(login)"
}
return "@\(userId.uuidString)"
} }
var displayName: String { var displayName: String {
@ -45,20 +56,17 @@ extension UserSearchResult {
if let custom = preferredCustomName { if let custom = preferredCustomName {
return custom return custom
} }
if let profileFull = trimmed(profile?.fullName) { if let login = login {
return profileFull return "@\(login)"
} }
if let profileCustom = trimmed(profile?.customName) { return "@\(userId.uuidString)"
return profileCustom
}
return loginHandle
} }
var avatarInitial: String { var avatarInitial: String {
let source = officialFullName let source = officialFullName
?? preferredCustomName ?? preferredCustomName
?? trimmed(profile?.login)
?? login ?? login
?? userId.uuidString
if let character = source.first(where: { !$0.isWhitespace && $0 != "@" }) { if let character = source.first(where: { !$0.isWhitespace && $0 != "@" }) {
return String(character).uppercased() return String(character).uppercased()
@ -67,7 +75,11 @@ extension UserSearchResult {
} }
var isOfficial: Bool { var isOfficial: Bool {
officialFullName != nil profile?.isVerified ?? false
}
var createdAt: Date? {
profile?.createdAt
} }
private func trimmed(_ value: String?) -> String? { private func trimmed(_ value: String?) -> String? {

View File

@ -583,7 +583,7 @@ private extension ChatsTab {
return custom 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)" let handle = "@\(profileLogin)"
if handle != user.loginHandle { if handle != user.loginHandle {
return handle return handle
@ -630,9 +630,9 @@ private extension ChatsTab {
func chatProfile(from user: UserSearchResult) -> ChatProfile { func chatProfile(from user: UserSearchResult) -> ChatProfile {
let profile = user.profile let profile = user.profile
let login = profile?.login ?? user.login let login = user.login ?? profile?.login
let fullName = user.officialFullName ?? user.fullName ?? profile?.fullName let fullName = user.officialFullName ?? profile?.fullName
let customName = user.preferredCustomName ?? user.customName ?? profile?.customName let customName = user.preferredCustomName ?? profile?.customName
return ChatProfile( return ChatProfile(
userId: user.userId.uuidString, userId: user.userId.uuidString,
@ -641,7 +641,7 @@ private extension ChatsTab {
customName: customName, customName: customName,
bio: profile?.bio, bio: profile?.bio,
lastSeen: profile?.lastSeen, lastSeen: profile?.lastSeen,
createdAt: profile?.createdAt createdAt: user.createdAt ?? profile?.createdAt
) )
} }