Load unread message state when the app loads.

This commit is contained in:
Garth Vander Houwen 2023-09-03 21:36:54 -07:00
parent 38501624c2
commit 0598b26f53
2 changed files with 10 additions and 2 deletions

View file

@ -614,10 +614,17 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate
do {
let fetchedNodeInfo = try context?.fetch(fetchNodeInfoRequest) as? [NodeInfoEntity] ?? []
if fetchedNodeInfo.count == 1 && fetchedNodeInfo[0].mqttConfig != nil {
//Subscribe to Mqtt Client Proxy if enabled
if fetchedNodeInfo[0].mqttConfig?.proxyToClientEnabled ?? false {
// Subscribe to Mqtt Client Proxy if enabled
if fetchedNodeInfo[0].mqttConfig?.enabled ?? false && fetchedNodeInfo[0].mqttConfig?.proxyToClientEnabled ?? false {
mqttManager.connectFromConfigSettings(node: fetchedNodeInfo[0])
}
// Set initial unread message badge states
var appState = AppState.shared
appState.unreadChannelMessages = fetchedNodeInfo[0].myInfo?.unreadMessages ?? 0
appState.unreadDirectMessages = fetchedNodeInfo[0].user?.unreadMessages ?? 0
appState.connectedNode = fetchedNodeInfo[0]
UIApplication.shared.applicationIconBadgeNumber = appState.unreadChannelMessages + appState.unreadDirectMessages
}
if fetchedNodeInfo.count == 1 && fetchedNodeInfo[0].rangeTestConfig?.enabled == true {
wantRangeTestPackets = true;

View file

@ -124,4 +124,5 @@ class AppState: ObservableObject {
@Published var tabSelection: Tab = .ble
@Published var unreadDirectMessages: Int = 0
@Published var unreadChannelMessages: Int = 0
@Published var connectedNode: NodeInfoEntity?
}