mirror of
https://github.com/lux-tel/session-ios.git
synced 2026-10-30 20:38:32 +00:00
• Added a few logs to the NotificationServiceExtension where it could potentially end execution without a resolution log being added • Updated export logs to provide additional debugging information • Tweaked the logs when failing to unwrap a message • Tweaked the poller logs • Fixed an issue where tapping on a "Call Missed" info message with an "(i)" wouldn't show a modal in all cases • Fixed an issue where group admins couldn't "Clear All Message" only on the current device • Fixed an issue where community conversations wouldn't have the correct created timestamp when linking devices
54 lines
2.1 KiB
Swift
54 lines
2.1 KiB
Swift
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
|
|
|
import Foundation
|
|
|
|
public enum Format {
|
|
private static let fileSizeFormatter: NumberFormatter = {
|
|
let result: NumberFormatter = NumberFormatter()
|
|
result.numberStyle = .decimal
|
|
result.minimumFractionDigits = 0
|
|
result.maximumFractionDigits = 1
|
|
|
|
return result
|
|
}()
|
|
private static let durationFormatter: DateComponentsFormatter = {
|
|
let formatter = DateComponentsFormatter()
|
|
formatter.unitsStyle = .positional
|
|
formatter.allowedUnits = [.minute, .second ]
|
|
formatter.zeroFormattingBehavior = [ .pad ]
|
|
|
|
return formatter
|
|
}()
|
|
private static let oneKilobyte: Double = 1024;
|
|
private static let oneMegabyte: Double = (oneKilobyte * 1024)
|
|
private static let oneGigabyte: Double = (oneMegabyte * 1024)
|
|
|
|
public static func fileSize(_ fileSize: UInt) -> String {
|
|
let fileSizeDouble: Double = Double(fileSize)
|
|
|
|
switch fileSizeDouble {
|
|
case oneGigabyte...Double.greatestFiniteMagnitude:
|
|
return (Format.fileSizeFormatter
|
|
.string(from: NSNumber(floatLiteral: (fileSizeDouble / oneGigabyte)))?
|
|
.appending("GB") ?? // stringlint:ignore
|
|
"attachmentsNa".localized())
|
|
|
|
case oneMegabyte...Double.greatestFiniteMagnitude:
|
|
return (Format.fileSizeFormatter
|
|
.string(from: NSNumber(floatLiteral: (fileSizeDouble / oneMegabyte)))?
|
|
.appending("MB") ?? // stringlint:ignore
|
|
"attachmentsNa".localized())
|
|
|
|
default:
|
|
return (Format.fileSizeFormatter
|
|
.string(from: NSNumber(floatLiteral: max(0.1, (fileSizeDouble / oneKilobyte))))?
|
|
.appending("KB") ?? // stringlint:ignore
|
|
"attachmentsNa".localized())
|
|
}
|
|
}
|
|
|
|
public static func duration(_ duration: TimeInterval) -> String {
|
|
return (Format.durationFormatter.string(from: duration) ?? "0:00") // stringlint:ignore
|
|
}
|
|
}
|