mirror of
https://github.com/mastodon/mastodon-ios
synced 2025-04-11 22:58:02 +02:00
Make search work with different accounts (IOS-196)
This commit is contained in:
parent
1514e5a2c2
commit
a44d4eed47
@ -5,6 +5,10 @@ import MastodonCore
|
||||
|
||||
extension FileManager {
|
||||
func searchItems(forUser userID: String) throws -> [Persistence.SearchHistory.Item] {
|
||||
return try searchItems().filter { $0.userID == userID }
|
||||
}
|
||||
|
||||
func searchItems() throws -> [Persistence.SearchHistory.Item] {
|
||||
guard let documentsDirectory else { return [] }
|
||||
|
||||
let searchHistoryPath = Persistence.searchHistory.filepath(baseURL: documentsDirectory)
|
||||
@ -16,7 +20,6 @@ extension FileManager {
|
||||
|
||||
do {
|
||||
let searchItems = try jsonDecoder.decode([Persistence.SearchHistory.Item].self, from: data)
|
||||
.filter { $0.userID == userID }
|
||||
.sorted { $0.updatedAt > $1.updatedAt }
|
||||
|
||||
return searchItems
|
||||
@ -28,7 +31,7 @@ extension FileManager {
|
||||
func addSearchItem(_ newSearchItem: Persistence.SearchHistory.Item) throws {
|
||||
guard let documentsDirectory else { return }
|
||||
|
||||
var searchItems = (try? searchItems(forUser: newSearchItem.userID)) ?? []
|
||||
var searchItems = (try? searchItems()) ?? []
|
||||
|
||||
if let index = searchItems.firstIndex(of: newSearchItem) {
|
||||
searchItems.remove(at: index)
|
||||
|
@ -19,7 +19,7 @@ extension Persistence.SearchHistory {
|
||||
}
|
||||
|
||||
public static func == (lhs: Persistence.SearchHistory.Item, rhs: Persistence.SearchHistory.Item) -> Bool {
|
||||
return lhs.account == rhs.account && lhs.hashtag == rhs.hashtag
|
||||
return lhs.account == rhs.account && lhs.hashtag == rhs.hashtag && lhs.userID == rhs.userID
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user