Revert "Add lastCredentialRenewTime and honour it in FeedlyRefreshAccessTokenOperation"

This reverts commit 8973adbdbd.
This commit is contained in:
Kiel Gillard 🤪 2020-05-20 11:18:09 +10:00
parent e5a7706bb7
commit 133544b748
3 changed files with 2 additions and 33 deletions

View File

@ -23,7 +23,6 @@ final class AccountMetadata: Codable {
case lastArticleFetchStartTime = "lastArticleFetch"
case lastArticleFetchEndTime
case endpointURL
case lastCredentialRenewTime = "lastCredentialRenewTime"
case performedApril2020RetentionPolicyChange
}
@ -82,16 +81,6 @@ final class AccountMetadata: Codable {
}
}
}
/// The last moment an account successfully renewed its credentials, or `nil` if no such moment exists.
/// An account delegate can use this value to decide when to next ask the service provider to renew credentials.
var lastCredentialRenewTime: Date? {
didSet {
if lastCredentialRenewTime != oldValue {
valueDidChange(.lastCredentialRenewTime)
}
}
}
var performedApril2020RetentionPolicyChange: Bool? {
didSet {

View File

@ -554,7 +554,7 @@ extension FeedlyAccountDelegate: FeedlyAPICallerDelegate {
}
}
let refreshAccessToken = FeedlyRefreshAccessTokenOperation(account: account, service: self, oauthClient: oauthAuthorizationClient, refreshDate: Date(), log: log)
let refreshAccessToken = FeedlyRefreshAccessTokenOperation(account: account, service: self, oauthClient: oauthAuthorizationClient, log: log)
refreshAccessToken.downloadProgress = refreshProgress
/// This must be strongly referenced by the completionBlock of the `FeedlyRefreshAccessTokenOperation`.

View File

@ -17,32 +17,14 @@ final class FeedlyRefreshAccessTokenOperation: FeedlyOperation {
let account: Account
let log: OSLog
/// The moment the refresh is being requested. The token will refresh only if the account's `lastCredentialRenewTime` is not on the same day as this moment. When nil, the operation will always refresh the token.
let refreshDate: Date?
init(account: Account, service: OAuthAccessTokenRefreshing, oauthClient: OAuthAuthorizationClient, refreshDate: Date?, log: OSLog) {
init(account: Account, service: OAuthAccessTokenRefreshing, oauthClient: OAuthAuthorizationClient, log: OSLog) {
self.oauthClient = oauthClient
self.service = service
self.account = account
self.refreshDate = refreshDate
self.log = log
}
override func run() {
// Only refresh the token if these dates are not on the same day.
let shouldRefresh: Bool = {
guard let date = refreshDate, let lastRenewDate = account.metadata.lastCredentialRenewTime else {
return true
}
return !Calendar.current.isDate(lastRenewDate, equalTo: date, toGranularity: .day)
}()
guard shouldRefresh else {
os_log(.debug, log: log, "Skipping access token renewal.")
didFinish()
return
}
let refreshToken: Credentials
do {
@ -82,8 +64,6 @@ final class FeedlyRefreshAccessTokenOperation: FeedlyOperation {
// Now store the access token because we want the account delegate to use it.
try account.storeCredentials(grant.accessToken)
account.metadata.lastCredentialRenewTime = Date()
didFinish()
} catch {
didFinish(with: error)