Merge pull request #862 from mastodon/fix-urlscheme-profile-resolve

fix(deeplinking): Fix profile resolving didn't use WebFinger so resolving non-local profiles might fail
This commit is contained in:
Marcus Kida 2023-01-11 15:31:22 +01:00 committed by GitHub
commit 83f4eb1d8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 68 deletions

View File

@ -94,14 +94,14 @@ final class RemoteProfileViewModel: ProfileViewModel {
super.init(context: context, authContext: authContext, optionalMastodonUser: nil)
let domain = authContext.mastodonAuthenticationBox.domain
let authorization = authContext.mastodonAuthenticationBox.userAuthorization
let authenticationBox = authContext.mastodonAuthenticationBox
Just(acct)
.asyncMap { acct in
try await context.apiService.accountSearch(
domain: domain,
query: .init(acct: acct),
authorization: authorization
)
.asyncMap { acct -> Mastodon.Response.Content<Mastodon.Entity.Account?> in
try await context.apiService.search(
query: .init(q: acct, type: .accounts, resolve: true),
authenticationBox: authenticationBox
).map { $0.accounts.first }
}
.retry(3)
.receive(on: DispatchQueue.main)
@ -114,11 +114,11 @@ final class RemoteProfileViewModel: ProfileViewModel {
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: remote user %s fetched", ((#file as NSString).lastPathComponent), #line, #function, acct)
}
} receiveValue: { [weak self] response in
guard let self = self else { return }
guard let self = self, let value = response.value else { return }
let managedObjectContext = context.managedObjectContext
let request = MastodonUser.sortedFetchRequest
request.fetchLimit = 1
request.predicate = MastodonUser.predicate(domain: domain, id: response.value.id)
request.predicate = MastodonUser.predicate(domain: domain, id: value.id)
guard let mastodonUser = managedObjectContext.safeFetch(request).first else {
assertionFailure()
return

View File

@ -240,34 +240,3 @@ extension APIService {
return result
}
}
extension APIService {
public func accountSearch(
domain: String,
query: Mastodon.API.Account.AccountLookupQuery,
authorization: Mastodon.API.OAuth.Authorization
) async throws -> Mastodon.Response.Content<Mastodon.Entity.Account> {
let response = try await Mastodon.API.Account.lookupAccount(
session: session,
domain: domain,
query: query,
authorization: authorization
).singleOutput()
// user
let managedObjectContext = self.backgroundManagedObjectContext
try await managedObjectContext.performChanges {
_ = Persistence.MastodonUser.createOrMerge(
in: managedObjectContext,
context: Persistence.MastodonUser.PersistContext(
domain: domain,
entity: response.value,
cache: nil,
networkDate: response.networkDate
)
)
}
return response
}
}