mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2025-02-02 20:16:54 +01:00
Add subscription id to Feed so that we can correctly rename Feedbin subscriptions
This commit is contained in:
parent
06626f10a7
commit
49116fd8e3
@ -126,6 +126,15 @@ public final class Feed: DisplayNameProvider, Renamable, UnreadCountProvider, Ha
|
||||
}
|
||||
}
|
||||
|
||||
public var subscriptionID: String? {
|
||||
get {
|
||||
return metadata.subscriptionID
|
||||
}
|
||||
set {
|
||||
metadata.subscriptionID = newValue
|
||||
}
|
||||
}
|
||||
|
||||
// Folder Name: Sync Service Relationship ID
|
||||
public var folderRelationship: [String: String]? {
|
||||
get {
|
||||
|
@ -26,6 +26,7 @@ final class FeedMetadata: Codable {
|
||||
case authors
|
||||
case contentHash
|
||||
case conditionalGetInfo
|
||||
case subscriptionID
|
||||
case folderRelationship
|
||||
}
|
||||
|
||||
@ -101,6 +102,14 @@ final class FeedMetadata: Codable {
|
||||
}
|
||||
}
|
||||
|
||||
var subscriptionID: String? {
|
||||
didSet {
|
||||
if subscriptionID != oldValue {
|
||||
valueDidChange(.subscriptionID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Folder Name: Sync Service Relationship ID
|
||||
var folderRelationship: [String: String]? {
|
||||
didSet {
|
||||
|
@ -188,11 +188,11 @@ final class FeedbinAPICaller: NSObject {
|
||||
|
||||
}
|
||||
|
||||
func renameFeed(feedID: String, newName: String, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
let callURL = feedbinBaseURL.appendingPathComponent("subscriptions/\(feedID).json")
|
||||
func renameFeed(subscriptionID: String, newName: String, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
let callURL = feedbinBaseURL.appendingPathComponent("subscriptions/\(subscriptionID)/update.json")
|
||||
let request = URLRequest(url: callURL, credentials: credentials)
|
||||
let payload = FeedbinUpdateSubscription(title: newName)
|
||||
transport.send(request: request, method: HTTPMethod.patch, payload: payload, completion: completion)
|
||||
transport.send(request: request, method: HTTPMethod.post, payload: payload, completion: completion)
|
||||
}
|
||||
|
||||
func retrieveTaggings(completionHandler completion: @escaping (Result<[FeedbinTagging]?, Error>) -> Void) {
|
||||
|
@ -16,6 +16,10 @@ import RSCore
|
||||
import RSWeb
|
||||
import os.log
|
||||
|
||||
public enum FeedbinAccountDelegateError: String, Error {
|
||||
case invalidParameter = "There was an invalid parameter passed."
|
||||
}
|
||||
|
||||
final class FeedbinAccountDelegate: AccountDelegate {
|
||||
|
||||
private let caller: FeedbinAPICaller
|
||||
@ -119,6 +123,7 @@ final class FeedbinAccountDelegate: AccountDelegate {
|
||||
case .created(let sub):
|
||||
DispatchQueue.main.async {
|
||||
let feed = account.createFeed(with: sub.name, url: sub.url, feedID: String(sub.feedID), homePageURL: sub.homePageURL)
|
||||
feed.subscriptionID = String(sub.subscriptionID)
|
||||
completion(.success(.created(feed)))
|
||||
}
|
||||
case .multipleChoice(let subs):
|
||||
@ -147,7 +152,13 @@ final class FeedbinAccountDelegate: AccountDelegate {
|
||||
|
||||
func renameFeed(for account: Account, with feed: Feed, to name: String, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
|
||||
caller.renameFeed(feedID: feed.feedID, newName: name) { result in
|
||||
// This error should never happen
|
||||
guard let subscriptionID = feed.subscriptionID else {
|
||||
completion(.failure(FeedbinAccountDelegateError.invalidParameter))
|
||||
return
|
||||
}
|
||||
|
||||
caller.renameFeed(subscriptionID: subscriptionID, newName: name) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
DispatchQueue.main.async {
|
||||
@ -336,6 +347,7 @@ private extension FeedbinAccountDelegate {
|
||||
feed.homePageURL = subscription.homePageURL
|
||||
} else {
|
||||
let feed = account.createFeed(with: subscription.name, url: subscription.url, feedID: subFeedId, homePageURL: subscription.homePageURL)
|
||||
feed.subscriptionID = String(subscription.subscriptionID)
|
||||
account.addFeed(feed, to: nil)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user