fix: suggestions account order
This commit is contained in:
parent
46fe59c920
commit
7f6e9fb907
|
@ -320,7 +320,10 @@ final class SearchViewModel: NSObject {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
if let users = mastodonUsers {
|
if let users = mastodonUsers {
|
||||||
recommendAccounts = users.map(\.objectID)
|
let sortedUsers = users.sorted { (user1, user2) -> Bool in
|
||||||
|
(ids.firstIndex(of: user1.id) ?? 0) < (ids.firstIndex(of: user2.id) ?? 0)
|
||||||
|
}
|
||||||
|
recommendAccounts = sortedUsers.map(\.objectID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ import UIKit
|
||||||
protocol SuggestionAccountViewModelDelegate: AnyObject {
|
protocol SuggestionAccountViewModelDelegate: AnyObject {
|
||||||
var homeTimelineNeedRefresh: PassthroughSubject<Void, Never> { get }
|
var homeTimelineNeedRefresh: PassthroughSubject<Void, Never> { get }
|
||||||
}
|
}
|
||||||
|
|
||||||
final class SuggestionAccountViewModel: NSObject {
|
final class SuggestionAccountViewModel: NSObject {
|
||||||
var disposeBag = Set<AnyCancellable>()
|
var disposeBag = Set<AnyCancellable>()
|
||||||
|
|
||||||
|
@ -110,20 +111,27 @@ final class SuggestionAccountViewModel: NSObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
func receiveAccounts(ids: [String]) {
|
func receiveAccounts(ids: [String]) {
|
||||||
guard let activeMastodonAuthenticationBox = context.authenticationService.activeMastodonAuthenticationBox.value else { return }
|
guard let activeMastodonAuthenticationBox = context.authenticationService.activeMastodonAuthenticationBox.value else {
|
||||||
let users: [MastodonUser]? = {
|
return
|
||||||
let request = MastodonUser.sortedFetchRequest
|
}
|
||||||
request.predicate = MastodonUser.predicate(domain: activeMastodonAuthenticationBox.domain, ids: ids)
|
let userFetchRequest = MastodonUser.sortedFetchRequest
|
||||||
request.returnsObjectsAsFaults = false
|
userFetchRequest.predicate = MastodonUser.predicate(domain: activeMastodonAuthenticationBox.domain, ids: ids)
|
||||||
|
let mastodonUsers: [MastodonUser]? = {
|
||||||
|
let userFetchRequest = MastodonUser.sortedFetchRequest
|
||||||
|
userFetchRequest.predicate = MastodonUser.predicate(domain: activeMastodonAuthenticationBox.domain, ids: ids)
|
||||||
|
userFetchRequest.returnsObjectsAsFaults = false
|
||||||
do {
|
do {
|
||||||
return try context.managedObjectContext.fetch(request)
|
return try self.context.managedObjectContext.fetch(userFetchRequest)
|
||||||
} catch {
|
} catch {
|
||||||
assertionFailure(error.localizedDescription)
|
assertionFailure(error.localizedDescription)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
if let accounts = users?.map(\.objectID) {
|
if let users = mastodonUsers {
|
||||||
self.accounts.value = accounts
|
let sortedUsers = users.sorted { (user1, user2) -> Bool in
|
||||||
|
(ids.firstIndex(of: user1.id) ?? 0) < (ids.firstIndex(of: user2.id) ?? 0)
|
||||||
|
}
|
||||||
|
accounts.value = sortedUsers.map(\.objectID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,7 +150,6 @@ final class SuggestionAccountViewModel: NSObject {
|
||||||
os_log("%{public}s[%{public}ld], %{public}s: follow failed. %s", (#file as NSString).lastPathComponent, #line, #function, error.localizedDescription)
|
os_log("%{public}s[%{public}ld], %{public}s: follow failed. %s", (#file as NSString).lastPathComponent, #line, #function, error.localizedDescription)
|
||||||
case .finished:
|
case .finished:
|
||||||
self.delegate?.homeTimelineNeedRefresh.send()
|
self.delegate?.homeTimelineNeedRefresh.send()
|
||||||
break
|
|
||||||
}
|
}
|
||||||
} receiveValue: { _ in
|
} receiveValue: { _ in
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue