mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2025-01-31 19:24:55 +01:00
Make progress on adding feeds.
This commit is contained in:
parent
a910841c65
commit
04612049f5
@ -163,9 +163,9 @@ private extension AddFeedController {
|
||||
return
|
||||
}
|
||||
|
||||
if let feed = folder.createFeedWithName(titleFromFeed, editedName: userEnteredTitle, urlString: feedURLString) {
|
||||
if let feed = account.createFeed(with: titleFromFeed, editedName: userEnteredTitle, url: feedURLString) {
|
||||
print(feedURLString)
|
||||
if folder.addItem(feed) {
|
||||
if account.addFeed(feed, to: folder) {
|
||||
NotificationCenter.default.post(name: UserDidAddFeedNotification, object: self, userInfo: [UserDidAddFeedKey: feed])
|
||||
}
|
||||
}
|
||||
|
@ -103,22 +103,36 @@ public final class Account: DisplayNameProvider, Hashable {
|
||||
// Return false if it couldn’t be added.
|
||||
// If it already existed in that folder, return true.
|
||||
|
||||
return true // TODO
|
||||
var didAddFeed = false
|
||||
let uniquedFeed = existingFeed(with: feed.feedID) ?? feed
|
||||
|
||||
if let folder = folder {
|
||||
didAddFeed = folder.addFeed(uniquedFeed)
|
||||
}
|
||||
else {
|
||||
if !topLevelObjectsContainsFeed(uniquedFeed) {
|
||||
topLevelObjects += [uniquedFeed]
|
||||
}
|
||||
didAddFeed = true
|
||||
}
|
||||
|
||||
updateFeedIDDictionary()
|
||||
return didAddFeed // TODO
|
||||
}
|
||||
|
||||
public func createFeed(with name: String, userEnteredName: String, url: String) -> Feed {
|
||||
public func createFeed(with name: String, editedName: String, url: String) -> Feed {
|
||||
|
||||
// For syncing, this may need to be an async method with a callback,
|
||||
// since it will likely need to call the server.
|
||||
|
||||
if let feed = existingFeed(withURL: url) {
|
||||
feed.editedName = userEnteredName
|
||||
feed.editedName = editedName
|
||||
return feed
|
||||
}
|
||||
|
||||
let feed = Feed(accountID: accountID, url: url, feedID: url)
|
||||
feed.name = name
|
||||
feed.editedName = userEnteredName
|
||||
feed.editedName = editedName
|
||||
return feed
|
||||
}
|
||||
|
||||
@ -181,7 +195,7 @@ extension Account {
|
||||
}
|
||||
}
|
||||
|
||||
// Mark: - FeedIDDictionary
|
||||
// MARK: - Private
|
||||
|
||||
private extension Account {
|
||||
|
||||
@ -193,6 +207,18 @@ private extension Account {
|
||||
}
|
||||
feedIDDictionary = d
|
||||
}
|
||||
|
||||
func topLevelObjectsContainsFeed(_ feed: Feed) -> Bool {
|
||||
|
||||
return topLevelObjects.contains(where: { (object) -> Bool in
|
||||
if let oneFeed = object as? Feed {
|
||||
if oneFeed.feedID == feed.feedID {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - OPMLRepresentable
|
||||
|
@ -95,6 +95,37 @@ public final class Folder: DisplayNameProvider, UnreadCountProvider {
|
||||
return d
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Feeds
|
||||
|
||||
func addFeed(_ feed: Feed) -> Bool {
|
||||
|
||||
// The feed has been uniqued at this point.
|
||||
// Return true in the case where the feed is already a child.
|
||||
|
||||
if childrenContainsFeed(feed) {
|
||||
return true
|
||||
}
|
||||
children += [feed]
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private extension Folder {
|
||||
|
||||
func childrenContainsFeed(_ feed: Feed) -> Bool {
|
||||
|
||||
return children.contains(where: { (object) -> Bool in
|
||||
if let oneFeed = object as? Feed {
|
||||
if oneFeed.feedID == feed.feedID {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Disk
|
||||
|
Loading…
x
Reference in New Issue
Block a user