2
2
mirror of https://github.com/mastodon/mastodon-ios synced 2025-04-11 22:58:02 +02:00

Additional clarification about user fetching me vs. not me, and do not cache accounts that are not me

This commit is contained in:
shannon 2024-12-11 13:33:27 -05:00
parent dbd05377b8
commit 131e116fc0
4 changed files with 8 additions and 11 deletions

View File

@ -61,7 +61,7 @@ extension DataSourceFacade {
coordinator.showLoading()
do {
guard let account = try await APIService.shared.fetchUser(
guard let account = try await APIService.shared.fetchNotMeUser( // ProfileViewController will fetch credentialed user later if this is actually me
username: username,
domain: domain,
authenticationBox: provider.authenticationBox

View File

@ -572,7 +572,7 @@ extension ProfileViewController {
return account
case .notMe(let me, let displayAccount, let relationship):
guard let domain = displayAccount.domain else { throw ProfileViewError.invalidDomain }
guard let refreshedAccount = try await APIService.shared.fetchUser(username: displayAccount.acct, domain: domain, authenticationBox: authenticationBox) else { throw ProfileViewError.accountNotFound }
guard let refreshedAccount = try await APIService.shared.fetchNotMeUser(username: displayAccount.acct, domain: domain, authenticationBox: authenticationBox) else { throw ProfileViewError.accountNotFound }
return refreshedAccount
}
}

View File

@ -54,10 +54,6 @@ public class PersistenceManager {
return account
}
public func cacheAccount(_ account: Mastodon.Entity.Account, for authenticationBox: MastodonAuthenticationBox) {
cacheAccount(account, forUserID: authenticationBox.authentication.userIdentifier())
}
public func cacheAccount(_ account: Mastodon.Entity.Account, forUserID userID: MastodonUserIdentifier) {
FileManager.default.store(account: account, forUserID: userID)
}

View File

@ -21,7 +21,7 @@ extension APIService {
authorization: authenticationBox.userAuthorization
).singleOutput().value
PersistenceManager.shared.cacheAccount(account, for: authenticationBox)
PersistenceManager.shared.cacheAccount(account, forUserID: authenticationBox.authentication.userIdentifier())
return account
}
@ -55,7 +55,7 @@ extension APIService {
accountCreatedAt: account.createdAt)
let authBox = MastodonAuthenticationBox(authentication: authentication)
PersistenceManager.shared.cacheAccount(account, for: authBox)
PersistenceManager.shared.cacheAccount(account, forUserID: authentication.userIdentifier())
AuthenticationServiceProvider.shared.activateAuthentication(authBox)
return authBox
}
@ -160,7 +160,7 @@ extension APIService {
}
extension APIService {
public func fetchUser(username: String, domain: String, authenticationBox: MastodonAuthenticationBox)
public func fetchNotMeUser(username: String, domain: String, authenticationBox: MastodonAuthenticationBox)
async throws -> Mastodon.Entity.Account? {
let query = Mastodon.API.Account.AccountLookupQuery(acct: "\(username)@\(domain)")
let authorization = authenticationBox.userAuthorization
@ -172,8 +172,9 @@ extension APIService {
authorization: authorization
).singleOutput()
PersistenceManager.shared.cacheAccount(response.value, for: authenticationBox)
let fetchedAccount = response.value
return response.value
return fetchedAccount
}
}