From 9a39584ccb2aebf61d17bba2ace32bb55c6a0a09 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Fri, 29 May 2026 18:58:37 -0700 Subject: [PATCH] Add activity reporting Feedly authentication operations. --- .../Feedly/FeedlyAccountDelegate.swift | 6 ++++++ .../OAuthAccountAuthorizationOperation.swift | 19 +++++++++++++++++++ .../Operations/FeedlyLogoutOperation.swift | 1 + .../FeedlyRefreshAccessTokenOperation.swift | 1 + 4 files changed, 27 insertions(+) diff --git a/Modules/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift b/Modules/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift index 951b055a3..71d367c0c 100644 --- a/Modules/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift +++ b/Modules/Account/Sources/Account/Feedly/FeedlyAccountDelegate.swift @@ -709,6 +709,9 @@ import Secrets func accountWillBeDeleted(_ account: Account) { Self.logger.debug("FeedlyAccountDelegate: accountWillBeDeleted") let logout = FeedlyLogoutOperation(account: account, service: caller) + logout.activityKind = .validateCredentials + logout.activityDetail = "Logging out of Feedly" + logout.activityAccountID = account.accountID // Dispatch on the shared queue because the lifetime of the account delegate is uncertain. FeedlyMainThreadOperationQueue.shared.add(logout) } @@ -788,6 +791,9 @@ extension FeedlyAccountDelegate: FeedlyAPICallerDelegate { let refreshAccessToken = FeedlyRefreshAccessTokenOperation(account: account, service: self, oauthClient: oauthAuthorizationClient) refreshAccessToken.downloadProgress = refreshProgress + refreshAccessToken.activityKind = .validateCredentials + refreshAccessToken.activityDetail = "Refreshing access token" + refreshAccessToken.activityAccountID = account.accountID /// This must be strongly referenced by the completionBlock of the `FeedlyRefreshAccessTokenOperation`. let refreshAccessTokenDelegate = RefreshAccessTokenOperationDelegate() diff --git a/Modules/Account/Sources/Account/Feedly/OAuthAccountAuthorizationOperation.swift b/Modules/Account/Sources/Account/Feedly/OAuthAccountAuthorizationOperation.swift index 2be655e5e..eab33f79b 100644 --- a/Modules/Account/Sources/Account/Feedly/OAuthAccountAuthorizationOperation.swift +++ b/Modules/Account/Sources/Account/Feedly/OAuthAccountAuthorizationOperation.swift @@ -9,6 +9,7 @@ import Foundation @preconcurrency import AuthenticationServices import os +import ActivityLog import RSCore @MainActor public protocol OAuthAccountAuthorizationOperationDelegate: AnyObject { @@ -66,6 +67,7 @@ public final class OAuthAccountAuthorizationOperation: MainThreadOperation, @unc nonisolated(unsafe) private let anchorProvider = PresentationAnchorProvider() nonisolated(unsafe) private var session: ASWebAuthenticationSession? private var error: Error? + private var activityID: Int? nonisolated private static let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "OAuthAccountAuthorizationOperation") public init(accountType: AccountType) { @@ -78,6 +80,11 @@ public final class OAuthAccountAuthorizationOperation: MainThreadOperation, @unc Self.logger.debug("OAuthAccountAuthorizationOperation: run") assert(presentationAnchor != nil, "\(self) outlived presentation anchor.") + let activityLog = ActivityLog.shared + let id = activityLog.createActivity(owner: .app, kind: .validateCredentials, detail: "Authorizing \(accountType.displayName)") + activityLog.didStart(id: id) + activityID = id + let request = Account.oauthAuthorizationCodeGrantRequest(for: accountType) guard let url = request.url else { @@ -106,6 +113,18 @@ public final class OAuthAccountAuthorizationOperation: MainThreadOperation, @unc override public func noteDidComplete() { Self.logger.debug("OAuthAccountAuthorizationOperation: noteDidComplete") + if let activityID { + let activityLog = ActivityLog.shared + if let error { + activityLog.didFail(id: activityID, error: error) + } else if isCanceled { + activityLog.didFail(id: activityID, error: CocoaError(.userCancelled)) + } else { + activityLog.didComplete(id: activityID) + } + self.activityID = nil + } + if isCanceled { Self.logger.debug("OAuthAccountAuthorizationOperation: noteDidComplete — canceled") session?.cancel() diff --git a/Modules/Account/Sources/Account/Feedly/Operations/FeedlyLogoutOperation.swift b/Modules/Account/Sources/Account/Feedly/Operations/FeedlyLogoutOperation.swift index 61a3005d3..e593ef2f5 100644 --- a/Modules/Account/Sources/Account/Feedly/Operations/FeedlyLogoutOperation.swift +++ b/Modules/Account/Sources/Account/Feedly/Operations/FeedlyLogoutOperation.swift @@ -24,6 +24,7 @@ final class FeedlyLogoutOperation: FeedlyOperation { } override func run() { + startActivityIfNeeded() Feedly.logger.info("Feedly: Requesting logout \(self.account.accountID, privacy: .public)") service.logout(completion: didCompleteLogout(_:)) } diff --git a/Modules/Account/Sources/Account/Feedly/Operations/FeedlyRefreshAccessTokenOperation.swift b/Modules/Account/Sources/Account/Feedly/Operations/FeedlyRefreshAccessTokenOperation.swift index da602dcf5..e2c7930ab 100644 --- a/Modules/Account/Sources/Account/Feedly/Operations/FeedlyRefreshAccessTokenOperation.swift +++ b/Modules/Account/Sources/Account/Feedly/Operations/FeedlyRefreshAccessTokenOperation.swift @@ -24,6 +24,7 @@ final class FeedlyRefreshAccessTokenOperation: FeedlyOperation { } override func run() { + startActivityIfNeeded() let refreshToken: Credentials do {