diff --git a/Frameworks/Account/FeedProvider/Reddit/RedditFeedProvider.swift b/Frameworks/Account/FeedProvider/Reddit/RedditFeedProvider.swift
index 3cab2a4f9..9886f95bb 100644
--- a/Frameworks/Account/FeedProvider/Reddit/RedditFeedProvider.swift
+++ b/Frameworks/Account/FeedProvider/Reddit/RedditFeedProvider.swift
@@ -27,6 +27,13 @@ public enum RedditFeedProviderError: LocalizedError {
}
}
+public enum RedditFeedType: Int {
+ case home = 0
+ case popular = 1
+ case all = 2
+ case subreddit = 3
+}
+
public final class RedditFeedProvider: FeedProvider {
var log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "RedditFeedProvider")
@@ -163,7 +170,12 @@ public final class RedditFeedProvider: FeedProvider {
return
}
- let api = "\(urlComponents.path).json"
+ let api: String
+ if urlComponents.path.isEmpty {
+ api = "/.json"
+ } else {
+ api = "\(urlComponents.path).json"
+ }
let splitPath = urlComponents.path.split(separator: "/")
let identifySubreddit: Bool
@@ -215,6 +227,39 @@ public final class RedditFeedProvider: FeedProvider {
}
}
+ public static func buildURL(_ type: RedditFeedType, username: String?, subreddit: String?) -> URL? {
+ var components = URLComponents()
+ components.scheme = "https"
+ components.host = "www.reddit.com"
+
+ switch type {
+ case .home:
+ guard let username = username else {
+ return nil
+ }
+ components.user = username
+ case .popular:
+ guard let username = username else {
+ return nil
+ }
+ components.user = username
+ components.path = "/r/popular"
+ case .all:
+ guard let username = username else {
+ return nil
+ }
+ components.user = username
+ components.path = "/r/all"
+ case .subreddit:
+ guard let subreddit = subreddit else {
+ return nil
+ }
+ components.path = "/r/\(subreddit)"
+ }
+
+ return components.url
+ }
+
}
// MARK: OAuth1SwiftProvider
diff --git a/Mac/AppDelegate.swift b/Mac/AppDelegate.swift
index 9b6b86094..94aa2d8ee 100644
--- a/Mac/AppDelegate.swift
+++ b/Mac/AppDelegate.swift
@@ -403,6 +403,12 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
if item.action == #selector(showAddWebFeedWindow(_:)) || item.action == #selector(showAddFolderWindow(_:)) {
return !isDisplayingSheet && !AccountManager.shared.activeAccounts.isEmpty
}
+ if item.action == #selector(showAddRedditFeedWindow(_:)) {
+ guard !isDisplayingSheet && !AccountManager.shared.activeAccounts.isEmpty else {
+ return false
+ }
+ return ExtensionPointManager.shared.isRedditEnabled
+ }
if item.action == #selector(showAddTwitterFeedWindow(_:)) {
guard !isDisplayingSheet && !AccountManager.shared.activeAccounts.isEmpty else {
return false
@@ -471,6 +477,12 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
addWebFeed(nil)
}
+ @IBAction func showAddRedditFeedWindow(_ sender: Any?) {
+ createAndShowMainWindowIfNecessary()
+ addFeedController = AddFeedController(hostWindow: mainWindowController!.window!)
+ addFeedController?.showAddFeedSheet(.redditFeed)
+ }
+
@IBAction func showAddTwitterFeedWindow(_ sender: Any?) {
createAndShowMainWindowIfNecessary()
addFeedController = AddFeedController(hostWindow: mainWindowController!.window!)
diff --git a/Mac/Base.lproj/AddRedditFeedSheet.xib b/Mac/Base.lproj/AddRedditFeedSheet.xib
new file mode 100644
index 000000000..cdffd1ec3
--- /dev/null
+++ b/Mac/Base.lproj/AddRedditFeedSheet.xib
@@ -0,0 +1,199 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Mac/Base.lproj/AddTwitterFeedSheet.xib b/Mac/Base.lproj/AddTwitterFeedSheet.xib
index 9e04ecb71..b23bb43bf 100644
--- a/Mac/Base.lproj/AddTwitterFeedSheet.xib
+++ b/Mac/Base.lproj/AddTwitterFeedSheet.xib
@@ -91,12 +91,12 @@ DQ
-
+
@@ -115,7 +115,7 @@ DQ
-
+
diff --git a/Mac/Base.lproj/Main.storyboard b/Mac/Base.lproj/Main.storyboard
index 5b2a00ebe..e646f425e 100644
--- a/Mac/Base.lproj/Main.storyboard
+++ b/Mac/Base.lproj/Main.storyboard
@@ -73,6 +73,12 @@
+