Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public enum ReaderSortingOption: String, CaseIterable {

public enum ReaderStream: String {
case discover = "discover"
case freshlyPressed = "freshly-pressed"
case firstPosts = "first-posts"
}

Expand Down
4 changes: 4 additions & 0 deletions Modules/Sources/WordPressKitObjC/ReaderPostServiceRemote.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ - (void)fetchPostsFromEndpoint:(NSURL *)endpoint
if (algorithm) {
params[ParamsKeyAlgorithm] = algorithm;
}
// TODO: refactor (add a new parameter
if ([endpoint.path hasSuffix:@"/freshly-pressed"]) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it use the offset-based paging?

[params removeAllObjects];
}

[self fetchPostsFromEndpoint:endpoint withParameters:params success:success failure:failure];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import WordPressShared

class ReaderDiscoverViewController: UIViewController, ReaderDiscoverHeaderViewDelegate {
private let headerView = ReaderDiscoverHeaderView()
private var selectedChannel: ReaderDiscoverChannel = .recommended
private var selectedChannel: ReaderDiscoverChannel = .freshlyPresed
private let topic: ReaderAbstractTopic
private var streamVC: ReaderStreamViewController?
private weak var selectInterestsVC: ReaderSelectInterestsViewController?
Expand Down Expand Up @@ -83,7 +83,7 @@ class ReaderDiscoverViewController: UIViewController, ReaderDiscoverHeaderViewDe
.filter { $0.slug != ReaderTagTopic.dailyPromptTag }
.map(ReaderDiscoverChannel.tag)

headerView.configure(channels: [.recommended, .firstPosts, .latest, .dailyPrompts] + channels)
headerView.configure(channels: [.freshlyPresed, .recommended, .firstPosts, .latest, .dailyPrompts] + channels)
headerView.setSelectedChannel(selectedChannel)
}

Expand All @@ -95,6 +95,8 @@ class ReaderDiscoverViewController: UIViewController, ReaderDiscoverHeaderViewDe

private func makeViewController(for channel: ReaderDiscoverChannel) -> ReaderStreamViewController {
switch channel {
case .freshlyPresed:
ReaderStreamViewController.controllerWithTopic(ReaderHelpers.getFreshlyPressedTopic())
case .recommended:
ReaderDiscoverStreamViewController(topic: topic)
case .firstPosts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ struct ReaderNotificationKeys {
return topic.path.hasSuffix("/freshly-pressed")
}

public static func getFreshlyPressedTopic(in context: NSManagedObjectContext = ContextManager.shared.mainContext) -> ReaderSiteTopic {
let path = "/rest/v1.2/freshly-pressed"
if let topic = try? ReaderSiteTopic.lookup(withFeedURL: path, in: context) {
return topic
}
let topic = context.insertNewObject(ofType: ReaderSiteTopic.self)
topic.feedURL = path
topic.path = path
try? context.save()
return topic
}

/// Check if the specified topic is for Discover
///
/// - Parameters:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ private final class ReaderDiscoverChannelView: UIView {
}

enum ReaderDiscoverChannel: Hashable {
/// Curated posts.
case freshlyPresed

/// The default channel showing your selected tags.
case recommended

Expand All @@ -207,6 +210,8 @@ enum ReaderDiscoverChannel: Hashable {

var localizedTitle: String {
switch self {
case .freshlyPresed:
NSLocalizedString("reader.discover.channel.freshlyPresed", value: "Freshly Pressed", comment: "Header view channel (filter)")
case .recommended:
NSLocalizedString("reader.discover.channel.recommended", value: "Recommended", comment: "Header view channel (filter)")
case .firstPosts:
Expand All @@ -230,6 +235,7 @@ enum ReaderDiscoverChannel: Hashable {

private var analyticsID: String {
switch self {
case .freshlyPresed: "freshly_presed"
case .recommended: "recommended"
case .firstPosts: "first_posts"
case .latest: "latest"
Expand Down