From e17091ff4fa9a3c291216be0c55ea9d81300bfff Mon Sep 17 00:00:00 2001 From: Garth Vander Houwen Date: Sat, 1 Jan 2022 19:08:36 -0800 Subject: [PATCH] V 1.43 Build 2 - Complete DM feature. Save the broadcast users if it does not exist when saving a myInfo --- Meshtastic Client.xcodeproj/project.pbxproj | 6 +++-- MeshtasticClient/Helpers/BLEManager.swift | 24 ++++++++++++++++- MeshtasticClient/Info.plist | 2 +- .../Views/Messages/UserMessageList.swift | 26 ++++++++++++++----- 4 files changed, 48 insertions(+), 10 deletions(-) diff --git a/Meshtastic Client.xcodeproj/project.pbxproj b/Meshtastic Client.xcodeproj/project.pbxproj index 98ec63f9..ddfb97c7 100644 --- a/Meshtastic Client.xcodeproj/project.pbxproj +++ b/Meshtastic Client.xcodeproj/project.pbxproj @@ -718,6 +718,7 @@ ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES; CODE_SIGN_ENTITLEMENTS = MeshtasticClient/MeshtasticClient.entitlements; CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 2; DEVELOPMENT_ASSET_PATHS = "\"MeshtasticClient/Preview Content\""; DEVELOPMENT_TEAM = GCH7VS5Y9R; ENABLE_PREVIEWS = YES; @@ -727,7 +728,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.42; + MARKETING_VERSION = 1.43; PRODUCT_BUNDLE_IDENTIFIER = gvh.MeshtasticClient; PRODUCT_NAME = "$(TARGET_NAME)"; SUPPORTS_MACCATALYST = YES; @@ -745,6 +746,7 @@ ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES; CODE_SIGN_ENTITLEMENTS = MeshtasticClient/MeshtasticClient.entitlements; CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 2; DEVELOPMENT_ASSET_PATHS = "\"MeshtasticClient/Preview Content\""; DEVELOPMENT_TEAM = GCH7VS5Y9R; ENABLE_PREVIEWS = YES; @@ -754,7 +756,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.42; + MARKETING_VERSION = 1.43; PRODUCT_BUNDLE_IDENTIFIER = gvh.MeshtasticClient; PRODUCT_NAME = "$(TARGET_NAME)"; SUPPORTS_MACCATALYST = YES; diff --git a/MeshtasticClient/Helpers/BLEManager.swift b/MeshtasticClient/Helpers/BLEManager.swift index 85a7c0a5..19e5afb1 100644 --- a/MeshtasticClient/Helpers/BLEManager.swift +++ b/MeshtasticClient/Helpers/BLEManager.swift @@ -425,7 +425,29 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph myInfo.maxChannels = Int32(bitPattern: decodedInfo.myInfo.maxChannels) connectedPeripheral.num = myInfo.myNodeNum connectedPeripheral.firmwareVersion = myInfo.firmwareVersion ?? "Unknown" - + + let fetchBCUserRequest: NSFetchRequest = NSFetchRequest.init(entityName: "UserEntity") + fetchBCUserRequest.predicate = NSPredicate(format: "num == %lld", Int64(decodedInfo.myInfo.myNodeNum)) + + do { + let fetchedUser = try context?.fetch(fetchBCUserRequest) as! [UserEntity] + + if fetchedUser.isEmpty { + // Save the broadcast user if it does not exist + let bcu: UserEntity = UserEntity(context: context!) + bcu.shortName = "ALL" + bcu.longName = "All - Broadcast" + bcu.hwModel = "UNSET" + bcu.num = Int64(broadcastNodeNum) + bcu.userId = "BROADCASTNODE" + print("💾 Saved the All - Broadcast User") + } + + } catch { + + print("💥 Error Saving the All - Broadcast User") + } + } else { fetchedMyInfo[0].myNodeNum = Int64(decodedInfo.myInfo.myNodeNum) diff --git a/MeshtasticClient/Info.plist b/MeshtasticClient/Info.plist index 21a3f47f..b5b09295 100644 --- a/MeshtasticClient/Info.plist +++ b/MeshtasticClient/Info.plist @@ -19,7 +19,7 @@ CFBundleShortVersionString $(MARKETING_VERSION) CFBundleVersion - 1 + $(CURRENT_PROJECT_VERSION) ITSAppUsesNonExemptEncryption LSApplicationCategoryType diff --git a/MeshtasticClient/Views/Messages/UserMessageList.swift b/MeshtasticClient/Views/Messages/UserMessageList.swift index 45fe3852..69f73223 100644 --- a/MeshtasticClient/Views/Messages/UserMessageList.swift +++ b/MeshtasticClient/Views/Messages/UserMessageList.swift @@ -28,18 +28,17 @@ struct UserMessageList: View { @State var showDeleteMessageAlert = false @State private var deleteMessageId: Int64 = 0 - @State var mergedMessageList: NSMutableOrderedSet? + @State var messageCount = 0 var body: some View { VStack { + let allMessages = user.value(forKey: "allMessages") as! [MessageEntity] + ScrollViewReader { scrollView in ScrollView { - // Use fetched property - let allMessages = user.value(forKey: "allMessages") - as! [MessageEntity] if allMessages.count > 0 { @@ -106,10 +105,25 @@ struct UserMessageList: View { .onAppear(perform: { self.bleManager.context = context - if mergedMessageList?.count ?? 0 > 0 { - scrollView.scrollTo((mergedMessageList![mergedMessageList!.count-1] as AnyObject).id, anchor: .bottom) + messageCount = ((user.sentMessages?.count ?? 0) + (user.receivedMessages?.count ?? 0)) + + if messageCount > 0 { + + //scrollView.scrollTo(allMessages[allMessages.count-1].id, anchor: .bottom) + //scrollView.scrollTo(allMessages[allMessages.endIndex - 1]) + //scrollView.scrollTo((allMessages[messageCount-1] as AnyObject).id, anchor: .bottom) + } }) + .onChange(of: user, perform: { newValue in + + messageCount = ((user.sentMessages?.count ?? 0) + (user.receivedMessages?.count ?? 0)) + if messageCount > 0 { + + //scrollView.scrollTo((allMessages[messageCount-1] as AnyObject).id, anchor: .bottom) + } + } + ) }