Fixed error 406 handling on supergroup creation

This commit is contained in:
Ilya Laktyushin 2019-06-25 23:46:36 +02:00
parent 855e98f9c5
commit f0bd7aeffd
4 changed files with 26 additions and 5 deletions

View File

@ -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<PeerId, CreateChannelError> {
@ -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

View File

@ -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<PeerId?, CreateGroupError> {

View File

@ -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: {

View File

@ -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: {