1
0
mirror of https://github.com/mastodon/mastodon-ios.git synced 2024-12-24 16:01:52 +01:00

chore(Widget): Fix picked account not desired account

This commit is contained in:
Marcus Kida 2023-02-07 09:07:37 +01:00
parent 0647cae24a
commit 0e303418d7
No known key found for this signature in database
GPG Key ID: 19FF64E08013CA40
2 changed files with 35 additions and 28 deletions

View File

@ -84,21 +84,24 @@ private extension FollowersCountWidgetProvider {
return completion(.unconfigured)
}
guard let desiredAccount: String = {
guard let account = configuration.account else {
return authBox.authenticationRecord.object(in: WidgetExtension.appContext.managedObjectContext)?.user.acct
}
return account
}() else {
guard
let desiredAccount = configuration.account ?? authBox.authenticationRecord.object(
in: WidgetExtension.appContext.managedObjectContext
)?.user.acct
else {
return completion(.unconfigured)
}
guard
let resultingAccount = try await WidgetExtension.appContext
.apiService
.search(query: .init(q: desiredAccount, type: .accounts), authenticationBox: authBox)
.value
.accounts
.first!
.first(where: { $0.acct == desiredAccount })
else {
return completion(.unconfigured)
}
let imageData = try await URLSession.shared.data(from: resultingAccount.avatarImageURLWithFallback(domain: authBox.domain)).0

View File

@ -82,27 +82,31 @@ private extension MultiFollowersCountWidgetProvider {
return completion(.unconfigured)
}
guard let desiredAccounts: [String] = {
guard let account = configuration.accounts?.compactMap({ $0 }) else {
if let acct = authBox.authenticationRecord.object(in: WidgetExtension.appContext.managedObjectContext)?.user.acct {
return [acct]
}
return nil
}
return account
}() else {
let desiredAccounts: [String]
if let configuredAccounts = configuration.accounts?.compactMap({ $0 }) {
desiredAccounts = configuredAccounts
} else if let currentlyLoggedInAccount = authBox.authenticationRecord.object(
in: WidgetExtension.appContext.managedObjectContext
)?.user.acct {
desiredAccounts = [currentlyLoggedInAccount]
} else {
return completion(.unconfigured)
}
var accounts = [MultiFollowersEntryAccountable]()
for desiredAccount in desiredAccounts {
guard
let resultingAccount = try await WidgetExtension.appContext
.apiService
.search(query: .init(q: desiredAccount, type: .accounts), authenticationBox: authBox)
.value
.accounts
.first!
.first(where: { $0.acct == desiredAccount })
else {
continue
}
let imageData = try await URLSession.shared.data(from: resultingAccount.avatarImageURLWithFallback(domain: authBox.domain)).0