mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-12-02 18:32:55 +00:00
Use new OPML parser.
This commit is contained in:
1 parent
76e1c07b2f
commit
9b570cc5ed
6 files changed
+16
-16
No files matched your search
@@ -533,13 +533,13 @@ public enum FetchType {
|
||||
settings.deleteSettings()
|
||||
}
|
||||
|
||||
func addOPMLItems(_ items: [RSOPMLItem]) {
|
||||
func addOPMLItems(_ items: [OPMLItem]) {
|
||||
for item in items {
|
||||
if let feedSpecifier = item.feedSpecifier {
|
||||
addFeedToTreeAtTopLevel(newFeed(with: feedSpecifier))
|
||||
} else {
|
||||
if let title = item.titleFromAttributes, let folder = ensureFolder(with: title) {
|
||||
folder.externalID = item.attributes?["nnw_externalID"] as? String
|
||||
folder.externalID = item.attributes?["nnw_externalID"]
|
||||
if let itemChildren = item.children {
|
||||
for itemChild in itemChildren {
|
||||
if let feedSpecifier = itemChild.feedSpecifier {
|
||||
@@ -552,7 +552,7 @@ public enum FetchType {
|
||||
}
|
||||
}
|
||||
|
||||
func loadOPMLItems(_ items: [RSOPMLItem]) {
|
||||
func loadOPMLItems(_ items: [OPMLItem]) {
|
||||
addOPMLItems(OPMLNormalizer.normalize(items))
|
||||
}
|
||||
|
||||
@@ -627,7 +627,7 @@ public enum FetchType {
|
||||
return folders?.first(where: { $0.externalID == externalID })
|
||||
}
|
||||
|
||||
func newFeed(with opmlFeedSpecifier: RSOPMLFeedSpecifier) -> Feed {
|
||||
func newFeed(with opmlFeedSpecifier: OPMLFeedSpecifier) -> Feed {
|
||||
let feedURL = opmlFeedSpecifier.feedURL
|
||||
let settings = feedSettings(feedURL: feedURL, feedID: feedURL)
|
||||
let feed = Feed(account: self, url: opmlFeedSpecifier.feedURL, settings: settings)
|
||||
|
||||
@@ -167,7 +167,7 @@ enum CloudKitAccountDelegateError: LocalizedError, Sendable {
|
||||
Self.logger.debug("CloudKitAccountDelegate: \(#function, privacy: .public)")
|
||||
let opmlData = try Data(contentsOf: opmlFile)
|
||||
let parserData = ParserData(url: opmlFile.absoluteString, data: opmlData)
|
||||
let opmlDocument = try RSOPMLParser.parseOPML(with: parserData)
|
||||
let opmlDocument = try OPMLParser.parseOPML(with: parserData)
|
||||
|
||||
// TODO: throw appropriate error if OPML file is empty.
|
||||
guard let opmlItems = opmlDocument.children, let rootExternalID = account.externalID else {
|
||||
|
||||
@@ -53,11 +53,11 @@ enum CloudKitAccountZoneError: LocalizedError {
|
||||
self.zoneID = CKRecordZone.ID(zoneName: "Account", ownerName: CKCurrentUserDefaultName)
|
||||
}
|
||||
|
||||
func importOPML(rootExternalID: String, items: [RSOPMLItem]) async throws {
|
||||
func importOPML(rootExternalID: String, items: [OPMLItem]) async throws {
|
||||
var records = [CKRecord]()
|
||||
var feedRecords = [String: CKRecord]()
|
||||
|
||||
func processFeed(feedSpecifier: RSOPMLFeedSpecifier, containerExternalID: String) {
|
||||
func processFeed(feedSpecifier: OPMLFeedSpecifier, containerExternalID: String) {
|
||||
if let feedRecord = feedRecords[feedSpecifier.feedURL], var containerExternalIDs = feedRecord[CloudKitFeed.Fields.containerExternalIDs] as? [String] {
|
||||
containerExternalIDs.append(containerExternalID)
|
||||
feedRecord[CloudKitFeed.Fields.containerExternalIDs] = containerExternalIDs
|
||||
@@ -286,7 +286,7 @@ enum CloudKitAccountZoneError: LocalizedError {
|
||||
}
|
||||
|
||||
private extension CloudKitAccountZone {
|
||||
func newFeedCKRecord(feedSpecifier: RSOPMLFeedSpecifier, containerExternalID: String) -> CKRecord {
|
||||
func newFeedCKRecord(feedSpecifier: OPMLFeedSpecifier, containerExternalID: String) -> CKRecord {
|
||||
let record = CKRecord(recordType: CloudKitFeed.recordType, recordID: generateRecordID())
|
||||
record[CloudKitFeed.Fields.url] = feedSpecifier.feedURL
|
||||
if let editedName = feedSpecifier.title {
|
||||
|
||||
@@ -65,7 +65,7 @@ import Secrets
|
||||
@MainActor func importOPML(for account: Account, opmlFile: URL) async throws {
|
||||
let opmlData = try Data(contentsOf: opmlFile)
|
||||
let parserData = ParserData(url: opmlFile.absoluteString, data: opmlData)
|
||||
let opmlDocument = try RSOPMLParser.parseOPML(with: parserData)
|
||||
let opmlDocument = try OPMLParser.parseOPML(with: parserData)
|
||||
|
||||
// TODO: throw appropriate error for empty OPML
|
||||
guard let children = opmlDocument.children else {
|
||||
|
||||
@@ -87,12 +87,12 @@ private extension OPMLFile {
|
||||
return fileData
|
||||
}
|
||||
|
||||
func parsedOPMLItems(fileData: Data) -> [RSOPMLItem]? {
|
||||
func parsedOPMLItems(fileData: Data) -> [OPMLItem]? {
|
||||
let parserData = ParserData(url: fileURL.absoluteString, data: fileData)
|
||||
var opmlDocument: RSOPMLDocument?
|
||||
var opmlDocument: OPMLDocument?
|
||||
|
||||
do {
|
||||
opmlDocument = try RSOPMLParser.parseOPML(with: parserData)
|
||||
opmlDocument = try OPMLParser.parseOPML(with: parserData)
|
||||
} catch {
|
||||
Self.logger.error("OPML import failed: \(error.localizedDescription)")
|
||||
return nil
|
||||
|
||||
@@ -11,16 +11,16 @@ import RSParser
|
||||
|
||||
final class OPMLNormalizer {
|
||||
|
||||
var normalizedOPMLItems = [RSOPMLItem]()
|
||||
var normalizedOPMLItems = [OPMLItem]()
|
||||
|
||||
static func normalize(_ items: [RSOPMLItem]) -> [RSOPMLItem] {
|
||||
static func normalize(_ items: [OPMLItem]) -> [OPMLItem] {
|
||||
let opmlNormalizer = OPMLNormalizer()
|
||||
opmlNormalizer.normalize(items)
|
||||
return opmlNormalizer.normalizedOPMLItems
|
||||
}
|
||||
|
||||
private func normalize(_ items: [RSOPMLItem], parentFolder: RSOPMLItem? = nil) {
|
||||
var feedsToAdd = [RSOPMLItem]()
|
||||
private func normalize(_ items: [OPMLItem], parentFolder: OPMLItem? = nil) {
|
||||
var feedsToAdd = [OPMLItem]()
|
||||
|
||||
for item in items {
|
||||
|
||||
|
||||
Reference in new issue
Block a user