Added CHANNELS_TOO_MUCH error support all across the app

This commit is contained in:
Ilya Laktyushin 2019-06-26 18:01:28 +02:00
parent 684a933fa3
commit 13a3a16c91
13 changed files with 2015 additions and 1996 deletions

View File

@ -4460,3 +4460,7 @@ Any member of this group will be able to see messages in the channel.";
"Activity.RemindAboutGroup" = "Send message to %@"; "Activity.RemindAboutGroup" = "Send message to %@";
"Activity.RemindAboutUser" = "Send message to %@"; "Activity.RemindAboutUser" = "Send message to %@";
"Activity.RemindAboutChannel" = "Read %@"; "Activity.RemindAboutChannel" = "Read %@";
"CreateGroup.ChannelsTooMuch" = "Sorry, you are a member of too many groups and channels. Please leave some before creating a new one.";
"Join.ChannelsTooMuch" = "Sorry, you are a member of too many groups and channels. Please leave some before joining one.";
"Invite.ChannelsTooMuch" = "Sorry, the target user is a member of too many groups and channels. Please ask them to leave some first.";

View File

@ -75,6 +75,7 @@ public enum AddChannelMemberError {
case generic case generic
case restricted case restricted
case limitExceeded case limitExceeded
case tooMuchJoined
case bot(PeerId) case bot(PeerId)
} }
@ -97,6 +98,8 @@ public func addChannelMember(account: Account, peerId: PeerId, memberId: PeerId)
|> map { [$0] } |> map { [$0] }
|> `catch` { error -> Signal<[Api.Updates], AddChannelMemberError> in |> `catch` { error -> Signal<[Api.Updates], AddChannelMemberError> in
switch error.errorDescription { switch error.errorDescription {
case "CHANNELS_TOO_MUCH":
return .fail(.tooMuchJoined)
case "USERS_TOO_MUCH": case "USERS_TOO_MUCH":
return .fail(.limitExceeded) return .fail(.limitExceeded)
case "USER_PRIVACY_RESTRICTED": case "USER_PRIVACY_RESTRICTED":
@ -190,6 +193,8 @@ public func addChannelMembers(account: Account, peerId: PeerId, memberIds: [Peer
let signal = account.network.request(Api.functions.channels.inviteToChannel(channel: inputChannel, users: inputUsers)) let signal = account.network.request(Api.functions.channels.inviteToChannel(channel: inputChannel, users: inputUsers))
|> mapError { error -> AddChannelMemberError in |> mapError { error -> AddChannelMemberError in
switch error.errorDescription { switch error.errorDescription {
case "CHANNELS_TOO_MUCH":
return .tooMuchJoined
case "USER_PRIVACY_RESTRICTED": case "USER_PRIVACY_RESTRICTED":
return .restricted return .restricted
case "USERS_TOO_MUCH": case "USERS_TOO_MUCH":

View File

@ -18,6 +18,7 @@ import Foundation
public enum CreateChannelError { public enum CreateChannelError {
case generic case generic
case restricted case restricted
case tooMuchJoined
case tooMuchLocationBasedGroups case tooMuchLocationBasedGroups
case serverProvided(String) case serverProvided(String)
} }
@ -43,6 +44,8 @@ private func createChannel(account: Account, title: String, description: String?
|> mapError { error -> CreateChannelError in |> mapError { error -> CreateChannelError in
if error.errorCode == 406 { if error.errorCode == 406 {
return .serverProvided(error.errorDescription) return .serverProvided(error.errorDescription)
} else if error.errorDescription == "CHANNELS_TOO_MUCH" {
return .tooMuchJoined
} else if error.errorDescription == "CHANNELS_ADMIN_LOCATED_TOO_MUCH" { } else if error.errorDescription == "CHANNELS_ADMIN_LOCATED_TOO_MUCH" {
return .tooMuchLocationBasedGroups return .tooMuchLocationBasedGroups
} else if error.errorDescription == "USER_RESTRICTED" { } else if error.errorDescription == "USER_RESTRICTED" {

View File

@ -19,6 +19,7 @@ public enum CreateGroupError {
case generic case generic
case privacy case privacy
case restricted case restricted
case tooMuchJoined
case tooMuchLocationBasedGroups case tooMuchLocationBasedGroups
case serverProvided(String) case serverProvided(String)
} }

View File

@ -11,6 +11,7 @@ import Foundation
public enum JoinChannelError { public enum JoinChannelError {
case generic case generic
case tooMuchJoined
} }
public func joinChannel(account: Account, peerId: PeerId) -> Signal<RenderedChannelParticipant?, JoinChannelError> { public func joinChannel(account: Account, peerId: PeerId) -> Signal<RenderedChannelParticipant?, JoinChannelError> {
@ -20,9 +21,13 @@ public func joinChannel(account: Account, peerId: PeerId) -> Signal<RenderedChan
|> mapToSignal { peer -> Signal<RenderedChannelParticipant?, JoinChannelError> in |> mapToSignal { peer -> Signal<RenderedChannelParticipant?, JoinChannelError> in
if let inputChannel = apiInputChannel(peer) { if let inputChannel = apiInputChannel(peer) {
return account.network.request(Api.functions.channels.joinChannel(channel: inputChannel)) return account.network.request(Api.functions.channels.joinChannel(channel: inputChannel))
|> mapError { _ -> JoinChannelError in |> mapError { error -> JoinChannelError in
if error.errorDescription == "CHANNELS_TOO_MUCH" {
return .tooMuchJoined
} else {
return .generic return .generic
} }
}
|> mapToSignal { updates -> Signal<RenderedChannelParticipant?, JoinChannelError> in |> mapToSignal { updates -> Signal<RenderedChannelParticipant?, JoinChannelError> in
account.stateManager.addUpdates(updates) account.stateManager.addUpdates(updates)

View File

@ -376,6 +376,8 @@ public func channelMembersController(context: AccountContext, peerId: PeerId) ->
switch error { switch error {
case .limitExceeded: case .limitExceeded:
text = presentationData.strings.Channel_ErrorAddTooMuch text = presentationData.strings.Channel_ErrorAddTooMuch
case .tooMuchJoined:
text = presentationData.strings.Invite_ChannelsTooMuch
case .generic: case .generic:
text = presentationData.strings.Login_UnknownError text = presentationData.strings.Login_UnknownError
case .restricted: case .restricted:

View File

@ -126,16 +126,21 @@ final class ChatChannelSubscriberInputPanelNode: ChatInputPanelNode {
strongSelf.activityIndicator.stopAnimating() strongSelf.activityIndicator.stopAnimating()
} }
} }
}).start(error: { [weak self] _ in }).start(error: { [weak self] error in
guard let strongSelf = self, let presentationInterfaceState = strongSelf.presentationInterfaceState, let peer = presentationInterfaceState.renderedPeer?.peer else { guard let strongSelf = self, let presentationInterfaceState = strongSelf.presentationInterfaceState, let peer = presentationInterfaceState.renderedPeer?.peer else {
return return
} }
let text: String let text: String
switch error {
case .tooMuchJoined:
text = presentationInterfaceState.strings.Join_ChannelsTooMuch
default:
if let channel = peer as? TelegramChannel, case .broadcast = channel.info { if let channel = peer as? TelegramChannel, case .broadcast = channel.info {
text = presentationInterfaceState.strings.Channel_ErrorAccessDenied text = presentationInterfaceState.strings.Channel_ErrorAccessDenied
} else { } else {
text = presentationInterfaceState.strings.Group_ErrorAccessDenied text = presentationInterfaceState.strings.Group_ErrorAccessDenied
} }
}
strongSelf.interfaceInteraction?.presentController(textAlertController(context: context, title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: presentationInterfaceState.strings.Common_OK, action: {})]), nil) strongSelf.interfaceInteraction?.presentController(textAlertController(context: context, title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: presentationInterfaceState.strings.Common_OK, action: {})]), nil)
})) }))
case .kicked: case .kicked:

View File

@ -262,6 +262,8 @@ public func createChannelController(context: AccountContext) -> ViewController {
switch error { switch error {
case .generic, .tooMuchLocationBasedGroups: case .generic, .tooMuchLocationBasedGroups:
text = presentationData.strings.Login_UnknownError text = presentationData.strings.Login_UnknownError
case .tooMuchJoined:
text = presentationData.strings.CreateGroup_ChannelsTooMuch
case .restricted: case .restricted:
text = presentationData.strings.Common_ActionNotAllowedError text = presentationData.strings.Common_ActionNotAllowedError
default: default:

View File

@ -356,6 +356,8 @@ public func createGroupController(context: AccountContext, peerIds: [PeerId], in
return .generic return .generic
case .restricted: case .restricted:
return .restricted return .restricted
case .tooMuchJoined:
return .tooMuchJoined
case .tooMuchLocationBasedGroups: case .tooMuchLocationBasedGroups:
return .tooMuchLocationBasedGroups return .tooMuchLocationBasedGroups
case let .serverProvided(error): case let .serverProvided(error):
@ -381,6 +383,8 @@ public func createGroupController(context: AccountContext, peerIds: [PeerId], in
return .generic return .generic
case .restricted: case .restricted:
return .restricted return .restricted
case .tooMuchJoined:
return .tooMuchJoined
case .tooMuchLocationBasedGroups: case .tooMuchLocationBasedGroups:
return .tooMuchLocationBasedGroups return .tooMuchLocationBasedGroups
case let .serverProvided(error): case let .serverProvided(error):
@ -448,6 +452,8 @@ public func createGroupController(context: AccountContext, peerIds: [PeerId], in
text = presentationData.strings.Login_UnknownError text = presentationData.strings.Login_UnknownError
case .restricted: case .restricted:
text = presentationData.strings.Common_ActionNotAllowedError text = presentationData.strings.Common_ActionNotAllowedError
case .tooMuchJoined:
text = presentationData.strings.CreateGroup_ChannelsTooMuch
case .tooMuchLocationBasedGroups: case .tooMuchLocationBasedGroups:
text = presentationData.strings.CreateGroup_ErrorLocatedGroupsTooMuch text = presentationData.strings.CreateGroup_ErrorLocatedGroupsTooMuch
default: default:

View File

@ -327,23 +327,6 @@ final class PeerChannelMemberCategoriesContextsManager {
|> mapToSignal { _ -> Signal<Void, AddChannelMemberError> in |> mapToSignal { _ -> Signal<Void, AddChannelMemberError> in
return .complete() return .complete()
} }
/*return addChannelMembers(account: account, peerId: peerId, memberIds: memberIds)
|> deliverOnMainQueue
|> beforeNext { [weak self] result in
if let strongSelf = self {
strongSelf.impl.with { impl in
for (contextPeerId, context) in impl.contexts {
if peerId == contextPeerId {
context.reset(.recent)
}
}
}
}
}
|> mapToSignal { _ -> Signal<Void, AddChannelMemberError> in
return .single(Void())
}*/
} }
func recentOnline(postbox: Postbox, network: Network, accountPeerId: PeerId, peerId: PeerId) -> Signal<Int32, NoError> { func recentOnline(postbox: Postbox, network: Network, accountPeerId: PeerId, peerId: PeerId) -> Signal<Int32, NoError> {