Skip to content

Commit 508c5a3

Browse files
committed
Refresh channel messages after retry
1 parent e169b28 commit 508c5a3

4 files changed

Lines changed: 27 additions & 11 deletions

File tree

Meshtastic/Views/Messages/ChannelMessageList.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,9 @@ struct ChannelMessageList: View {
372372
}
373373
#endif
374374
}
375+
},
376+
onMessageRetried: {
377+
loadMessages(markReadAfterLoad: routerIsShowingThisChannel())
375378
}
376379
)
377380

Meshtastic/Views/Messages/ChannelMessageRow.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ struct ChannelMessageRow: View {
2020
@Binding var messageToHighlight: Int64
2121
let scrollView: ScrollViewProxy
2222
let onTapback: (MessageEntity) -> Void
23+
let onMessageRetried: () -> Void
2324

2425
private var isCurrentUser: Bool {
2526
Int64(preferredPeripheralNum) == message.fromUser?.num
@@ -35,7 +36,8 @@ struct ChannelMessageRow: View {
3536
messageFieldFocused: FocusState<Bool>.Binding,
3637
messageToHighlight: Binding<Int64>,
3738
scrollView: ScrollViewProxy,
38-
onTapback: @escaping (MessageEntity) -> Void) {
39+
onTapback: @escaping (MessageEntity) -> Void,
40+
onMessageRetried: @escaping () -> Void = {}) {
3941
// Initialize ObservedObject with the concrete instance
4042
self.message = message
4143
self.replyMessage = replyMessage
@@ -48,6 +50,7 @@ struct ChannelMessageRow: View {
4850
self._messageToHighlight = messageToHighlight
4951
self.scrollView = scrollView
5052
self.onTapback = onTapback
53+
self.onMessageRetried = onMessageRetried
5154
}
5255

5356
var body: some View {
@@ -142,7 +145,12 @@ struct ChannelMessageRow: View {
142145
}
143146

144147
if let deliveryStatus, deliveryStatus.canRetry {
145-
RetryButton(message: message, destination: .channel(channel), status: deliveryStatus)
148+
RetryButton(
149+
message: message,
150+
destination: .channel(channel),
151+
status: deliveryStatus,
152+
onMessageSent: onMessageRetried
153+
)
146154
}
147155
}
148156

Meshtastic/Views/Messages/RetryButton.swift

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,21 @@ struct RetryButton: View {
88
let message: MessageEntity
99
let destination: MessageDestination
1010
let status: MessageDeliveryStatus
11+
let onMessageSent: (() -> Void)?
1112
@State private var isShowingDetails = false
1213

14+
init(
15+
message: MessageEntity,
16+
destination: MessageDestination,
17+
status: MessageDeliveryStatus,
18+
onMessageSent: (() -> Void)? = nil
19+
) {
20+
self.message = message
21+
self.destination = destination
22+
self.status = status
23+
self.onMessageSent = onMessageSent
24+
}
25+
1326
var body: some View {
1427
Button {
1528
isShowingDetails = true
@@ -52,11 +65,7 @@ struct RetryButton: View {
5265
try await accessoryManager.sendMessage(message: payload, toUserNum: userNum, channel: channel,
5366
isEmoji: isEmoji, replyID: replyID)
5467
if case .channel = destination {
55-
// We must refresh the channel to trigger a view update since its relationship
56-
// to messages is via a weak fetched property which is not updated by
57-
// `bleManager.sendMessage` unlike the user entity.
58-
Task { @MainActor in
59-
}
68+
await MainActor.run { onMessageSent?() }
6069
}
6170
} catch {
6271
// Best effort

MeshtasticTests/RoutingAndMiscTests.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@ struct RoutingErrorDetailedTests {
8181
}
8282
}
8383

84-
@Test func description_noChannelUsesSourceBackedMeaning() {
85-
#expect(RoutingError.noChannel.description == "The sender or recipient could not use a matching channel/key for this message.")
86-
}
87-
8884
@Test func description_usesActionableDesignIssueWording() {
8985
let expected: [(RoutingError, String)] = [
9086
(.maxRetransmit, "No node confirmed this message. Try again when you have better signal or more mesh coverage."),

0 commit comments

Comments
 (0)