fix(Widget): User lookup for widget does not yield correct result

This commit is contained in:
Marcus Kida 2023-02-07 12:36:13 +01:00
parent e88dea0034
commit 736c3b515f
No known key found for this signature in database
GPG Key ID: 19FF64E08013CA40
5 changed files with 15 additions and 17 deletions

View File

@ -30,15 +30,6 @@ class FollowersCountIntentHandler: INExtension, FollowersCountIntentHandling {
.apiService
.search(query: .init(q: searchTerm), authenticationBox: authenticationBox)
return INObjectCollection(items: results.value.accounts.map { $0.acctWithDomain(localDomain: authenticationBox.domain) as NSString })
}
}
extension Mastodon.Entity.Account {
func acctWithDomain(localDomain: String) -> String {
guard acct.contains("@") else {
return "\(acct)@\(localDomain)"
}
return acct
return INObjectCollection(items: results.value.accounts.map { $0.acctWithDomainIfMissing(authenticationBox.domain) as NSString })
}
}

View File

@ -22,6 +22,6 @@ class MultiFollowersCountIntentHandler: INExtension, MultiFollowersCountIntentHa
.apiService
.search(query: .init(q: searchTerm), authenticationBox: authenticationBox)
return INObjectCollection(items: results.value.accounts.map { $0.acctWithDomain(localDomain: authenticationBox.domain) as NSString })
return INObjectCollection(items: results.value.accounts.map { $0.acctWithDomainIfMissing(authenticationBox.domain) as NSString })
}
}

View File

@ -82,6 +82,13 @@ extension Mastodon.Entity {
case muteExpiresAt = "mute_expires_at"
}
}
}
extension Mastodon.Entity.Account {
public func acctWithDomainIfMissing(_ localDomain: String) -> String {
guard acct.contains("@") else {
return "\(acct)@\(localDomain)"
}
return acct
}
}

View File

@ -88,7 +88,7 @@ private extension FollowersCountWidgetProvider {
guard
let desiredAccount = configuration.account ?? authBox.authenticationRecord.object(
in: WidgetExtension.appContext.managedObjectContext
)?.user.acct
)?.user.acctWithDomain
else {
return completion(.unconfigured)
}
@ -99,7 +99,7 @@ private extension FollowersCountWidgetProvider {
.search(query: .init(q: desiredAccount, type: .accounts), authenticationBox: authBox)
.value
.accounts
.first(where: { $0.acct == desiredAccount })
.first(where: { $0.acctWithDomainIfMissing(authBox.domain) == desiredAccount })
else {
return completion(.unconfigured)
}

View File

@ -88,7 +88,7 @@ private extension MultiFollowersCountWidgetProvider {
desiredAccounts = configuredAccounts
} else if let currentlyLoggedInAccount = authBox.authenticationRecord.object(
in: WidgetExtension.appContext.managedObjectContext
)?.user.acct {
)?.user.acctWithDomain {
desiredAccounts = [currentlyLoggedInAccount]
} else {
return completion(.unconfigured)
@ -103,7 +103,7 @@ private extension MultiFollowersCountWidgetProvider {
.search(query: .init(q: desiredAccount, type: .accounts), authenticationBox: authBox)
.value
.accounts
.first(where: { $0.acct == desiredAccount })
.first(where: { $0.acctWithDomainIfMissing(authBox.domain) == desiredAccount })
else {
continue
}