fix edit privacy
This commit is contained in:
parent
fb8413e68c
commit
06bdcac917
@ -110,6 +110,41 @@ struct ProfilePermissionsRequestPayload: Encodable {
|
|||||||
let forceAutoDeleteMessagesInPrivate: Bool
|
let forceAutoDeleteMessagesInPrivate: Bool
|
||||||
let maxMessageAutoDeleteSeconds: Int?
|
let maxMessageAutoDeleteSeconds: Int?
|
||||||
let autoDeleteAfterDays: Int?
|
let autoDeleteAfterDays: Int?
|
||||||
|
|
||||||
|
enum CodingKeys: String, CodingKey {
|
||||||
|
case isSearchable = "is_searchable"
|
||||||
|
case allowMessageForwarding = "allow_message_forwarding"
|
||||||
|
case allowMessagesFromNonContacts = "allow_messages_from_non_contacts"
|
||||||
|
case showProfilePhotoToNonContacts = "show_profile_photo_to_non_contacts"
|
||||||
|
case lastSeenVisibility = "last_seen_visibility"
|
||||||
|
case showBioToNonContacts = "show_bio_to_non_contacts"
|
||||||
|
case showStoriesToNonContacts = "show_stories_to_non_contacts"
|
||||||
|
case allowServerChats = "allow_server_chats"
|
||||||
|
case publicInvitePermission = "public_invite_permission"
|
||||||
|
case groupInvitePermission = "group_invite_permission"
|
||||||
|
case callPermission = "call_permission"
|
||||||
|
case forceAutoDeleteMessagesInPrivate = "force_auto_delete_messages_in_private"
|
||||||
|
case maxMessageAutoDeleteSeconds = "max_message_auto_delete_seconds"
|
||||||
|
case autoDeleteAfterDays = "auto_delete_after_days"
|
||||||
|
}
|
||||||
|
|
||||||
|
func encode(to encoder: Encoder) throws {
|
||||||
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||||
|
try container.encode(isSearchable, forKey: .isSearchable)
|
||||||
|
try container.encode(allowMessageForwarding, forKey: .allowMessageForwarding)
|
||||||
|
try container.encode(allowMessagesFromNonContacts, forKey: .allowMessagesFromNonContacts)
|
||||||
|
try container.encode(showProfilePhotoToNonContacts, forKey: .showProfilePhotoToNonContacts)
|
||||||
|
try container.encode(lastSeenVisibility, forKey: .lastSeenVisibility)
|
||||||
|
try container.encode(showBioToNonContacts, forKey: .showBioToNonContacts)
|
||||||
|
try container.encode(showStoriesToNonContacts, forKey: .showStoriesToNonContacts)
|
||||||
|
try container.encode(allowServerChats, forKey: .allowServerChats)
|
||||||
|
try container.encode(publicInvitePermission, forKey: .publicInvitePermission)
|
||||||
|
try container.encode(groupInvitePermission, forKey: .groupInvitePermission)
|
||||||
|
try container.encode(callPermission, forKey: .callPermission)
|
||||||
|
try container.encode(forceAutoDeleteMessagesInPrivate, forKey: .forceAutoDeleteMessagesInPrivate)
|
||||||
|
try container.encodeIfPresent(maxMessageAutoDeleteSeconds, forKey: .maxMessageAutoDeleteSeconds)
|
||||||
|
try container.encodeIfPresent(autoDeleteAfterDays, forKey: .autoDeleteAfterDays)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ProfileUpdateRequestPayload: Encodable {
|
struct ProfileUpdateRequestPayload: Encodable {
|
||||||
|
|||||||
@ -76,6 +76,8 @@ final class ProfileService {
|
|||||||
func updateProfile(_ payload: ProfileUpdateRequestPayload, completion: @escaping (Result<String, Error>) -> Void) {
|
func updateProfile(_ payload: ProfileUpdateRequestPayload, completion: @escaping (Result<String, Error>) -> Void) {
|
||||||
let encoder = JSONEncoder()
|
let encoder = JSONEncoder()
|
||||||
encoder.keyEncodingStrategy = .convertToSnakeCase
|
encoder.keyEncodingStrategy = .convertToSnakeCase
|
||||||
|
|
||||||
|
print("payload \(payload)")
|
||||||
|
|
||||||
guard let body = try? encoder.encode(payload) else {
|
guard let body = try? encoder.encode(payload) else {
|
||||||
let message = NSLocalizedString("Не удалось подготовить данные запроса.", comment: "Profile update encoding error")
|
let message = NSLocalizedString("Не удалось подготовить данные запроса.", comment: "Profile update encoding error")
|
||||||
|
|||||||
@ -166,15 +166,23 @@ struct EditPrivacyView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func formattedAutoDeleteSeconds(_ value: Int) -> String {
|
private func formattedAutoDeleteSeconds(_ value: Int) -> String {
|
||||||
|
let secondsString = "\(value) сек."
|
||||||
|
|
||||||
switch value {
|
switch value {
|
||||||
case ..<60:
|
case ..<60:
|
||||||
return "\(value) сек."
|
return secondsString
|
||||||
case 60..<3600:
|
case 60..<3600:
|
||||||
let minutes = value / 60
|
let minutes = value / 60
|
||||||
return "\(minutes) мин."
|
return "\(secondsString) (≈ \(minutes) мин.)"
|
||||||
default:
|
default:
|
||||||
let hours = Double(value) / 3600.0
|
let hours = Double(value) / 3600.0
|
||||||
return String(format: "%.1f ч.", hours)
|
let formattedHours: String
|
||||||
|
if hours.truncatingRemainder(dividingBy: 1) == 0 {
|
||||||
|
formattedHours = String(format: "%.0f", hours)
|
||||||
|
} else {
|
||||||
|
formattedHours = String(format: "%.1f", hours)
|
||||||
|
}
|
||||||
|
return "\(secondsString) (≈ \(formattedHours) ч.)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user