Compare commits
2 Commits
288f855e2f
...
5414f2329c
Author | SHA1 | Date |
---|---|---|
Shadowfacts | 5414f2329c | |
Shadowfacts | 08045dd1e9 |
|
@ -143,9 +143,12 @@ struct ComposeAutocompleteMentionsView: View {
|
|||
|
||||
localSearchWorkItem.cancel()
|
||||
|
||||
// if the query has changed, don't bother loading the now-outdated results
|
||||
if case .mention(query) = uiState.autocompleteState {
|
||||
self.loadAccounts(accounts.map { .pachyderm($0) }, query: query)
|
||||
// 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 case .mention(query) = uiState.autocompleteState {
|
||||
self.loadAccounts(accounts.map { .pachyderm($0) }, query: query)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -161,8 +164,20 @@ struct ComposeAutocompleteMentionsView: View {
|
|||
return res
|
||||
}
|
||||
.filter(\.1.matched)
|
||||
// todo: it would be nice to prioritize followee/follower accounts, but relationships aren't cached
|
||||
.sorted { $0.1.score > $1.1.score }
|
||||
.map { (account, res) -> (EitherAccount, Int) in
|
||||
// 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)
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
//
|
||||
|
||||
import UIKit
|
||||
import Pachyderm
|
||||
|
||||
class MyProfileViewController: ProfileViewController {
|
||||
|
||||
|
@ -21,7 +22,7 @@ class MyProfileViewController: ProfileViewController {
|
|||
|
||||
DispatchQueue.main.async {
|
||||
self.accountID = account.id
|
||||
self.setAvatarTabBarImage()
|
||||
self.setAvatarTabBarImage(account: account)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -38,12 +39,7 @@ class MyProfileViewController: ProfileViewController {
|
|||
NotificationCenter.default.addObserver(self, selector: #selector(preferencesChanged), name: .preferencesChanged, object: nil)
|
||||
}
|
||||
|
||||
private func setAvatarTabBarImage() {
|
||||
guard let id = mastodonController.account?.id,
|
||||
let account = mastodonController.persistentContainer.account(for: id) else {
|
||||
return
|
||||
}
|
||||
|
||||
private func setAvatarTabBarImage<Account: AccountProtocol>(account: Account) {
|
||||
_ = ImageCache.avatars.get(account.avatar, completion: { [weak self] (data) in
|
||||
guard let self = self, let data = data, let image = UIImage(data: data) else { return }
|
||||
DispatchQueue.main.async {
|
||||
|
@ -61,7 +57,12 @@ class MyProfileViewController: ProfileViewController {
|
|||
}
|
||||
|
||||
@objc private func preferencesChanged() {
|
||||
setAvatarTabBarImage()
|
||||
guard let id = mastodonController.account?.id,
|
||||
let account = mastodonController.persistentContainer.account(for: id) else {
|
||||
return
|
||||
}
|
||||
|
||||
setAvatarTabBarImage(account: account)
|
||||
}
|
||||
|
||||
// MARK: - Interaction
|
||||
|
|
Loading…
Reference in New Issue