-
Notifications
You must be signed in to change notification settings - Fork 440
Fix #3249: Add RSS feed parser to Brave Today #3317
Conversation
There was a problem hiding this 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/Settings/Brave Today/BraveTodayAddSourceViewController.swift
Show resolved
Hide resolved
80959b5
to
8ad4192
Compare
b358e1e
to
487aa47
Compare
} | ||
if description.isEmpty, let text = doc?.root?.childNodes(ofTypes: [.Text, .Element]).map({ node in | ||
node.stringValue | ||
.trimmingCharacters(in: .whitespacesAndNewlines) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
487aa47
to
dc636a4
Compare
@@ -0,0 +1,137 @@ | |||
// Copyright 2020 The Brave Authors. All rights reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: 2021
There was a problem hiding this comment.
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
87020e9
to
d0800bf
Compare
Client/Frontend/Settings/Brave Today/BraveTodayAddSourceViewController.swift
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
d0800bf
to
401043b
Compare
@iccub Sorry some requirements changed post approval, can you please review the most recent commit! Thanks! |
{ | ||
"package": "FeedKit", | ||
"repositoryURL": "https://github.com/nmdias/FeedKit.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "68493a33d862c33c9a9f67ec729b3b7df1b20ade", | ||
"version": "9.1.2" | ||
} | ||
}, |
There was a problem hiding this comment.
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
will re-review tomorrow morning, thanks |
There was a problem hiding this 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(_): |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
Summary of Changes
This pull request fixes #3249
Submitter Checklist:
NSLocalizableString()
Test Plan:
On Add Source page:
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.
Test being able to add feeds via OPML by pasting an OPML URL in the search field (examples: https://planet.mozilla.org/opml.xml, http://hosting.opml.org/dave/spec/subscriptionList.opml)Test being able to add feeds via OPML by using the "Import OPML" button below (copy above examples into Files.app)Repeat tests above with OPML files that don't include RSS feeds (http://hosting.opml.org/dave/spec/states.opml)On Brave Today settings
On Brave Today
Reviewer Checklist:
QA/(Yes|No)
release-notes/(include|exclude)
bug
/enhancement