Replace items instead of adding them (IOS-196)

This commit is contained in:
Nathan Mattes 2023-11-23 14:28:55 +01:00
parent 59c6d31ca4
commit 6b0fe64262
2 changed files with 15 additions and 1 deletions

View File

@ -28,6 +28,10 @@ extension FileManager {
var searchItems = (try? searchItems(forUser: newSearchItem.userID)) ?? []
if let index = searchItems.firstIndex(of: newSearchItem) {
searchItems.remove(at: index)
}
searchItems.append(newSearchItem)
let jsonEncoder = JSONEncoder()

View File

@ -5,11 +5,21 @@ import MastodonCore
import MastodonSDK
extension Persistence.SearchHistory {
struct Item: Codable {
struct Item: Codable, Hashable, Equatable {
let updatedAt: Date
let userID: Mastodon.Entity.Account.ID
let account: Mastodon.Entity.Account?
let hashtag: Mastodon.Entity.Tag?
func hash(into hasher: inout Hasher) {
hasher.combine(userID)
hasher.combine(account)
hasher.combine(hashtag)
}
public static func == (lhs: Persistence.SearchHistory.Item, rhs: Persistence.SearchHistory.Item) -> Bool {
return lhs.account == rhs.account && lhs.hashtag == rhs.hashtag
}
}
}