KDChat/KDChat/KDChatApp.swift
Blake Oliver 8a39e5939f
Add swiftData message persistence and reactive side effects
Persistence:
- SavedMessage SwiftData model with index on [buffer, timestamp]
- @Query in ChatBufferView/DMListView/DMConversationView — SwiftData is the single source of truth, no in-memory dictionary
- Settings: Save Messages toggle, Save Debug Buffer toggle, Delete After picker (1d/1w/1m/1y/never), Delete All with confirmation dialog
- Expired and debug messages purged on launch based on settings
- Say messages go to debug buffer only (not all buffers)

Reactive side effects:
- Sound, haptic, and VoiceOver announcement all fire from ChatBufferView's onChange(of: messages.count)
- Sound plays for active buffer or background buffers if enabled
- Haptic and announcement fire on active buffer only, current session only (I'll add a toggle to announce other buffers next)
- Status haptic for Say messages stays imperative in model (global event, not per-buffer)
- Removed trigger counters and lastAnnouncement from ConnectionManager

DM conversation fix:
- Track DM recipient via lastDMRecipientId; tag outgoing echoes with partner ID in characterId
- Conversation view filters on characterId == partnerId (shows only that conversation)

Other:
- modelContext set in ContentView.onAppear (available for all screens)
- Instant scroll (no animation), respects Reduce Motion
2026-04-05 18:46:38 -06:00

19 lines
375 B
Swift

import SwiftData
import SwiftUI
@main
struct KDChatApp: App {
@State private var connectionManager = ConnectionManager()
init() {
SoundPlayer.configureSession()
}
var body: some Scene {
WindowGroup {
ContentView()
.environment(connectionManager)
}
.modelContainer(for: SavedMessage.self)
}
}