Add activity reporting Feedly authentication operations.

This commit is contained in:
Brent Simmons committed 2026-05-29 18:58:37 -07:00
1 parent a0359f17fa
commit 9a39584ccb
4 files changed
+27

No files matched your search

@@ -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()
@@ -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()
@@ -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(_:))
}
@@ -24,6 +24,7 @@ final class FeedlyRefreshAccessTokenOperation: FeedlyOperation {
}
override func run() {
startActivityIfNeeded()
let refreshToken: Credentials
do {