Fix OPML importing.
This commit is contained in:
parent
8d5e568cde
commit
649f62207f
|
@ -253,7 +253,8 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
|||
return false // TODO
|
||||
}
|
||||
|
||||
public func addFolder(_ folder: Folder, to containingFolder: Folder?) -> Bool {
|
||||
@discardableResult
|
||||
public func addFolder(_ folder: Folder, to parentFolder: Folder?) -> Bool {
|
||||
|
||||
return false // TODO
|
||||
}
|
||||
|
@ -263,7 +264,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
|||
guard let children = opmlDocument.children else {
|
||||
return
|
||||
}
|
||||
importOPMLItems(children, parentFolder: nil, foldersAllowed: true)
|
||||
importOPMLItems(children, parentFolder: nil)
|
||||
dirty = true
|
||||
}
|
||||
|
||||
|
@ -472,22 +473,37 @@ private extension Account {
|
|||
})
|
||||
}
|
||||
|
||||
func importOPMLItems(_ items: [RSOPMLItem], parentFolder: Folder?, foldersAllowed: Bool) {
|
||||
func createFeed(with opmlFeedSpecifier: RSOPMLFeedSpecifier) -> Feed {
|
||||
|
||||
for item in items {
|
||||
let feed = Feed(accountID: accountID, url: opmlFeedSpecifier.feedURL, feedID: opmlFeedSpecifier.feedURL)
|
||||
feed.editedName = opmlFeedSpecifier.title
|
||||
return feed
|
||||
}
|
||||
|
||||
func importOPMLItems(_ items: [RSOPMLItem], parentFolder: Folder?) {
|
||||
|
||||
items.forEach { (item) in
|
||||
|
||||
if let feedSpecifier = item.feedSpecifier {
|
||||
if hasFeed(withURL: feedSpecifier.feedURL) {
|
||||
continue
|
||||
let feed = createFeed(with: feedSpecifier)
|
||||
addFeed(feed, to: parentFolder)
|
||||
return
|
||||
}
|
||||
|
||||
guard item.isFolder, let itemChildren = item.children else {
|
||||
return
|
||||
}
|
||||
|
||||
if item.isFolder {
|
||||
// TODO: possibly support sub folders.
|
||||
|
||||
guard let folderName = item.titleFromAttributes else {
|
||||
// Folder doesn’t have a name, so it won’t be created, and its items will go one level up.
|
||||
importOPMLItems(itemChildren, parentFolder: parentFolder)
|
||||
return
|
||||
}
|
||||
else {
|
||||
|
||||
if let folder = ensureFolder(with: folderName) {
|
||||
importOPMLItems(itemChildren, parentFolder: folder)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,9 @@ public protocol Container {
|
|||
func hasAtLeastOneFeed() -> Bool
|
||||
func objectIsChild(_ object: AnyObject) -> Bool
|
||||
|
||||
func hasChildFolder(with: String) -> Bool
|
||||
func childFolder(with: String) -> Folder?
|
||||
|
||||
//Recursive
|
||||
func flattenedFeeds() -> Set<Feed>
|
||||
func hasFeed(with feedID: String) -> Bool
|
||||
|
@ -52,6 +55,22 @@ public extension Container {
|
|||
return false
|
||||
}
|
||||
|
||||
func hasChildFolder(with name: String) -> Bool {
|
||||
|
||||
return childFolder(with: name) != nil
|
||||
}
|
||||
|
||||
func childFolder(with name: String) -> Folder? {
|
||||
|
||||
for child in children {
|
||||
if let folder = child as? Folder, folder.name == name {
|
||||
return folder
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func objectIsChild(_ object: AnyObject) -> Bool {
|
||||
|
||||
for child in children {
|
||||
|
|
|
@ -8,16 +8,17 @@
|
|||
|
||||
@import Foundation;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface RSOPMLFeedSpecifier : NSObject
|
||||
|
||||
- (instancetype)initWithTitle:(NSString * _Nullable)title feedDescription:(NSString * _Nullable)feedDescription homePageURL:(NSString * _Nullable)homePageURL feedURL:(NSString *)feedURL;
|
||||
|
||||
- (instancetype)initWithTitle:(NSString *)title feedDescription:(NSString *)feedDescription homePageURL:(NSString *)homePageURL feedURL:(NSString *)feedURL;
|
||||
|
||||
@property (nonatomic, readonly) NSString *title;
|
||||
@property (nonatomic, readonly) NSString *feedDescription;
|
||||
@property (nonatomic, readonly) NSString *homePageURL;
|
||||
@property (nonatomic, nullable, readonly) NSString *title;
|
||||
@property (nonatomic, nullable, readonly) NSString *feedDescription;
|
||||
@property (nonatomic, nullable, readonly) NSString *homePageURL;
|
||||
@property (nonatomic, readonly) NSString *feedURL;
|
||||
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
|
|
@ -10,17 +10,21 @@
|
|||
|
||||
@class RSOPMLFeedSpecifier;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface RSOPMLItem : NSObject
|
||||
|
||||
@property (nonatomic) NSDictionary *attributes;
|
||||
@property (nonatomic) NSArray <RSOPMLItem *> *children;
|
||||
@property (nonatomic, nullable) NSDictionary *attributes;
|
||||
@property (nonatomic, nullable) NSArray <RSOPMLItem *> *children;
|
||||
|
||||
- (void)addChild:(RSOPMLItem *)child;
|
||||
|
||||
@property (nonatomic, readonly) RSOPMLFeedSpecifier *feedSpecifier; //May be nil.
|
||||
@property (nonatomic, nullable, readonly) RSOPMLFeedSpecifier *feedSpecifier;
|
||||
|
||||
@property (nonatomic, readonly) NSString *titleFromAttributes; //May be nil.
|
||||
@property (nonatomic, nullable, readonly) NSString *titleFromAttributes;
|
||||
@property (nonatomic, readonly) BOOL isFolder;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
|
|
Loading…
Reference in New Issue