From 71f5b51350cd2b85a8ac64d49905f3d59b77fd65 Mon Sep 17 00:00:00 2001 From: Stanislav Dmitrenko <7953703+avently@users.noreply.github.com> Date: Fri, 13 Jan 2023 19:05:53 +0000 Subject: [PATCH] ios: change network config in NSE when updated via UI (#1731) * ios: Apply changed network config to NSE * Better * Separate function * rename Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> --- apps/ios/SimpleX NSE/NotificationService.swift | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/apps/ios/SimpleX NSE/NotificationService.swift b/apps/ios/SimpleX NSE/NotificationService.swift index 7d6c6c485e..0c5f9308e6 100644 --- a/apps/ios/SimpleX NSE/NotificationService.swift +++ b/apps/ios/SimpleX NSE/NotificationService.swift @@ -154,6 +154,7 @@ class NotificationService: UNNotificationServiceExtension { } var chatStarted = false +var networkConfig: NetCfg = getNetCfg() func startChat() -> DBMigrationResult? { hs_init(0, nil) @@ -166,7 +167,7 @@ func startChat() -> DBMigrationResult? { if let user = apiGetActiveUser() { logger.debug("active user \(String(describing: user))") do { - try setNetworkConfig(getNetCfg()) + try setNetworkConfig(networkConfig) let justStarted = try apiStartChat() chatStarted = true if justStarted { @@ -188,6 +189,7 @@ func startChat() -> DBMigrationResult? { func receiveMessages() async { logger.debug("NotificationService receiveMessages") while true { + updateNetCfg() if let msg = await chatRecvMsg() { if let (id, ntf) = await receivedMsgNtf(msg) { await PendingNtfs.shared.createStream(id) @@ -241,6 +243,19 @@ func receivedMsgNtf(_ res: ChatResponse) async -> (String, UNMutableNotification } } +func updateNetCfg() { + let newNetConfig = getNetCfg() + if newNetConfig != networkConfig { + logger.debug("NotificationService applying changed network config") + do { + try setNetworkConfig(networkConfig) + networkConfig = newNetConfig + } catch { + logger.error("NotificationService apply changed network config error: \(responseError(error), privacy: .public)") + } + } +} + func apiGetActiveUser() -> User? { let r = sendSimpleXCmd(.showActiveUser) logger.debug("apiGetActiveUser sendSimpleXCmd responce: \(String(describing: r))")