diff --git a/Swiftgram/SGSettingsUI/Sources/SGSettingsController.swift b/Swiftgram/SGSettingsUI/Sources/SGSettingsController.swift index eec32fb1a6..07bc1a05a8 100644 --- a/Swiftgram/SGSettingsUI/Sources/SGSettingsController.swift +++ b/Swiftgram/SGSettingsUI/Sources/SGSettingsController.swift @@ -92,6 +92,7 @@ private enum SGBoolSetting: String { case forceEmojiTab case forceBuiltInMic case hideChannelBottomButton + case confirmCalls } private enum SGOneFromManySetting: String { @@ -162,6 +163,8 @@ private func SGControllerEntries(presentationData: PresentationData, callListSet entries.append(.notice(id: id.count, section: .profiles, text: i18n("Settings.ShowRegDate.Notice", lang))) entries.append(.toggle(id: id.count, section: .profiles, settingName: .showCreationDate, value: SGSimpleSettings.shared.showCreationDate, text: i18n("Settings.ShowCreationDate", lang), enabled: true)) entries.append(.notice(id: id.count, section: .profiles, text: i18n("Settings.ShowCreationDate.Notice", lang))) + entries.append(.toggle(id: id.count, section: .profiles, settingName: .confirmCalls, value: SGSimpleSettings.shared.confirmCalls, text: i18n("Settings.CallConfirmation", lang), enabled: true)) + entries.append(.notice(id: id.count, section: .profiles, text: i18n("Settings.CallConfirmation.Notice", lang))) entries.append(.header(id: id.count, section: .stories, text: presentationData.strings.AutoDownloadSettings_Stories.uppercased(), badge: nil)) entries.append(.toggle(id: id.count, section: .stories, settingName: .hideStories, value: SGSettings.hideStories, text: i18n("Settings.Stories.Hide", lang), enabled: true)) @@ -446,6 +449,8 @@ public func sgSettingsController(context: AccountContext/*, focusOnItemTag: Int? SGSimpleSettings.shared.forceBuiltInMic = value case .hideChannelBottomButton: SGSimpleSettings.shared.hideChannelBottomButton = value + case .confirmCalls: + SGSimpleSettings.shared.confirmCalls = value } }, updateSliderValue: { setting, value in switch (setting) { diff --git a/Swiftgram/SGSimpleSettings/Sources/SimpleSettings.swift b/Swiftgram/SGSimpleSettings/Sources/SimpleSettings.swift index 3c4a52699e..83e77a31cd 100644 --- a/Swiftgram/SGSimpleSettings/Sources/SimpleSettings.swift +++ b/Swiftgram/SGSimpleSettings/Sources/SimpleSettings.swift @@ -104,6 +104,7 @@ public class SGSimpleSettings { case forceBuiltInMic case hideChannelBottomButton case forceSystemSharing + case confirmCalls } public enum DownloadSpeedBoostValues: String, CaseIterable { @@ -192,6 +193,7 @@ public class SGSimpleSettings { Keys.forceEmojiTab.rawValue: false, Keys.hideChannelBottomButton.rawValue: false, Keys.forceSystemSharing.rawValue: false, + Keys.confirmCalls.rawValue: true, ] @UserDefault(key: Keys.hidePhoneInSettings.rawValue) @@ -360,6 +362,9 @@ public class SGSimpleSettings { @UserDefault(key: Keys.forceSystemSharing.rawValue) public var forceSystemSharing: Bool + + @UserDefault(key: Keys.confirmCalls.rawValue) + public var confirmCalls: Bool } extension SGSimpleSettings { diff --git a/Swiftgram/SGStrings/Strings/en.lproj/SGLocalizable.strings b/Swiftgram/SGStrings/Strings/en.lproj/SGLocalizable.strings index d880d17ad6..c1a328bcf8 100644 --- a/Swiftgram/SGStrings/Strings/en.lproj/SGLocalizable.strings +++ b/Swiftgram/SGStrings/Strings/en.lproj/SGLocalizable.strings @@ -134,4 +134,13 @@ "Settings.forceBuiltInMic" = "Force Device Microphone"; "Settings.forceBuiltInMic.Notice" = "If enabled, app will use only device microphone even if headphones are connected."; -"Settings.hideChannelBottomButton" = "Hide Channel Bottom Panel"; \ No newline at end of file +"Settings.hideChannelBottomButton" = "Hide Channel Bottom Panel"; + +"Settings.CallConfirmation" = "Call Confirmation"; +"Settings.CallConfirmation.Notice" = "Swiftgram will ask for your confirmation before making a call."; + +/* Confirmation before making a Call */ +"CallConfirmation.Audio.Title" = "Make a Call?"; + +/* Confirmation before making a Video Call */ +"CallConfirmation.Video.Title" = "Make a Video Call?"; diff --git a/submodules/TelegramUI/Sources/AccountContext.swift b/submodules/TelegramUI/Sources/AccountContext.swift index 31c602eaee..897a95b6e7 100644 --- a/submodules/TelegramUI/Sources/AccountContext.swift +++ b/submodules/TelegramUI/Sources/AccountContext.swift @@ -1,3 +1,6 @@ +import SGStrings +import SGSimpleSettings + import Foundation import SwiftSignalKit import UIKit @@ -655,6 +658,8 @@ public final class AccountContextImpl: AccountContext { } public func requestCall(peerId: PeerId, isVideo: Bool, completion: @escaping () -> Void) { + // MARK: Swiftgram + let makeCall = { guard let callResult = self.sharedContext.callManager?.requestCall(context: self, peerId: peerId, isVideo: isVideo, endCurrentIfAny: false) else { return } @@ -722,6 +727,19 @@ public final class AccountContextImpl: AccountContext { } else { completion() } + // MARK: Swiftgram + } + if SGSimpleSettings.shared.confirmCalls { + let presentationData = self.sharedContext.currentPresentationData.with { $0 } + self.sharedContext.mainWindow?.present(textAlertController(context: self, title: nil, text: isVideo ? i18n("CallConfirmation.Video.Title", presentationData.strings.baseLanguageCode) : i18n("CallConfirmation.Audio.Title", presentationData.strings.baseLanguageCode), actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_No, action: {}), TextAlertAction(type: .genericAction, title: presentationData.strings.Common_Yes, action: { [weak self] in + guard let _ = self else { + return + } + makeCall() + })]), on: .root) + } else { + makeCall() + } } }