Make FeedlyEntry Hashable, and make some other structs Equatable, so we can put FeedlyEntrys in sets.

This commit is contained in:
Brent Simmons 2024-04-27 11:17:19 -07:00
parent 5bc255410c
commit 4f04578bd7
5 changed files with 37 additions and 7 deletions

View File

@ -8,8 +8,12 @@
import Foundation import Foundation
public struct FeedlyCategory: Decodable, Sendable { public struct FeedlyCategory: Decodable, Sendable, Equatable {
public let label: String public let label: String
public let id: String public let id: String
public static func ==(lhs: FeedlyCategory, rhs: FeedlyCategory) -> Bool {
lhs.label == rhs.label && lhs.id == rhs.id
}
} }

View File

@ -8,7 +8,7 @@
import Foundation import Foundation
public struct FeedlyEntry: Decodable, Sendable { public struct FeedlyEntry: Decodable, Sendable, Hashable {
/// the unique, immutable ID for this particular article. /// the unique, immutable ID for this particular article.
public let id: String public let id: String
@ -16,7 +16,7 @@ public struct FeedlyEntry: Decodable, Sendable {
/// the articles title. This string does not contain any HTML markup. /// the articles title. This string does not contain any HTML markup.
public let title: String? public let title: String?
public struct Content: Decodable, Sendable { public struct Content: Decodable, Sendable, Equatable {
public enum Direction: String, Decodable, Sendable { public enum Direction: String, Decodable, Sendable {
case leftToRight = "ltr" case leftToRight = "ltr"
@ -25,6 +25,10 @@ public struct FeedlyEntry: Decodable, Sendable {
public let content: String? public let content: String?
public let direction: Direction? public let direction: Direction?
public static func ==(lhs: Content, rhs: Content) -> Bool {
lhs.content == rhs.content && lhs.direction == rhs.direction
}
} }
/// This object typically has two values: content for the content itself, and direction (ltr for left-to-right, rtl for right-to-left). The content itself contains sanitized HTML markup. /// This object typically has two values: content for the content itself, and direction (ltr for left-to-right, rtl for right-to-left). The content itself contains sanitized HTML markup.
@ -63,4 +67,13 @@ public struct FeedlyEntry: Decodable, Sendable {
/// A list of media links (videos, images, sound etc) provided by the feed. Some entries do not have a summary or content, only a collection of media links. /// A list of media links (videos, images, sound etc) provided by the feed. Some entries do not have a summary or content, only a collection of media links.
public let enclosure: [FeedlyLink]? public let enclosure: [FeedlyLink]?
public func hash(into hasher: inout Hasher) {
hasher.combine(id)
}
public static func ==(lhs: FeedlyEntry, rhs: FeedlyEntry) -> Bool {
lhs.id == rhs.id && lhs.title == rhs.title && lhs.content == rhs.content && lhs.summary == rhs.summary && lhs.author == rhs.author && lhs.crawled == rhs.crawled && lhs.recrawled == rhs.recrawled && lhs.origin == rhs.origin && lhs.canonical == rhs.canonical && lhs.alternate == rhs.alternate && lhs.unread == rhs.unread && lhs.tags == rhs.tags && lhs.categories == rhs.categories && lhs.enclosure == rhs.enclosure
}
} }

View File

@ -8,7 +8,7 @@
import Foundation import Foundation
public struct FeedlyLink: Decodable, Sendable { public struct FeedlyLink: Decodable, Sendable, Equatable {
public let href: String public let href: String
@ -16,4 +16,8 @@ public struct FeedlyLink: Decodable, Sendable {
/// When `nil`, it's probably a web page? /// When `nil`, it's probably a web page?
/// https://groups.google.com/forum/#!searchin/feedly-cloud/feed$20url%7Csort:date/feedly-cloud/Rx3dVd4aTFQ/Hf1ZfLJoCQAJ /// https://groups.google.com/forum/#!searchin/feedly-cloud/feed$20url%7Csort:date/feedly-cloud/Rx3dVd4aTFQ/Hf1ZfLJoCQAJ
public let type: String? public let type: String?
public static func ==(lhs: FeedlyLink, rhs: FeedlyLink) -> Bool {
lhs.href == rhs.href && lhs.type == rhs.type
}
} }

View File

@ -8,9 +8,14 @@
import Foundation import Foundation
public struct FeedlyOrigin: Decodable, Sendable { public struct FeedlyOrigin: Decodable, Sendable, Equatable {
public let title: String? public let title: String?
public let streamID: String? public let streamID: String?
public let htmlUrl: String? public let htmlURL: String?
public static func ==(lhs: FeedlyOrigin, rhs: FeedlyOrigin) -> Bool {
lhs.title == rhs.title && lhs.streamID == rhs.streamID && lhs.htmlURL == rhs.htmlURL
}
} }

View File

@ -8,8 +8,12 @@
import Foundation import Foundation
public struct FeedlyTag: Decodable, Sendable { public struct FeedlyTag: Decodable, Sendable, Equatable {
public let id: String public let id: String
public let label: String? public let label: String?
public static func ==(lhs: FeedlyTag, rhs: FeedlyTag) -> Bool {
lhs.id == rhs.id && lhs.label == rhs.label
}
} }