diff --git a/Meshtastic.xcodeproj/project.pbxproj b/Meshtastic.xcodeproj/project.pbxproj index d55d4e87..09f44353 100644 --- a/Meshtastic.xcodeproj/project.pbxproj +++ b/Meshtastic.xcodeproj/project.pbxproj @@ -632,16 +632,16 @@ DDC2E15626CE248E0042C5E4 /* Meshtastic */ = { isa = PBXGroup; children = ( - DDDB443E29F79A9400EE2349 /* Extensions */, DD90860A26F645B700DC5189 /* Meshtastic.entitlements */, DD8ED9C6289CE4A100B3B0AB /* Enums */, + DD86D40D2881BDB300BAEB7A /* Export */, + DDDB443E29F79A9400EE2349 /* Extensions */, + DDC2E1A526CEB32B0042C5E4 /* Helpers */, + DDC2E18826CE24EE0042C5E4 /* Model */, DDC4D5662754996200A4208E /* Persistence */, DDAF8C5626ED07740058C060 /* Protobufs */, - DD86D40D2881BDB300BAEB7A /* Export */, - DDC2E1A526CEB32B0042C5E4 /* Helpers */, - DDC2E18726CE24E40042C5E4 /* Views */, - DDC2E18826CE24EE0042C5E4 /* Model */, DDC2E18926CE24F70042C5E4 /* Resources */, + DDC2E18726CE24E40042C5E4 /* Views */, DDC2E15726CE248E0042C5E4 /* MeshtasticApp.swift */, DDC2E16526CE248F0042C5E4 /* Info.plist */, DDC2E15D26CE248F0042C5E4 /* Preview Content */, @@ -760,14 +760,14 @@ DDC4D5662754996200A4208E /* Persistence */ = { isa = PBXGroup; children = ( + DD58C5F12919AD3C00D5BEFB /* ChannelEntityExtension.swift */, + 6DEDA55B2A9592F900321D2E /* MessageEntityExtension.swift */, DDC4D567275499A500A4208E /* Persistence.swift */, DD5394FD276BA0EF00AD86B1 /* PositionEntityExtension.swift */, - DDD9E4E3284B208E003777C5 /* UserEntityExtension.swift */, - DD58C5F12919AD3C00D5BEFB /* ChannelEntityExtension.swift */, DD964FC52975DBFD007C176F /* QueryCoreData.swift */, DD3CC6C128EB9D4900FA9159 /* UpdateCoreData.swift */, + DDD9E4E3284B208E003777C5 /* UserEntityExtension.swift */, DD964FC1297272AE007C176F /* WaypointEntityExtension.swift */, - 6DEDA55B2A9592F900321D2E /* MessageEntityExtension.swift */, ); path = Persistence; sourceTree = ""; diff --git a/Meshtastic/Helpers/BLEManager.swift b/Meshtastic/Helpers/BLEManager.swift index e6f93622..88b00ce4 100644 --- a/Meshtastic/Helpers/BLEManager.swift +++ b/Meshtastic/Helpers/BLEManager.swift @@ -718,6 +718,7 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate } newMessage.messagePayload = message newMessage.messagePayloadMarkdown = generateMessageMarkdown(message: message) + newMessage.read = true let dataType = PortNum.textMessageApp var messageQuotesReplaced = message.replacingOccurrences(of: "’", with: "'") diff --git a/Meshtastic/Helpers/MeshPackets.swift b/Meshtastic/Helpers/MeshPackets.swift index 073ee7ff..fcf99fa5 100644 --- a/Meshtastic/Helpers/MeshPackets.swift +++ b/Meshtastic/Helpers/MeshPackets.swift @@ -766,6 +766,11 @@ func textMessageAppPacket(packet: MeshPacket, blockRangeTest: Bool, connectedNod if messageSaved { if newMessage.fromUser != nil && newMessage.toUser != nil && !(newMessage.fromUser?.mute ?? false) { + // Set Unread Message Indicators + if packet.to == connectedNode { + var state = AppState.shared + state.unreadDirectMessages = newMessage.toUser?.unreadMessages ?? 0 + } // Create an iOS Notification for the received DM message and schedule it immediately let manager = LocalNotificationManager() manager.notifications = [ diff --git a/Meshtastic/MeshtasticApp.swift b/Meshtastic/MeshtasticApp.swift index b5f24076..d92d14b9 100644 --- a/Meshtastic/MeshtasticApp.swift +++ b/Meshtastic/MeshtasticApp.swift @@ -14,6 +14,7 @@ struct MeshtasticAppleApp: App { @State var incomingUrl: URL? @State var channelSettings: String? @StateObject var appState = AppState.shared + var body: some Scene { WindowGroup { ContentView() @@ -121,4 +122,6 @@ class AppState: ObservableObject { static let shared = AppState() @Published var tabSelection: Tab = .ble + @Published var unreadDirectMessages: Int = 0 + @Published var unreadChannelMessages: Int = 0 } diff --git a/Meshtastic/MeshtasticAppDelegate.swift b/Meshtastic/MeshtasticAppDelegate.swift index 0d130ccb..0918f9ea 100644 --- a/Meshtastic/MeshtasticAppDelegate.swift +++ b/Meshtastic/MeshtasticAppDelegate.swift @@ -9,7 +9,12 @@ import SwiftUI class MeshtasticAppDelegate: NSObject, UIApplicationDelegate, UNUserNotificationCenterDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { - print("App launched!") + print("🚀 Meshtstic Apple App launched!") + // Default User Default Values + UserDefaults.standard.register(defaults: ["blockRangeTest" : true]) + UserDefaults.standard.register(defaults: ["meshMapRecentering" : true]) + UserDefaults.standard.register(defaults: ["meshMapShowNodeHistory" : true]) + UserDefaults.standard.register(defaults: ["meshMapShowRouteLines" : true]) UNUserNotificationCenter.current().delegate = self return true } diff --git a/Meshtastic/Model/PeripheralModel.swift b/Meshtastic/Model/PeripheralModel.swift index ef7230a0..2382f7cb 100644 --- a/Meshtastic/Model/PeripheralModel.swift +++ b/Meshtastic/Model/PeripheralModel.swift @@ -12,18 +12,6 @@ struct Peripheral: Identifiable { var lastUpdate: Date var peripheral: CBPeripheral -// init(id: String, num: Int64, name: String, shortName: String, longName: String, firmwareVersion: String, rssi: Int, lastUpdate: Date, peripheral: CBPeripheral) { -// self.id = id -// self.num = num -// self.name = name -// self.shortName = shortName -// self.longName = longName -// self.firmwareVersion = firmwareVersion -// self.rssi = rssi -// self.lastUpdate = lastUpdate -// self.peripheral = peripheral -// } - func getSignalStrength() -> BLESignalStrength { if NSNumber(value: rssi).compare(NSNumber(-65)) == ComparisonResult.orderedDescending { return BLESignalStrength.strong diff --git a/Meshtastic/Persistence/UserEntityExtension.swift b/Meshtastic/Persistence/UserEntityExtension.swift index 1786a45b..927c0372 100644 --- a/Meshtastic/Persistence/UserEntityExtension.swift +++ b/Meshtastic/Persistence/UserEntityExtension.swift @@ -18,7 +18,6 @@ extension UserEntity { } var unreadMessages: Int { - let unreadMessages = messageList.filter{ ($0 as AnyObject).read == false } return unreadMessages.count } diff --git a/Meshtastic/Views/ContentView.swift b/Meshtastic/Views/ContentView.swift index a80e06c6..35b2a9ea 100644 --- a/Meshtastic/Views/ContentView.swift +++ b/Meshtastic/Views/ContentView.swift @@ -13,7 +13,7 @@ struct ContentView: View { Label("messages", systemImage: "message") } .tag(Tab.contacts) - // .badge(42) + .badge(appState.unreadDirectMessages + appState.unreadChannelMessages) Connect() .tabItem { Label("bluetooth", systemImage: "antenna.radiowaves.left.and.right") diff --git a/Meshtastic/Views/Helpers/CircleText.swift b/Meshtastic/Views/Helpers/CircleText.swift index 3b84b0d8..bd2f0b0d 100644 --- a/Meshtastic/Views/Helpers/CircleText.swift +++ b/Meshtastic/Views/Helpers/CircleText.swift @@ -23,6 +23,7 @@ struct CircleText: View { .minimumScaleFactor(0.001) .frame(width: circleSize * 0.94, height: circleSize * 0.94, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/) } + .aspectRatio(1, contentMode: .fit) } } diff --git a/Meshtastic/Views/Messages/UserMessageList.swift b/Meshtastic/Views/Messages/UserMessageList.swift index 68dfbbd8..e4829d0e 100644 --- a/Meshtastic/Views/Messages/UserMessageList.swift +++ b/Meshtastic/Views/Messages/UserMessageList.swift @@ -10,6 +10,7 @@ import CoreData struct UserMessageList: View { + @StateObject var appState = AppState.shared @Environment(\.managedObjectContext) var context @EnvironmentObject var bleManager: BLEManager @@ -222,6 +223,8 @@ struct UserMessageList: View { do { try context.save() print("Read message \(message.messageId) ") + appState.unreadDirectMessages = user.unreadMessages + } catch { print("Failed to read message \(message.messageId)") }