diff --git a/yobble/Network/ChatModels.swift b/yobble/Network/ChatModels.swift index 8b575b4..3166def 100644 --- a/yobble/Network/ChatModels.swift +++ b/yobble/Network/ChatModels.swift @@ -172,6 +172,7 @@ struct ChatProfile: Decodable { let permissions: ChatPermissions? let profilePermissions: ChatProfilePermissions? let relationship: RelationshipStatus? + let rating: Int? let isOfficial: Bool private enum CodingKeys: String, CodingKey { @@ -187,6 +188,7 @@ struct ChatProfile: Decodable { case permissions case profilePermissions case relationship + case rating case isOfficial case isVerified } @@ -205,12 +207,43 @@ 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 ratingPayload = try container.decodeIfPresent(ChatProfileRatingPayload.self, forKey: .rating) + self.rating = ratingPayload?.resolvedRating let explicitOfficial = try container.decodeIfPresent(Bool.self, forKey: .isOfficial) let verifiedFlag = try container.decodeIfPresent(Bool.self, forKey: .isVerified) self.isOfficial = explicitOfficial ?? verifiedFlag ?? false } } +private struct ChatProfileRatingPayload: Decodable { + let status: String? + let rating: Int? + + private enum CodingKeys: String, CodingKey { + case rating + case status + } + + init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + status = try container.decodeIfPresent(String.self, forKey: .status) + + if let intValue = try? container.decode(Int.self, forKey: .rating) { + rating = intValue + } else if let stringValue = try? container.decode(String.self, forKey: .rating), + let intValue = Int(stringValue) { + rating = intValue + } else { + rating = nil + } + } + + var resolvedRating: Int? { + guard status?.lowercased() == "fine" else { return nil } + return rating + } +} + extension ChatProfile { init( userId: String, @@ -225,6 +258,7 @@ extension ChatProfile { permissions: ChatPermissions? = nil, profilePermissions: ChatProfilePermissions? = nil, relationship: RelationshipStatus? = nil, + rating: Int? = nil, isOfficial: Bool = false ) { self.userId = userId @@ -239,6 +273,7 @@ extension ChatProfile { self.permissions = permissions self.profilePermissions = profilePermissions self.relationship = relationship + self.rating = rating self.isOfficial = isOfficial } } diff --git a/yobble/Resources/Localizable.xcstrings b/yobble/Resources/Localizable.xcstrings index fc75f28..0d3d713 100644 --- a/yobble/Resources/Localizable.xcstrings +++ b/yobble/Resources/Localizable.xcstrings @@ -43,6 +43,9 @@ } } }, + "%d из 5" : { + "comment" : "Message profile rating format" + }, "%d символов" : { "comment" : "feedback: character count", "localizations" : { @@ -1497,6 +1500,9 @@ } } }, + "Недоступно" : { + "comment" : "Message profile rating unavailable" + }, "Неизвестная ошибка" : { "localizations" : { "en" : { @@ -2546,6 +2552,9 @@ }, "Режим мессенжера" : { + }, + "Рейтинг собеседника" : { + "comment" : "Message profile rating title" }, "Сборка:" : { "localizations" : { diff --git a/yobble/Views/Chat/MessageProfileView.swift b/yobble/Views/Chat/MessageProfileView.swift index 79290ae..df8f838 100644 --- a/yobble/Views/Chat/MessageProfileView.swift +++ b/yobble/Views/Chat/MessageProfileView.swift @@ -244,6 +244,15 @@ struct MessageProfileView: View { value: membership ) } + + if loginDisplay != nil || membershipDescription != nil { + rowDivider + } + + infoRow( + title: NSLocalizedString("Рейтинг собеседника", comment: "Message profile rating title"), + value: ratingDisplayValue + ) } } @@ -616,6 +625,18 @@ struct MessageProfileView: View { ) } + private var ratingDisplayValue: String { + guard let rating = chat.chatData?.rating else { + return NSLocalizedString("Недоступно", comment: "Message profile rating unavailable") + } + + let safeRating = max(0, min(5, rating)) + return String( + format: NSLocalizedString("%d из 5", comment: "Message profile rating format"), + safeRating + ) + } + private var chatTypeDescription: String { switch chat.chatType { case .self: