Skip to content

Commit

Permalink
Add NotificationGroup struct
Browse files Browse the repository at this point in the history
  • Loading branch information
whattherestimefor committed Dec 19, 2024
1 parent 9a7b321 commit f046999
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Mastodon/Coordinator/SceneCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,17 @@ 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(
maxID: Mastodon.Entity.Status.ID? = nil,
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f046999

Please sign in to comment.