diff --git a/yobble.xcodeproj/xcuserdata/cheykrym.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/yobble.xcodeproj/xcuserdata/cheykrym.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 2e74ecd..981c53c 100644 --- a/yobble.xcodeproj/xcuserdata/cheykrym.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/yobble.xcodeproj/xcuserdata/cheykrym.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -3,54 +3,4 @@ uuid = "AEE1609A-17B4-4FCC-80A6-0D556940F4D7" type = "1" version = "2.0"> - - - - - - - - - - - - - - diff --git a/yobble/Network/ChatModels.swift b/yobble/Network/ChatModels.swift index 0e9ef85..1ceef01 100644 --- a/yobble/Network/ChatModels.swift +++ b/yobble/Network/ChatModels.swift @@ -171,6 +171,7 @@ struct ChatProfile: Decodable { let permissions: ChatPermissions? let profilePermissions: ChatProfilePermissions? let relationship: RelationshipStatus? + let isOfficial: Bool private enum CodingKeys: String, CodingKey { case userId @@ -184,6 +185,8 @@ struct ChatProfile: Decodable { case permissions case profilePermissions case relationship + case isOfficial + case isVerified } init(from decoder: Decoder) throws { @@ -199,6 +202,9 @@ struct ChatProfile: Decodable { self.permissions = try container.decodeIfPresent(ChatPermissions.self, forKey: .permissions) self.profilePermissions = try container.decodeIfPresent(ChatProfilePermissions.self, forKey: .profilePermissions) self.relationship = try container.decodeIfPresent(RelationshipStatus.self, forKey: .relationship) + let explicitOfficial = try container.decodeIfPresent(Bool.self, forKey: .isOfficial) + let verifiedFlag = try container.decodeIfPresent(Bool.self, forKey: .isVerified) + self.isOfficial = explicitOfficial ?? verifiedFlag ?? false } } @@ -214,7 +220,8 @@ extension ChatProfile { stories: [JSONValue] = [], permissions: ChatPermissions? = nil, profilePermissions: ChatProfilePermissions? = nil, - relationship: RelationshipStatus? = nil + relationship: RelationshipStatus? = nil, + isOfficial: Bool = false ) { self.userId = userId self.login = login @@ -227,6 +234,7 @@ extension ChatProfile { self.permissions = permissions self.profilePermissions = profilePermissions self.relationship = relationship + self.isOfficial = isOfficial } } diff --git a/yobble/Network/SearchModels.swift b/yobble/Network/SearchModels.swift index 3c7c1ed..1b4b115 100644 --- a/yobble/Network/SearchModels.swift +++ b/yobble/Network/SearchModels.swift @@ -30,14 +30,14 @@ struct SearchProfile: Decodable { } extension UserSearchResult { - var officialFullName: String? { - trimmed(profile?.fullName) - } - var preferredCustomName: String? { trimmed(profile?.customName) } + var officialFullName: String? { + trimmed(profile?.fullName) + } + var login: String? { trimmed(profile?.login) } @@ -63,8 +63,8 @@ extension UserSearchResult { } var avatarInitial: String { - let source = officialFullName - ?? preferredCustomName + let source = preferredCustomName + ?? officialFullName ?? login ?? userId.uuidString diff --git a/yobble/Views/Tab/ChatsTab.swift b/yobble/Views/Tab/ChatsTab.swift index 38d7c77..05e8904 100644 --- a/yobble/Views/Tab/ChatsTab.swift +++ b/yobble/Views/Tab/ChatsTab.swift @@ -631,7 +631,7 @@ private extension ChatsTab { func chatProfile(from user: UserSearchResult) -> ChatProfile { let profile = user.profile let login = user.login ?? profile?.login - let fullName = user.officialFullName ?? profile?.fullName + let fullName = profile?.fullName let customName = user.preferredCustomName ?? profile?.customName return ChatProfile( @@ -641,7 +641,8 @@ private extension ChatsTab { customName: customName, bio: profile?.bio, lastSeen: profile?.lastSeen, - createdAt: user.createdAt ?? profile?.createdAt + createdAt: user.createdAt ?? profile?.createdAt, + isOfficial: user.isOfficial ) } @@ -789,13 +790,6 @@ private struct ChatRowView: View { } } - private var officialFullName: String? { - guard let name = chat.chatData?.fullName?.trimmingCharacters(in: .whitespacesAndNewlines), !name.isEmpty else { - return nil - } - return NSLocalizedString(name, comment: "") - } - private var loginDisplay: String? { guard let login = chat.chatData?.login?.trimmingCharacters(in: .whitespacesAndNewlines), !login.isEmpty else { return nil @@ -804,7 +798,21 @@ private struct ChatRowView: View { } private var isOfficial: Bool { - officialFullName != nil + chat.chatData?.isOfficial ?? false + } + + private var officialDisplayName: String? { + guard isOfficial else { return nil } + + if let customName = chat.chatData?.customName?.trimmingCharacters(in: .whitespacesAndNewlines), !customName.isEmpty { + return customName + } + + if let name = chat.chatData?.fullName?.trimmingCharacters(in: .whitespacesAndNewlines), !name.isEmpty { + return NSLocalizedString(name, comment: "") + } + + return loginDisplay } private var isDeletedUser: Bool { @@ -868,19 +876,21 @@ private struct ChatRowView: View { let login = trimmed(profile.login) let customName = trimmed(profile.customName) let fullName = trimmed(profile.fullName) - let isOfficialProfile = fullName != nil - - if isOfficialProfile, let login { - if let customName { - return "@\(login) (\(customName))" - } - return "@\(login)" - } + let isOfficialProfile = profile.isOfficial if let customName { return customName } + if isOfficialProfile { + if let fullName { + return fullName + } + if let login { + return "@\(login)" + } + } + if let login { return "@\(login)" } @@ -904,10 +914,12 @@ private struct ChatRowView: View { private var initial: String { let sourceName: String - if let full = officialFullName { - sourceName = full - } else if let custom = chat.chatData?.customName, !custom.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty { + if let custom = chat.chatData?.customName, !custom.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty { sourceName = custom + } else if let displayName = officialDisplayName { + sourceName = displayName + } else if let full = chat.chatData?.fullName?.trimmingCharacters(in: .whitespacesAndNewlines), !full.isEmpty { + sourceName = full } else if let login = chat.chatData?.login?.trimmingCharacters(in: .whitespacesAndNewlines), !login.isEmpty { sourceName = login } else { @@ -966,7 +978,7 @@ private struct ChatRowView: View { ) VStack(alignment: .leading, spacing: 4) { - if let officialName = officialFullName { + if let officialName = officialDisplayName { HStack(spacing: 6) { if #available(iOS 16.0, *) { Text(officialName)