forked from shadowfacts/Tusker
Prioritize followed/following accounts in mention suggestions
This commit is contained in:
parent
288f855e2f
commit
08045dd1e9
|
@ -143,12 +143,15 @@ struct ComposeAutocompleteMentionsView: View {
|
||||||
|
|
||||||
localSearchWorkItem.cancel()
|
localSearchWorkItem.cancel()
|
||||||
|
|
||||||
|
// dispatch back to the main thread because loadAccounts uses CoreData
|
||||||
|
DispatchQueue.main.async {
|
||||||
// if the query has changed, don't bother loading the now-outdated results
|
// if the query has changed, don't bother loading the now-outdated results
|
||||||
if case .mention(query) = uiState.autocompleteState {
|
if case .mention(query) = uiState.autocompleteState {
|
||||||
self.loadAccounts(accounts.map { .pachyderm($0) }, query: query)
|
self.loadAccounts(accounts.map { .pachyderm($0) }, query: query)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private func loadAccounts(_ accounts: [EitherAccount], query: String) {
|
private func loadAccounts(_ accounts: [EitherAccount], query: String) {
|
||||||
// when sorting account suggestions, ignore the domain component of the acct unless the user is typing it themself
|
// when sorting account suggestions, ignore the domain component of the acct unless the user is typing it themself
|
||||||
|
@ -161,8 +164,20 @@ struct ComposeAutocompleteMentionsView: View {
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
.filter(\.1.matched)
|
.filter(\.1.matched)
|
||||||
// todo: it would be nice to prioritize followee/follower accounts, but relationships aren't cached
|
.map { (account, res) -> (EitherAccount, Int) in
|
||||||
.sorted { $0.1.score > $1.1.score }
|
// give higher weight to accounts that the user follows or is followed by
|
||||||
|
var score = res.score
|
||||||
|
if let relationship = mastodonController.persistentContainer.relationship(forAccount: account.id) {
|
||||||
|
if relationship.following {
|
||||||
|
score += 3
|
||||||
|
}
|
||||||
|
if relationship.followedBy {
|
||||||
|
score += 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (account, score)
|
||||||
|
}
|
||||||
|
.sorted { $0.1 > $1.1 }
|
||||||
.map(\.0)
|
.map(\.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue