diff --git a/Ring/Ring/Constants/Generated/Strings.swift b/Ring/Ring/Constants/Generated/Strings.swift index 4ffa5f6bcffe2efa524370ff53833b8af61d39a6..c7c61167de5d7a9f1077809ad7230b85933d9d33 100644 --- a/Ring/Ring/Constants/Generated/Strings.swift +++ b/Ring/Ring/Constants/Generated/Strings.swift @@ -115,6 +115,8 @@ internal enum L10n { internal static let other = L10n.tr("Localizable", "accountPage.other") /// Enter account password internal static let passwordPlaceholder = L10n.tr("Localizable", "accountPage.passwordPlaceholder") + /// Auto connect on local network + internal static let peerDiscovery = L10n.tr("Localizable", "accountPage.peerDiscovery") /// Provide proxy address internal static let proxyAddressAlert = L10n.tr("Localizable", "accountPage.proxyAddressAlert") /// In order to receive notifications, please enable proxy diff --git a/Ring/Ring/Features/Me/Me/MeViewController.swift b/Ring/Ring/Features/Me/Me/MeViewController.swift index 1719a21ed501d931b06f4472f9ae4672815566ef..f30cc058424b7e400f07b94ef1af3fdcdc85d022 100644 --- a/Ring/Ring/Features/Me/Me/MeViewController.swift +++ b/Ring/Ring/Features/Me/Me/MeViewController.swift @@ -456,6 +456,28 @@ class MeViewController: EditProfileViewController, StoryboardBased, ViewModelBas self?.viewModel.enableNotifications(enable: value) }).disposed(by: cell.disposeBag) return cell + case .peerDiscovery: + let cell = DisposableCell() + cell.backgroundColor = UIColor.jamiBackgroundColor + cell.textLabel?.text = L10n.AccountPage.peerDiscovery + let switchView = UISwitch() + cell.selectionStyle = .none + cell.accessoryType = UITableViewCell.AccessoryType.disclosureIndicator + cell.accessoryView = switchView + self.viewModel.peerDiscoveryEnabled + .asObservable() + .startWith(self.viewModel.peerDiscoveryEnabled.value) + .observeOn(MainScheduler.instance) + .bind(to: switchView.rx.value) + .disposed(by: cell.disposeBag) + switchView.rx + .isOn.changed + .debounce(0.2, scheduler: MainScheduler.instance) + .distinctUntilChanged().asObservable() + .subscribe(onNext: {[weak self] enable in + self?.viewModel.enablePeerDiscovery(enable: enable) + }).disposed(by: cell.disposeBag) + return cell case .sipUserName(let value): let cell = self .configureSipCredentialsCell(cellType: .sipUserName(value: value), @@ -493,8 +515,8 @@ class MeViewController: EditProfileViewController, StoryboardBased, ViewModelBas state.asObservable() .observeOn(MainScheduler.instance) .subscribe(onNext: { (status) in - cell.detailTextLabel?.text = status - }).disposed(by: cell.disposeBag) + cell.detailTextLabel?.text = status + }).disposed(by: cell.disposeBag) return cell case .boothMode: let cell = DisposableCell(style: .subtitle, reuseIdentifier: self.jamiIDCell) diff --git a/Ring/Ring/Features/Me/Me/MeViewModel.swift b/Ring/Ring/Features/Me/Me/MeViewModel.swift index dec3a49ca65b1f893e9cf4eb6700fe88b919d9d0..30dde46b086b838e742f7d0321574743993c7ed5 100644 --- a/Ring/Ring/Features/Me/Me/MeViewModel.swift +++ b/Ring/Ring/Features/Me/Me/MeViewModel.swift @@ -55,6 +55,7 @@ enum SettingsSection: SectionModelType { case enableAccount case changePassword case boothMode + case peerDiscovery } var items: [SectionRow] { @@ -212,6 +213,7 @@ class MeViewModel: ViewModel, Stateable { lazy var otherJamiSettings: Observable<SettingsSection> = { return Observable .just(SettingsSection.accountSettings( items: [.sectionHeader(title: L10n.AccountPage.other), + .peerDiscovery, .blockedList, .accountState(state: self.accountStatus), .enableAccount, @@ -693,6 +695,16 @@ class MeViewModel: ViewModel, Stateable { return Variable<Bool>(true) }() + lazy var peerDiscoveryEnabled: Variable<Bool> = { + if let account = self.accountService.currentAccount, + let details = account.details { + let enable = details.get(withConfigKeyModel: + ConfigKeyModel.init(withKey: .dhtPeerDiscovery)).boolValue + return Variable<Bool>(enable) + } + return Variable<Bool>(true) + }() + func enableAccount(enable: Bool) { if self.accountEnabled.value == enable {return} guard let account = self.accountService.currentAccount else {return} @@ -700,6 +712,13 @@ class MeViewModel: ViewModel, Stateable { accountEnabled.value = enable } + func enablePeerDiscovery(enable: Bool) { + guard self.peerDiscoveryEnabled.value != enable, + let account = self.accountService.currentAccount else { return } + self.accountService.enablePeerDiscovery(enable: enable, accountId: account.id) + peerDiscoveryEnabled.value = enable + } + // MARK: Sip Credentials let sipUsername = Variable<String>("") let sipPassword = Variable<String>("") diff --git a/Ring/Ring/Resources/en.lproj/Localizable.strings b/Ring/Ring/Resources/en.lproj/Localizable.strings index 62ac328782e74ca858f210fe77a2ab999d4818d3..331546d490ace4c6ba7f1d747283abd408c18e0c 100644 --- a/Ring/Ring/Resources/en.lproj/Localizable.strings +++ b/Ring/Ring/Resources/en.lproj/Localizable.strings @@ -218,6 +218,7 @@ "accountPage.boothModeExplanation" = "In booth mode conversation history not saved and jami functionality limited by making outgoing calls. When you enable booth mode all your conversations will be removed."; "accountPage.noBoothMode" = "To enable Booth mode you need to create account password first."; "accountPage.boothModeAlertMessage" = "After enabling booth mode all your conversations will be removed."; +"accountPage.peerDiscovery" = "Auto connect on local network"; //Account "account.sipUsername" = "User Name"; diff --git a/Ring/Ring/Services/AccountsService.swift b/Ring/Ring/Services/AccountsService.swift index 949e6c67a466edd8e4f9efa8870b3a4287a14744..e5169c916f7ab7d6dab687dcfd45ae254631308f 100644 --- a/Ring/Ring/Services/AccountsService.swift +++ b/Ring/Ring/Services/AccountsService.swift @@ -528,13 +528,7 @@ class AccountsService: AccountAdapterDelegate { if details .get(withConfigKeyModel: ConfigKeyModel(withKey: ConfigKey.ringtonePath)) == filename && details - .get(withConfigKeyModel: ConfigKeyModel(withKey: ConfigKey.ringtoneEnabled)) == "false" && - details - .get(withConfigKeyModel: ConfigKeyModel(withKey: ConfigKey.dhtPeerDiscovery)) == "false" && - details - .get(withConfigKeyModel: ConfigKeyModel(withKey: ConfigKey.accountPeerDiscovery)) == "false" && - details - .get(withConfigKeyModel: ConfigKeyModel(withKey: ConfigKey.accountPublish)) == "false" { + .get(withConfigKeyModel: ConfigKeyModel(withKey: ConfigKey.ringtoneEnabled)) == "false" { return } details @@ -543,15 +537,6 @@ class AccountsService: AccountAdapterDelegate { details .set(withConfigKeyModel: ConfigKeyModel(withKey: ConfigKey.ringtoneEnabled), withValue: "false") - details - .set(withConfigKeyModel: ConfigKeyModel(withKey: ConfigKey.dhtPeerDiscovery), - withValue: "false") - details - .set(withConfigKeyModel: ConfigKeyModel(withKey: ConfigKey.accountPeerDiscovery), - withValue: "false") - details - .set(withConfigKeyModel: ConfigKeyModel(withKey: ConfigKey.accountPublish), - withValue: "false") setAccountDetails(forAccountId: accountId, withDetails: details) } @@ -709,14 +694,8 @@ class AccountsService: AccountAdapterDelegate { } accountDetails!.updateValue("oversip", forKey: ConfigKey.accountDTMFType.rawValue) accountDetails!.updateValue("true", forKey: ConfigKey.videoEnabled.rawValue) - accountDetails!.updateValue("default.wav", forKey: ConfigKey.ringtonePath.rawValue) accountDetails!.updateValue(accountType, forKey: ConfigKey.accountType.rawValue) accountDetails!.updateValue("true", forKey: ConfigKey.accountUpnpEnabled.rawValue) - if accountType == AccountType.ring.rawValue { - accountDetails!.updateValue("false", forKey: ConfigKey.dhtPeerDiscovery.rawValue) - accountDetails!.updateValue("false", forKey: ConfigKey.accountPeerDiscovery.rawValue) - accountDetails!.updateValue("false", forKey: ConfigKey.accountPublish.rawValue) - } return accountDetails! } @@ -969,11 +948,18 @@ class AccountsService: AccountAdapterDelegate { } func enableAccount(enable: Bool, accountId: String) { + self.switchAccountPropertyTo(state: enable, accountId: accountId, property: ConfigKeyModel(withKey: ConfigKey.accountEnable)); + } + + func enablePeerDiscovery(enable: Bool, accountId: String) { + self.switchAccountPropertyTo(state: enable, accountId: accountId, property: ConfigKeyModel(withKey: ConfigKey.dhtPeerDiscovery)); + } + + func switchAccountPropertyTo(state: Bool, accountId: String, property: ConfigKeyModel) { let accountDetails = self.getAccountDetails(fromAccountId: accountId) - if accountDetails.get(withConfigKeyModel: ConfigKeyModel(withKey: ConfigKey.accountEnable)) != enable.toString() { - accountDetails.set(withConfigKeyModel: ConfigKeyModel(withKey: ConfigKey.accountEnable), withValue: enable.toString()) - self.setAccountDetails(forAccountId: accountId, withDetails: accountDetails) - } + guard accountDetails.get(withConfigKeyModel: property) != state.toString() else { return } + accountDetails.set(withConfigKeyModel: property, withValue: state.toString()) + self.setAccountDetails(forAccountId: accountId, withDetails: accountDetails) } // MARK: - observable account data