43 lines
1.1 KiB
Swift
43 lines
1.1 KiB
Swift
import Foundation
|
|
|
|
struct GetPushNotificationListResponse: Decodable {
|
|
let totalCount: Int
|
|
let items: [PushNotificationListItem]
|
|
}
|
|
|
|
struct PushNotificationListItem: Decodable {
|
|
let id: Int
|
|
let senderNickname: String
|
|
let senderProfileImage: String?
|
|
let message: String
|
|
let category: String
|
|
let deepLink: String?
|
|
let sentAt: String
|
|
}
|
|
|
|
extension PushNotificationListItem {
|
|
func relativeSentAtText(now: Date = Date()) -> String {
|
|
guard let sentDate = DateParser.parse(sentAt) else {
|
|
return sentAt
|
|
}
|
|
|
|
let interval = max(0, now.timeIntervalSince(sentDate))
|
|
if interval < 60 {
|
|
return I18n.Time.justNow
|
|
}
|
|
|
|
if interval < 3600 {
|
|
let minutes = max(1, Int(interval / 60))
|
|
return I18n.Time.minutesAgo(minutes)
|
|
}
|
|
|
|
if interval < 86_400 {
|
|
let hours = max(1, Int(interval / 3600))
|
|
return I18n.Time.hoursAgo(hours)
|
|
}
|
|
|
|
let days = max(1, Int(interval / 86_400))
|
|
return I18n.Time.daysAgo(days)
|
|
}
|
|
}
|