mirror of
https://github.com/mastodon/mastodon-ios.git
synced 2024-12-24 16:01:52 +01:00
Clean search-history for one user only (IOS-196)
This commit is contained in:
parent
a44d4eed47
commit
361ad357db
@ -39,23 +39,32 @@ extension FileManager {
|
||||
|
||||
searchItems.append(newSearchItem)
|
||||
|
||||
storeJSON(searchItems, .searchHistory)
|
||||
}
|
||||
|
||||
private func storeJSON(_ encodable: Encodable, _ persistence: Persistence) {
|
||||
guard let documentsDirectory else { return }
|
||||
|
||||
let jsonEncoder = JSONEncoder()
|
||||
jsonEncoder.dateEncodingStrategy = .iso8601
|
||||
do {
|
||||
let data = try jsonEncoder.encode(searchItems)
|
||||
let data = try jsonEncoder.encode(encodable)
|
||||
|
||||
let searchHistoryPath = Persistence.searchHistory.filepath(baseURL: documentsDirectory)
|
||||
let searchHistoryPath = persistence.filepath(baseURL: documentsDirectory)
|
||||
try data.write(to: searchHistoryPath)
|
||||
} catch {
|
||||
debugPrint(error.localizedDescription)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func removeSearchHistory() {
|
||||
func removeSearchHistory(forUser userID: String) {
|
||||
guard let documentsDirectory else { return }
|
||||
|
||||
let searchHistoryPath = Persistence.searchHistory.filepath(baseURL: documentsDirectory)
|
||||
try? removeItem(at: searchHistoryPath)
|
||||
var searchItems = (try? searchItems()) ?? []
|
||||
let newSearchItems = searchItems.filter { $0.userID != userID }
|
||||
|
||||
storeJSON(newSearchItems, .searchHistory)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -98,7 +98,9 @@ extension SearchHistoryViewController: SearchHistorySectionHeaderCollectionReusa
|
||||
_ searchHistorySectionHeaderCollectionReusableView: SearchHistorySectionHeaderCollectionReusableView,
|
||||
clearButtonDidPressed button: UIButton
|
||||
) {
|
||||
FileManager.default.removeSearchHistory()
|
||||
let userID = authContext.mastodonAuthenticationBox.userID
|
||||
|
||||
FileManager.default.removeSearchHistory(forUser: userID)
|
||||
viewModel.items = []
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user