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