From 10359784f77a8f168b9f6b4002f3075a65d3df5e Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Sun, 21 Jan 2024 17:42:23 -0800 Subject: [PATCH] Set tapbacks to read as scrolling by in messages --- .../Views/Messages/ChannelMessageList.swift | 15 +++++++++++++++ Meshtastic/Views/Messages/UserMessageList.swift | 14 ++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/Meshtastic/Views/Messages/ChannelMessageList.swift b/Meshtastic/Views/Messages/ChannelMessageList.swift index be590909..e1a8811d 100644 --- a/Meshtastic/Views/Messages/ChannelMessageList.swift +++ b/Meshtastic/Views/Messages/ChannelMessageList.swift @@ -190,6 +190,20 @@ struct ChannelMessageList: View { .fixedSize() .padding(.bottom, 1) } + .onAppear { + if !tapback.read { + tapback.read = true + do { + try context.save() + print("📖 Read message \(message.messageId) ") + appState.unreadChannelMessages = myInfo.unreadMessages + UIApplication.shared.applicationIconBadgeNumber = appState.unreadChannelMessages + appState.unreadDirectMessages + context.refresh(myInfo, mergeChanges: true) + } catch { + print("Failed to read tapback \(tapback.messageId)") + } + } + } } } .padding(10) @@ -199,6 +213,7 @@ struct ChannelMessageList: View { ) } } + HStack { if currentUser && message.receivedACK { // Ack Received diff --git a/Meshtastic/Views/Messages/UserMessageList.swift b/Meshtastic/Views/Messages/UserMessageList.swift index 8116f7fd..d0c9c0e1 100644 --- a/Meshtastic/Views/Messages/UserMessageList.swift +++ b/Meshtastic/Views/Messages/UserMessageList.swift @@ -167,6 +167,20 @@ struct UserMessageList: View { .fixedSize() .padding(.bottom, 1) } + .onAppear { + if !tapback.read { + tapback.read = true + do { + try context.save() + print("📖 Read tapback \(tapback.messageId) ") + appState.unreadDirectMessages = user.unreadMessages + UIApplication.shared.applicationIconBadgeNumber = appState.unreadChannelMessages + appState.unreadDirectMessages + + } catch { + print("Failed to read tapback \(tapback.messageId)") + } + } + } } } .padding(10)