From f0bd7aeffdc2001e6b72c4729c4ca3e4ba081451 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Tue, 25 Jun 2019 23:46:36 +0200 Subject: [PATCH] Fixed error 406 handling on supergroup creation --- .../TelegramCore/ChannelCreation.swift | 5 ++++- .../TelegramCore/TelegramCore/CreateGroup.swift | 1 + .../TelegramUI/CreateChannelController.swift | 8 ++++++-- .../TelegramUI/CreateGroupController.swift | 17 +++++++++++++++-- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/submodules/TelegramCore/TelegramCore/ChannelCreation.swift b/submodules/TelegramCore/TelegramCore/ChannelCreation.swift index 567a7f1b4b..e5e4a21c8b 100644 --- a/submodules/TelegramCore/TelegramCore/ChannelCreation.swift +++ b/submodules/TelegramCore/TelegramCore/ChannelCreation.swift @@ -19,6 +19,7 @@ public enum CreateChannelError { case generic case restricted case tooMuchLocationBasedGroups + case serverProvided(String) } private func createChannel(account: Account, title: String, description: String?, isSupergroup:Bool, location: (latitude: Double, longitude: Double, address: String)? = nil) -> Signal { @@ -40,7 +41,9 @@ private func createChannel(account: Account, title: String, description: String? return account.network.request(Api.functions.channels.createChannel(flags: flags, title: title, about: description ?? "", geoPoint: geoPoint, address: address), automaticFloodWait: false) |> mapError { error -> CreateChannelError in - if error.errorDescription == "CHANNELS_ADMIN_LOCATED_TOO_MUCH" { + if error.errorCode == 406 { + return .serverProvided(error.errorDescription) + } else if error.errorDescription == "CHANNELS_ADMIN_LOCATED_TOO_MUCH" { return .tooMuchLocationBasedGroups } else if error.errorDescription == "USER_RESTRICTED" { return .restricted diff --git a/submodules/TelegramCore/TelegramCore/CreateGroup.swift b/submodules/TelegramCore/TelegramCore/CreateGroup.swift index 6a2bc5d015..a7707e72b3 100644 --- a/submodules/TelegramCore/TelegramCore/CreateGroup.swift +++ b/submodules/TelegramCore/TelegramCore/CreateGroup.swift @@ -20,6 +20,7 @@ public enum CreateGroupError { case privacy case restricted case tooMuchLocationBasedGroups + case serverProvided(String) } public func createGroup(account: Account, title: String, peerIds: [PeerId]) -> Signal { diff --git a/submodules/TelegramUI/TelegramUI/CreateChannelController.swift b/submodules/TelegramUI/TelegramUI/CreateChannelController.swift index cb9e30b61c..9f01800eb9 100644 --- a/submodules/TelegramUI/TelegramUI/CreateChannelController.swift +++ b/submodules/TelegramUI/TelegramUI/CreateChannelController.swift @@ -258,14 +258,18 @@ public func createChannelController(context: AccountContext) -> ViewController { replaceControllerImpl?(controller) }, error: { error in let presentationData = context.sharedContext.currentPresentationData.with { $0 } - let text: String + let text: String? switch error { case .generic, .tooMuchLocationBasedGroups: text = presentationData.strings.Login_UnknownError case .restricted: text = presentationData.strings.Common_ActionNotAllowedError + default: + text = nil + } + if let text = text { + presentControllerImpl?(textAlertController(context: context, title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})]), nil) } - presentControllerImpl?(textAlertController(context: context, title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})]), nil) })) } }, changeProfilePhoto: { diff --git a/submodules/TelegramUI/TelegramUI/CreateGroupController.swift b/submodules/TelegramUI/TelegramUI/CreateGroupController.swift index b2309751b0..c5ccb77daa 100644 --- a/submodules/TelegramUI/TelegramUI/CreateGroupController.swift +++ b/submodules/TelegramUI/TelegramUI/CreateGroupController.swift @@ -358,6 +358,8 @@ public func createGroupController(context: AccountContext, peerIds: [PeerId], in return .restricted case .tooMuchLocationBasedGroups: return .tooMuchLocationBasedGroups + case let .serverProvided(error): + return .serverProvided(error) } } case .locatedGroup: @@ -381,6 +383,8 @@ public func createGroupController(context: AccountContext, peerIds: [PeerId], in return .restricted case .tooMuchLocationBasedGroups: return .tooMuchLocationBasedGroups + case let .serverProvided(error): + return .serverProvided(error) } } } @@ -431,8 +435,12 @@ public func createGroupController(context: AccountContext, peerIds: [PeerId], in } } }, error: { error in + if case .serverProvided = error { + return + } + let presentationData = context.sharedContext.currentPresentationData.with { $0 } - let text: String + let text: String? switch error { case .privacy: text = presentationData.strings.Privacy_GroupsAndChannels_InviteToChannelMultipleError @@ -442,8 +450,13 @@ public func createGroupController(context: AccountContext, peerIds: [PeerId], in text = presentationData.strings.Common_ActionNotAllowedError case .tooMuchLocationBasedGroups: text = presentationData.strings.CreateGroup_ErrorLocatedGroupsTooMuch + default: + text = nil + } + + if let text = text { + presentControllerImpl?(textAlertController(context: context, title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})]), nil) } - presentControllerImpl?(textAlertController(context: context, title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})]), nil) })) } }, changeProfilePhoto: {