initial commit: Proximity iOS app proposal, full Swift code scaffold, reference backend, testing docs, generated Xcode project
This commit is contained in:
44
Proximity/Services/Network/GraphStore.swift
Normal file
44
Proximity/Services/Network/GraphStore.swift
Normal file
@@ -0,0 +1,44 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user