Add comprehensive logging and force UI updates for delivery status

- Add logging to track what delivery status is shown in UI
- Add logging when green/blue checkmarks appear
- Force complete dictionary reassignment to trigger SwiftUI updates
- Add diagnostics to understand why blue checkmarks aren't showing
This commit is contained in:
jack
2025-07-06 22:26:56 +02:00
parent c9a594d0b5
commit ab5af1546d
2 changed files with 25 additions and 8 deletions
+18 -8
View File
@@ -946,7 +946,14 @@ class ChatViewModel: ObservableObject {
}
func getPrivateChatMessages(for peerID: String) -> [BitchatMessage] {
return privateChats[peerID] ?? []
let messages = privateChats[peerID] ?? []
if !messages.isEmpty {
print("[UI] Getting \(messages.count) messages for peer \(peerID)")
if let lastMessage = messages.last {
print("[UI] Last message status: \(lastMessage.deliveryStatus?.displayText ?? "none")")
}
}
return messages
}
func getPeerIDForNickname(_ nickname: String) -> String? {
@@ -2135,21 +2142,24 @@ extension ChatViewModel: BitchatDelegate {
}
// Update in private chats
for (peerID, var chatMessages) in privateChats {
var updatedPrivateChats = privateChats
for (peerID, var chatMessages) in updatedPrivateChats {
if let index = chatMessages.firstIndex(where: { $0.id == messageID }) {
var updatedMessage = chatMessages[index]
updatedMessage.deliveryStatus = status
chatMessages[index] = updatedMessage
privateChats[peerID] = chatMessages
updatedPrivateChats[peerID] = chatMessages
print("[Delivery] Updated message in private chat with \(peerID)")
// Force UI update by triggering objectWillChange
DispatchQueue.main.async { [weak self] in
self?.objectWillChange.send()
}
}
}
// Force complete reassignment to trigger SwiftUI update
DispatchQueue.main.async { [weak self] in
guard let self = self else { return }
self.privateChats = updatedPrivateChats
self.objectWillChange.send()
}
// Update in room messages
for (room, var roomMsgs) in roomMessages {
if let index = roomMsgs.firstIndex(where: { $0.id == messageID }) {
+7
View File
@@ -494,6 +494,7 @@ struct ContentView: View {
// Delivery status indicator for private messages
if message.isPrivate && message.sender == viewModel.nickname,
let status = message.deliveryStatus {
let _ = print("[UI] Message \(message.id) has status: \(status)")
DeliveryStatusView(status: status, colorScheme: colorScheme)
.padding(.leading, 4)
.alignmentGuide(.firstTextBaseline) { _ in 12 }
@@ -1104,6 +1105,9 @@ struct DeliveryStatusView: View {
}
.foregroundColor(textColor.opacity(0.8))
.help("Delivered to \(nickname)")
.onAppear {
print("[UI] Showing GREEN checkmarks for delivered status to \(nickname)")
}
case .read(let nickname, _):
HStack(spacing: -2) {
@@ -1114,6 +1118,9 @@ struct DeliveryStatusView: View {
}
.foregroundColor(Color.blue)
.help("Read by \(nickname)")
.onAppear {
print("[UI] Showing BLUE checkmarks for read status by \(nickname)")
}
case .failed(let reason):
Image(systemName: "exclamationmark.triangle")