From a16c6be659b1b59de3fcf74e36cd180132d695aa Mon Sep 17 00:00:00 2001 From: Austin Payne Date: Wed, 21 Feb 2024 00:28:55 -0700 Subject: [PATCH] fix: channel message retry not updating ack state --- Meshtastic/Views/Messages/ChannelMessageList.swift | 2 +- Meshtastic/Views/Messages/RetryButton.swift | 11 +++++++++++ Meshtastic/Views/Messages/UserMessageList.swift | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Meshtastic/Views/Messages/ChannelMessageList.swift b/Meshtastic/Views/Messages/ChannelMessageList.swift index d645b613..22438b6c 100644 --- a/Meshtastic/Views/Messages/ChannelMessageList.swift +++ b/Meshtastic/Views/Messages/ChannelMessageList.swift @@ -64,7 +64,7 @@ struct ChannelMessageList: View { } if currentUser && message.canRetry { - RetryButton(message: message) + RetryButton(message: message, destination: .channel(channel)) } } diff --git a/Meshtastic/Views/Messages/RetryButton.swift b/Meshtastic/Views/Messages/RetryButton.swift index 116a31c1..1e2065bd 100644 --- a/Meshtastic/Views/Messages/RetryButton.swift +++ b/Meshtastic/Views/Messages/RetryButton.swift @@ -5,6 +5,7 @@ struct RetryButton: View { @EnvironmentObject var bleManager: BLEManager let message: MessageEntity + let destination: MessageDestination @State var isShowingConfirmation = false var body: some View { @@ -46,6 +47,16 @@ struct RetryButton: View { ) { // Best effort, unlikely since we already checked BLE state print("Failed to resend message \(messageID)") + } else { + switch destination { + case .user: + break + case let .channel(channel): + // We must refresh the channel to trigger a view update since its relationship + // to messages is via a weak fetched property which is not updated by + // `bleManager.sendMessage` unlike the user entity. + context.refresh(channel, mergeChanges: true) + } } } Button("Cancel", role: .cancel) {} diff --git a/Meshtastic/Views/Messages/UserMessageList.swift b/Meshtastic/Views/Messages/UserMessageList.swift index 7816167d..7f0660ee 100644 --- a/Meshtastic/Views/Messages/UserMessageList.swift +++ b/Meshtastic/Views/Messages/UserMessageList.swift @@ -57,7 +57,7 @@ struct UserMessageList: View { } if currentUser && message.canRetry || (message.receivedACK && !message.realACK) { - RetryButton(message: message) + RetryButton(message: message, destination: .user(user)) } }