mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-05-15 16:45:46 +00:00
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>
This commit is contained in:
committed by
GitHub
parent
20cec4db11
commit
71f5b51350
@@ -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))")
|
||||
|
||||
Reference in New Issue
Block a user