Add visual save indicator button for rooms

- Add bookmark icon button in room header to toggle save status
- Use bookmark.fill when room is saved, bookmark when not
- Button shows yellow when saved, default color when not
- Integrate with existing /save command functionality
- Add savedRooms published property for reactive UI updates
This commit is contained in:
jack
2025-07-05 19:35:37 +02:00
parent e6aced4cb4
commit f7ebcd6032
2 changed files with 20 additions and 0 deletions
+10
View File
@@ -48,6 +48,7 @@ class ChatViewModel: ObservableObject {
@Published var roomKeyCommitments: [String: String] = [:] // room -> SHA256(derivedKey) for verification
@Published var showPasswordPrompt: Bool = false
@Published var passwordPromptRoom: String? = nil
@Published var savedRooms: Set<String> = [] // Rooms saved for message retention
let meshService = BluetoothMeshService()
private let userDefaults = UserDefaults.standard
@@ -70,6 +71,7 @@ class ChatViewModel: ObservableObject {
loadFavorites()
loadJoinedRooms()
loadRoomData()
savedRooms = MessageRetentionService.shared.getFavoriteRooms()
meshService.delegate = self
// Log startup info
@@ -930,6 +932,7 @@ class ChatViewModel: ObservableObject {
// Clear all retained messages
MessageRetentionService.shared.deleteAllStoredMessages()
savedRooms.removeAll()
// Clear message retry queue
MessageRetryService.shared.clearRetryQueue()
@@ -1590,6 +1593,13 @@ extension ChatViewModel: BitchatDelegate {
let isFavorite = MessageRetentionService.shared.toggleFavoriteRoom(room)
let status = isFavorite ? "saved" : "unsaved"
// Update published property
if isFavorite {
savedRooms.insert(room)
} else {
savedRooms.remove(room)
}
// If just marked as favorite, load any previously saved messages
if isFavorite {
let savedMessages = MessageRetentionService.shared.loadMessagesForRoom(room)
+10
View File
@@ -296,6 +296,16 @@ struct ContentView: View {
Spacer()
HStack(spacing: 8) {
// Save button
Button(action: {
viewModel.sendMessage("/save")
}) {
Image(systemName: viewModel.savedRooms.contains(currentRoom) ? "bookmark.fill" : "bookmark")
.font(.system(size: 16))
.foregroundColor(viewModel.savedRooms.contains(currentRoom) ? Color.yellow : textColor)
}
.buttonStyle(.plain)
// Password button for room creator only
if viewModel.roomCreators[currentRoom] == viewModel.meshService.myPeerID {
Button(action: {