Change Feed Providers so that they supply a homePageURL now
This commit is contained in:
parent
9cf338f2d9
commit
8c61a7a602
|
@ -582,24 +582,24 @@ private extension CloudKitAccountDelegate {
|
|||
func createProviderWebFeed(for account: Account, urlComponents: URLComponents, editedName: String?, container: Container, feedProvider: FeedProvider, completion: @escaping (Result<WebFeed, Error>) -> Void) {
|
||||
refreshProgress.addToNumberOfTasksAndRemaining(6)
|
||||
|
||||
feedProvider.assignName(urlComponents) { result in
|
||||
feedProvider.metaData(urlComponents) { result in
|
||||
self.refreshProgress.completeTask()
|
||||
switch result {
|
||||
|
||||
case .success(let name):
|
||||
case .success(let metaData):
|
||||
|
||||
guard let urlString = urlComponents.url?.absoluteString else {
|
||||
completion(.failure(AccountError.createErrorNotFound))
|
||||
return
|
||||
}
|
||||
|
||||
self.accountZone.createWebFeed(url: urlString, name: name, editedName: editedName, container: container) { result in
|
||||
self.accountZone.createWebFeed(url: urlString, name: metaData.name, editedName: editedName, container: container) { result in
|
||||
|
||||
self.refreshProgress.completeTask()
|
||||
switch result {
|
||||
case .success(let externalID):
|
||||
|
||||
let feed = account.createWebFeed(with: name, url: urlString, webFeedID: urlString, homePageURL: nil)
|
||||
let feed = account.createWebFeed(with: metaData.name, url: urlString, webFeedID: urlString, homePageURL: metaData.homePageURL)
|
||||
feed.editedName = editedName
|
||||
feed.externalID = externalID
|
||||
container.addWebFeed(feed)
|
||||
|
|
|
@ -16,6 +16,11 @@ public enum FeedProviderAbility {
|
|||
case none
|
||||
}
|
||||
|
||||
public struct FeedProviderFeedMetaData {
|
||||
let name: String
|
||||
let homePageURL: String?
|
||||
}
|
||||
|
||||
public protocol FeedProvider {
|
||||
|
||||
/// Informs the caller of the ability for this feed provider to service the given URL
|
||||
|
@ -25,7 +30,7 @@ public protocol FeedProvider {
|
|||
func iconURL(_ urlComponents: URLComponents, completion: @escaping (Result<String, Error>) -> Void)
|
||||
|
||||
/// Construct a Name for the new feed
|
||||
func assignName(_ urlComponents: URLComponents, completion: @escaping (Result<String, Error>) -> Void)
|
||||
func metaData(_ urlComponents: URLComponents, completion: @escaping (Result<FeedProviderFeedMetaData, Error>) -> Void)
|
||||
|
||||
/// Refresh all the article entries (ParsedItems)
|
||||
func refresh(_ webFeed: WebFeed, completion: @escaping (Result<Set<ParsedItem>, Error>) -> Void)
|
||||
|
|
|
@ -109,21 +109,26 @@ public final class RedditFeedProvider: FeedProvider {
|
|||
}
|
||||
}
|
||||
|
||||
public func assignName(_ urlComponents: URLComponents, completion: @escaping (Result<String, Error>) -> Void) {
|
||||
public func metaData(_ urlComponents: URLComponents, completion: @escaping (Result<FeedProviderFeedMetaData, Error>) -> Void) {
|
||||
let path = urlComponents.path
|
||||
|
||||
if path == "" || path == "/" {
|
||||
let name = NSLocalizedString("Reddit Timeline", comment: "Reddit Timeline")
|
||||
completion(.success(name))
|
||||
let metaData = FeedProviderFeedMetaData(name: name, homePageURL: "https://www.reddit.com")
|
||||
completion(.success(metaData))
|
||||
return
|
||||
}
|
||||
|
||||
var name = String(path.suffix(from: path.index(after: path.startIndex)))
|
||||
if name.last == "/" {
|
||||
_ = name.popLast()
|
||||
let splitPath = path.split(separator: "/")
|
||||
guard splitPath.count > 1 else {
|
||||
completion(.failure(RedditFeedProviderError.unknown))
|
||||
return
|
||||
}
|
||||
|
||||
let name = "\(splitPath[0])/\(splitPath[1])"
|
||||
let homePageURL = "https://www.reddit.com/\(name)"
|
||||
|
||||
completion(.success(name))
|
||||
completion(.success(FeedProviderFeedMetaData(name: name, homePageURL: homePageURL)))
|
||||
}
|
||||
|
||||
public func refresh(_ webFeed: WebFeed, completion: @escaping (Result<Set<ParsedItem>, Error>) -> Void) {
|
||||
|
|
|
@ -35,6 +35,7 @@ public enum TwitterFeedType: Int {
|
|||
|
||||
public struct TwitterFeedProvider: FeedProvider {
|
||||
|
||||
private static let homeURL = "https://www.twitter.com"
|
||||
private static let server = "api.twitter.com"
|
||||
private static let apiBase = "https://api.twitter.com/1.1/"
|
||||
private static let userAgentHeaders = UserAgent.headers() as! [String: String]
|
||||
|
@ -125,36 +126,38 @@ public struct TwitterFeedProvider: FeedProvider {
|
|||
}
|
||||
}
|
||||
|
||||
public func assignName(_ urlComponents: URLComponents, completion: @escaping (Result<String, Error>) -> Void) {
|
||||
public func metaData(_ urlComponents: URLComponents, completion: @escaping (Result<FeedProviderFeedMetaData, Error>) -> Void) {
|
||||
switch urlComponents.path {
|
||||
|
||||
case "", "/", "/home":
|
||||
let name = NSLocalizedString("Twitter Timeline", comment: "Twitter Timeline")
|
||||
completion(.success(name))
|
||||
completion(.success(FeedProviderFeedMetaData(name: name, homePageURL: Self.homeURL)))
|
||||
|
||||
case "/notifications/mentions":
|
||||
let name = NSLocalizedString("Twitter Mentions", comment: "Twitter Mentions")
|
||||
completion(.success(name))
|
||||
|
||||
completion(.success(FeedProviderFeedMetaData(name: name, homePageURL: Self.homeURL)))
|
||||
|
||||
case "/search":
|
||||
if let query = urlComponents.queryItems?.first(where: { $0.name == "q" })?.value {
|
||||
let localized = NSLocalizedString("Twitter Search: %@", comment: "Twitter Search")
|
||||
let searchName = NSString.localizedStringWithFormat(localized as NSString, query) as String
|
||||
completion(.success(searchName))
|
||||
let name = NSString.localizedStringWithFormat(localized as NSString, query) as String
|
||||
completion(.success(FeedProviderFeedMetaData(name: name, homePageURL: Self.homeURL)))
|
||||
} else {
|
||||
let name = NSLocalizedString("Twitter Search", comment: "Twitter Search")
|
||||
completion(.success(name))
|
||||
completion(.success(FeedProviderFeedMetaData(name: name, homePageURL: Self.homeURL)))
|
||||
}
|
||||
|
||||
default:
|
||||
if let hashtag = deriveHashtag(urlComponents) {
|
||||
completion(.success("#\(hashtag)"))
|
||||
completion(.success(FeedProviderFeedMetaData(name: "#\(hashtag)", homePageURL: Self.homeURL)))
|
||||
} else if let screenName = deriveScreenName(urlComponents) {
|
||||
retrieveUser(screenName: screenName) { result in
|
||||
switch result {
|
||||
case .success(let user):
|
||||
if let userName = user.name {
|
||||
completion(.success(userName))
|
||||
var urlComponents = URLComponents(string: Self.homeURL)
|
||||
urlComponents?.path = "/\(screenName)"
|
||||
completion(.success(FeedProviderFeedMetaData(name: userName, homePageURL: urlComponents?.url?.absoluteString)))
|
||||
} else {
|
||||
completion(.failure(TwitterFeedProviderError.screenNameNotFound))
|
||||
}
|
||||
|
|
|
@ -250,18 +250,18 @@ private extension LocalAccountDelegate {
|
|||
func createProviderWebFeed(for account: Account, urlComponents: URLComponents, editedName: String?, container: Container, feedProvider: FeedProvider, completion: @escaping (Result<WebFeed, Error>) -> Void) {
|
||||
refreshProgress.addToNumberOfTasksAndRemaining(2)
|
||||
|
||||
feedProvider.assignName(urlComponents) { result in
|
||||
feedProvider.metaData(urlComponents) { result in
|
||||
self.refreshProgress.completeTask()
|
||||
switch result {
|
||||
|
||||
case .success(let name):
|
||||
case .success(let metaData):
|
||||
|
||||
guard let urlString = urlComponents.url?.absoluteString else {
|
||||
completion(.failure(AccountError.createErrorNotFound))
|
||||
return
|
||||
}
|
||||
|
||||
let feed = account.createWebFeed(with: name, url: urlString, webFeedID: urlString, homePageURL: nil)
|
||||
let feed = account.createWebFeed(with: metaData.name, url: urlString, webFeedID: urlString, homePageURL: metaData.homePageURL)
|
||||
feed.editedName = editedName
|
||||
container.addWebFeed(feed)
|
||||
|
||||
|
|
Loading…
Reference in New Issue