2
2
mirror of https://github.com/mastodon/mastodon-ios synced 2025-04-11 22:58:02 +02:00

Add NotificationGroup struct

This commit is contained in:
shannon 2024-12-19 15:21:30 -05:00
parent 9a7b3215e0
commit f04699960f
6 changed files with 70 additions and 17 deletions

View File

@ -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)

View File

@ -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

View File

@ -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:

View File

@ -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

View File

@ -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)
}
}

View File

@ -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