2024-12-12 15:33:46 +00:00
|
|
|
import Foundation
|
|
|
|
|
|
|
|
/// Contains a list of all notifications for the logged in user and the numbers of unread notifications.
|
2024-12-22 16:24:48 +00:00
|
|
|
public struct NotificationFeed: Hashable, Sendable {
|
|
|
|
public enum Category: String, CaseIterable, Sendable {
|
2024-12-12 15:33:46 +00:00
|
|
|
case all = ""
|
|
|
|
case upvotes = "upvotes"
|
|
|
|
case mentions = "mentions"
|
|
|
|
case comments = "comments"
|
|
|
|
case subscriptions = "subs"
|
|
|
|
}
|
|
|
|
|
|
|
|
/// The time when the notifications were last checked.
|
|
|
|
public let lastChecked: Date
|
|
|
|
|
|
|
|
/// The list of all notifications for the logged in user.
|
|
|
|
public let notifications: [Notification]
|
|
|
|
|
|
|
|
/// The numbers of unread notifications.
|
|
|
|
public let unreadNumbers: UnreadNumbers
|
|
|
|
|
|
|
|
/// Infos about the user name and avatar for each user id.
|
|
|
|
public let userInfos: [UserInfo]
|
|
|
|
|
|
|
|
public init(lastChecked: Date, notifications: [Notification], unreadNumbers: NotificationFeed.UnreadNumbers, userInfos: [UserInfo]) {
|
|
|
|
self.lastChecked = lastChecked
|
|
|
|
self.notifications = notifications
|
|
|
|
self.unreadNumbers = unreadNumbers
|
|
|
|
self.userInfos = userInfos
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension NotificationFeed {
|
|
|
|
struct CodingData: Decodable {
|
2024-12-18 14:08:14 +00:00
|
|
|
struct Container: Decodable {
|
|
|
|
let data: NotificationFeed.CodingData
|
|
|
|
}
|
|
|
|
|
2024-12-12 15:33:46 +00:00
|
|
|
let check_time: Int
|
|
|
|
let items: [Notification.CodingData]
|
|
|
|
let unread: UnreadNumbers.CodingData
|
2024-12-23 14:42:59 +00:00
|
|
|
let username_map: [String: NotificationFeed.UserInfo.UsernameMapEntryCodingData]
|
2024-12-12 15:33:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension NotificationFeed.CodingData {
|
|
|
|
var decoded: NotificationFeed {
|
|
|
|
.init(
|
|
|
|
lastChecked: Date(timeIntervalSince1970: TimeInterval(check_time)),
|
|
|
|
notifications: items.map(\.decoded),
|
|
|
|
unreadNumbers: unread.decoded,
|
2024-12-23 14:42:59 +00:00
|
|
|
userInfos: username_map.map { (key, value) in
|
|
|
|
.init(avatar: value.avatar.decoded, username: value.name, userId: Int(key) ?? 0)
|
|
|
|
}
|
2024-12-12 15:33:46 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|