add rating
This commit is contained in:
parent
95a5c77cb9
commit
549b2126a9
@ -172,7 +172,7 @@ struct ChatProfile: Decodable {
|
||||
let permissions: ChatPermissions?
|
||||
let profilePermissions: ChatProfilePermissions?
|
||||
let relationship: RelationshipStatus?
|
||||
let rating: Int?
|
||||
let rating: Double?
|
||||
let isOfficial: Bool
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
@ -217,7 +217,7 @@ struct ChatProfile: Decodable {
|
||||
|
||||
private struct ChatProfileRatingPayload: Decodable {
|
||||
let status: String?
|
||||
let rating: Int?
|
||||
let rating: Double?
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case rating
|
||||
@ -228,17 +228,19 @@ private struct ChatProfileRatingPayload: Decodable {
|
||||
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
|
||||
if let doubleValue = try? container.decode(Double.self, forKey: .rating) {
|
||||
rating = doubleValue
|
||||
} else if let stringValue = try? container.decode(String.self, forKey: .rating),
|
||||
let intValue = Int(stringValue) {
|
||||
rating = intValue
|
||||
let doubleValue = Double(stringValue) {
|
||||
rating = doubleValue
|
||||
} else if let intValue = try? container.decode(Int.self, forKey: .rating) {
|
||||
rating = Double(intValue)
|
||||
} else {
|
||||
rating = nil
|
||||
}
|
||||
}
|
||||
|
||||
var resolvedRating: Int? {
|
||||
var resolvedRating: Double? {
|
||||
guard status?.lowercased() == "fine" else { return nil }
|
||||
return rating
|
||||
}
|
||||
@ -258,7 +260,7 @@ extension ChatProfile {
|
||||
permissions: ChatPermissions? = nil,
|
||||
profilePermissions: ChatProfilePermissions? = nil,
|
||||
relationship: RelationshipStatus? = nil,
|
||||
rating: Int? = nil,
|
||||
rating: Double? = nil,
|
||||
isOfficial: Bool = false
|
||||
) {
|
||||
self.userId = userId
|
||||
|
||||
@ -33,6 +33,9 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"%@ из 5" : {
|
||||
"comment" : "Message profile rating format"
|
||||
},
|
||||
"%@: %@" : {
|
||||
"localizations" : {
|
||||
"ru" : {
|
||||
@ -43,9 +46,6 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"%d из 5" : {
|
||||
"comment" : "Message profile rating format"
|
||||
},
|
||||
"%d символов" : {
|
||||
"comment" : "feedback: character count",
|
||||
"localizations" : {
|
||||
|
||||
@ -631,9 +631,11 @@ struct MessageProfileView: View {
|
||||
}
|
||||
|
||||
let safeRating = max(0, min(5, rating))
|
||||
let formatted = MessageProfileView.ratingFormatter.string(from: NSNumber(value: safeRating))
|
||||
?? String(format: "%.1f", safeRating)
|
||||
return String(
|
||||
format: NSLocalizedString("%d из 5", comment: "Message profile rating format"),
|
||||
safeRating
|
||||
format: NSLocalizedString("%@ из 5", comment: "Message profile rating format"),
|
||||
formatted
|
||||
)
|
||||
}
|
||||
|
||||
@ -938,6 +940,14 @@ struct MessageProfileView: View {
|
||||
formatter.timeStyle = .none
|
||||
return formatter
|
||||
}()
|
||||
|
||||
private static let ratingFormatter: NumberFormatter = {
|
||||
let formatter = NumberFormatter()
|
||||
formatter.numberStyle = .decimal
|
||||
formatter.minimumFractionDigits = 1
|
||||
formatter.maximumFractionDigits = 1
|
||||
return formatter
|
||||
}()
|
||||
|
||||
private func bioFirstLines(_ text: String, count: Int) -> String {
|
||||
let lines = text.split(separator: "\n", omittingEmptySubsequences: false)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user