diff --git a/submodules/TelegramCore/TelegramCore/ChannelOwnershipTransfer.swift b/submodules/TelegramCore/TelegramCore/ChannelOwnershipTransfer.swift index 26ebaf4c7a..a72975a992 100644 --- a/submodules/TelegramCore/TelegramCore/ChannelOwnershipTransfer.swift +++ b/submodules/TelegramCore/TelegramCore/ChannelOwnershipTransfer.swift @@ -21,6 +21,7 @@ public enum ChannelOwnershipTransferError { case adminsTooMuch case userPublicChannelsTooMuch case userLocatedGroupsTooMuch + case tooMuchJoined case restricted case userBlocked } @@ -64,6 +65,8 @@ public func checkOwnershipTranfserAvailability(postbox: Postbox, network: Networ return .restricted } else if error.errorDescription == "USER_BLOCKED" { return .userBlocked + } else if error.errorDescription == "CHANNELS_TOO_MUCH" { + return .tooMuchJoined } return .generic } diff --git a/submodules/TelegramCore/TelegramCore/JoinLink.swift b/submodules/TelegramCore/TelegramCore/JoinLink.swift index b204bb6da5..b82edfd858 100644 --- a/submodules/TelegramCore/TelegramCore/JoinLink.swift +++ b/submodules/TelegramCore/TelegramCore/JoinLink.swift @@ -14,6 +14,11 @@ #endif #endif +public enum JoinLinkError { + case generic + case tooMuchJoined +} + func apiUpdatesGroups(_ updates: Api.Updates) -> [Api.Chat] { switch updates { case let .updates( _, _, chats, _, _): @@ -31,31 +36,31 @@ public enum ExternalJoiningChatState { case invalidHash } -public func joinChatInteractively(with hash: String, account: Account) -> Signal { +public func joinChatInteractively(with hash: String, account: Account) -> Signal { return account.network.request(Api.functions.messages.importChatInvite(hash: hash)) - |> map(Optional.init) - |> `catch` { _ -> Signal in - return .single(nil) - } - |> mapToSignal { updates -> Signal in - if let updates = updates { - account.stateManager.addUpdates(updates) - if let peerId = apiUpdatesGroups(updates).first?.peerId { - return account.postbox.multiplePeersView([peerId]) - |> filter { view in - return view.peers[peerId] != nil - } - |> take(1) - |> map { _ in - return peerId - } - |> timeout(5.0, queue: Queue.concurrentDefaultQueue(), alternate: .single(nil)) - } - return .single(nil) + |> mapError { error -> JoinLinkError in + if error.errorDescription == "CHANNELS_TOO_MUCH" { + return .tooMuchJoined } else { - return .single(nil) + return .generic } } + |> mapToSignal { updates -> Signal in + account.stateManager.addUpdates(updates) + if let peerId = apiUpdatesGroups(updates).first?.peerId { + return account.postbox.multiplePeersView([peerId]) + |> introduceError(JoinLinkError.self) + |> filter { view in + return view.peers[peerId] != nil + } + |> take(1) + |> map { _ in + return peerId + } + |> timeout(5.0, queue: Queue.concurrentDefaultQueue(), alternate: .single(nil) |> introduceError(JoinLinkError.self)) + } + return .single(nil) + } } public func joinLinkInformation(_ hash: String, account: Account) -> Signal { diff --git a/submodules/TelegramUI/TelegramUI/JoinLinkPreviewController.swift b/submodules/TelegramUI/TelegramUI/JoinLinkPreviewController.swift index 9c33b501fd..6ff6b8c655 100644 --- a/submodules/TelegramUI/TelegramUI/JoinLinkPreviewController.swift +++ b/submodules/TelegramUI/TelegramUI/JoinLinkPreviewController.swift @@ -105,6 +105,13 @@ public final class JoinLinkPreviewController: ViewController { strongSelf.dismiss() } } + }, error: { [weak self] error in + if let strongSelf = self { + if case .tooMuchJoined = error { + strongSelf.present(textAlertController(context: strongSelf.context, title: nil, text: strongSelf.presentationData.strings.Join_ChannelsTooMuch, actions: [TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: {})]), in: .window(.root)) + strongSelf.dismiss() + } + } })) } } diff --git a/submodules/TelegramUI/TelegramUI/LocationBroadcastNavigationAccessoryPanel.swift b/submodules/TelegramUI/TelegramUI/LocationBroadcastNavigationAccessoryPanel.swift index 6a170aae68..f8d6f8f136 100644 --- a/submodules/TelegramUI/TelegramUI/LocationBroadcastNavigationAccessoryPanel.swift +++ b/submodules/TelegramUI/TelegramUI/LocationBroadcastNavigationAccessoryPanel.swift @@ -32,7 +32,7 @@ final class LocationBroadcastNavigationAccessoryPanel: ASDisplayNode { private let separatorNode: ASDisplayNode private var validLayout: (CGSize, CGFloat, CGFloat)? - private var peersAndMode: ([Peer], LocationBroadcastNavigationAccessoryPanelMode)? + private var peersAndMode: ([Peer], LocationBroadcastNavigationAccessoryPanelMode, Bool)? init(accountPeerId: PeerId, theme: PresentationTheme, strings: PresentationStrings, tapAction: @escaping () -> Void, close: @escaping () -> Void) { self.accountPeerId = accountPeerId @@ -108,7 +108,7 @@ final class LocationBroadcastNavigationAccessoryPanel: ASDisplayNode { let titleString = NSAttributedString(string: self.strings.Conversation_LiveLocation, font: titleFont, textColor: self.theme.rootController.navigationBar.primaryTextColor) var subtitleString: NSAttributedString? - if let (peers, mode) = self.peersAndMode { + if let (peers, mode, canClose) = self.peersAndMode { switch mode { case .summary: let text: String @@ -119,6 +119,7 @@ final class LocationBroadcastNavigationAccessoryPanel: ASDisplayNode { } subtitleString = NSAttributedString(string: text, font: subtitleFont, textColor: self.theme.rootController.navigationBar.secondaryTextColor) case .peer: + self.closeButton.isHidden = !canClose let filteredPeers = peers.filter { $0.id != self.accountPeerId } @@ -172,8 +173,8 @@ final class LocationBroadcastNavigationAccessoryPanel: ASDisplayNode { transition.updateFrame(node: self.separatorNode, frame: CGRect(origin: CGPoint(x: 0.0, y: size.height - UIScreenPixel), size: CGSize(width: size.width, height: UIScreenPixel))) } - func update(peers: [Peer], mode: LocationBroadcastNavigationAccessoryPanelMode) { - self.peersAndMode = (peers, mode) + func update(peers: [Peer], mode: LocationBroadcastNavigationAccessoryPanelMode, canClose: Bool) { + self.peersAndMode = (peers, mode, canClose) if let layout = validLayout { self.updateLayout(size: layout.0, leftInset: layout.1, rightInset: layout.2, transition: .immediate) } diff --git a/submodules/TelegramUI/TelegramUI/TelegramController.swift b/submodules/TelegramUI/TelegramUI/TelegramController.swift index a8b312ca8d..52f845c2a1 100644 --- a/submodules/TelegramUI/TelegramUI/TelegramController.swift +++ b/submodules/TelegramUI/TelegramUI/TelegramController.swift @@ -184,24 +184,24 @@ public class TelegramController: ViewController, KeyShortcutResponder { peers?.append(author) } } - return (peers, nil) + return (peers, outgoingMessages) } default: self.locationBroadcastMode = .summary signal = liveLocationManager.summaryManager.broadcastingToMessages() - |> map { messages -> ([Peer]?, [MessageId: Message]?) in - if messages.isEmpty { - return (nil, nil) - } else { - var peers: [Peer] = [] - for message in messages.values.sorted(by: { $0.index < $1.index }) { - if let peer = message.peers[message.id.peerId] { - peers.append(peer) - } + |> map { messages -> ([Peer]?, [MessageId: Message]?) in + if messages.isEmpty { + return (nil, nil) + } else { + var peers: [Peer] = [] + for message in messages.values.sorted(by: { $0.index < $1.index }) { + if let peer = message.peers[message.id.peerId] { + peers.append(peer) } - return (peers, messages) } + return (peers, messages) } + } } @@ -223,7 +223,16 @@ public class TelegramController: ViewController, KeyShortcutResponder { if wasEmpty != (peers == nil) { strongSelf.requestLayout(transition: .animated(duration: 0.4, curve: .spring)) } else if let peers = peers, let locationBroadcastMode = strongSelf.locationBroadcastMode { - strongSelf.locationBroadcastAccessoryPanel?.update(peers: peers, mode: locationBroadcastMode) + var canClose = true + if case let .peer(peerId) = strongSelf.locationBroadcastPanelSource, let messages = messages { + canClose = false + for messageId in messages.keys { + if messageId.peerId == peerId { + canClose = true + } + } + } + strongSelf.locationBroadcastAccessoryPanel?.update(peers: peers, mode: locationBroadcastMode, canClose: canClose) } } } @@ -401,7 +410,18 @@ public class TelegramController: ViewController, KeyShortcutResponder { } self.locationBroadcastAccessoryPanel = locationBroadcastAccessoryPanel locationBroadcastAccessoryPanel.frame = panelFrame - locationBroadcastAccessoryPanel.update(peers: locationBroadcastPeers, mode: locationBroadcastMode) + + var canClose = true + if case let .peer(peerId) = self.locationBroadcastPanelSource, let messages = self.locationBroadcastMessages { + canClose = false + for messageId in messages.keys { + if messageId.peerId == peerId { + canClose = true + } + } + } + + locationBroadcastAccessoryPanel.update(peers: locationBroadcastPeers, mode: locationBroadcastMode, canClose: canClose) locationBroadcastAccessoryPanel.updateLayout(size: panelFrame.size, leftInset: layout.safeInsets.left, rightInset: layout.safeInsets.right, transition: .immediate) if transition.isAnimated { locationBroadcastAccessoryPanel.animateIn(transition) diff --git a/submodules/TelegramUI/TelegramUI/UniversalVideoGalleryItem.swift b/submodules/TelegramUI/TelegramUI/UniversalVideoGalleryItem.swift index a116dcecb7..62820724c3 100644 --- a/submodules/TelegramUI/TelegramUI/UniversalVideoGalleryItem.swift +++ b/submodules/TelegramUI/TelegramUI/UniversalVideoGalleryItem.swift @@ -890,7 +890,7 @@ final class UniversalVideoGalleryItemNode: ZoomableContentGalleryItemNode { transformedSuperFrame = transformedSuperFrame.offsetBy(dx: videoNode.position.x - previousFrame.center.x, dy: videoNode.position.y - previousFrame.center.y) } - let initialScale = min(videoNode.layer.bounds.width / node.0.view.bounds.width, videoNode.layer.bounds.height / node.0.view.bounds.height) + let initialScale: CGFloat = 1.0 //min(videoNode.layer.bounds.width / node.0.view.bounds.width, videoNode.layer.bounds.height / node.0.view.bounds.height) let targetScale = max(transformedFrame.size.width / videoNode.layer.bounds.size.width, transformedFrame.size.height / videoNode.layer.bounds.size.height) videoNode.backgroundColor = .clear