From 131e116fc043bbbf1ab2540d79c456563619e919 Mon Sep 17 00:00:00 2001 From: shannon Date: Wed, 11 Dec 2024 13:33:27 -0500 Subject: [PATCH] Additional clarification about user fetching me vs. not me, and do not cache accounts that are not me --- .../Protocol/Provider/DataSourceFacade+Profile.swift | 2 +- Mastodon/Scene/Profile/ProfileViewController.swift | 2 +- .../MastodonCore/Persistence/PersistenceManager.swift | 4 ---- .../MastodonCore/Service/API/APIService+Account.swift | 11 ++++++----- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/Mastodon/Protocol/Provider/DataSourceFacade+Profile.swift b/Mastodon/Protocol/Provider/DataSourceFacade+Profile.swift index d4138b2ee..e9aac72e5 100644 --- a/Mastodon/Protocol/Provider/DataSourceFacade+Profile.swift +++ b/Mastodon/Protocol/Provider/DataSourceFacade+Profile.swift @@ -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 diff --git a/Mastodon/Scene/Profile/ProfileViewController.swift b/Mastodon/Scene/Profile/ProfileViewController.swift index 7f950477c..deba8b3c4 100644 --- a/Mastodon/Scene/Profile/ProfileViewController.swift +++ b/Mastodon/Scene/Profile/ProfileViewController.swift @@ -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 } } diff --git a/MastodonSDK/Sources/MastodonCore/Persistence/PersistenceManager.swift b/MastodonSDK/Sources/MastodonCore/Persistence/PersistenceManager.swift index ae3bce86a..2d9e41577 100644 --- a/MastodonSDK/Sources/MastodonCore/Persistence/PersistenceManager.swift +++ b/MastodonSDK/Sources/MastodonCore/Persistence/PersistenceManager.swift @@ -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) } diff --git a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Account.swift b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Account.swift index 1142bf736..3a29d8925 100644 --- a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Account.swift +++ b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Account.swift @@ -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 } }