Repository: TootSDK/TootSDK
Pull request #280 (2024-05-08 16:03:23)

Add report, signup and severed relationship notification types


Patch:
diff --git a/Sources/TootSDK/Models/Alerts.swift b/Sources/TootSDK/Models/Alerts.swift
index 3fada32..de23ea1 100644
--- a/Sources/TootSDK/Models/Alerts.swift
+++ b/Sources/TootSDK/Models/Alerts.swift
@@ -12,7 +12,9 @@ public struct Alerts: Codable, Hashable, Sendable {
         poll: Bool? = nil,
         followRequest: Bool? = nil,
         post: Bool? = nil,
-        update: Bool? = nil
+        update: Bool? = nil,
+        adminSignUp: Bool? = nil,
+        adminReport: Bool? = nil
     ) {
         self.follow = follow
         self.favourite = favourite
@@ -22,6 +24,8 @@ public struct Alerts: Codable, Hashable, Sendable {
         self.followRequest = followRequest
         self.post = post
         self.update = update
+        self.adminSignUp = adminSignUp
+        self.adminReport = adminReport
     }
 
     /// Receive a push notification when someone has followed you.
@@ -40,6 +44,10 @@ public struct Alerts: Codable, Hashable, Sendable {
     public var post: Bool?
     /// Receive a push notification when a post you boosted with has been edited.
     public var update: Bool?
+    /// Receive a push notification when someone signs up.
+    public var adminSignUp: Bool?
+    /// Receive a push notification about a new report.
+    public var adminReport: Bool?
 
     enum CodingKeys: String, CodingKey {
         case follow
@@ -50,5 +58,7 @@ public struct Alerts: Codable, Hashable, Sendable {
         case followRequest
         case post = "status"
         case update
+        case adminSignUp = "admin.sign_up"
+        case adminReport = "admin.report"
     }
 }
diff --git a/Sources/TootSDK/Models/RelationshipSeveranceEvent.swift b/Sources/TootSDK/Models/RelationshipSeveranceEvent.swift
new file mode 100644
index 0000000..7c4b3c6
--- /dev/null
+++ b/Sources/TootSDK/Models/RelationshipSeveranceEvent.swift
@@ -0,0 +1,23 @@
+//
+//  RelationshipSeveranceEvent.swift
+//
+//
+//  Created by Łukasz Rutkowski on 08/05/2024.
+//
+
+import Foundation
+
+public struct RelationshipSeveranceEvent: Codable, Sendable, Hashable, Identifiable {
+    public let id: String
+    public let type: EventType
+    public let purged: Bool
+    public let targetName: String
+    public let relationshipsCount: Int?
+    public let createdAt: Date
+
+    public enum EventType: String, Codable, Sendable {
+        case domainBlock = "domain_block"
+        case userDomainBlock = "user_domain_block"
+        case accountSuspension = "account_suspension"
+    }
+}
diff --git a/Sources/TootSDK/Models/Report.swift b/Sources/TootSDK/Models/Report.swift
index 9471638..6fdfdd5 100644
--- a/Sources/TootSDK/Models/Report.swift
+++ b/Sources/TootSDK/Models/Report.swift
@@ -4,7 +4,7 @@
 import Foundation
 
 /// Reports filed against users and/or posts, to be taken action on by moderators.
-public struct Report: Codable, Hashable, Identifiable {
+public struct Report: Codable, Hashable, Identifiable, Sendable {
     public var id: String
     public var actionTaken: Bool?
     public var actionTakenAt: Date?
diff --git a/Sources/TootSDK/Models/TootNotification.swift b/Sources/TootSDK/Models/TootNotification.swift
index 292477a..0237c3e 100644
--- a/Sources/TootSDK/Models/TootNotification.swift
+++ b/Sources/TootSDK/Models/TootNotification.swift
@@ -5,12 +5,22 @@ import Foundation
 
 /// Represents a notification of an event relevant to the user.
 public struct TootNotification: Codable, Hashable, Identifiable, Sendable {
-    public init(id: String, type: TootNotification.NotificationType, account: Account, createdAt: Date, post: Post? = nil) {
+    public init(
+        id: String,
+        type: TootNotification.NotificationType,
+        account: Account,
+        createdAt: Date,
+        post: Post? = nil,
+        report: Report? = nil,
+        relationshipSeveranceEvent: RelationshipSeveranceEvent? = nil
+    ) {
         self.id = id
         self.type = type
         self.account = account
         self.createdAt = createdAt
         self.post = post
+        self.report = report
+        self.relationshipSeveranceEvent = relationshipSeveranceEvent
     }
 
     /// The id of the notification in the database.
@@ -23,6 +33,10 @@ public struct TootNotification: Codable, Hashable, Identifiable, Sendable {
     public var createdAt: Date
     /// Post that was the object of the notification, e.g. in mentions, reposts, favourites, or polls.
     public var post: Post?
+    /// Report that was the object of the notification. Attached when type of the notification is ``NotificationType/adminReport``.
+    public var report: Report?
+    /// Summary of the event that caused follow relationships to be severed. Attached when type of the notification is ``NotificationType/severedRelationships``.
+    public var relationshipSeveranceEvent: RelationshipSeveranceEvent?
 
     public enum NotificationType: String, Codable, Sendable, CaseIterable {
         /// Someone followed you
@@ -41,6 +55,12 @@ public struct TootNotification: Codable, Hashable, Identifiable, Sendable {
         case post = "status"
         /// A post you interacted with has been edited
         case update = "update"
+        /// Someone signed up
+        case adminSignUp = "admin.sign_up"
+        /// A new report has been filed
+        case adminReport = "admin.report"
+        /// Some of your follow relationships have been severed as a result of a moderation or block event
+        case severedRelationships = "severed_relationships"
 
         /// Returns notification types supported by the given `flavour`.
         public static func supported(by flavour: TootSDKFlavour) -> Set<NotificationType> {
@@ -87,6 +107,8 @@ public struct TootNotification: Codable, Hashable, Identifiable, Sendable {
         case account
         case createdAt
         case post = "status"
+        case report
+        case relationshipSeveranceEvent = "relationship_severance_event"
     }
 }
 
diff --git a/Sources/TootSDK/TootClient/TootClient+Notifications.swift b/Sources/TootSDK/TootClient/TootClient+Notifications.swift
index 149af64..1b56646 100644
--- a/Sources/TootSDK/TootClient/TootClient+Notifications.swift
+++ b/Sources/TootSDK/TootClient/TootClient+Notifications.swift
@@ -183,6 +183,14 @@ extension TootClient {
             queryParameters.append(.init(name: "data[alerts][update]", value: String(alert).lowercased()))
         }
 
+        if let alert = data?.alerts?.adminSignUp {
+            queryParameters.append(.init(name: "data[alerts][admin.sign_up]", value: String(alert).lowercased()))
+        }
+
+        if let alert = data?.alerts?.adminReport {
+            queryParameters.append(.init(name: "data[alerts][admin.report]", value: String(alert).lowercased()))
+        }
+
         if let policy = data?.policy {
             queryParameters.append(.init(name: "data[policy]", value: policy.rawValue))
         }


Test patch:
diff --git a/Tests/TootSDKTests/TootNotificationParamsTests.swift b/Tests/TootSDKTests/TootNotificationParamsTests.swift
index bdc2c90..ee9ad9e 100644
--- a/Tests/TootSDKTests/TootNotificationParamsTests.swift
+++ b/Tests/TootSDKTests/TootNotificationParamsTests.swift
@@ -110,11 +110,14 @@ final class TootNotificationParamsTests: XCTestCase {
         XCTAssertEqual(
             query,
             [
+                URLQueryItem(name: "exclude_types[]", value: "admin.report"),
+                URLQueryItem(name: "exclude_types[]", value: "admin.sign_up"),
                 URLQueryItem(name: "exclude_types[]", value: "follow"),
                 URLQueryItem(name: "exclude_types[]", value: "follow_request"),
                 URLQueryItem(name: "exclude_types[]", value: "mention"),
                 URLQueryItem(name: "exclude_types[]", value: "poll"),
                 URLQueryItem(name: "exclude_types[]", value: "reblog"),
+                URLQueryItem(name: "exclude_types[]", value: "severed_relationships"),
                 URLQueryItem(name: "exclude_types[]", value: "status"),
                 URLQueryItem(name: "exclude_types[]", value: "update"),
             ], "Incorrect params for \(flavour)")