mirror of
https://github.com/mastodon/mastodon-ios
synced 2025-04-11 22:58:02 +02:00

- Add basic, json-based persistence (it's WIP and pragmatic aka dirty, see FileManager+SearchHistory)
53 lines
1.4 KiB
Swift
53 lines
1.4 KiB
Swift
//
|
|
// DataSourceFacade+SearchHistory.swift
|
|
// Mastodon
|
|
//
|
|
// Created by MainasuK on 2022-1-20.
|
|
//
|
|
|
|
import Foundation
|
|
import CoreDataStack
|
|
import MastodonCore
|
|
import UIKit
|
|
|
|
extension DataSourceFacade {
|
|
|
|
static func responseToCreateSearchHistory(
|
|
provider: ViewControllerWithDependencies & AuthContextProvider,
|
|
item: DataSourceItem
|
|
) async {
|
|
switch item {
|
|
case .account(account: let account, relationship: _):
|
|
let now = Date()
|
|
let userID = provider.authContext.mastodonAuthenticationBox.userID
|
|
let searchEntry = Persistence.SearchHistory.Item(
|
|
updatedAt: now,
|
|
userID: userID,
|
|
account: account,
|
|
hashtag: nil
|
|
)
|
|
|
|
try? FileManager.default.addSearchItem(searchEntry)
|
|
case .hashtag(let tag):
|
|
|
|
let now = Date()
|
|
let userID = provider.authContext.mastodonAuthenticationBox.userID
|
|
let searchEntry = Persistence.SearchHistory.Item(
|
|
updatedAt: now,
|
|
userID: userID,
|
|
account: nil,
|
|
hashtag: tag
|
|
)
|
|
|
|
try? FileManager.default.addSearchItem(searchEntry)
|
|
case .status:
|
|
break
|
|
case .user(_):
|
|
break
|
|
case .notification:
|
|
break
|
|
|
|
}
|
|
}
|
|
}
|