mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Unread direct messages indicator
This commit is contained in:
parent
06f39d40f2
commit
7b9d6b11cf
10 changed files with 28 additions and 23 deletions
|
|
@ -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 = "<group>";
|
||||
|
|
|
|||
|
|
@ -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: "'")
|
||||
|
|
|
|||
|
|
@ -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 = [
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ extension UserEntity {
|
|||
}
|
||||
|
||||
var unreadMessages: Int {
|
||||
|
||||
let unreadMessages = messageList.filter{ ($0 as AnyObject).read == false }
|
||||
return unreadMessages.count
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue