mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 19:05:20 +00:00
Fix UI not updating for delivery status changes
- Use message ID instead of index for ForEach to trigger proper updates - Add explicit objectWillChange.send() when updating delivery status - Fix scroll-to-bottom logic to use message IDs - This should make blue checkmarks appear when read receipts are received
This commit is contained in:
@@ -2142,6 +2142,11 @@ extension ChatViewModel: BitchatDelegate {
|
|||||||
chatMessages[index] = updatedMessage
|
chatMessages[index] = updatedMessage
|
||||||
privateChats[peerID] = chatMessages
|
privateChats[peerID] = chatMessages
|
||||||
print("[Delivery] Updated message in private chat with \(peerID)")
|
print("[Delivery] Updated message in private chat with \(peerID)")
|
||||||
|
|
||||||
|
// Force UI update by triggering objectWillChange
|
||||||
|
DispatchQueue.main.async { [weak self] in
|
||||||
|
self?.objectWillChange.send()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2152,6 +2157,11 @@ extension ChatViewModel: BitchatDelegate {
|
|||||||
updatedMessage.deliveryStatus = status
|
updatedMessage.deliveryStatus = status
|
||||||
roomMsgs[index] = updatedMessage
|
roomMsgs[index] = updatedMessage
|
||||||
roomMessages[room] = roomMsgs
|
roomMessages[room] = roomMsgs
|
||||||
|
|
||||||
|
// Force UI update
|
||||||
|
DispatchQueue.main.async { [weak self] in
|
||||||
|
self?.objectWillChange.send()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -439,7 +439,7 @@ struct ContentView: View {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
ForEach(Array(messages.enumerated()), id: \.offset) { index, message in
|
ForEach(messages, id: \.id) { message in
|
||||||
VStack(alignment: .leading, spacing: 4) {
|
VStack(alignment: .leading, spacing: 4) {
|
||||||
// Check if current user is mentioned
|
// Check if current user is mentioned
|
||||||
let isMentioned = message.mentions?.contains(viewModel.nickname) ?? false
|
let isMentioned = message.mentions?.contains(viewModel.nickname) ?? false
|
||||||
@@ -505,16 +505,16 @@ struct ContentView: View {
|
|||||||
}
|
}
|
||||||
.padding(.horizontal, 12)
|
.padding(.horizontal, 12)
|
||||||
.padding(.vertical, 2)
|
.padding(.vertical, 2)
|
||||||
.id(index)
|
.id(message.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.padding(.vertical, 8)
|
.padding(.vertical, 8)
|
||||||
}
|
}
|
||||||
.background(backgroundColor)
|
.background(backgroundColor)
|
||||||
.onChange(of: viewModel.messages.count) { _ in
|
.onChange(of: viewModel.messages.count) { _ in
|
||||||
if viewModel.selectedPrivateChatPeer == nil {
|
if viewModel.selectedPrivateChatPeer == nil && !viewModel.messages.isEmpty {
|
||||||
withAnimation {
|
withAnimation {
|
||||||
proxy.scrollTo(viewModel.messages.count - 1, anchor: .bottom)
|
proxy.scrollTo(viewModel.messages.last?.id, anchor: .bottom)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -523,7 +523,7 @@ struct ContentView: View {
|
|||||||
let messages = viewModel.privateChats[peerID],
|
let messages = viewModel.privateChats[peerID],
|
||||||
!messages.isEmpty {
|
!messages.isEmpty {
|
||||||
withAnimation {
|
withAnimation {
|
||||||
proxy.scrollTo(messages.count - 1, anchor: .bottom)
|
proxy.scrollTo(messages.last?.id, anchor: .bottom)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user