b1dcf15ff7
- NotificationsTests: 8 tests against andros feed covering kinds, emojis, parents, authorFeedURL and error handling - OrgSocialNotification.id: changed from post URL to "kind:postURL" — the relay can return the same post URL for different kinds (reply + mention simultaneously), so the ID must be composite
42 lines
1.2 KiB
Swift
42 lines
1.2 KiB
Swift
import Foundation
|
|
|
|
/// A single notification returned by the relay for a given feed.
|
|
public struct OrgSocialNotification: Sendable, Identifiable {
|
|
|
|
public enum Kind: String, Sendable {
|
|
case mention
|
|
case reaction
|
|
case reply
|
|
case boost
|
|
case unknown
|
|
}
|
|
|
|
/// Unique ID: kind + post URL combined (the relay can return the same post URL for different kinds).
|
|
public var id: String { "\(kind.rawValue):\(post)" }
|
|
|
|
/// What kind of interaction this is.
|
|
public var kind: Kind
|
|
|
|
/// URL of the post that triggered the notification (e.g. `https://shom.dev/social.org#2025-…`).
|
|
public var post: String
|
|
|
|
/// For reactions: the emoji used.
|
|
public var emoji: String?
|
|
|
|
/// The post that was reacted/replied to (nil for mentions).
|
|
public var parent: String?
|
|
|
|
/// Nick/author extracted from the triggering post URL (everything before the first `#`).
|
|
public var authorFeedURL: URL? {
|
|
let base = post.components(separatedBy: "#").first ?? post
|
|
return URL(string: base)
|
|
}
|
|
|
|
public init(kind: Kind, post: String, emoji: String? = nil, parent: String? = nil) {
|
|
self.kind = kind
|
|
self.post = post
|
|
self.emoji = emoji
|
|
self.parent = parent
|
|
}
|
|
}
|