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

Conversation

kylehickinson
Copy link
Collaborator

@kylehickinson kylehickinson commented Feb 16, 2021

Summary of Changes

This pull request fixes #3249

Submitter Checklist:

  • Unit Tests are updated to cover new or changed functionality
  • User-facing strings use NSLocalizableString()

Test Plan:

On Add Source page:

  • Test being able to search for feeds via a website (example: type in "9to5mac.com", "theverge.com", etc.)
  • Test being able to add feed directly via URL

Repeat tests with all of the above but using pages that don't exist (blahblahblahdfdsa.com), pages that don't have feeds (google.com), pages that have only 1 feed, pages that have multiple feeds.

Repeat tests above with OPML files that don't include RSS feeds (http://hosting.opml.org/dave/spec/states.opml)

On Brave Today settings

  • Verify custom sources are added there
  • Verify that they can be deleted via swipe gesture

On Brave Today

  • Verify custom sources appear in the Brave Today page
  • Verify they can be enabled/disabled via long-press like normal sources
    • After toggling, verify their enabled/disabled status is correct in the Brave Today settings

Reviewer Checklist:

  • Issues include necessary QA labels:
    • QA/(Yes|No)
    • release-notes/(include|exclude)
    • bug / enhancement
  • Necessary security reviews have taken place.
  • Adequate unit test coverage exists to prevent regressions.
  • Adequate test plan exists for QA to validate (if applicable).
  • Issue is assigned to a milestone (should happen at merge time).

Copy link
Contributor

@iccub iccub left a comment

Choose a reason for hiding this comment

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

left some nitpick comments, will run the app later and make another review round

Client/Frontend/Brave Today/Composer/FeedDataSource.swift Outdated Show resolved Hide resolved
Client/Frontend/Brave Today/Composer/FeedDataSource.swift Outdated Show resolved Hide resolved
Client/Frontend/Brave Today/Composer/FeedDataSource.swift Outdated Show resolved Hide resolved
Data/models/RSSFeedSource.swift Outdated Show resolved Hide resolved
Data/models/RSSFeedSource.swift Show resolved Hide resolved
Data/models/RSSFeedSource.swift Show resolved Hide resolved
}
if description.isEmpty, let text = doc?.root?.childNodes(ofTypes: [.Text, .Element]).map({ node in
node.stringValue
.trimmingCharacters(in: .whitespacesAndNewlines)
Copy link
Contributor

Choose a reason for hiding this comment

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

text nodes can have html content as well, may be escapeHTML here?

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 tested what stringValue returns here and it automatically decodes HTML entities (i.e. & became &), so I don't think we need further calls

if let html = feedItem.contentHtml {
let doc = try? HTMLDocument(string: html)
if imageURL == nil, let src = doc?.firstChild(xpath: "//img[@src]")?.attr("src") {
imageURL = URL(string: src, relativeTo: location.url.domainURL)
Copy link
Contributor

Choose a reason for hiding this comment

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

Filter for only valid schemes http, https:, data: (may be)?

var description = ""
var imageURL: URL?
if let thumbnail = feedItem.media?.mediaThumbnails?.first?.attributes?.url {
imageURL = URL(string: thumbnail, relativeTo: location.url.domainURL)
Copy link
Contributor

Choose a reason for hiding this comment

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

} else if feedItem.content?.attributes?.type == "html", let html = feedItem.content?.value {
// Find one in description?
let doc = try? HTMLDocument(string: html)
if imageURL == nil, let src = doc?.firstChild(xpath: "//img[@src]")?.attr("src") {
Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -0,0 +1,137 @@
// Copyright 2020 The Brave Authors. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: 2021

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah that's because our custom header is hard-coded, I'll open up a separate PR to update it, but all files created since Jan will have 2020

Copy link
Contributor

@jumde jumde left a comment

Choose a reason for hiding this comment

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

lgtm

@kylehickinson kylehickinson added this to the 1.25 milestone Mar 4, 2021
@kylehickinson kylehickinson added the blocked If a ticket is blocked for some reason, if not using a sub-block label, please provide info in issue label Mar 8, 2021
@kylehickinson kylehickinson modified the milestones: 1.25, 1.24 Mar 11, 2021
@kylehickinson kylehickinson removed the blocked If a ticket is blocked for some reason, if not using a sub-block label, please provide info in issue label Mar 11, 2021
@kylehickinson
Copy link
Collaborator Author

@iccub Sorry some requirements changed post approval, can you please review the most recent commit! Thanks!

Comment on lines +4 to +12
{
"package": "FeedKit",
"repositoryURL": "https://github.com/nmdias/FeedKit.git",
"state": {
"branch": null,
"revision": "68493a33d862c33c9a9f67ec729b3b7df1b20ade",
"version": "9.1.2"
}
},
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

@iccub
Copy link
Contributor

iccub commented Mar 11, 2021

will re-review tomorrow morning, thanks

Copy link
Contributor

@iccub iccub left a comment

Choose a reason for hiding this comment

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

found small stuff only, will run the app now and leave final review

case .success(let feed):
self.sources.append(feed.source)
self.items.append(contentsOf: feed.items)
case .failure(_):
Copy link
Contributor

Choose a reason for hiding this comment

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

we can skip brackets here i believe

static func parse(data: Data) -> OPML? {
guard let document = try? XMLDocument(data: data),
let _ = document.firstChild(xpath: "//opml") else {
log.info("Failed to parse XML document")
Copy link
Contributor

Choose a reason for hiding this comment

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

warning or error log levels would be better here imo

}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return section == 0 ? secureLocations.count : insecureLocations.count
Copy link
Contributor

Choose a reason for hiding this comment

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

return can be skipped

pageTask = session.dataTask(with: url) { [weak self] (data, response, error) in
guard let self = self else { return }
if let error = error as? URLError, error.code == .cancelled {
return
Copy link
Contributor

Choose a reason for hiding this comment

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

do we not want to return completion handler here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point, no reason to handle cancelled and return without handler. If we dismiss the screen, the error will not display anyways since self will be nil

@kylehickinson kylehickinson merged commit ec963f6 into development Mar 12, 2021
@kylehickinson kylehickinson deleted the brave-today-rss branch March 12, 2021 17:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Custom RSS to Brave Today
4 participants