45 lines
1.2 KiB
Swift
45 lines
1.2 KiB
Swift
import Foundation
|
|
import SwiftData
|
|
|
|
/// Local persistence for the encounter graph using SwiftData (SQLite-backed).
|
|
///
|
|
/// The graph lives **on-device** by default. The user is in control of what
|
|
/// syncs to the server. Encounters are stored as anonymous silhouettes until
|
|
/// mutual consent promotes them to revealed connections.
|
|
@Model
|
|
final class GraphStore {
|
|
|
|
var encounters: [Encounter] = []
|
|
var connections: [Connection] = []
|
|
var messages: [ChatMessage] = []
|
|
|
|
init() {}
|
|
|
|
// MARK: - Encounters
|
|
|
|
func addEncounter(_ encounter: Encounter) {
|
|
encounters.insert(encounter, at: 0)
|
|
}
|
|
|
|
func encounter(byToken token: String) -> Encounter? {
|
|
encounters.first { $0.remoteAnonToken == token }
|
|
}
|
|
|
|
func updateStatus(_ status: EncounterStatus, for token: String) {
|
|
guard let idx = encounters.firstIndex(where: { $0.remoteAnonToken == token }) else { return }
|
|
encounters[idx].status = status
|
|
}
|
|
|
|
// MARK: - Connections
|
|
|
|
func addConnection(_ connection: Connection) {
|
|
connections.insert(connection, at: 0)
|
|
}
|
|
|
|
// MARK: - Messages
|
|
|
|
func addMessage(_ message: ChatMessage) {
|
|
messages.append(message)
|
|
}
|
|
}
|