diff --git a/Mastodon/Coordinator/SceneCoordinator.swift b/Mastodon/Coordinator/SceneCoordinator.swift index e336e9a556..490503a18f 100644 --- a/Mastodon/Coordinator/SceneCoordinator.swift +++ b/Mastodon/Coordinator/SceneCoordinator.swift @@ -90,7 +90,7 @@ final public class SceneCoordinator { }() // show notification related content - guard let type = Mastodon.Entity.Notification.NotificationType(rawValue: pushNotification.notificationType) else { return } + guard let type = Mastodon.Entity.NotificationType(rawValue: pushNotification.notificationType) else { return } guard let me = authenticationBox.cachedAccount else { return } let notificationID = String(pushNotification.notificationID) diff --git a/MastodonSDK/Sources/MastodonCore/Extension/MastodonSDK/Mastodon+Entity+Notification+Type.swift b/MastodonSDK/Sources/MastodonCore/Extension/MastodonSDK/Mastodon+Entity+Notification+Type.swift index ec05ea3c70..674e2e7f9b 100644 --- a/MastodonSDK/Sources/MastodonCore/Extension/MastodonSDK/Mastodon+Entity+Notification+Type.swift +++ b/MastodonSDK/Sources/MastodonCore/Extension/MastodonSDK/Mastodon+Entity+Notification+Type.swift @@ -11,7 +11,7 @@ import UIKit import MastodonAsset import MastodonLocalization -extension Mastodon.Entity.Notification.NotificationType { +extension Mastodon.Entity.NotificationType { public var color: UIColor { get { var color: UIColor diff --git a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Notification.swift b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Notification.swift index 9af896130d..74cd25a723 100644 --- a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Notification.swift +++ b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Notification.swift @@ -26,8 +26,8 @@ extension APIService { ) async throws -> Mastodon.Response.Content<[Mastodon.Entity.Notification]> { let authorization = authenticationBox.userAuthorization - let types: [Mastodon.Entity.Notification.NotificationType]? - let excludedTypes: [Mastodon.Entity.Notification.NotificationType]? + let types: [Mastodon.Entity.NotificationType]? + let excludedTypes: [Mastodon.Entity.NotificationType]? switch scope { case .everything: diff --git a/MastodonSDK/Sources/MastodonSDK/API/Mastodon+API+Notifications.swift b/MastodonSDK/Sources/MastodonSDK/API/Mastodon+API+Notifications.swift index 7244c6e9c6..03e591d2c3 100644 --- a/MastodonSDK/Sources/MastodonSDK/API/Mastodon+API+Notifications.swift +++ b/MastodonSDK/Sources/MastodonSDK/API/Mastodon+API+Notifications.swift @@ -90,8 +90,8 @@ extension Mastodon.API.Notifications { public let sinceID: Mastodon.Entity.Status.ID? public let minID: Mastodon.Entity.Status.ID? public let limit: Int? - public let types: [Mastodon.Entity.Notification.NotificationType]? - public let excludeTypes: [Mastodon.Entity.Notification.NotificationType]? + public let types: [Mastodon.Entity.NotificationType]? + public let excludeTypes: [Mastodon.Entity.NotificationType]? public let accountID: String? public init( @@ -99,8 +99,8 @@ extension Mastodon.API.Notifications { sinceID: Mastodon.Entity.Status.ID? = nil, minID: Mastodon.Entity.Status.ID? = nil, limit: Int? = nil, - types: [Mastodon.Entity.Notification.NotificationType]? = nil, - excludeTypes: [Mastodon.Entity.Notification.NotificationType]? = nil, + types: [Mastodon.Entity.NotificationType]? = nil, + excludeTypes: [Mastodon.Entity.NotificationType]? = nil, accountID: String? = nil ) { self.maxID = maxID diff --git a/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Notification.swift b/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Notification.swift index f29a5fff4f..953b1fd8d0 100644 --- a/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Notification.swift +++ b/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Notification.swift @@ -20,25 +20,69 @@ extension Mastodon.Entity { public typealias ID = String public let id: ID - public let type: Type + public let type: NotificationType public let createdAt: Date + public let groupKey: String? public let account: Account public let status: Status? + public let report: Report? +// public let relationshipSeverenceEvent: RelationshipSeveranceEvent? public let accountWarning: AccountWarning? enum CodingKeys: String, CodingKey { case id case type + case groupKey = "group_key" case createdAt = "created_at" case account case status + case report + case accountWarning = "moderation_warning" + } + } + + /// NotificationGroup + /// + /// - Since: 4.3.0 + /// - Version: 4.3.0 + /// # Last Update + /// 2024/12/19 + /// # Reference + /// [Document](https://docs.joinmastodon.org/methods/grouped_notifications/#NotificationGroup) + public struct NotificationGroup: Codable, Sendable { + public typealias ID = String + + public let id: ID + public let notificationsCount: Int + public let type: NotificationType + public let mostRecentNotificationID: ID + public let pageOldestID: ID? // ID of the oldest notification from this group represented within the current page. This is only returned when paginating through notification groups. Useful when polling new notifications. + public let pageNewestID: ID? // ID of the newest notification from this group represented within the current page. This is only returned when paginating through notification groups. Useful when polling new notifications. + public let latestPageNotificationAt: Date? // Date at which the most recent notification from this group within the current page has been created. This is only returned when paginating through notification groups. + public let sampleAccountIDs: [String] // IDs of some of the accounts who most recently triggered notifications in this group. + public let statusID: ID? + public let report: Report? + // public let relationshipSeverenceEvent: RelationshipSeveranceEvent? + public let accountWarning: AccountWarning? + + enum CodingKeys: String, CodingKey { + case id = "group_key" + case notificationsCount = "notifications_count" + case type + case mostRecentNotificationID = "most_recent_notification_id" + case pageOldestID = "page_min_id" + case pageNewestID = "page_max_id" + case latestPageNotificationAt = "latest_page_notification_at" + case sampleAccountIDs = "sample_account_ids" + case statusID = "status_id" + case report = "report" case accountWarning = "moderation_warning" } } } extension Mastodon.Entity { - public struct AccountWarning: Codable { + public struct AccountWarning: Codable, Sendable { public typealias ID = String public let id: ID @@ -57,7 +101,7 @@ extension Mastodon.Entity { case statusIds = "status_ids" } - public enum Action: String, Codable { + public enum Action: String, Codable, Sendable { case none case disable case markStatusesAsSensitive @@ -77,11 +121,11 @@ extension Mastodon.Entity { } } - public struct Appeal: Codable { + public struct Appeal: Codable, Sendable { public let text: String public let state: State - public enum State: String, Codable { + public enum State: String, Codable, Sendable { case approved case rejected case pending @@ -90,9 +134,8 @@ extension Mastodon.Entity { } } -extension Mastodon.Entity.Notification { - public typealias NotificationType = Type - public enum `Type`: RawRepresentable, Codable, Sendable { +extension Mastodon.Entity { + public enum NotificationType: RawRepresentable, Codable, Sendable { case follow case followRequest case mention @@ -143,3 +186,13 @@ extension Mastodon.Entity.Notification: Hashable { hasher.combine(id) } } + +extension Mastodon.Entity.NotificationGroup: Hashable { + public static func == (lhs: Mastodon.Entity.NotificationGroup, rhs: Mastodon.Entity.NotificationGroup) -> Bool { + lhs.id == rhs.id + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(id) + } +} diff --git a/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Report.swift b/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Report.swift index 5b2571206b..a6e817bbe1 100644 --- a/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Report.swift +++ b/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Report.swift @@ -16,7 +16,7 @@ extension Mastodon.Entity { /// 2021/1/29 /// # Reference /// [Document](https://docs.joinmastodon.org/entities/report/) - public struct Report: Codable { + public struct Report: Codable, Sendable { public typealias ID = String public let id: ID // undocumented