From 2baf7ae2cbcc13433fd11a29ebf085f1580fbf26 Mon Sep 17 00:00:00 2001 From: cheykrym Date: Tue, 21 Oct 2025 01:04:28 +0300 Subject: [PATCH] fix search model --- yobble/Network/SearchModels.swift | 44 ++++++++++++++++++++----------- yobble/Views/Tab/ChatsTab.swift | 10 +++---- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/yobble/Network/SearchModels.swift b/yobble/Network/SearchModels.swift index d137296..3c7c1ed 100644 --- a/yobble/Network/SearchModels.swift +++ b/yobble/Network/SearchModels.swift @@ -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? { diff --git a/yobble/Views/Tab/ChatsTab.swift b/yobble/Views/Tab/ChatsTab.swift index 96fb8fd..38d7c77 100644 --- a/yobble/Views/Tab/ChatsTab.swift +++ b/yobble/Views/Tab/ChatsTab.swift @@ -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 ) }