diff --git a/TelegramUI/AuthorizationSequenceAwaitingAccountResetController.swift b/TelegramUI/AuthorizationSequenceAwaitingAccountResetController.swift index cc410c27d6..7618a5c578 100644 --- a/TelegramUI/AuthorizationSequenceAwaitingAccountResetController.swift +++ b/TelegramUI/AuthorizationSequenceAwaitingAccountResetController.swift @@ -27,7 +27,7 @@ final class AuthorizationSequenceAwaitingAccountResetController: ViewController } } - init(strings: PresentationStrings, theme: AuthorizationTheme) { + init(strings: PresentationStrings, theme: AuthorizationTheme, back: @escaping () -> Void) { self.strings = strings self.theme = theme @@ -37,6 +37,13 @@ final class AuthorizationSequenceAwaitingAccountResetController: ViewController self.statusBar.statusBarStyle = theme.statusBarStyle + self.attemptNavigation = { _ in + return false + } + self.navigationBar?.backPressed = { + back() + } + self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: " ", style: .plain, target: self, action: nil) self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: self.strings.Settings_Logout, style: .plain, target: self, action: #selector(self.logoutPressed)) } diff --git a/TelegramUI/AuthorizationSequenceCodeEntryController.swift b/TelegramUI/AuthorizationSequenceCodeEntryController.swift index 333ef6536b..9a26e4a97b 100644 --- a/TelegramUI/AuthorizationSequenceCodeEntryController.swift +++ b/TelegramUI/AuthorizationSequenceCodeEntryController.swift @@ -33,7 +33,7 @@ final class AuthorizationSequenceCodeEntryController: ViewController { } } - init(strings: PresentationStrings, theme: AuthorizationTheme, openUrl: @escaping (String) -> Void) { + init(strings: PresentationStrings, theme: AuthorizationTheme, openUrl: @escaping (String) -> Void, back: @escaping () -> Void) { self.strings = strings self.theme = theme self.openUrl = openUrl @@ -48,16 +48,15 @@ final class AuthorizationSequenceCodeEntryController: ViewController { self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: self.strings.Common_Next, style: .done, target: self, action: #selector(self.nextPressed)) - self.attemptNavigation = { [weak self] f in - guard let strongSelf = self else { - return true - } - strongSelf.present(standardTextAlertController(theme: AlertControllerTheme(authTheme: theme), title: nil, text: strings.Login_CancelPhoneVerification, actions: [TextAlertAction(type: .genericAction, title: strings.Login_CancelPhoneVerificationContinue, action: { - }), TextAlertAction(type: .defaultAction, title: strings.Login_CancelPhoneVerificationStop, action: { - f() - })]), in: .window(.root)) + self.attemptNavigation = { _ in return false } + self.navigationBar?.backPressed = { [weak self] in + self?.present(standardTextAlertController(theme: AlertControllerTheme(authTheme: theme), title: nil, text: strings.Login_CancelPhoneVerification, actions: [TextAlertAction(type: .genericAction, title: strings.Login_CancelPhoneVerificationContinue, action: { + }), TextAlertAction(type: .defaultAction, title: strings.Login_CancelPhoneVerificationStop, action: { + back() + })]), in: .window(.root)) + } } required init(coder aDecoder: NSCoder) { diff --git a/TelegramUI/AuthorizationSequenceController.swift b/TelegramUI/AuthorizationSequenceController.swift index 87cf3194ac..b05e5e8914 100644 --- a/TelegramUI/AuthorizationSequenceController.swift +++ b/TelegramUI/AuthorizationSequenceController.swift @@ -34,13 +34,6 @@ public final class AuthorizationSequenceController: NavigationController { super.init(mode: .single, theme: NavigationControllerTheme(navigationBar: AuthorizationSequenceController.navigationBarTheme(theme), emptyAreaColor: .black, emptyDetailIcon: nil)) self.stateDisposable = (account.postbox.stateView() - |> filter { view in - if view.state is UnauthorizedAccountState || view.state == nil { - return true - } else { - return false - } - } |> map { view -> UnauthorizedAccountStateContents in if let state = view.state as? UnauthorizedAccountState { return state.contents @@ -114,6 +107,13 @@ public final class AuthorizationSequenceController: NavigationController { } else { controller = AuthorizationSequencePhoneEntryController(network: self.account.network, strings: self.strings, theme: self.theme, openUrl: { [weak self] url in self?.openUrl(url) + }, back: { [weak self] in + guard let strongSelf = self else { + return + } + let _ = strongSelf.account.postbox.transaction({ transaction -> Void in + transaction.setState(UnauthorizedAccountState(isTestingEnvironment: strongSelf.account.testingEnvironment, masterDatacenterId: strongSelf.account.masterDatacenterId, contents: .empty)) + }).start() }) controller.loginWithNumber = { [weak self, weak controller] number in if let strongSelf = self { @@ -222,6 +222,15 @@ public final class AuthorizationSequenceController: NavigationController { } else { controller = AuthorizationSequenceCodeEntryController(strings: self.strings, theme: self.theme, openUrl: { [weak self] url in self?.openUrl(url) + }, back: { [weak self] in + guard let strongSelf = self else { + return + } + let countryCode = defaultCountryCode() + + let _ = (strongSelf.account.postbox.transaction { transaction -> Void in + transaction.setState(UnauthorizedAccountState(isTestingEnvironment: strongSelf.account.testingEnvironment, masterDatacenterId: strongSelf.account.masterDatacenterId, contents: .phoneEntry(countryCode: countryCode, number: ""))) + }).start() }) controller.loginWithCode = { [weak self, weak controller] code in if let strongSelf = self { @@ -390,7 +399,16 @@ public final class AuthorizationSequenceController: NavigationController { if let currentController = currentController { controller = currentController } else { - controller = AuthorizationSequencePasswordEntryController(strings: self.strings, theme: self.theme) + controller = AuthorizationSequencePasswordEntryController(strings: self.strings, theme: self.theme, back: { [weak self] in + guard let strongSelf = self else { + return + } + let countryCode = defaultCountryCode() + + let _ = (strongSelf.account.postbox.transaction { transaction -> Void in + transaction.setState(UnauthorizedAccountState(isTestingEnvironment: strongSelf.account.testingEnvironment, masterDatacenterId: strongSelf.account.masterDatacenterId, contents: .phoneEntry(countryCode: countryCode, number: ""))) + }).start() + }) controller.loginWithPassword = { [weak self, weak controller] password in if let strongSelf = self { controller?.inProgress = true @@ -489,7 +507,16 @@ public final class AuthorizationSequenceController: NavigationController { if let currentController = currentController { controller = currentController } else { - controller = AuthorizationSequencePasswordRecoveryController(strings: self.strings, theme: self.theme) + controller = AuthorizationSequencePasswordRecoveryController(strings: self.strings, theme: self.theme, back: { [weak self] in + guard let strongSelf = self else { + return + } + let countryCode = defaultCountryCode() + + let _ = (strongSelf.account.postbox.transaction { transaction -> Void in + transaction.setState(UnauthorizedAccountState(isTestingEnvironment: strongSelf.account.testingEnvironment, masterDatacenterId: strongSelf.account.masterDatacenterId, contents: .phoneEntry(countryCode: countryCode, number: ""))) + }).start() + }) controller.recoverWithCode = { [weak self, weak controller] code in if let strongSelf = self { controller?.inProgress = true @@ -543,7 +570,16 @@ public final class AuthorizationSequenceController: NavigationController { if let currentController = currentController { controller = currentController } else { - controller = AuthorizationSequenceAwaitingAccountResetController(strings: self.strings, theme: self.theme) + controller = AuthorizationSequenceAwaitingAccountResetController(strings: self.strings, theme: self.theme, back: { [weak self] in + guard let strongSelf = self else { + return + } + let countryCode = defaultCountryCode() + + let _ = (strongSelf.account.postbox.transaction { transaction -> Void in + transaction.setState(UnauthorizedAccountState(isTestingEnvironment: strongSelf.account.testingEnvironment, masterDatacenterId: strongSelf.account.masterDatacenterId, contents: .phoneEntry(countryCode: countryCode, number: ""))) + }).start() + }) controller.reset = { [weak self, weak controller] in if let strongSelf = self, let strongController = controller { strongController.present(standardTextAlertController(theme: AlertControllerTheme(authTheme: strongSelf.theme), title: nil, text: strongSelf.strings.TwoStepAuth_ResetAccountConfirmation, actions: [ @@ -598,7 +634,16 @@ public final class AuthorizationSequenceController: NavigationController { if let currentController = currentController { controller = currentController } else { - controller = AuthorizationSequenceSignUpController(strings: self.strings, theme: self.theme) + controller = AuthorizationSequenceSignUpController(strings: self.strings, theme: self.theme, back: { [weak self] in + guard let strongSelf = self else { + return + } + let countryCode = defaultCountryCode() + + let _ = (strongSelf.account.postbox.transaction { transaction -> Void in + transaction.setState(UnauthorizedAccountState(isTestingEnvironment: strongSelf.account.testingEnvironment, masterDatacenterId: strongSelf.account.masterDatacenterId, contents: .phoneEntry(countryCode: countryCode, number: ""))) + }).start() + }) controller.signUpWithName = { [weak self, weak controller] firstName, lastName, avatarData in if let strongSelf = self { controller?.inProgress = true diff --git a/TelegramUI/AuthorizationSequencePasswordEntryController.swift b/TelegramUI/AuthorizationSequencePasswordEntryController.swift index 10c3999803..722ceba444 100644 --- a/TelegramUI/AuthorizationSequencePasswordEntryController.swift +++ b/TelegramUI/AuthorizationSequencePasswordEntryController.swift @@ -39,7 +39,7 @@ final class AuthorizationSequencePasswordEntryController: ViewController { } } - init(strings: PresentationStrings, theme: AuthorizationTheme) { + init(strings: PresentationStrings, theme: AuthorizationTheme, back: @escaping () -> Void) { self.strings = strings self.theme = theme @@ -51,6 +51,13 @@ final class AuthorizationSequencePasswordEntryController: ViewController { self.statusBar.statusBarStyle = theme.statusBarStyle + self.attemptNavigation = { _ in + return false + } + self.navigationBar?.backPressed = { + back() + } + self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: self.strings.Common_Next, style: .done, target: self, action: #selector(self.nextPressed)) } diff --git a/TelegramUI/AuthorizationSequencePasswordRecoveryController.swift b/TelegramUI/AuthorizationSequencePasswordRecoveryController.swift index bbb4cd4450..d9fb450719 100644 --- a/TelegramUI/AuthorizationSequencePasswordRecoveryController.swift +++ b/TelegramUI/AuthorizationSequencePasswordRecoveryController.swift @@ -29,7 +29,7 @@ final class AuthorizationSequencePasswordRecoveryController: ViewController { } } - init(strings: PresentationStrings, theme: AuthorizationTheme) { + init(strings: PresentationStrings, theme: AuthorizationTheme, back: @escaping () -> Void) { self.strings = strings self.theme = theme @@ -41,6 +41,13 @@ final class AuthorizationSequencePasswordRecoveryController: ViewController { self.statusBar.statusBarStyle = theme.statusBarStyle + self.attemptNavigation = { _ in + return false + } + self.navigationBar?.backPressed = { + back() + } + self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: self.strings.Common_Next, style: .done, target: self, action: #selector(self.nextPressed)) } diff --git a/TelegramUI/AuthorizationSequencePhoneEntryController.swift b/TelegramUI/AuthorizationSequencePhoneEntryController.swift index c4b5320fc3..c3f5d30444 100644 --- a/TelegramUI/AuthorizationSequencePhoneEntryController.swift +++ b/TelegramUI/AuthorizationSequencePhoneEntryController.swift @@ -33,7 +33,7 @@ final class AuthorizationSequencePhoneEntryController: ViewController { private let hapticFeedback = HapticFeedback() - init(network: Network, strings: PresentationStrings, theme: AuthorizationTheme, openUrl: @escaping (String) -> Void) { + init(network: Network, strings: PresentationStrings, theme: AuthorizationTheme, openUrl: @escaping (String) -> Void, back: @escaping () -> Void) { self.network = network self.strings = strings self.theme = theme @@ -46,6 +46,12 @@ final class AuthorizationSequencePhoneEntryController: ViewController { self.hasActiveInput = true self.statusBar.statusBarStyle = theme.statusBarStyle + self.attemptNavigation = { _ in + return false + } + self.navigationBar?.backPressed = { + back() + } self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: strings.Common_Next, style: .done, target: self, action: #selector(self.nextPressed)) } diff --git a/TelegramUI/AuthorizationSequenceSignUpController.swift b/TelegramUI/AuthorizationSequenceSignUpController.swift index 55ff399240..7f74b277d2 100644 --- a/TelegramUI/AuthorizationSequenceSignUpController.swift +++ b/TelegramUI/AuthorizationSequenceSignUpController.swift @@ -33,7 +33,7 @@ final class AuthorizationSequenceSignUpController: ViewController { } } - init(strings: PresentationStrings, theme: AuthorizationTheme) { + init(strings: PresentationStrings, theme: AuthorizationTheme, back: @escaping () -> Void) { self.strings = strings self.theme = theme @@ -45,15 +45,17 @@ final class AuthorizationSequenceSignUpController: ViewController { self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: self.strings.Common_Next, style: .done, target: self, action: #selector(self.nextPressed)) - self.attemptNavigation = { [weak self] f in + self.attemptNavigation = { _ in + return false + } + self.navigationBar?.backPressed = { [weak self] in guard let strongSelf = self else { - return true + return } strongSelf.present(standardTextAlertController(theme: AlertControllerTheme(authTheme: theme), title: nil, text: strings.Login_CancelSignUpConfirmation, actions: [TextAlertAction(type: .genericAction, title: strings.Login_CancelPhoneVerificationContinue, action: { }), TextAlertAction(type: .defaultAction, title: strings.Login_CancelPhoneVerificationStop, action: { - f() + back() })]), in: .window(.root)) - return false } } diff --git a/TelegramUI/ChatController.swift b/TelegramUI/ChatController.swift index 893abd8192..8808cb46ac 100644 --- a/TelegramUI/ChatController.swift +++ b/TelegramUI/ChatController.swift @@ -4548,7 +4548,7 @@ public final class ChatController: TelegramController, KeyShortcutResponder, Gal guard let strongSelf = self else { return } - let complete = results.count >= Int(totalCount) + let complete = results.count == 0 var navigateIndex: MessageIndex? strongSelf.updateChatPresentationInterfaceState(animated: true, interactive: true, { current in if let data = current.search { @@ -4563,7 +4563,7 @@ public final class ChatController: TelegramController, KeyShortcutResponder, Gal } } navigateIndex = currentIndex - return current.updatedSearch(data.withUpdatedResultsState(ChatSearchResultsState(messageIndices: messageIndices, currentId: currentIndex?.id, totalCount: totalCount, complete: complete))) + return current.updatedSearch(data.withUpdatedResultsState(ChatSearchResultsState(messageIndices: messageIndices, currentId: currentIndex?.id, totalCount: max(Int32(messageIndices.count), totalCount), complete: complete))) } else { return current } @@ -4599,7 +4599,7 @@ public final class ChatController: TelegramController, KeyShortcutResponder, Gal guard let strongSelf = self else { return } - let complete = results.count != 0 + let complete = results.count == 0 strongSelf.updateChatPresentationInterfaceState(animated: true, interactive: true, { current in if let data = current.search, let previousResultsState = data.resultsState { let previousSet = Set(previousResultsState.messageIndices) @@ -4607,7 +4607,7 @@ public final class ChatController: TelegramController, KeyShortcutResponder, Gal var mergedIndices = messageIndices.filter({ !previousSet.contains($0) }) mergedIndices.append(contentsOf: previousResultsState.messageIndices) - return current.updatedSearch(data.withUpdatedResultsState(ChatSearchResultsState(messageIndices: mergedIndices, currentId: previousResultsState.currentId, totalCount: totalCount, complete: complete))) + return current.updatedSearch(data.withUpdatedResultsState(ChatSearchResultsState(messageIndices: mergedIndices, currentId: previousResultsState.currentId, totalCount: max(totalCount, Int32(mergedIndices.count)), complete: complete))) } else { return current } diff --git a/TelegramUI/ChatEmptyNode.swift b/TelegramUI/ChatEmptyNode.swift index cca1bf3409..0fa3817388 100644 --- a/TelegramUI/ChatEmptyNode.swift +++ b/TelegramUI/ChatEmptyNode.swift @@ -256,7 +256,7 @@ private final class ChatEmptyNodeGroupChatContent: ASDisplayNode, ChatEmptyNodeC let insets = UIEdgeInsets(top: 15.0, left: 15.0, bottom: 15.0, right: 15.0) let titleSpacing: CGFloat = 5.0 let subtitleSpacing: CGFloat = 10.0 - let iconInset: CGFloat = 17.0 + let iconInset: CGFloat = 19.0 var contentWidth: CGFloat = 100.0 var contentHeight: CGFloat = 0.0 diff --git a/TelegramUI/ChatHistoryEntriesForView.swift b/TelegramUI/ChatHistoryEntriesForView.swift index fdfc4c1449..5a1a1518ad 100644 --- a/TelegramUI/ChatHistoryEntriesForView.swift +++ b/TelegramUI/ChatHistoryEntriesForView.swift @@ -99,7 +99,7 @@ func chatHistoryEntriesForView(location: ChatLocation, view: MessageHistoryView, if let cachedPeerData = cachedPeerData as? CachedUserData, let botInfo = cachedPeerData.botInfo, !botInfo.description.isEmpty { entries.insert(.ChatInfoEntry(botInfo.description, presentationData), at: 0) } - if case let .MessageEntry(entry) = view.entries[0] { + if entries.count == 1, case let .MessageEntry(entry) = view.entries[0] { if let peer = entry.0.peers[entry.0.id.peerId] as? TelegramGroup, case .creator = peer.role { entries.remove(at: 0) }