Skip downloading feeds from X/Twitter, since those sites will never return a feed. (X/Twitter URLs may still be in people’s feeds lists due to prior Twitter integration, that has since gone away at Twitter’s initiative.)

This commit is contained in:
Brent Simmons
2024-11-30 13:18:04 -08:00
parent 23cb45161a
commit 8c811e75ba

View File

@@ -36,7 +36,9 @@ final class LocalAccountRefresher {
public func refreshFeeds(_ feeds: Set<WebFeed>, completion: (() -> Void)? = nil) {
guard !feeds.isEmpty else {
let filteredFeeds = feeds.filter { !Self.feedIsDisallowed($0) }
guard !filteredFeeds.isEmpty else {
Task { @MainActor in
completion?()
}
@@ -44,11 +46,11 @@ final class LocalAccountRefresher {
}
urlToFeedDictionary.removeAll()
for feed in feeds {
for feed in filteredFeeds {
urlToFeedDictionary[feed.url] = feed
}
let urls = feeds.compactMap { feed in
let urls = filteredFeeds.compactMap { feed in
URL(unicodeString: feed.url)
}
@@ -122,6 +124,36 @@ extension LocalAccountRefresher: DownloadSessionDelegate {
}
}
// MARK: - Private
private extension LocalAccountRefresher {
/// These hosts will never return a feed.
static let badHosts = ["twitter.com", "www.twitter.com", "x.com", "www.x.com"]
/// Return true if we wont download that feed.
///
/// We will never get a feed from X/Twitter, for instance.
static func feedIsDisallowed(_ feed: WebFeed) -> Bool {
guard let url = URL(unicodeString: feed.url) else {
return true
}
guard let lowercaseHost = url.host()?.lowercased() else {
return true
}
for badHost in badHosts {
if lowercaseHost == badHost {
return true
}
}
return false
}
}
// MARK: - Utility
private extension Data {