From 8d38a8db0cf438520743a35160f47347533a9de3 Mon Sep 17 00:00:00 2001 From: Peter Iakovlev Date: Tue, 25 Dec 2018 17:58:09 +0400 Subject: [PATCH] Fixed video layer crash on iOS 8.x --- TelegramUI/ChatController.swift | 16 +++++----- .../ChatInterfaceStateContextMenus.swift | 18 +++++++++-- TelegramUI/ChatTextInputPanelNode.swift | 30 ++++++++++++++++++- TelegramUI/MediaPlayerNode.swift | 7 ++++- TelegramUI/NavigateToChatController.swift | 2 +- TelegramUI/NetworkStatusTitleView.swift | 2 +- TelegramUI/PeerReportController.swift | 3 +- TelegramUI/SampleBufferPool.swift | 7 ++++- TelegramUI/SoftwareVideoThumbnailLayer.swift | 7 ++++- 9 files changed, 74 insertions(+), 18 deletions(-) diff --git a/TelegramUI/ChatController.swift b/TelegramUI/ChatController.swift index ad2364e7c8..5528cf2bee 100644 --- a/TelegramUI/ChatController.swift +++ b/TelegramUI/ChatController.swift @@ -1270,13 +1270,15 @@ public final class ChatController: TelegramController, KeyShortcutResponder, Gal } var hasBots: Bool = false - if let cachedGroupData = peerView.cachedData as? CachedGroupData { - if !cachedGroupData.botInfos.isEmpty { - hasBots = true - } - } else if let cachedChannelData = peerView.cachedData as? CachedChannelData { - if !cachedChannelData.botInfos.isEmpty { - hasBots = true + if let peer = peerView.peers[peerView.peerId] { + if let cachedGroupData = peerView.cachedData as? CachedGroupData { + if !cachedGroupData.botInfos.isEmpty { + hasBots = true + } + } else if let cachedChannelData = peerView.cachedData as? CachedChannelData, let channel = peer as? TelegramChannel, case .group = channel.info { + if !cachedChannelData.botInfos.isEmpty { + hasBots = true + } } } diff --git a/TelegramUI/ChatInterfaceStateContextMenus.swift b/TelegramUI/ChatInterfaceStateContextMenus.swift index fefaf410d3..b2606cfc68 100644 --- a/TelegramUI/ChatInterfaceStateContextMenus.swift +++ b/TelegramUI/ChatInterfaceStateContextMenus.swift @@ -590,9 +590,15 @@ private func canPerformEditingActions(limits: LimitsConfiguration, accountPeerId let timestamp = Int32(CFAbsoluteTimeGetCurrent() + NSTimeIntervalSince1970) if message.timestamp + limits.maxMessageEditingInterval > timestamp { return true - } else { - return false } + + if let peer = message.peers[message.id.peerId] as? TelegramChannel { + if peer.hasAdminRights(.canPinMessages) { + return true + } + } + + return false } func chatAvailableMessageActions(postbox: Postbox, accountPeerId: PeerId, messageIds: Set) -> Signal { @@ -682,8 +688,14 @@ func chatAvailableMessageActions(postbox: Postbox, accountPeerId: PeerId, messag for media in message.media { if let _ = media as? TelegramMediaImage { hasMediaToReport = true - } else if let file = media as? TelegramMediaFile, file.isVideo { + } else if let _ = media as? TelegramMediaFile { hasMediaToReport = true + } else if let webpage = media as? TelegramMediaWebpage, case let .Loaded(content) = webpage.content { + if let _ = content.image { + hasMediaToReport = true + } else if let _ = content.file { + hasMediaToReport = true + } } } if hasMediaToReport { diff --git a/TelegramUI/ChatTextInputPanelNode.swift b/TelegramUI/ChatTextInputPanelNode.swift index ef4975a017..5583cc67b8 100644 --- a/TelegramUI/ChatTextInputPanelNode.swift +++ b/TelegramUI/ChatTextInputPanelNode.swift @@ -1219,7 +1219,7 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate { } @objc func editableTextNodeDidChangeSelection(_ editableTextNode: ASEditableTextNode, fromSelectedRange: NSRange, toSelectedRange: NSRange, dueToEditing: Bool) { - if !dueToEditing && !updatingInputState { + if !dueToEditing && !self.updatingInputState { let inputTextState = self.inputTextState self.interfaceInteraction?.updateTextInputStateAndMode({ _, inputMode in return (inputTextState, inputMode) }) } @@ -1307,6 +1307,34 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate { @objc func editableTextNode(_ editableTextNode: ASEditableTextNode, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool { self.updateActivity() + var cleanText = text + let removeSequences: [String] = ["\u{202d}", "\u{202c}"] + for sequence in removeSequences { + inner: while true { + if let range = cleanText.range(of: sequence) { + cleanText.removeSubrange(range) + } else { + break inner + } + } + } + if cleanText != text { + let string = NSMutableAttributedString(attributedString: editableTextNode.attributedText ?? NSAttributedString()) + var textColor: UIColor = .black + var accentTextColor: UIColor = .blue + var baseFontSize: CGFloat = 17.0 + if let presentationInterfaceState = self.presentationInterfaceState { + textColor = presentationInterfaceState.theme.chat.inputPanel.inputTextColor + accentTextColor = presentationInterfaceState.theme.chat.inputPanel.panelControlAccentColor + baseFontSize = max(17.0, presentationInterfaceState.fontSize.baseDisplaySize) + } + let cleanReplacementString = textAttributedStringForStateText(NSAttributedString(string: cleanText), fontSize: baseFontSize, textColor: textColor, accentTextColor: accentTextColor) + string.replaceCharacters(in: range, with: cleanReplacementString) + self.textInputNode?.attributedText = string + self.textInputNode?.selectedRange = NSMakeRange(range.lowerBound + cleanReplacementString.length, 0) + self.updateTextNodeText(animated: true) + return false + } return true } diff --git a/TelegramUI/MediaPlayerNode.swift b/TelegramUI/MediaPlayerNode.swift index b954b288af..ba4d384b40 100644 --- a/TelegramUI/MediaPlayerNode.swift +++ b/TelegramUI/MediaPlayerNode.swift @@ -4,9 +4,14 @@ import AsyncDisplayKit import SwiftSignalKit import AVFoundation +private final class MediaPlayerNodeLayerNullAction: NSNull { + @objc override func run(forKey event: String, object anObject: Any, arguments dict: [AnyHashable : Any]?) { + } +} + private final class MediaPlayerNodeLayer: AVSampleBufferDisplayLayer { override func action(forKey event: String) -> CAAction? { - return NSNull() + return MediaPlayerNodeLayerNullAction() } } diff --git a/TelegramUI/NavigateToChatController.swift b/TelegramUI/NavigateToChatController.swift index c322f812ca..db118e3dd5 100644 --- a/TelegramUI/NavigateToChatController.swift +++ b/TelegramUI/NavigateToChatController.swift @@ -50,7 +50,7 @@ public func navigateToChatController(navigationController: NavigationController, resolvedKeepStack = false } if resolvedKeepStack { - navigationController.pushViewController(controller, completion: completion) + navigationController.pushViewController(controller, animated: animated, completion: completion) } else { navigationController.replaceAllButRootController(controller, animated: animated, completion: completion) } diff --git a/TelegramUI/NetworkStatusTitleView.swift b/TelegramUI/NetworkStatusTitleView.swift index f3fb05719f..5fe6b22e37 100644 --- a/TelegramUI/NetworkStatusTitleView.swift +++ b/TelegramUI/NetworkStatusTitleView.swift @@ -57,7 +57,7 @@ final class NetworkStatusTitleView: UIView, NavigationBarTitleView, NavigationBa var theme: PresentationTheme { didSet { - self.titleNode.attributedText = NSAttributedString(string: self.title.text, font: Font.medium(17.0), textColor: self.theme.rootController.navigationBar.primaryTextColor) + self.titleNode.attributedText = NSAttributedString(string: self.title.text, font: Font.bold(17.0), textColor: self.theme.rootController.navigationBar.primaryTextColor) if self.isPasscodeSet { self.lockView.setIsLocked(self.isManuallyLocked, theme: self.theme, animated: false) diff --git a/TelegramUI/PeerReportController.swift b/TelegramUI/PeerReportController.swift index b48827e297..9aae60adb7 100644 --- a/TelegramUI/PeerReportController.swift +++ b/TelegramUI/PeerReportController.swift @@ -34,7 +34,7 @@ func peerReportOptionsController(account: Account, subject: PeerReportSubject, p var items: [ActionSheetItem] = [] for option in options { let title: String - var color: ActionSheetButtonColor = .accent + let color: ActionSheetButtonColor = .accent switch option { case .spam: title = presentationData.strings.ReportPeer_ReasonSpam @@ -44,7 +44,6 @@ func peerReportOptionsController(account: Account, subject: PeerReportSubject, p title = presentationData.strings.ReportPeer_ReasonPornography case .childAbuse: title = presentationData.strings.ReportPeer_ReasonChildAbuse - color = .destructive case .copyright: title = presentationData.strings.ReportPeer_ReasonCopyright case .other: diff --git a/TelegramUI/SampleBufferPool.swift b/TelegramUI/SampleBufferPool.swift index 576fb3ce92..421d90ad1a 100644 --- a/TelegramUI/SampleBufferPool.swift +++ b/TelegramUI/SampleBufferPool.swift @@ -3,9 +3,14 @@ import UIKit import AVFoundation import SwiftSignalKit +private final class SampleBufferLayerImplNullAction: NSNull { + @objc override func run(forKey event: String, object anObject: Any, arguments dict: [AnyHashable : Any]?) { + } +} + private final class SampleBufferLayerImpl: AVSampleBufferDisplayLayer { override func action(forKey event: String) -> CAAction? { - return NSNull() + return SampleBufferLayerImplNullAction() } deinit { diff --git a/TelegramUI/SoftwareVideoThumbnailLayer.swift b/TelegramUI/SoftwareVideoThumbnailLayer.swift index 46f2b7a36a..1f3be19ec4 100644 --- a/TelegramUI/SoftwareVideoThumbnailLayer.swift +++ b/TelegramUI/SoftwareVideoThumbnailLayer.swift @@ -4,6 +4,11 @@ import TelegramCore import Postbox import SwiftSignalKit +private final class SoftwareVideoThumbnailLayerNullAction: NSNull { + @objc override func run(forKey event: String, object anObject: Any, arguments dict: [AnyHashable : Any]?) { + } +} + final class SoftwareVideoThumbnailLayer: CALayer { var disposable: Disposable? @@ -49,6 +54,6 @@ final class SoftwareVideoThumbnailLayer: CALayer { } override func action(forKey event: String) -> CAAction? { - return NSNull() + return SoftwareVideoThumbnailLayerNullAction() } }