Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Fix #3249: Add RSS feed parser to Brave Today #3317

Merged
merged 17 commits into from
Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 18 additions & 0 deletions BraveShared/BraveStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1772,6 +1772,24 @@ extension Strings {
value: "Add",
comment: "To add a list of 1 or more rss feeds"
)
public static let rssFeedLimitExceededAlertTitle = NSLocalizedString(
"today.rssFeedLimitExceededAlertTitle",
bundle: .braveShared,
value: "Feed limit exceeded",
comment: ""
)
public static let rssFeedLimitExceededAlertMessage = NSLocalizedString(
"today.rssFeedLimitExceededAlertMessage",
bundle: .braveShared,
value: "The free ad-supported version of Brave Today includes 5 RSS feeds. You can customize your feed selections from the Sources list.",
comment: ""
)
public static let rssFeedLimitRemainingFooter = NSLocalizedString(
"today.rssFeedLimitRemainingFooter",
bundle: .braveShared,
value: "You currently have %d RSS feeds in your Sources list. The free ad-supported version of Brave Today includes 5 RSS feeds. Support for unlimited feeds and OPML import will be coming soon. You can customize your feed selections from the Sources list.",
comment: "%d will be a number (i.e. 4)"
)
public static let insecureSourcesHeader = NSLocalizedString(
"today.insecureSourcesHeader",
bundle: .braveShared,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
{
"object": {
"pins": [
{
"package": "FeedKit",
"repositoryURL": "https://github.com/nmdias/FeedKit.git",
"state": {
"branch": null,
"revision": "68493a33d862c33c9a9f67ec729b3b7df1b20ade",
"version": "9.1.2"
}
},
Comment on lines +4 to +12
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think somewhere along the line of rebase + force push it got removed, nothing changed with the version

{
"package": "Fuzi",
"repositoryURL": "https://github.com/cezheng/Fuzi",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ struct RSSFeedLocation: Hashable {
}

extension FeedDataSource {
/// The maximum number of RSS sources that can be added
static let maximumNumberOfRSSFeeds = 5
/// Whether or not OPML parsing is avaialable
static let isOPMLParsingAvailable = false

// MARK: - RSS Sources

Expand All @@ -38,6 +42,9 @@ extension FeedDataSource {
if !location.url.isWebPage(includeDataURIs: false) {
return false
}
if rssFeedLocations.count >= Self.maximumNumberOfRSSFeeds {
return false
}
let feedUrl = location.url.absoluteString
if RSSFeedSource.get(with: feedUrl) != nil {
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,22 @@ class BraveTodayAddSourceResultsViewController: UITableViewController {
}
}

private func showMaximumReachedAlert() {
let alert = UIAlertController(
title: Strings.BraveToday.rssFeedLimitExceededAlertTitle,
message: Strings.BraveToday.rssFeedLimitExceededAlertMessage,
preferredStyle: .alert
)
alert.addAction(.init(title: Strings.OKString, style: .default))
present(alert, animated: true)
}

@objc private func tappedAdd() {
let numberOfAddedFeeds = feedDataSource.rssFeedLocations.count
if numberOfAddedFeeds + selectedLocations.count > FeedDataSource.maximumNumberOfRSSFeeds {
showMaximumReachedAlert()
return
}
// Add selected sources to feed
for location in selectedLocations {
feedDataSource.addRSSFeedLocation(location)
Expand Down Expand Up @@ -124,6 +139,14 @@ class BraveTodayAddSourceResultsViewController: UITableViewController {
}
return nil
}

override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
if section == tableView.numberOfSections - 1 {
let feedCount = feedDataSource.rssFeedLocations.count
return String.localizedStringWithFormat(Strings.BraveToday.rssFeedLimitRemainingFooter, feedCount)
}
return nil
}
}

private class FeedLocationCell: UITableViewCell, TableViewReusable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,13 @@ class BraveTodayAddSourceViewController: UITableViewController {
return
}

// Check if `data` is actually an OPML list
if let opml = OPMLParser.parse(data: data), !opml.outlines.isEmpty {
let locations = opml.outlines.compactMap(self.rssLocationFromOPMLOutline)
completion(locations.isEmpty ? .failure(.noFeedsFound) : .success(locations))
return
if FeedDataSource.isOPMLParsingAvailable {
// Check if `data` is actually an OPML list
if let opml = OPMLParser.parse(data: data), !opml.outlines.isEmpty {
let locations = opml.outlines.compactMap(self.rssLocationFromOPMLOutline)
completion(locations.isEmpty ? .failure(.noFeedsFound) : .success(locations))
return
}
iccub marked this conversation as resolved.
Show resolved Hide resolved
}

// Ensure page is reloaded to final landing page before looking for
Expand Down Expand Up @@ -301,7 +303,7 @@ class BraveTodayAddSourceViewController: UITableViewController {
}

override func numberOfSections(in tableView: UITableView) -> Int {
2
FeedDataSource.isOPMLParsingAvailable ? 2 : 1
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
Expand Down