Add activity for feed redirect.

This commit is contained in:
Brent Simmons committed 2026-06-14 10:48:37 -07:00
1 parent 3f96ef0d79
commit 63ec024119
4 files changed
+40

No files matched your search

@@ -213,6 +213,17 @@ import os
ActivityLog.shared.didStart(owner, kind: .refreshFeedContent(feedURL: feed.url))
}
func downloadSession(_ downloadSession: DownloadSession, didFollowRedirectFor url: URL, from fromURL: URL, to toURL: URL, statusCode: Int) {
guard let owner = activityOwner else {
return
}
let detail = urlToFeedDictionary[url.absoluteString]?.nameForDisplay
let activityLog = ActivityLog.shared
let id = activityLog.createActivity(owner: owner, kind: .followFeedRedirect, detail: detail)
activityLog.didStart(id: id)
activityLog.didComplete(id: id, message: "\(Self.redirectStatusDescription(statusCode)): \(fromURL.absoluteString) → \(toURL.absoluteString)", durationIsSignificant: false)
}
func downloadSession(_ downloadSession: DownloadSession, didSkip url: URL, reason: String) {
guard let owner = activityOwner else {
return
@@ -567,6 +578,23 @@ private extension LocalAccountRefresher {
static func url(for feed: Feed) -> URL? {
URL(string: feed.url)
}
static func redirectStatusDescription(_ statusCode: Int) -> String {
switch statusCode {
case HTTPResponseCode.redirectPermanent:
return "301 Moved Permanently"
case HTTPResponseCode.redirectTemporary:
return "302 Found"
case HTTPResponseCode.redirectSeeOther:
return "303 See Other"
case HTTPResponseCode.redirectVeryTemporary:
return "307 Temporary Redirect"
case HTTPResponseCode.redirectPermanentPreservingMethod:
return "308 Permanent Redirect"
default:
return "\(statusCode)"
}
}
}
// MARK: - Utility
@@ -17,6 +17,7 @@ public enum ActivityKind: Sendable, Hashable {
case refreshArticleStatuses
case refreshFeedList
case refreshFeedContent(feedURL: String) // per-feed
case followFeedRedirect
case refreshMissingArticles
case importOPML
@@ -72,6 +73,8 @@ public enum ActivityKind: Sendable, Hashable {
return NSLocalizedString("Refreshing statuses", bundle: .module, comment: "Activity kind")
case .refreshFeedList:
return NSLocalizedString("Refreshing feed list", bundle: .module, comment: "Activity kind")
case .followFeedRedirect:
return NSLocalizedString("Feed redirect", bundle: .module, comment: "Activity kind")
case .refreshMissingArticles:
return NSLocalizedString("Refreshing missing articles", bundle: .module, comment: "Activity kind")
case .importOPML:
@@ -101,6 +101,9 @@
}
}
},
"Feed redirect" : {
"comment" : "Activity kind"
},
"Fetching %@" : {
"comment" : "Activity kind — fetching a candidate URL during feed finding"
},
@@ -21,6 +21,7 @@ import RSCore
func downloadSession(_ downloadSession: DownloadSession, downloadDidComplete: URL, response: URLResponse?, data: Data, error: NSError?)
func downloadSession(_ downloadSession: DownloadSession, shouldContinueAfterReceivingData: Data, url: URL) -> Bool
func downloadSession(_ downloadSession: DownloadSession, httpError statusCode: Int, url: URL)
func downloadSession(_ downloadSession: DownloadSession, didFollowRedirectFor url: URL, from fromURL: URL, to toURL: URL, statusCode: Int)
func downloadSessionDidComplete(_ downloadSession: DownloadSession)
}
@@ -152,6 +153,11 @@ extension DownloadSession: @preconcurrency URLSessionTaskDelegate {
}
}
if let taskInfo = infoForTask(task), let toURL = request.url {
let fromURL = response.url ?? taskInfo.url
delegate.downloadSession(self, didFollowRedirectFor: taskInfo.url, from: fromURL, to: toURL, statusCode: response.statusCode)
}
var modifiedRequest = request
modifiedRequest.addSpecialCaseUserAgentIfNeeded()