Files
andros a31bc807cb Initial iOS port of meshmonitor-chat.el
SwiftUI app for the MeshMonitor REST API: setup screen with token
storage in Keychain, welcome dashboard mirroring the Emacs welcome
buffer, and channel/node/DM/unread lists with a shared chat view
supporting both channel and direct messages.
2026-04-14 15:30:21 +02:00

35 lines
815 B
Swift

import Foundation
import Observation
@Observable
final class ReadTracker {
private static let storeKey = "mm.readTimestamps"
private(set) var timestamps: [String: TimeInterval]
init() {
let raw = UserDefaults.standard.dictionary(forKey: Self.storeKey) ?? [:]
var dict: [String: TimeInterval] = [:]
for (k, v) in raw {
if let n = v as? Double { dict[k] = n }
else if let n = v as? Int { dict[k] = TimeInterval(n) }
}
self.timestamps = dict
}
func lastRead(for nodeId: String) -> TimeInterval {
timestamps[nodeId] ?? 0
}
func markRead(_ nodeId: String, at time: Date) {
let ts = time.timeIntervalSince1970
if (timestamps[nodeId] ?? 0) < ts {
timestamps[nodeId] = ts
persist()
}
}
private func persist() {
UserDefaults.standard.set(timestamps, forKey: Self.storeKey)
}
}