Feature/3637 pusher url

This commit is contained in:
Frank Rotermund
2022-11-16 10:28:50 +00:00
committed by Arnfried Griesert
parent 3a6c5d5b9f
commit 12a982724f
5 changed files with 55 additions and 5 deletions

View File

@@ -200,7 +200,7 @@ class BWIBuildSettings: NSObject {
var serverConfigDefaultHomeserverUrlString = "" var serverConfigDefaultHomeserverUrlString = ""
var serverConfigDefaultIdentityServerUrlString = "" var serverConfigDefaultIdentityServerUrlString = ""
var serverConfigPreSelections = ["":""] var serverConfigPreSelections = ["":""]
var serverConfigSygnalAPIUrlString = "" var serverConfigSygnalAPIUrlString = "https://push-local/_matrix/push/v1/notify"
// Note: Set empty strings to hide the related entry in application settings // Note: Set empty strings to hide the related entry in application settings
var applicationCopyrightUrlString = "https://messenger.bwi.de/copyright" var applicationCopyrightUrlString = "https://messenger.bwi.de/copyright"

View File

@@ -1863,6 +1863,17 @@ NSString *const AppDelegateUniversalLinkDidChangeNotification = @"AppDelegateUni
} }
[self handleAppState]; [self handleAppState];
// bwi: check if pusher url has changed and push needs to be enabled again
PusherURLHelper* pusherHelper = [[PusherURLHelper alloc] init];
if ([pusherHelper isChangedPusherURL]) {
[pusherHelper savePusherURL];
MXKAccount* account = [MXKAccountManager sharedManager].activeAccounts.firstObject;
if ( account ) {
[self.pushNotificationService registerUserNotificationSettings];
}
}
}]; }];
// Register an observer in order to handle new account // Register an observer in order to handle new account

View File

@@ -148,8 +148,6 @@ extension UserDefaults
func pusherUrl() -> String { func pusherUrl() -> String {
if let url = appConfig.pusherUrl { if let url = appConfig.pusherUrl {
return url return url
} else if let url = ServerURLHelper.shared.pusherUrl() {
return url
} else { } else {
return BWIBuildSettings.shared.serverConfigSygnalAPIUrlString return BWIBuildSettings.shared.serverConfigSygnalAPIUrlString
} }

View File

@@ -0,0 +1,41 @@
//
/*
* Copyright (c) 2022 BWI GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import Foundation
@objcMembers class PusherURLHelper : NSObject {
// returns true if there is no pusherURL saved or when it has changed
func isChangedPusherURL() -> Bool {
let currentPushURL = AppConfigService.shared.pusherUrl()
guard let oldPusherURL = UserDefaults.standard.string(forKey: "BWIPusherURL") else {
return true
}
return oldPusherURL != currentPushURL
}
func savePusherURL() {
let currentPushURL = AppConfigService.shared.pusherUrl()
UserDefaults.standard.set(currentPushURL, forKey: "BWIPusherURL")
UserDefaults.standard
.synchronize()
}
}

View File

@@ -49,12 +49,11 @@ import Foundation
for urlSet in urls { for urlSet in urls {
if let dict = urlSet as? Dictionary<String,String> { if let dict = urlSet as? Dictionary<String,String> {
if let server = dict[serverUrlKey], if let server = dict[serverUrlKey],
let pusher = dict[pusherUrlKey],
let flavor = dict[flavorUrlKey], let flavor = dict[flavorUrlKey],
let name = dict[nameKey], let name = dict[nameKey],
let permalink = dict[permalinkKey] , let permalink = dict[permalinkKey] ,
let analytics = dict[analyticsKey] { let analytics = dict[analyticsKey] {
serverSettings.append(ServerSetting(name:name, serverUrl: server, pusherUrl: pusher, flavor: flavor, permalink:permalink, analytics: analytics)) serverSettings.append(ServerSetting(name:name, serverUrl: server, pusherUrl: "", flavor: flavor, permalink:permalink, analytics: analytics))
} }
} }
} }
@@ -89,6 +88,7 @@ import Foundation
} }
} }
func pusherUrl() -> String? { func pusherUrl() -> String? {
if serverSettings.indices.contains(selectedIndex) { if serverSettings.indices.contains(selectedIndex) {
return serverSettings[selectedIndex].pusherUrl return serverSettings[selectedIndex].pusherUrl