From 463e8230eef6432db68fb721b4bcd4956f93ea1e Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Thu, 29 Dec 2022 16:26:00 -0800 Subject: [PATCH] * Real Ack UI and data structure for DM's * Save canned messages messages to core data --- Meshtastic.xcodeproj/project.pbxproj | 4 +- Meshtastic/Helpers/MeshPackets.swift | 39 ++- .../Meshtastic.xcdatamodeld/.xccurrentversion | 2 +- .../contents | 279 ++++++++++++++++++ .../Views/Messages/UserMessageList.swift | 3 +- .../Config/Module/CannedMessagesConfig.swift | 6 + de.lproj/Localizable.strings | 1 + en.lproj/Localizable.strings | 1 + 8 files changed, 329 insertions(+), 6 deletions(-) create mode 100644 Meshtastic/Meshtastic.xcdatamodeld/MeshtasticDataModelV5.xcdatamodel/contents diff --git a/Meshtastic.xcodeproj/project.pbxproj b/Meshtastic.xcodeproj/project.pbxproj index 50e4621a..ab1f5b8b 100644 --- a/Meshtastic.xcodeproj/project.pbxproj +++ b/Meshtastic.xcodeproj/project.pbxproj @@ -152,6 +152,7 @@ DD415827285859C4009B0E59 /* TelemetryConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TelemetryConfig.swift; sourceTree = ""; }; DD41582928585C32009B0E59 /* RangeTestConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RangeTestConfig.swift; sourceTree = ""; }; DD457187293C7E63000C49FB /* SignalStrengthIndicator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignalStrengthIndicator.swift; sourceTree = ""; }; + DD457BC4295D5E35004BCE4D /* MeshtasticDataModelV5.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = MeshtasticDataModelV5.xcdatamodel; sourceTree = ""; }; DD47E3CD26F103C600029299 /* NodeList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NodeList.swift; sourceTree = ""; }; DD47E3D526F17ED900029299 /* CircleText.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CircleText.swift; sourceTree = ""; }; DD47E3D826F3093800029299 /* MessageBubble.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageBubble.swift; sourceTree = ""; }; @@ -1210,12 +1211,13 @@ DD3CC6BA28E366DF00FA9159 /* Meshtastic.xcdatamodeld */ = { isa = XCVersionGroup; children = ( + DD457BC4295D5E35004BCE4D /* MeshtasticDataModelV5.xcdatamodel */, DDEE03EC29544A1000FCAD57 /* MeshtasticDataModelV4.xcdatamodel */, DDCDC69A29467643004C1DDA /* MeshtasticDataModelV3.xcdatamodel */, DD5D0A9A2931AD6B00F7EA61 /* MeshtasticDataModelV2.xcdatamodel */, DD3CC6BB28E366DF00FA9159 /* MeshtasticDataModel.xcdatamodel */, ); - currentVersion = DDEE03EC29544A1000FCAD57 /* MeshtasticDataModelV4.xcdatamodel */; + currentVersion = DD457BC4295D5E35004BCE4D /* MeshtasticDataModelV5.xcdatamodel */; name = Meshtastic.xcdatamodeld; path = Meshtastic/Meshtastic.xcdatamodeld; sourceTree = ""; diff --git a/Meshtastic/Helpers/MeshPackets.swift b/Meshtastic/Helpers/MeshPackets.swift index f6336b9a..0606f543 100644 --- a/Meshtastic/Helpers/MeshPackets.swift +++ b/Meshtastic/Helpers/MeshPackets.swift @@ -1076,9 +1076,35 @@ func nodeInfoAppPacket (packet: MeshPacket, context: NSManagedObjectContext) { } func adminAppPacket (packet: MeshPacket, context: NSManagedObjectContext) { - - if let messages = try? CannedMessageModuleConfig(serializedData: packet.decoded.payload) { - print(messages) + if let cmmc = try? CannedMessageModuleConfig(serializedData: packet.decoded.payload) { + + let fetchNodeRequest: NSFetchRequest = NSFetchRequest.init(entityName: "NodeInfoEntity") + fetchNodeRequest.predicate = NSPredicate(format: "num == %lld", Int64(packet.from)) + + do { + let fetchedNode = try context.fetch(fetchNodeRequest) as! [NodeInfoEntity] + if fetchedNode.count == 1 { + + let messages = String(cmmc.textFormatString()) + .replacingOccurrences(of: "11: ", with: "") + .replacingOccurrences(of: "\"", with: "") + .trimmingCharacters(in: .whitespacesAndNewlines) + fetchedNode[0].cannedMessageConfig?.messages = messages + do { + try context.save() + MeshLogger.log("💾 Updated Canned Messages Messages For: \(fetchedNode[0].num)") + } catch { + + context.rollback() + + let nsError = error as NSError + print("💥 Error Saving NodeInfoEntity from POSITION_APP \(nsError)") + } + } + + } catch { + print("💥 Error Deserializing POSITION_APP packet.") + } } } @@ -1184,6 +1210,13 @@ func routingPacket (packet: MeshPacket, connectedNodeNum: Int64, context: NSMana do { let fetchedMessage = try context.fetch(fetchMessageRequest) as? [MessageEntity] if fetchedMessage?.count ?? 0 > 0 { + + if fetchedMessage![0].toUser != nil { + // Real ACK from DM Recipient + if packet.to != packet.from { + fetchedMessage![0].realACK = true + } + } fetchedMessage![0].ackError = Int32(routingMessage.errorReason.rawValue) if routingMessage.errorReason == Routing.Error.none { diff --git a/Meshtastic/Meshtastic.xcdatamodeld/.xccurrentversion b/Meshtastic/Meshtastic.xcdatamodeld/.xccurrentversion index a8bccd83..1b3c637e 100644 --- a/Meshtastic/Meshtastic.xcdatamodeld/.xccurrentversion +++ b/Meshtastic/Meshtastic.xcdatamodeld/.xccurrentversion @@ -3,6 +3,6 @@ _XCCurrentVersionName - MeshtasticDataModelV4.xcdatamodel + MeshtasticDataModelV5.xcdatamodel diff --git a/Meshtastic/Meshtastic.xcdatamodeld/MeshtasticDataModelV5.xcdatamodel/contents b/Meshtastic/Meshtastic.xcdatamodeld/MeshtasticDataModelV5.xcdatamodel/contents new file mode 100644 index 00000000..1f463d49 --- /dev/null +++ b/Meshtastic/Meshtastic.xcdatamodeld/MeshtasticDataModelV5.xcdatamodel/contents @@ -0,0 +1,279 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Meshtastic/Views/Messages/UserMessageList.swift b/Meshtastic/Views/Messages/UserMessageList.swift index 83fd25f3..a9452616 100644 --- a/Meshtastic/Views/Messages/UserMessageList.swift +++ b/Meshtastic/Views/Messages/UserMessageList.swift @@ -116,6 +116,7 @@ struct UserMessageList: View { if currentUser && message.receivedACK { VStack { Text("received.ack")+Text(" \(message.receivedACK ? "✔️" : "")") + Text("received.ack.real")+Text(" \(message.realACK ? "✔️" : "")") } } else if currentUser && message.ackError == 0 { // Empty Error @@ -181,7 +182,7 @@ struct UserMessageList: View { let ackErrorVal = RoutingError(rawValue: Int(message.ackError)) if currentUser && message.receivedACK { // Ack Received - Text("\(ackErrorVal?.display ?? "No Error" )").font(.caption2).foregroundColor(.gray) + Text("\(ackErrorVal?.display ?? "No Error" )").font(.caption2).foregroundColor(message.realACK ? .gray : .orange) } else if currentUser && message.ackError == 0 { // Empty Error Text("Waiting to be acknowledged. . .").font(.caption2).foregroundColor(.orange) diff --git a/Meshtastic/Views/Settings/Config/Module/CannedMessagesConfig.swift b/Meshtastic/Views/Settings/Config/Module/CannedMessagesConfig.swift index a7b16b39..65922a38 100644 --- a/Meshtastic/Views/Settings/Config/Module/CannedMessagesConfig.swift +++ b/Meshtastic/Views/Settings/Config/Module/CannedMessagesConfig.swift @@ -261,6 +261,10 @@ struct CannedMessagesConfig: View { // Should show a saved successfully alert once I know that to be true // for now just disable the button after a successful save hasMessagesChanges = false + if !hasChanges { + bleManager.sendReboot(destNum: node!.num) + goBack() + } } } } @@ -282,7 +286,9 @@ struct CannedMessagesConfig: View { self.inputbrokerEventCw = Int(node?.cannedMessageConfig?.inputbrokerEventCw ?? 0) self.inputbrokerEventCcw = Int(node?.cannedMessageConfig?.inputbrokerEventCcw ?? 0) self.inputbrokerEventPress = Int(node?.cannedMessageConfig?.inputbrokerEventPress ?? 0) + self.messages = node?.cannedMessageConfig?.messages ?? "" self.hasChanges = false + self.hasMessagesChanges = false } .onChange(of: configPreset) { newPreset in diff --git a/de.lproj/Localizable.strings b/de.lproj/Localizable.strings index bde184d0..bc42706c 100644 --- a/de.lproj/Localizable.strings +++ b/de.lproj/Localizable.strings @@ -133,6 +133,7 @@ "range.test.config"="Entfernungstest Konfiguration"; "reply"="Antworten"; "received.ack"="Empfangsbestätigung"; +"received.ack.real"="Recipient Ack"; "routing.acknowledged"="Bestätigt"; "routing.noroute"="Keine Route"; "routing.gotnak"="Negative Empfangsbestätigung empfangen"; diff --git a/en.lproj/Localizable.strings b/en.lproj/Localizable.strings index dbe62ed9..0f9c881e 100644 --- a/en.lproj/Localizable.strings +++ b/en.lproj/Localizable.strings @@ -133,6 +133,7 @@ "range.test.config"="Range Test Config"; "reply"="Reply"; "received.ack"="Received Ack"; +"received.ack.real"="Recipient Ack"; "routing.acknowledged"="Acknowledged"; "routing.noroute"="No Route"; "routing.gotnak"="Received a negative acknowledgment";