version 1.0
This commit is contained in:
@@ -32,9 +32,11 @@ struct ChatView: View {
|
||||
}
|
||||
.onAppear {
|
||||
scrollToLatest(using: proxy)
|
||||
Task { await session.markVisibleMessagesRead() }
|
||||
}
|
||||
.onChange(of: session.messages.last?.id) { _, _ in
|
||||
scrollToLatest(using: proxy)
|
||||
Task { await session.markVisibleMessagesRead() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,6 +53,12 @@ struct SettingsView: View {
|
||||
Text(appVersion)
|
||||
}
|
||||
}
|
||||
|
||||
Section {
|
||||
Button("Quit Fchati", role: .destructive) {
|
||||
NSApplication.shared.terminate(nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
.formStyle(.grouped)
|
||||
.padding()
|
||||
|
||||
@@ -101,6 +101,17 @@ final class AppSession: ObservableObject {
|
||||
try await sendAndStore(message)
|
||||
}
|
||||
|
||||
func markVisibleMessagesRead() async {
|
||||
let unread = messages.filter { !$0.isRead && $0.from != KeychainStore.installationID }
|
||||
guard !unread.isEmpty else { return }
|
||||
|
||||
let ids = unread.map { $0.id }
|
||||
ids.forEach { markMessageAsRead(id: $0) }
|
||||
|
||||
let receipt = WSMessage(type: "read", messageIDs: ids)
|
||||
try? await webSocket.send(receipt)
|
||||
}
|
||||
|
||||
func unpair() {
|
||||
incomingMessagesTask?.cancel()
|
||||
incomingMessagesTask = nil
|
||||
@@ -192,6 +203,14 @@ final class AppSession: ObservableObject {
|
||||
await storeIncomingMessage(chatMessage)
|
||||
NotificationManager.shared.notify(from: chatMessage.fromName, body: chatMessage.body)
|
||||
|
||||
case "peer.joined":
|
||||
// The partner just came online — save their identity and transition to connected.
|
||||
if let peerID = message.peerID, let peerName = message.fromName {
|
||||
KeychainStore.peerID = peerID
|
||||
KeychainStore.peerName = peerName
|
||||
state = .connected(peerID: peerID, peerName: peerName)
|
||||
}
|
||||
|
||||
case "read":
|
||||
for id in message.messageIDs ?? [] {
|
||||
markMessageAsRead(id: id)
|
||||
|
||||
Reference in New Issue
Block a user