From 63ec02411913c0ea0fbd20862ba220a489925844 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 14 Jun 2026 10:48:37 -0700 Subject: [PATCH] Add activity for feed redirect. --- .../LocalAccount/LocalAccountRefresher.swift | 28 +++++++++++++++++++ .../Sources/ActivityLog/ActivityKind.swift | 3 ++ .../Resources/Localizable.xcstrings | 3 ++ .../RSWeb/Sources/RSWeb/DownloadSession.swift | 6 ++++ 4 files changed, 40 insertions(+) diff --git a/Modules/Account/Sources/Account/LocalAccount/LocalAccountRefresher.swift b/Modules/Account/Sources/Account/LocalAccount/LocalAccountRefresher.swift index 31559e1be..baec17f28 100644 --- a/Modules/Account/Sources/Account/LocalAccount/LocalAccountRefresher.swift +++ b/Modules/Account/Sources/Account/LocalAccount/LocalAccountRefresher.swift @@ -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 diff --git a/Modules/ActivityLog/Sources/ActivityLog/ActivityKind.swift b/Modules/ActivityLog/Sources/ActivityLog/ActivityKind.swift index 8cdfb92b6..0e3747e5b 100644 --- a/Modules/ActivityLog/Sources/ActivityLog/ActivityKind.swift +++ b/Modules/ActivityLog/Sources/ActivityLog/ActivityKind.swift @@ -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: diff --git a/Modules/ActivityLog/Sources/ActivityLog/Resources/Localizable.xcstrings b/Modules/ActivityLog/Sources/ActivityLog/Resources/Localizable.xcstrings index b9fb0dc5b..046cc0149 100644 --- a/Modules/ActivityLog/Sources/ActivityLog/Resources/Localizable.xcstrings +++ b/Modules/ActivityLog/Sources/ActivityLog/Resources/Localizable.xcstrings @@ -101,6 +101,9 @@ } } }, + "Feed redirect" : { + "comment" : "Activity kind" + }, "Fetching %@" : { "comment" : "Activity kind — fetching a candidate URL during feed finding" }, diff --git a/Modules/RSWeb/Sources/RSWeb/DownloadSession.swift b/Modules/RSWeb/Sources/RSWeb/DownloadSession.swift index 66c3c26e7..5959e13c3 100755 --- a/Modules/RSWeb/Sources/RSWeb/DownloadSession.swift +++ b/Modules/RSWeb/Sources/RSWeb/DownloadSession.swift @@ -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()