From 14547a459c44da5f08cc88a1a679a5361dbd2474 Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Mon, 7 Nov 2022 18:51:17 -0800 Subject: [PATCH] Fix up multi channel send --- Meshtastic/Helpers/BLEManager.swift | 18 +++--------------- .../Views/Messages/ChannelMessageList.swift | 4 ++-- .../Views/Messages/UserMessageList.swift | 4 ++-- 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/Meshtastic/Helpers/BLEManager.swift b/Meshtastic/Helpers/BLEManager.swift index 080b3216..f796aeed 100644 --- a/Meshtastic/Helpers/BLEManager.swift +++ b/Meshtastic/Helpers/BLEManager.swift @@ -651,7 +651,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph } } - public func sendMessage(message: String, toUserNum: Int64, isEmoji: Bool, replyID: Int64) -> Bool { + public func sendMessage(message: String, toUserNum: Int64, channel: Int32, isEmoji: Bool, replyID: Int64) -> Bool { var success = false @@ -698,25 +698,13 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph newMessage.messageTimestamp = Int32(Date().timeIntervalSince1970) newMessage.receivedACK = false newMessage.toUser = fetchedUsers.first(where: { $0.num == toUserNum }) + newMessage.fromUser = fetchedUsers.first(where: { $0.num == fromUserNum }) newMessage.isEmoji = isEmoji newMessage.admin = false - + newMessage.channel = channel if replyID > 0 { - newMessage.replyID = replyID } - if newMessage.toUser == nil { - - let bcu: UserEntity = UserEntity(context: context!) - bcu.shortName = "ALL" - bcu.longName = "All - Broadcast" - bcu.hwModel = "UNSET" - bcu.num = Int64(broadcastNodeNum) - bcu.userId = "BROADCASTNODE" - newMessage.toUser = bcu - } - - newMessage.fromUser = fetchedUsers.first(where: { $0.num == fromUserNum }) newMessage.messagePayload = message let dataType = PortNum.textMessageApp diff --git a/Meshtastic/Views/Messages/ChannelMessageList.swift b/Meshtastic/Views/Messages/ChannelMessageList.swift index 5e256313..ec47a979 100644 --- a/Meshtastic/Views/Messages/ChannelMessageList.swift +++ b/Meshtastic/Views/Messages/ChannelMessageList.swift @@ -73,7 +73,7 @@ struct ChannelMessageList: View { Menu("Tapback response") { ForEach(Tapbacks.allCases) { tb in Button(action: { - if bleManager.sendMessage(message: tb.emojiString, toUserNum: Int64(channel.index), isEmoji: true, replyID: message.messageId) { + if bleManager.sendMessage(message: tb.emojiString, toUserNum: 0, channel: channel.index, isEmoji: true, replyID: message.messageId) { print("Sent \(tb.emojiString) Tapback") self.context.refresh(channel, mergeChanges: true) } else { print("\(tb.emojiString) Tapback Failed") } @@ -287,7 +287,7 @@ struct ChannelMessageList: View { .overlay(RoundedRectangle(cornerRadius: 20).stroke(.tertiary, lineWidth: 1)) .padding(.bottom, 15) Button(action: { - if bleManager.sendMessage(message: typingMessage, toUserNum: Int64(channel.index), isEmoji: false, replyID: replyMessageId) { + if bleManager.sendMessage(message: typingMessage, toUserNum: 0, channel: channel.index, isEmoji: false, replyID: replyMessageId) { typingMessage = "" focusedField = nil replyMessageId = 0 diff --git a/Meshtastic/Views/Messages/UserMessageList.swift b/Meshtastic/Views/Messages/UserMessageList.swift index 3e13716c..c083b9da 100644 --- a/Meshtastic/Views/Messages/UserMessageList.swift +++ b/Meshtastic/Views/Messages/UserMessageList.swift @@ -75,7 +75,7 @@ struct UserMessageList: View { Menu("Tapback response") { ForEach(Tapbacks.allCases) { tb in Button(action: { - if bleManager.sendMessage(message: tb.emojiString, toUserNum: user.num, isEmoji: true, replyID: message.messageId) { + if bleManager.sendMessage(message: tb.emojiString, toUserNum: user.num, channel: 0, isEmoji: true, replyID: message.messageId) { print("Sent \(tb.emojiString) Tapback") self.context.refresh(user, mergeChanges: true) } else { print("\(tb.emojiString) Tapback Failed") } @@ -303,7 +303,7 @@ struct UserMessageList: View { .overlay(RoundedRectangle(cornerRadius: 20).stroke(.tertiary, lineWidth: 1)) .padding(.bottom, 15) Button(action: { - if bleManager.sendMessage(message: typingMessage, toUserNum: user.num, isEmoji: false, replyID: replyMessageId) { + if bleManager.sendMessage(message: typingMessage, toUserNum: user.num, channel: 0, isEmoji: false, replyID: replyMessageId) { typingMessage = "" focusedField = nil replyMessageId = 0