diff --git a/submodules/AccountContext/Sources/AccountContext.swift b/submodules/AccountContext/Sources/AccountContext.swift index c4ac2bf9a1..8599be57d8 100644 --- a/submodules/AccountContext/Sources/AccountContext.swift +++ b/submodules/AccountContext/Sources/AccountContext.swift @@ -408,6 +408,7 @@ public protocol SharedAccountContext: class { var currentAutomaticMediaDownloadSettings: Atomic { get } var automaticMediaDownloadSettings: Signal { get } + var currentAutodownloadSettings: Atomic { get } var immediateExperimentalUISettings: ExperimentalUISettings { get } var currentInAppNotificationSettings: Atomic { get } var currentMediaInputSettings: Atomic { get } diff --git a/submodules/AccountContext/Sources/OpenChatMessage.swift b/submodules/AccountContext/Sources/OpenChatMessage.swift index 1e3507fc3c..4ff4350a6f 100644 --- a/submodules/AccountContext/Sources/OpenChatMessage.swift +++ b/submodules/AccountContext/Sources/OpenChatMessage.swift @@ -25,7 +25,7 @@ public final class OpenChatMessageParams { public let modal: Bool public let dismissInput: () -> Void public let present: (ViewController, Any?) -> Void - public let transitionNode: (MessageId, Media) -> (ASDisplayNode, () -> (UIView?, UIView?))? + public let transitionNode: (MessageId, Media) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? public let addToTransitionSurface: (UIView) -> Void public let openUrl: (String) -> Void public let openPeer: (Peer, ChatControllerInteractionNavigateToPeer) -> Void @@ -46,7 +46,7 @@ public final class OpenChatMessageParams { modal: Bool = false, dismissInput: @escaping () -> Void, present: @escaping (ViewController, Any?) -> Void, - transitionNode: @escaping (MessageId, Media) -> (ASDisplayNode, () -> (UIView?, UIView?))?, + transitionNode: @escaping (MessageId, Media) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))?, addToTransitionSurface: @escaping (UIView) -> Void, openUrl: @escaping (String) -> Void, openPeer: @escaping (Peer, ChatControllerInteractionNavigateToPeer) -> Void, diff --git a/submodules/ChatListUI/Sources/Node/ChatListBadgeNode.swift b/submodules/ChatListUI/Sources/Node/ChatListBadgeNode.swift index 92d837b2d9..8e1ff49f1f 100644 --- a/submodules/ChatListUI/Sources/Node/ChatListBadgeNode.swift +++ b/submodules/ChatListUI/Sources/Node/ChatListBadgeNode.swift @@ -33,8 +33,6 @@ private func measureString(_ string: String) -> String { } } -private let badgeFont = Font.regular(14.0) - final class ChatListBadgeNode: ASDisplayNode { private let backgroundNode: ASImageNode private let textNode: TextNode @@ -63,13 +61,13 @@ final class ChatListBadgeNode: ASDisplayNode { self.addSubnode(self.textNode) } - func asyncLayout() -> (CGSize, UIImage?, ChatListBadgeContent) -> (CGSize, (Bool, Bool) -> Void) { + func asyncLayout() -> (CGSize, CGFloat, UIFont, UIImage?, ChatListBadgeContent) -> (CGSize, (Bool, Bool) -> Void) { let textLayout = TextNode.asyncLayout(self.textNode) let measureTextLayout = TextNode.asyncLayout(self.measureTextNode) let currentContent = self.content - return { [weak self] boundingSize, backgroundImage, content in + return { [weak self] boundingSize, imageWidth, badgeFont, backgroundImage, content in var badgeWidth: CGFloat = 0.0 var textLayoutAndApply: (TextNodeLayout, () -> TextNode)? @@ -79,14 +77,14 @@ final class ChatListBadgeNode: ASDisplayNode { let (measureLayout, _) = measureTextLayout(TextNodeLayoutArguments(attributedString: NSAttributedString(string: measureString(text.string), font: badgeFont, textColor: .black), backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .end, constrainedSize: boundingSize, alignment: .natural, cutout: nil, insets: UIEdgeInsets())) - badgeWidth = max(20.0, measureLayout.size.width + 10.0) + badgeWidth = max(imageWidth, measureLayout.size.width + imageWidth / 2.0) case .mention, .blank: - badgeWidth = 20.0 + badgeWidth = imageWidth case .none: badgeWidth = 0.0 } - return (CGSize(width: badgeWidth, height: 20.0), { animated, bounce in + return (CGSize(width: badgeWidth, height: imageWidth), { animated, bounce in if let strongSelf = self { strongSelf.content = content @@ -98,7 +96,7 @@ final class ChatListBadgeNode: ASDisplayNode { return } - let badgeWidth = max(20.0, badgeWidth) + let badgeWidth = max(imageWidth, badgeWidth) let previousBadgeWidth = !strongSelf.backgroundNode.frame.width.isZero ? strongSelf.backgroundNode.frame.width : badgeWidth var animateTextNode = false diff --git a/submodules/ChatListUI/Sources/Node/ChatListItem.swift b/submodules/ChatListUI/Sources/Node/ChatListItem.swift index c18e29e168..c44aa5fc0a 100644 --- a/submodules/ChatListUI/Sources/Node/ChatListItem.swift +++ b/submodules/ChatListUI/Sources/Node/ChatListItem.swift @@ -654,7 +654,7 @@ class ChatListItemNode: ItemListRevealOptionsItemNode { let titleFont = Font.medium(floor(item.presentationData.fontSize.itemListBaseFontSize * 16.0 / 17.0)) let textFont = Font.regular(floor(item.presentationData.fontSize.itemListBaseFontSize * 15.0 / 17.0)) let dateFont = Font.regular(floor(item.presentationData.fontSize.itemListBaseFontSize * 14.0 / 17.0)) - let badgeFont = Font.regular(14.0) + let badgeFont = Font.regular(floor(item.presentationData.fontSize.itemListBaseFontSize * 14.0 / 17.0)) let account = item.context.account var message: Message? @@ -777,9 +777,11 @@ class ChatListItemNode: ItemListRevealOptionsItemNode { let enableChatListPhotos = item.context.sharedContext.immediateExperimentalUISettings.chatListPhotos - let avatarDiameter = floor(item.presentationData.fontSize.baseDisplaySize * 60.0 / 17.0) + let avatarDiameter = min(60.0, floor(item.presentationData.fontSize.baseDisplaySize * 60.0 / 17.0)) let avatarLeftInset = 18.0 + avatarDiameter + let badgeDiameter = floor(item.presentationData.fontSize.baseDisplaySize * 20.0 / 17.0) + let leftInset: CGFloat = params.leftInset + avatarLeftInset enum ContentData { @@ -995,10 +997,10 @@ class ChatListItemNode: ItemListRevealOptionsItemNode { } else { let badgeTextColor: UIColor if unreadCount.muted { - currentBadgeBackgroundImage = PresentationResourcesChatList.badgeBackgroundInactive(item.presentationData.theme) + currentBadgeBackgroundImage = PresentationResourcesChatList.badgeBackgroundInactive(item.presentationData.theme, diameter: badgeDiameter) badgeTextColor = theme.unreadBadgeInactiveTextColor } else { - currentBadgeBackgroundImage = PresentationResourcesChatList.badgeBackgroundActive(item.presentationData.theme) + currentBadgeBackgroundImage = PresentationResourcesChatList.badgeBackgroundActive(item.presentationData.theme, diameter: badgeDiameter) badgeTextColor = theme.unreadBadgeActiveTextColor } let unreadCountText = compactNumericCountString(Int(unreadCount.count), decimalSeparator: item.presentationData.dateTimeFormat.decimalSeparator) @@ -1012,7 +1014,7 @@ class ChatListItemNode: ItemListRevealOptionsItemNode { if let mutedCount = unreadCount.mutedCount, mutedCount > 0 { let mutedUnreadCountText = compactNumericCountString(Int(mutedCount), decimalSeparator: item.presentationData.dateTimeFormat.decimalSeparator) - currentMentionBadgeImage = PresentationResourcesChatList.badgeBackgroundInactive(item.presentationData.theme) + currentMentionBadgeImage = PresentationResourcesChatList.badgeBackgroundInactive(item.presentationData.theme, diameter: badgeDiameter) mentionBadgeContent = .text(NSAttributedString(string: mutedUnreadCountText, font: badgeFont, textColor: theme.unreadBadgeInactiveTextColor)) } } @@ -1024,13 +1026,13 @@ class ChatListItemNode: ItemListRevealOptionsItemNode { if !isPeerGroup { if totalMentionCount > 0 { if Namespaces.PeerGroup.archive == item.peerGroupId { - currentMentionBadgeImage = PresentationResourcesChatList.badgeBackgroundInactiveMention(item.presentationData.theme) + currentMentionBadgeImage = PresentationResourcesChatList.badgeBackgroundInactiveMention(item.presentationData.theme, diameter: badgeDiameter) } else { - currentMentionBadgeImage = PresentationResourcesChatList.badgeBackgroundMention(item.presentationData.theme) + currentMentionBadgeImage = PresentationResourcesChatList.badgeBackgroundMention(item.presentationData.theme, diameter: badgeDiameter) } mentionBadgeContent = .mention } else if item.index.pinningIndex != nil && !isAd && currentBadgeBackgroundImage == nil { - currentPinnedIconImage = PresentationResourcesChatList.badgeBackgroundPinned(item.presentationData.theme) + currentPinnedIconImage = PresentationResourcesChatList.badgeBackgroundPinned(item.presentationData.theme, diameter: badgeDiameter) } } @@ -1105,9 +1107,9 @@ class ChatListItemNode: ItemListRevealOptionsItemNode { let (dateLayout, dateApply) = dateLayout(TextNodeLayoutArguments(attributedString: dateAttributedString, backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .end, constrainedSize: CGSize(width: rawContentWidth, height: CGFloat.greatestFiniteMagnitude), alignment: .natural, cutout: nil, insets: UIEdgeInsets())) - let (badgeLayout, badgeApply) = badgeLayout(CGSize(width: rawContentWidth, height: CGFloat.greatestFiniteMagnitude), currentBadgeBackgroundImage, badgeContent) + let (badgeLayout, badgeApply) = badgeLayout(CGSize(width: rawContentWidth, height: CGFloat.greatestFiniteMagnitude), badgeDiameter, badgeFont, currentBadgeBackgroundImage, badgeContent) - let (mentionBadgeLayout, mentionBadgeApply) = mentionBadgeLayout(CGSize(width: rawContentWidth, height: CGFloat.greatestFiniteMagnitude), currentMentionBadgeImage, mentionBadgeContent) + let (mentionBadgeLayout, mentionBadgeApply) = mentionBadgeLayout(CGSize(width: rawContentWidth, height: CGFloat.greatestFiniteMagnitude), badgeDiameter, badgeFont, currentMentionBadgeImage, mentionBadgeContent) var badgeSize: CGFloat = 0.0 if !badgeLayout.width.isZero { @@ -1656,7 +1658,7 @@ class ChatListItemNode: ItemListRevealOptionsItemNode { transition.updateFrame(node: reorderControlNode, frame: reorderControlFrame) } - let avatarDiameter = floor(item.presentationData.fontSize.baseDisplaySize * 60.0 / 17.0) + let avatarDiameter = min(60.0, floor(item.presentationData.fontSize.baseDisplaySize * 60.0 / 17.0)) let avatarLeftInset = 18.0 + avatarDiameter let leftInset: CGFloat = params.leftInset + avatarLeftInset diff --git a/submodules/ContactsPeerItem/Sources/ContactsPeerItem.swift b/submodules/ContactsPeerItem/Sources/ContactsPeerItem.swift index f0eba4a8ab..7e9ef44c72 100644 --- a/submodules/ContactsPeerItem/Sources/ContactsPeerItem.swift +++ b/submodules/ContactsPeerItem/Sources/ContactsPeerItem.swift @@ -591,10 +591,10 @@ public class ContactsPeerItemNode: ItemListRevealOptionsItemNode { let badgeTextColor: UIColor switch badge.type { case .inactive: - currentBadgeBackgroundImage = PresentationResourcesChatList.badgeBackgroundInactive(item.presentationData.theme) + currentBadgeBackgroundImage = PresentationResourcesChatList.badgeBackgroundInactive(item.presentationData.theme, diameter: 20.0) badgeTextColor = item.presentationData.theme.chatList.unreadBadgeInactiveTextColor case .active: - currentBadgeBackgroundImage = PresentationResourcesChatList.badgeBackgroundActive(item.presentationData.theme) + currentBadgeBackgroundImage = PresentationResourcesChatList.badgeBackgroundActive(item.presentationData.theme, diameter: 20.0) badgeTextColor = item.presentationData.theme.chatList.unreadBadgeActiveTextColor } let badgeAttributedString = NSAttributedString(string: badge.count > 0 ? "\(badge.count)" : " ", font: badgeFont, textColor: badgeTextColor) diff --git a/submodules/Database/ValueBox/Sources/SqliteValueBox.swift b/submodules/Database/ValueBox/Sources/SqliteValueBox.swift index 4bfb081c1c..a26511d475 100644 --- a/submodules/Database/ValueBox/Sources/SqliteValueBox.swift +++ b/submodules/Database/ValueBox/Sources/SqliteValueBox.swift @@ -1773,8 +1773,14 @@ public final class SqliteValueBox: ValueBox { statement.reset() } - public func fullTextRemove(_ table: ValueBoxFullTextTable, itemId: String) { + public func fullTextRemove(_ table: ValueBoxFullTextTable, itemId: String, secure: Bool) { if let _ = self.fullTextTables[table.id] { + if secure != self.secureDeleteEnabled { + self.secureDeleteEnabled = secure + let result = database.execute("PRAGMA secure_delete=\(secure ? 1 : 0)") + precondition(result) + } + guard let itemIdData = itemId.data(using: .utf8) else { return } diff --git a/submodules/Database/ValueBox/Sources/ValueBox.swift b/submodules/Database/ValueBox/Sources/ValueBox.swift index 18cc7faeaa..255ee011ed 100644 --- a/submodules/Database/ValueBox/Sources/ValueBox.swift +++ b/submodules/Database/ValueBox/Sources/ValueBox.swift @@ -83,7 +83,7 @@ public protocol ValueBox { func removeRange(_ table: ValueBoxTable, start: ValueBoxKey, end: ValueBoxKey) func fullTextSet(_ table: ValueBoxFullTextTable, collectionId: String, itemId: String, contents: String, tags: String) func fullTextMatch(_ table: ValueBoxFullTextTable, collectionId: String?, query: String, tags: String?, values: (String, String) -> Bool) - func fullTextRemove(_ table: ValueBoxFullTextTable, itemId: String) + func fullTextRemove(_ table: ValueBoxFullTextTable, itemId: String, secure: Bool) func removeAllFromTable(_ table: ValueBoxTable) func removeTable(_ table: ValueBoxTable) func renameTable(_ table: ValueBoxTable, to toTable: ValueBoxTable) diff --git a/submodules/Display/Display/NativeWindowHostView.swift b/submodules/Display/Display/NativeWindowHostView.swift index 7529222a06..b408471db7 100644 --- a/submodules/Display/Display/NativeWindowHostView.swift +++ b/submodules/Display/Display/NativeWindowHostView.swift @@ -246,6 +246,10 @@ private final class WindowRootViewController: UIViewController, UIViewController self.previousPreviewingHostView = nil } } + + override public func present(_ viewControllerToPresent: UIViewController, animated flag: Bool, completion: (() -> Void)? = nil) { + super.present(viewControllerToPresent, animated: flag, completion: completion) + } } private final class NativeWindow: UIWindow, WindowHost { diff --git a/submodules/Display/Display/TransformImageArguments.swift b/submodules/Display/Display/TransformImageArguments.swift index 122de00a10..ae8051f6ea 100644 --- a/submodules/Display/Display/TransformImageArguments.swift +++ b/submodules/Display/Display/TransformImageArguments.swift @@ -40,7 +40,12 @@ public struct TransformImageArguments: Equatable { public var drawingRect: CGRect { let cornersExtendedEdges = self.corners.extendedEdges - return CGRect(x: cornersExtendedEdges.left + self.intrinsicInsets.left, y: cornersExtendedEdges.top + self.intrinsicInsets.top, width: self.boundingSize.width, height: self.boundingSize.height); + return CGRect(x: cornersExtendedEdges.left + self.intrinsicInsets.left, y: cornersExtendedEdges.top + self.intrinsicInsets.top, width: self.boundingSize.width, height: self.boundingSize.height) + } + + public var imageRect: CGRect { + let drawingRect = self.drawingRect + return CGRect(x: drawingRect.minX + floor((drawingRect.width - self.imageSize.width) / 2.0), y: drawingRect.minX + floor((drawingRect.height - self.imageSize.height) / 2.0), width: self.imageSize.width, height: self.imageSize.height) } public var insets: UIEdgeInsets { diff --git a/submodules/Display/Display/ViewController.swift b/submodules/Display/Display/ViewController.swift index 206a52060c..392644c300 100644 --- a/submodules/Display/Display/ViewController.swift +++ b/submodules/Display/Display/ViewController.swift @@ -457,8 +457,7 @@ public enum ViewControllerNavigationPresentation { } override open func present(_ viewControllerToPresent: UIViewController, animated flag: Bool, completion: (() -> Void)? = nil) { - super.present(viewControllerToPresent, animated: flag, completion: completion) - return + self.view.window?.rootViewController?.present(viewControllerToPresent, animated: flag, completion: completion) } override open func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) { diff --git a/submodules/GalleryUI/Sources/GalleryController.swift b/submodules/GalleryUI/Sources/GalleryController.swift index 24ac0a6c2d..53b10ecb22 100644 --- a/submodules/GalleryUI/Sources/GalleryController.swift +++ b/submodules/GalleryUI/Sources/GalleryController.swift @@ -222,10 +222,10 @@ public func galleryItemForEntry(context: AccountContext, presentationData: Prese } public final class GalleryTransitionArguments { - public let transitionNode: (ASDisplayNode, () -> (UIView?, UIView?)) + public let transitionNode: (ASDisplayNode, CGRect, () -> (UIView?, UIView?)) public let addToTransitionSurface: (UIView) -> Void - public init(transitionNode: (ASDisplayNode, () -> (UIView?, UIView?)), addToTransitionSurface: @escaping (UIView) -> Void) { + public init(transitionNode: (ASDisplayNode, CGRect, () -> (UIView?, UIView?)), addToTransitionSurface: @escaping (UIView) -> Void) { self.transitionNode = transitionNode self.addToTransitionSurface = addToTransitionSurface } diff --git a/submodules/GalleryUI/Sources/GalleryControllerNode.swift b/submodules/GalleryUI/Sources/GalleryControllerNode.swift index 31a920962c..0c82bd5bec 100644 --- a/submodules/GalleryUI/Sources/GalleryControllerNode.swift +++ b/submodules/GalleryUI/Sources/GalleryControllerNode.swift @@ -11,7 +11,7 @@ open class GalleryControllerNode: ASDisplayNode, UIScrollViewDelegate, UIGesture public let footerNode: GalleryFooterNode public var currentThumbnailContainerNode: GalleryThumbnailContainerNode? public var overlayNode: ASDisplayNode? - public var transitionDataForCentralItem: (() -> ((ASDisplayNode, () -> (UIView?, UIView?))?, (UIView) -> Void)?)? + public var transitionDataForCentralItem: (() -> ((ASDisplayNode, CGRect, () -> (UIView?, UIView?))?, (UIView) -> Void)?)? public var dismiss: (() -> Void)? public var containerLayout: (CGFloat, ContainerViewLayout)? diff --git a/submodules/GalleryUI/Sources/GalleryItemNode.swift b/submodules/GalleryUI/Sources/GalleryItemNode.swift index 7a91e6988a..ce3d8b3c59 100644 --- a/submodules/GalleryUI/Sources/GalleryItemNode.swift +++ b/submodules/GalleryUI/Sources/GalleryItemNode.swift @@ -80,10 +80,10 @@ open class GalleryItemNode: ASDisplayNode { open func visibilityUpdated(isVisible: Bool) { } - open func animateIn(from node: (ASDisplayNode, () -> (UIView?, UIView?)), addToTransitionSurface: (UIView) -> Void) { + open func animateIn(from node: (ASDisplayNode, CGRect, () -> (UIView?, UIView?)), addToTransitionSurface: (UIView) -> Void) { } - open func animateOut(to node: (ASDisplayNode, () -> (UIView?, UIView?)), addToTransitionSurface: (UIView) -> Void, completion: @escaping () -> Void) { + open func animateOut(to node: (ASDisplayNode, CGRect, () -> (UIView?, UIView?)), addToTransitionSurface: (UIView) -> Void, completion: @escaping () -> Void) { } open func contentSize() -> CGSize? { diff --git a/submodules/GalleryUI/Sources/Items/ChatAnimationGalleryItem.swift b/submodules/GalleryUI/Sources/Items/ChatAnimationGalleryItem.swift index b7b82d1d3d..f4f24f1221 100644 --- a/submodules/GalleryUI/Sources/Items/ChatAnimationGalleryItem.swift +++ b/submodules/GalleryUI/Sources/Items/ChatAnimationGalleryItem.swift @@ -238,7 +238,7 @@ final class ChatAnimationGalleryItemNode: ZoomableContentGalleryItemNode { })) } - override func animateIn(from node: (ASDisplayNode, () -> (UIView?, UIView?)), addToTransitionSurface: (UIView) -> Void) { + override func animateIn(from node: (ASDisplayNode, CGRect, () -> (UIView?, UIView?)), addToTransitionSurface: (UIView) -> Void) { var transformedFrame = node.0.view.convert(node.0.view.bounds, to: self.containerNode.view) let transformedSuperFrame = node.0.view.convert(node.0.view.bounds, to: self.containerNode.view.superview) @@ -254,7 +254,7 @@ final class ChatAnimationGalleryItemNode: ZoomableContentGalleryItemNode { self.statusNodeContainer.layer.animateScale(from: 0.5, to: 1.0, duration: 0.25, timingFunction: kCAMediaTimingFunctionSpring) } - override func animateOut(to node: (ASDisplayNode, () -> (UIView?, UIView?)), addToTransitionSurface: (UIView) -> Void, completion: @escaping () -> Void) { + override func animateOut(to node: (ASDisplayNode, CGRect, () -> (UIView?, UIView?)), addToTransitionSurface: (UIView) -> Void, completion: @escaping () -> Void) { var transformedFrame = node.0.view.convert(node.0.view.bounds, to: self.containerNode.view) let transformedSuperFrame = node.0.view.convert(node.0.view.bounds, to: self.containerNode.view.superview) let transformedSelfFrame = node.0.view.convert(node.0.view.bounds, to: self.view) @@ -264,7 +264,7 @@ final class ChatAnimationGalleryItemNode: ZoomableContentGalleryItemNode { var boundsCompleted = false var copyCompleted = false - let (maybeCopyView, copyViewBackgrond) = node.1() + let (maybeCopyView, copyViewBackgrond) = node.2() copyViewBackgrond?.alpha = 0.0 let copyView = maybeCopyView! diff --git a/submodules/GalleryUI/Sources/Items/ChatDocumentGalleryItem.swift b/submodules/GalleryUI/Sources/Items/ChatDocumentGalleryItem.swift index 2bc400d803..1537d93a17 100644 --- a/submodules/GalleryUI/Sources/Items/ChatDocumentGalleryItem.swift +++ b/submodules/GalleryUI/Sources/Items/ChatDocumentGalleryItem.swift @@ -307,7 +307,7 @@ class ChatDocumentGalleryItemNode: ZoomableContentGalleryItemNode, WKNavigationD return self._title.get() } - override func animateIn(from node: (ASDisplayNode, () -> (UIView?, UIView?)), addToTransitionSurface: (UIView) -> Void) { + override func animateIn(from node: (ASDisplayNode, CGRect, () -> (UIView?, UIView?)), addToTransitionSurface: (UIView) -> Void) { var transformedFrame = node.0.view.convert(node.0.view.bounds, to: self.webView) let transformedSuperFrame = node.0.view.convert(node.0.view.bounds, to: self.webView.superview) @@ -323,7 +323,7 @@ class ChatDocumentGalleryItemNode: ZoomableContentGalleryItemNode, WKNavigationD self.statusNodeContainer.layer.animateScale(from: 0.5, to: 1.0, duration: 0.25, timingFunction: kCAMediaTimingFunctionSpring) } - override func animateOut(to node: (ASDisplayNode, () -> (UIView?, UIView?)), addToTransitionSurface: (UIView) -> Void, completion: @escaping () -> Void) { + override func animateOut(to node: (ASDisplayNode, CGRect, () -> (UIView?, UIView?)), addToTransitionSurface: (UIView) -> Void, completion: @escaping () -> Void) { var transformedFrame = node.0.view.convert(node.0.view.bounds, to: self.webView) let transformedSuperFrame = node.0.view.convert(node.0.view.bounds, to: self.webView.superview) let transformedSelfFrame = node.0.view.convert(node.0.view.bounds, to: self.view) @@ -333,7 +333,7 @@ class ChatDocumentGalleryItemNode: ZoomableContentGalleryItemNode, WKNavigationD var boundsCompleted = false var copyCompleted = false - let (maybeCopyView, copyViewBackgrond) = node.1() + let (maybeCopyView, copyViewBackgrond) = node.2() copyViewBackgrond?.alpha = 0.0 let copyView = maybeCopyView! diff --git a/submodules/GalleryUI/Sources/Items/ChatExternalFileGalleryItem.swift b/submodules/GalleryUI/Sources/Items/ChatExternalFileGalleryItem.swift index 78099a5279..c0714f5fd1 100644 --- a/submodules/GalleryUI/Sources/Items/ChatExternalFileGalleryItem.swift +++ b/submodules/GalleryUI/Sources/Items/ChatExternalFileGalleryItem.swift @@ -242,7 +242,7 @@ class ChatExternalFileGalleryItemNode: GalleryItemNode { return self._title.get() } - override func animateIn(from node: (ASDisplayNode, () -> (UIView?, UIView?)), addToTransitionSurface: (UIView) -> Void) { + override func animateIn(from node: (ASDisplayNode, CGRect, () -> (UIView?, UIView?)), addToTransitionSurface: (UIView) -> Void) { var transformedFrame = node.0.view.convert(node.0.view.bounds, to: self.containerNode.view) let transformedSuperFrame = node.0.view.convert(node.0.view.bounds, to: self.containerNode.view.superview) @@ -258,7 +258,7 @@ class ChatExternalFileGalleryItemNode: GalleryItemNode { self.statusNodeContainer.layer.animateScale(from: 0.5, to: 1.0, duration: 0.25, timingFunction: kCAMediaTimingFunctionSpring) } - override func animateOut(to node: (ASDisplayNode, () -> (UIView?, UIView?)), addToTransitionSurface: (UIView) -> Void, completion: @escaping () -> Void) { + override func animateOut(to node: (ASDisplayNode, CGRect, () -> (UIView?, UIView?)), addToTransitionSurface: (UIView) -> Void, completion: @escaping () -> Void) { var transformedFrame = node.0.view.convert(node.0.view.bounds, to: self.containerNode.view) let transformedSuperFrame = node.0.view.convert(node.0.view.bounds, to: self.containerNode.view.superview) let transformedSelfFrame = node.0.view.convert(node.0.view.bounds, to: self.view) @@ -268,7 +268,7 @@ class ChatExternalFileGalleryItemNode: GalleryItemNode { var boundsCompleted = false var copyCompleted = false - let (maybeCopyView, copyViewBackgrond) = node.1() + let (maybeCopyView, copyViewBackgrond) = node.2() copyViewBackgrond?.alpha = 0.0 let copyView = maybeCopyView! diff --git a/submodules/GalleryUI/Sources/Items/ChatImageGalleryItem.swift b/submodules/GalleryUI/Sources/Items/ChatImageGalleryItem.swift index d749afdf78..083195070c 100644 --- a/submodules/GalleryUI/Sources/Items/ChatImageGalleryItem.swift +++ b/submodules/GalleryUI/Sources/Items/ChatImageGalleryItem.swift @@ -277,7 +277,7 @@ final class ChatImageGalleryItemNode: ZoomableContentGalleryItemNode { } let baseNavigationController = strongSelf.baseNavigationController() baseNavigationController?.view.endEditing(true) - let controller = StickerPackScreen(context: context, stickerPacks: packs, sendSticker: nil) + let controller = StickerPackScreen(context: context, mainStickerPack: packs[0], stickerPacks: packs, sendSticker: nil) (baseNavigationController?.topViewController as? ViewController)?.present(controller, in: .window(.root), with: nil) }) } @@ -350,14 +350,20 @@ final class ChatImageGalleryItemNode: ZoomableContentGalleryItemNode { })) } - override func animateIn(from node: (ASDisplayNode, () -> (UIView?, UIView?)), addToTransitionSurface: (UIView) -> Void) { + override func animateIn(from node: (ASDisplayNode, CGRect, () -> (UIView?, UIView?)), addToTransitionSurface: (UIView) -> Void) { var transformedFrame = node.0.view.convert(node.0.view.bounds, to: self.imageNode.view) let transformedSuperFrame = node.0.view.convert(node.0.view.bounds, to: self.imageNode.view.superview) let transformedSelfFrame = node.0.view.convert(node.0.view.bounds, to: self.view) - let transformedCopyViewFinalFrame = self.imageNode.view.convert(self.imageNode.view.bounds, to: self.view) - let (maybeSurfaceCopyView, _) = node.1() - let (maybeCopyView, copyViewBackgrond) = node.1() + /*let projectedScale = CGPoint(x: self.imageNode.view.bounds.width / node.1.width, y: self.imageNode.view.bounds.height / node.1.height) + let scaledLocalImageViewBounds = CGRect(x: -node.1.minX * projectedScale.x, y: -node.1.minY * projectedScale.y, width: node.0.bounds.width * projectedScale.x, height: node.0.bounds.height * projectedScale.y)*/ + + let scaledLocalImageViewBounds = self.imageNode.view.bounds + + let transformedCopyViewFinalFrame = self.imageNode.view.convert(scaledLocalImageViewBounds, to: self.view) + + let (maybeSurfaceCopyView, _) = node.2() + let (maybeCopyView, copyViewBackgrond) = node.2() copyViewBackgrond?.alpha = 0.0 let surfaceCopyView = maybeSurfaceCopyView! let copyView = maybeCopyView! @@ -368,7 +374,7 @@ final class ChatImageGalleryItemNode: ZoomableContentGalleryItemNode { var transformedSurfaceFinalFrame: CGRect? if let contentSurface = surfaceCopyView.superview { transformedSurfaceFrame = node.0.view.convert(node.0.view.bounds, to: contentSurface) - transformedSurfaceFinalFrame = self.imageNode.view.convert(self.imageNode.view.bounds, to: contentSurface) + transformedSurfaceFinalFrame = self.imageNode.view.convert(scaledLocalImageViewBounds, to: contentSurface) } if let transformedSurfaceFrame = transformedSurfaceFrame { @@ -378,7 +384,7 @@ final class ChatImageGalleryItemNode: ZoomableContentGalleryItemNode { self.view.insertSubview(copyView, belowSubview: self.scrollNode.view) copyView.frame = transformedSelfFrame - copyView.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2, removeOnCompletion: false) + copyView.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, removeOnCompletion: false) surfaceCopyView.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.25, removeOnCompletion: false) @@ -409,7 +415,7 @@ final class ChatImageGalleryItemNode: ZoomableContentGalleryItemNode { self.statusNodeContainer.layer.animateScale(from: 0.5, to: 1.0, duration: 0.25, timingFunction: kCAMediaTimingFunctionSpring) } - override func animateOut(to node: (ASDisplayNode, () -> (UIView?, UIView?)), addToTransitionSurface: (UIView) -> Void, completion: @escaping () -> Void) { + override func animateOut(to node: (ASDisplayNode, CGRect, () -> (UIView?, UIView?)), addToTransitionSurface: (UIView) -> Void, completion: @escaping () -> Void) { self.fetchDisposable.set(nil) var transformedFrame = node.0.view.convert(node.0.view.bounds, to: self.imageNode.view) @@ -421,8 +427,8 @@ final class ChatImageGalleryItemNode: ZoomableContentGalleryItemNode { var boundsCompleted = false var copyCompleted = false - let (maybeSurfaceCopyView, _) = node.1() - let (maybeCopyView, copyViewBackgrond) = node.1() + let (maybeSurfaceCopyView, _) = node.2() + let (maybeCopyView, copyViewBackgrond) = node.2() copyViewBackgrond?.alpha = 0.0 let surfaceCopyView = maybeSurfaceCopyView! let copyView = maybeCopyView! diff --git a/submodules/GalleryUI/Sources/Items/UniversalVideoGalleryItem.swift b/submodules/GalleryUI/Sources/Items/UniversalVideoGalleryItem.swift index 253455e154..d5db0a11cf 100644 --- a/submodules/GalleryUI/Sources/Items/UniversalVideoGalleryItem.swift +++ b/submodules/GalleryUI/Sources/Items/UniversalVideoGalleryItem.swift @@ -747,7 +747,7 @@ final class UniversalVideoGalleryItemNode: ZoomableContentGalleryItemNode { } } - override func animateIn(from node: (ASDisplayNode, () -> (UIView?, UIView?)), addToTransitionSurface: (UIView) -> Void) { + override func animateIn(from node: (ASDisplayNode, CGRect, () -> (UIView?, UIView?)), addToTransitionSurface: (UIView) -> Void) { guard let videoNode = self.videoNode else { return } @@ -773,8 +773,8 @@ final class UniversalVideoGalleryItemNode: ZoomableContentGalleryItemNode { var transformedSelfFrame = node.0.view.convert(node.0.view.bounds, to: self.view) let transformedCopyViewFinalFrame = videoNode.view.convert(videoNode.view.bounds, to: self.view) - let (maybeSurfaceCopyView, _) = node.1() - let (maybeCopyView, copyViewBackgrond) = node.1() + let (maybeSurfaceCopyView, _) = node.2() + let (maybeCopyView, copyViewBackgrond) = node.2() copyViewBackgrond?.alpha = 0.0 let surfaceCopyView = maybeSurfaceCopyView! let copyView = maybeCopyView! @@ -859,7 +859,7 @@ final class UniversalVideoGalleryItemNode: ZoomableContentGalleryItemNode { } } - override func animateOut(to node: (ASDisplayNode, () -> (UIView?, UIView?)), addToTransitionSurface: (UIView) -> Void, completion: @escaping () -> Void) { + override func animateOut(to node: (ASDisplayNode, CGRect, () -> (UIView?, UIView?)), addToTransitionSurface: (UIView) -> Void, completion: @escaping () -> Void) { guard let videoNode = self.videoNode else { completion() return @@ -875,8 +875,8 @@ final class UniversalVideoGalleryItemNode: ZoomableContentGalleryItemNode { var boundsCompleted = true var copyCompleted = false - let (maybeSurfaceCopyView, _) = node.1() - let (maybeCopyView, copyViewBackgrond) = node.1() + let (maybeSurfaceCopyView, _) = node.2() + let (maybeCopyView, copyViewBackgrond) = node.2() copyViewBackgrond?.alpha = 0.0 let surfaceCopyView = maybeSurfaceCopyView! let copyView = maybeCopyView! @@ -1169,14 +1169,14 @@ final class UniversalVideoGalleryItemNode: ZoomableContentGalleryItemNode { (baseNavigationController?.topViewController as? ViewController)?.present(gallery, in: .window(.root), with: GalleryControllerPresentationArguments(transitionArguments: { id, media in if let overlayNode = overlayNode, let overlaySupernode = overlayNode.supernode { - return GalleryTransitionArguments(transitionNode: (overlayNode, { [weak overlayNode] in + return GalleryTransitionArguments(transitionNode: (overlayNode, overlayNode.bounds, { [weak overlayNode] in return (overlayNode?.view.snapshotContentTree(), nil) }), addToTransitionSurface: { [weak overlaySupernode, weak overlayNode] view in overlaySupernode?.view.addSubview(view) overlayNode?.canAttachContent = false }) } else if let info = context.sharedContext.mediaManager.galleryHiddenMediaManager.findTarget(messageId: id, media: media) { - return GalleryTransitionArguments(transitionNode: (info.1, { + return GalleryTransitionArguments(transitionNode: (info.1, info.1.bounds, { return info.2() }), addToTransitionSurface: info.0) } diff --git a/submodules/HorizontalPeerItem/Sources/HorizontalPeerItem.swift b/submodules/HorizontalPeerItem/Sources/HorizontalPeerItem.swift index fee77ef7d4..bbff42ee43 100644 --- a/submodules/HorizontalPeerItem/Sources/HorizontalPeerItem.swift +++ b/submodules/HorizontalPeerItem/Sources/HorizontalPeerItem.swift @@ -148,10 +148,10 @@ public final class HorizontalPeerItemNode: ListViewItemNode { let badgeTextColor: UIColor let (unreadCount, isMuted) = unreadBadge if isMuted { - currentBadgeBackgroundImage = PresentationResourcesChatList.badgeBackgroundInactive(item.theme) + currentBadgeBackgroundImage = PresentationResourcesChatList.badgeBackgroundInactive(item.theme, diameter: 20.0) badgeTextColor = item.theme.chatList.unreadBadgeInactiveTextColor } else { - currentBadgeBackgroundImage = PresentationResourcesChatList.badgeBackgroundActive(item.theme) + currentBadgeBackgroundImage = PresentationResourcesChatList.badgeBackgroundActive(item.theme, diameter: 20.0) badgeTextColor = item.theme.chatList.unreadBadgeActiveTextColor } badgeAttributedString = NSAttributedString(string: unreadCount > 0 ? "\(unreadCount)" : " ", font: badgeFont, textColor: badgeTextColor) diff --git a/submodules/InstantPageUI/Sources/InstantImageGalleryItem.swift b/submodules/InstantPageUI/Sources/InstantImageGalleryItem.swift index 64034b701b..9254384396 100644 --- a/submodules/InstantPageUI/Sources/InstantImageGalleryItem.swift +++ b/submodules/InstantPageUI/Sources/InstantImageGalleryItem.swift @@ -161,14 +161,14 @@ final class InstantImageGalleryItemNode: ZoomableContentGalleryItemNode { self.footerContentNode.setShareMedia(fileReference.abstract) } - override func animateIn(from node: (ASDisplayNode, () -> (UIView?, UIView?)), addToTransitionSurface: (UIView) -> Void) { + override func animateIn(from node: (ASDisplayNode, CGRect, () -> (UIView?, UIView?)), addToTransitionSurface: (UIView) -> Void) { var transformedFrame = node.0.view.convert(node.0.view.bounds, to: self.imageNode.view) let transformedSuperFrame = node.0.view.convert(node.0.view.bounds, to: self.imageNode.view.superview) let transformedSelfFrame = node.0.view.convert(node.0.view.bounds, to: self.view) let transformedCopyViewFinalFrame = self.imageNode.view.convert(self.imageNode.view.bounds, to: self.view) - let surfaceCopyView = node.1().0! - let copyView = node.1().0! + let surfaceCopyView = node.2().0! + let copyView = node.2().0! addToTransitionSurface(surfaceCopyView) @@ -217,7 +217,7 @@ final class InstantImageGalleryItemNode: ZoomableContentGalleryItemNode { self.statusNodeContainer.layer.animateScale(from: 0.5, to: 1.0, duration: 0.25, timingFunction: kCAMediaTimingFunctionSpring)*/ } - override func animateOut(to node: (ASDisplayNode, () -> (UIView?, UIView?)), addToTransitionSurface: (UIView) -> Void, completion: @escaping () -> Void) { + override func animateOut(to node: (ASDisplayNode, CGRect, () -> (UIView?, UIView?)), addToTransitionSurface: (UIView) -> Void, completion: @escaping () -> Void) { self.fetchDisposable.set(nil) var transformedFrame = node.0.view.convert(node.0.view.bounds, to: self.imageNode.view) @@ -229,8 +229,8 @@ final class InstantImageGalleryItemNode: ZoomableContentGalleryItemNode { var boundsCompleted = false var copyCompleted = false - let copyView = node.1().0! - let surfaceCopyView = node.1().0! + let copyView = node.2().0! + let surfaceCopyView = node.2().0! addToTransitionSurface(surfaceCopyView) diff --git a/submodules/InstantPageUI/Sources/InstantPageArticleNode.swift b/submodules/InstantPageUI/Sources/InstantPageArticleNode.swift index a493fa8efa..e1387d4885 100644 --- a/submodules/InstantPageUI/Sources/InstantPageArticleNode.swift +++ b/submodules/InstantPageUI/Sources/InstantPageArticleNode.swift @@ -125,7 +125,7 @@ final class InstantPageArticleNode: ASDisplayNode, InstantPageNode { func updateLayout(size: CGSize, transition: ContainedViewLayoutTransition) { } - func transitionNode(media: InstantPageMedia) -> (ASDisplayNode, () -> (UIView?, UIView?))? { + func transitionNode(media: InstantPageMedia) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? { return nil } diff --git a/submodules/InstantPageUI/Sources/InstantPageAudioNode.swift b/submodules/InstantPageUI/Sources/InstantPageAudioNode.swift index 1fb19aa1b7..ce5b312d17 100644 --- a/submodules/InstantPageUI/Sources/InstantPageAudioNode.swift +++ b/submodules/InstantPageUI/Sources/InstantPageAudioNode.swift @@ -236,7 +236,7 @@ final class InstantPageAudioNode: ASDisplayNode, InstantPageNode { } } - func transitionNode(media: InstantPageMedia) -> (ASDisplayNode, () -> (UIView?, UIView?))? { + func transitionNode(media: InstantPageMedia) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? { return nil } diff --git a/submodules/InstantPageUI/Sources/InstantPageContentNode.swift b/submodules/InstantPageUI/Sources/InstantPageContentNode.swift index d8e9ef8b55..134effc594 100644 --- a/submodules/InstantPageUI/Sources/InstantPageContentNode.swift +++ b/submodules/InstantPageUI/Sources/InstantPageContentNode.swift @@ -315,7 +315,7 @@ final class InstantPageContentNode : ASDisplayNode { self.requestLayoutUpdate?(animated) } - func transitionNode(media: InstantPageMedia) -> (ASDisplayNode, () -> (UIView?, UIView?))? { + func transitionNode(media: InstantPageMedia) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? { for (_, itemNode) in self.visibleItemsWithNodes { if let transitionNode = itemNode.transitionNode(media: media) { return transitionNode diff --git a/submodules/InstantPageUI/Sources/InstantPageControllerNode.swift b/submodules/InstantPageUI/Sources/InstantPageControllerNode.swift index 8c2715a22f..78efcea7db 100644 --- a/submodules/InstantPageUI/Sources/InstantPageControllerNode.swift +++ b/submodules/InstantPageUI/Sources/InstantPageControllerNode.swift @@ -891,7 +891,7 @@ final class InstantPageControllerNode: ASDisplayNode, UIScrollViewDelegate { self.present(controller, ContextMenuControllerPresentationArguments(sourceNodeAndRect: { [weak self] in if let strongSelf = self { for (_, itemNode) in strongSelf.visibleItemsWithNodes { - if let (node, _) = itemNode.transitionNode(media: media) { + if let (node, _, _) = itemNode.transitionNode(media: media) { return (strongSelf.scrollNode, node.convert(node.bounds, to: strongSelf.scrollNode), strongSelf, strongSelf.bounds) } } diff --git a/submodules/InstantPageUI/Sources/InstantPageDetailsNode.swift b/submodules/InstantPageUI/Sources/InstantPageDetailsNode.swift index 168e061e2c..41cedc6bc0 100644 --- a/submodules/InstantPageUI/Sources/InstantPageDetailsNode.swift +++ b/submodules/InstantPageUI/Sources/InstantPageDetailsNode.swift @@ -143,7 +143,7 @@ final class InstantPageDetailsNode: ASDisplayNode, InstantPageNode { } - func transitionNode(media: InstantPageMedia) -> (ASDisplayNode, () -> (UIView?, UIView?))? { + func transitionNode(media: InstantPageMedia) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? { return self.contentNode.transitionNode(media: media) } diff --git a/submodules/InstantPageUI/Sources/InstantPageFeedbackNode.swift b/submodules/InstantPageUI/Sources/InstantPageFeedbackNode.swift index 352782f4a0..0cbba86791 100644 --- a/submodules/InstantPageUI/Sources/InstantPageFeedbackNode.swift +++ b/submodules/InstantPageUI/Sources/InstantPageFeedbackNode.swift @@ -90,7 +90,7 @@ final class InstantPageFeedbackNode: ASDisplayNode, InstantPageNode { func updateLayout(size: CGSize, transition: ContainedViewLayoutTransition) { } - func transitionNode(media: InstantPageMedia) -> (ASDisplayNode, () -> (UIView?, UIView?))? { + func transitionNode(media: InstantPageMedia) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? { return nil } diff --git a/submodules/InstantPageUI/Sources/InstantPageImageNode.swift b/submodules/InstantPageUI/Sources/InstantPageImageNode.swift index f12e3f3a2c..77f4f746f6 100644 --- a/submodules/InstantPageUI/Sources/InstantPageImageNode.swift +++ b/submodules/InstantPageUI/Sources/InstantPageImageNode.swift @@ -245,10 +245,10 @@ final class InstantPageImageNode: ASDisplayNode, InstantPageNode { } } - func transitionNode(media: InstantPageMedia) -> (ASDisplayNode, () -> (UIView?, UIView?))? { + func transitionNode(media: InstantPageMedia) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? { if media == self.media { let imageNode = self.imageNode - return (self.imageNode, { [weak imageNode] in + return (self.imageNode, self.imageNode.bounds, { [weak imageNode] in return (imageNode?.view.snapshotContentTree(unhide: true), nil) }) } else { diff --git a/submodules/InstantPageUI/Sources/InstantPageNode.swift b/submodules/InstantPageUI/Sources/InstantPageNode.swift index 6d1745963b..3eb643e1b4 100644 --- a/submodules/InstantPageUI/Sources/InstantPageNode.swift +++ b/submodules/InstantPageUI/Sources/InstantPageNode.swift @@ -7,7 +7,7 @@ import TelegramPresentationData protocol InstantPageNode { func updateIsVisible(_ isVisible: Bool) - func transitionNode(media: InstantPageMedia) -> (ASDisplayNode, () -> (UIView?, UIView?))? + func transitionNode(media: InstantPageMedia) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? func updateHiddenMedia(media: InstantPageMedia?) func update(strings: PresentationStrings, theme: InstantPageTheme) diff --git a/submodules/InstantPageUI/Sources/InstantPagePeerReferenceNode.swift b/submodules/InstantPageUI/Sources/InstantPagePeerReferenceNode.swift index 410488dc4c..ffad4284c0 100644 --- a/submodules/InstantPageUI/Sources/InstantPagePeerReferenceNode.swift +++ b/submodules/InstantPageUI/Sources/InstantPagePeerReferenceNode.swift @@ -290,7 +290,7 @@ final class InstantPagePeerReferenceNode: ASDisplayNode, InstantPageNode { } } - func transitionNode(media: InstantPageMedia) -> (ASDisplayNode, () -> (UIView?, UIView?))? { + func transitionNode(media: InstantPageMedia) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? { return nil } diff --git a/submodules/InstantPageUI/Sources/InstantPagePlayableVideoNode.swift b/submodules/InstantPageUI/Sources/InstantPagePlayableVideoNode.swift index cd9a6d87ec..12150b846d 100644 --- a/submodules/InstantPageUI/Sources/InstantPagePlayableVideoNode.swift +++ b/submodules/InstantPageUI/Sources/InstantPagePlayableVideoNode.swift @@ -149,9 +149,9 @@ final class InstantPagePlayableVideoNode: ASDisplayNode, InstantPageNode, Galler } } - func transitionNode(media: InstantPageMedia) -> (ASDisplayNode, () -> (UIView?, UIView?))? { + func transitionNode(media: InstantPageMedia) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? { if media == self.media { - return (self, { [weak self] in + return (self, self.bounds, { [weak self] in return (self?.view.snapshotContentTree(unhide: true), nil) }) } else { diff --git a/submodules/InstantPageUI/Sources/InstantPageScrollableNode.swift b/submodules/InstantPageUI/Sources/InstantPageScrollableNode.swift index 33f5a4aa84..547ae8fbf7 100644 --- a/submodules/InstantPageUI/Sources/InstantPageScrollableNode.swift +++ b/submodules/InstantPageUI/Sources/InstantPageScrollableNode.swift @@ -98,7 +98,7 @@ final class InstantPageScrollableNode: ASScrollNode, InstantPageNode { func updateLayout(size: CGSize, transition: ContainedViewLayoutTransition) { } - func transitionNode(media: InstantPageMedia) -> (ASDisplayNode, () -> (UIView?, UIView?))? { + func transitionNode(media: InstantPageMedia) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? { return nil } diff --git a/submodules/InstantPageUI/Sources/InstantPageSlideshowItemNode.swift b/submodules/InstantPageUI/Sources/InstantPageSlideshowItemNode.swift index ca2a03bdba..136f9a9cc7 100644 --- a/submodules/InstantPageUI/Sources/InstantPageSlideshowItemNode.swift +++ b/submodules/InstantPageUI/Sources/InstantPageSlideshowItemNode.swift @@ -54,7 +54,7 @@ private final class InstantPageSlideshowItemNode: ASDisplayNode { } } - func transitionNode(media: InstantPageMedia) -> (ASDisplayNode, () -> (UIView?, UIView?))? { + func transitionNode(media: InstantPageMedia) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? { if let node = self.contentNode as? InstantPageNode { return node.transitionNode(media: media) } @@ -363,7 +363,7 @@ private final class InstantPageSlideshowPagerNode: ASDisplayNode, UIScrollViewDe } } - func transitionNode(media: InstantPageMedia) -> (ASDisplayNode, () -> (UIView?, UIView?))? { + func transitionNode(media: InstantPageMedia) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? { for node in self.itemNodes { if let transitionNode = node.transitionNode(media: media) { return transitionNode @@ -422,7 +422,7 @@ final class InstantPageSlideshowNode: ASDisplayNode, InstantPageNode { } } - func transitionNode(media: InstantPageMedia) -> (ASDisplayNode, () -> (UIView?, UIView?))? { + func transitionNode(media: InstantPageMedia) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? { return self.pagerNode.transitionNode(media: media) } diff --git a/submodules/InstantPageUI/Sources/InstantPageWebEmbedNode.swift b/submodules/InstantPageUI/Sources/InstantPageWebEmbedNode.swift index b6e0575550..31de3d5bdd 100644 --- a/submodules/InstantPageUI/Sources/InstantPageWebEmbedNode.swift +++ b/submodules/InstantPageUI/Sources/InstantPageWebEmbedNode.swift @@ -113,7 +113,7 @@ final class InstantPageWebEmbedNode: ASDisplayNode, InstantPageNode { self.webView?.frame = self.bounds } - func transitionNode(media: InstantPageMedia) -> (ASDisplayNode, () -> (UIView?, UIView?))? { + func transitionNode(media: InstantPageMedia) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? { return nil } diff --git a/submodules/ItemListAvatarAndNameInfoItem/Sources/ItemListAvatarAndNameItem.swift b/submodules/ItemListAvatarAndNameInfoItem/Sources/ItemListAvatarAndNameItem.swift index 42e64b5ab6..d0cebfc0fe 100644 --- a/submodules/ItemListAvatarAndNameInfoItem/Sources/ItemListAvatarAndNameItem.swift +++ b/submodules/ItemListAvatarAndNameInfoItem/Sources/ItemListAvatarAndNameItem.swift @@ -1078,9 +1078,9 @@ public class ItemListAvatarAndNameInfoItemNode: ListViewItemNode, ItemListItemNo } } - public func avatarTransitionNode() -> ((ASDisplayNode, () -> (UIView?, UIView?)), CGRect) { + public func avatarTransitionNode() -> ((ASDisplayNode, CGRect, () -> (UIView?, UIView?)), CGRect) { let avatarNode = self.avatarNode - return ((self.avatarNode, { [weak avatarNode] in + return ((self.avatarNode, self.avatarNode.bounds, { [weak avatarNode] in return (avatarNode?.view.snapshotContentTree(unhide: true), nil) }), self.avatarNode.bounds) } diff --git a/submodules/LegacyComponents/LegacyComponents/TGAttachmentCarouselItemView.h b/submodules/LegacyComponents/LegacyComponents/TGAttachmentCarouselItemView.h index 54638ed711..562545338a 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGAttachmentCarouselItemView.h +++ b/submodules/LegacyComponents/LegacyComponents/TGAttachmentCarouselItemView.h @@ -3,6 +3,7 @@ #import #import +#import @class TGMediaSelectionContext; @class TGMediaEditingContext; @@ -52,6 +53,7 @@ @property (nonatomic, assign) bool collapsed; @property (nonatomic, strong) NSString *recipientName; +@property (nonatomic, assign) TGMediaVideoConversionPreset defaultVideoPreset; - (instancetype)initWithContext:(id)context camera:(bool)hasCamera selfPortrait:(bool)selfPortrait forProfilePhoto:(bool)forProfilePhoto assetType:(TGMediaAssetType)assetType saveEditedPhotos:(bool)saveEditedPhotos allowGrouping:(bool)allowGrouping; diff --git a/submodules/LegacyComponents/LegacyComponents/TGAttachmentCarouselItemView.m b/submodules/LegacyComponents/LegacyComponents/TGAttachmentCarouselItemView.m index 27e58db3ca..ad79b6f4a0 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGAttachmentCarouselItemView.m +++ b/submodules/LegacyComponents/LegacyComponents/TGAttachmentCarouselItemView.m @@ -801,7 +801,7 @@ const NSUInteger TGAttachmentDisplayedAssetLimit = 500; if ([cell isKindOfClass:[TGAttachmentAssetCell class]]) thumbnailImage = cell.imageView.image; - TGMediaPickerModernGalleryMixin *mixin = [[TGMediaPickerModernGalleryMixin alloc] initWithContext:_context item:asset fetchResult:_fetchResult parentController:self.parentController thumbnailImage:thumbnailImage selectionContext:_selectionContext editingContext:_editingContext suggestionContext:self.suggestionContext hasCaptions:(_allowCaptions && !_forProfilePhoto) allowCaptionEntities:self.allowCaptionEntities hasTimer:self.hasTimer onlyCrop:self.onlyCrop inhibitDocumentCaptions:_inhibitDocumentCaptions inhibitMute:self.inhibitMute asFile:self.asFile itemsLimit:TGAttachmentDisplayedAssetLimit recipientName:self.recipientName hasSilentPosting:self.hasSilentPosting hasSchedule:self.hasSchedule reminder:self.reminder]; + TGMediaPickerModernGalleryMixin *mixin = [[TGMediaPickerModernGalleryMixin alloc] initWithContext:_context item:asset fetchResult:_fetchResult parentController:self.parentController thumbnailImage:thumbnailImage selectionContext:_selectionContext editingContext:_editingContext suggestionContext:self.suggestionContext hasCaptions:(_allowCaptions && !_forProfilePhoto) allowCaptionEntities:self.allowCaptionEntities hasTimer:self.hasTimer onlyCrop:self.onlyCrop inhibitDocumentCaptions:_inhibitDocumentCaptions inhibitMute:self.inhibitMute asFile:self.asFile itemsLimit:TGAttachmentDisplayedAssetLimit recipientName:self.recipientName defaultVideoPreset:self.defaultVideoPreset hasSilentPosting:self.hasSilentPosting hasSchedule:self.hasSchedule reminder:self.reminder]; mixin.presentScheduleController = self.presentScheduleController; __weak TGAttachmentCarouselItemView *weakSelf = self; mixin.thumbnailSignalForItem = ^SSignal *(id item) @@ -864,7 +864,7 @@ const NSUInteger TGAttachmentDisplayedAssetLimit = 500; { id windowManager = [_context makeOverlayWindowManager]; - TGPhotoEditorController *controller = [[TGPhotoEditorController alloc] initWithContext:[windowManager context] item:asset intent:_disableStickers ? TGPhotoEditorControllerSignupAvatarIntent : TGPhotoEditorControllerAvatarIntent adjustments:nil caption:nil screenImage:thumbnailImage availableTabs:[TGPhotoEditorController defaultTabsForAvatarIntent] selectedTab:TGPhotoEditorCropTab]; + TGPhotoEditorController *controller = [[TGPhotoEditorController alloc] initWithContext:[windowManager context] item:asset intent:_disableStickers ? TGPhotoEditorControllerSignupAvatarIntent : TGPhotoEditorControllerAvatarIntent adjustments:nil caption:nil screenImage:thumbnailImage availableTabs:[TGPhotoEditorController defaultTabsForAvatarIntent] selectedTab:TGPhotoEditorCropTab defaultVideoPreset:_defaultVideoPreset]; controller.editingContext = _editingContext; controller.dontHideStatusBar = true; diff --git a/submodules/LegacyComponents/LegacyComponents/TGCameraController.h b/submodules/LegacyComponents/LegacyComponents/TGCameraController.h index 087ed30219..673891afc5 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGCameraController.h +++ b/submodules/LegacyComponents/LegacyComponents/TGCameraController.h @@ -2,6 +2,7 @@ #import #import #import +#import @class PGCamera; @class TGCameraPreviewView; @@ -45,6 +46,7 @@ typedef enum { @property (nonatomic, strong) NSArray *forcedEntities; @property (nonatomic, strong) NSString *recipientName; +@property (nonatomic, assign) TGMediaVideoConversionPreset defaultVideoPreset; @property (nonatomic, copy) void(^finishedWithResults)(TGOverlayController *controller, TGMediaSelectionContext *selectionContext, TGMediaEditingContext *editingContext, id currentItem, bool silentPosting, int32_t scheduleTime); @property (nonatomic, copy) void(^finishedWithPhoto)(TGOverlayController *controller, UIImage *resultImage, NSString *caption, NSArray *entities, NSArray *stickers, NSNumber *timer); diff --git a/submodules/LegacyComponents/LegacyComponents/TGCameraController.m b/submodules/LegacyComponents/LegacyComponents/TGCameraController.m index 9dc0ceded3..340a625835 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGCameraController.m +++ b/submodules/LegacyComponents/LegacyComponents/TGCameraController.m @@ -1247,7 +1247,7 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus }]; bool hasCamera = !self.inhibitMultipleCapture && ((_intent == TGCameraControllerGenericIntent && !_shortcut) || (_intent == TGCameraControllerPassportMultipleIntent)); - TGMediaPickerGalleryModel *model = [[TGMediaPickerGalleryModel alloc] initWithContext:windowContext items:galleryItems focusItem:focusItem selectionContext:_items.count > 1 ? selectionContext : nil editingContext:editingContext hasCaptions:self.allowCaptions allowCaptionEntities:self.allowCaptionEntities hasTimer:self.hasTimer onlyCrop:_intent == TGCameraControllerPassportIntent || _intent == TGCameraControllerPassportIdIntent || _intent == TGCameraControllerPassportMultipleIntent inhibitDocumentCaptions:self.inhibitDocumentCaptions hasSelectionPanel:true hasCamera:hasCamera recipientName:self.recipientName]; + TGMediaPickerGalleryModel *model = [[TGMediaPickerGalleryModel alloc] initWithContext:windowContext items:galleryItems focusItem:focusItem selectionContext:_items.count > 1 ? selectionContext : nil editingContext:editingContext hasCaptions:self.allowCaptions allowCaptionEntities:self.allowCaptionEntities hasTimer:self.hasTimer onlyCrop:_intent == TGCameraControllerPassportIntent || _intent == TGCameraControllerPassportIdIntent || _intent == TGCameraControllerPassportMultipleIntent inhibitDocumentCaptions:self.inhibitDocumentCaptions hasSelectionPanel:true hasCamera:hasCamera recipientName:self.recipientName defaultVideoPreset:self.defaultVideoPreset]; model.inhibitMute = self.inhibitMute; model.controller = galleryController; model.suggestionContext = self.suggestionContext; @@ -1651,7 +1651,7 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus if (_intent == TGCameraControllerSignupAvatarIntent) { intent = TGPhotoEditorControllerSignupAvatarIntent; } - TGPhotoEditorController *controller = [[TGPhotoEditorController alloc] initWithContext:windowContext item:image intent:(TGPhotoEditorControllerFromCameraIntent | intent) adjustments:nil caption:nil screenImage:image availableTabs:[TGPhotoEditorController defaultTabsForAvatarIntent] selectedTab:TGPhotoEditorCropTab]; + TGPhotoEditorController *controller = [[TGPhotoEditorController alloc] initWithContext:windowContext item:image intent:(TGPhotoEditorControllerFromCameraIntent | intent) adjustments:nil caption:nil screenImage:image availableTabs:[TGPhotoEditorController defaultTabsForAvatarIntent] selectedTab:TGPhotoEditorCropTab defaultVideoPreset:_defaultVideoPreset]; __weak TGPhotoEditorController *weakController = controller; controller.beginTransitionIn = ^UIView *(CGRect *referenceFrame, __unused UIView **parentView) { @@ -1735,7 +1735,7 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus default: { - TGCameraPhotoPreviewController *controller = _shortcut ? [[TGCameraPhotoPreviewController alloc] initWithContext:windowContext image:image metadata:metadata recipientName:self.recipientName backButtonTitle:TGLocalized(@"Camera.Retake") doneButtonTitle:TGLocalized(@"Common.Next") saveCapturedMedia:_saveCapturedMedia saveEditedPhotos:_saveEditedPhotos] : [[TGCameraPhotoPreviewController alloc] initWithContext:windowContext image:image metadata:metadata recipientName:self.recipientName saveCapturedMedia:_saveCapturedMedia saveEditedPhotos:_saveEditedPhotos]; + TGCameraPhotoPreviewController *controller = _shortcut ? [[TGCameraPhotoPreviewController alloc] initWithContext:windowContext image:image metadata:metadata recipientName:self.recipientName backButtonTitle:TGLocalized(@"Camera.Retake") doneButtonTitle:TGLocalized(@"Common.Next") saveCapturedMedia:_saveCapturedMedia saveEditedPhotos:_saveEditedPhotos defaultVideoPreset:_defaultVideoPreset] : [[TGCameraPhotoPreviewController alloc] initWithContext:windowContext image:image metadata:metadata recipientName:self.recipientName saveCapturedMedia:_saveCapturedMedia saveEditedPhotos:_saveEditedPhotos defaultVideoPreset:_defaultVideoPreset]; controller.allowCaptions = self.allowCaptions; controller.shouldStoreAssets = self.shouldStoreCapturedAssets; controller.suggestionContext = self.suggestionContext; diff --git a/submodules/LegacyComponents/LegacyComponents/TGCameraPhotoPreviewController.h b/submodules/LegacyComponents/LegacyComponents/TGCameraPhotoPreviewController.h index 19ad139c2a..8aaa1a4636 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGCameraPhotoPreviewController.h +++ b/submodules/LegacyComponents/LegacyComponents/TGCameraPhotoPreviewController.h @@ -1,5 +1,6 @@ #import #import +#import @class PGCameraShotMetadata; @class PGPhotoEditorValues; @@ -26,8 +27,8 @@ @property (nonatomic, assign) bool hasSilentPosting; @property (nonatomic, assign) bool hasSchedule; -- (instancetype)initWithContext:(id)context image:(UIImage *)image metadata:(PGCameraShotMetadata *)metadata recipientName:(NSString *)recipientName saveCapturedMedia:(bool)saveCapturedMedia saveEditedPhotos:(bool)saveEditedPhotos; -- (instancetype)initWithContext:(id)context image:(UIImage *)image metadata:(PGCameraShotMetadata *)metadata recipientName:(NSString *)recipientName backButtonTitle:(NSString *)backButtonTitle doneButtonTitle:(NSString *)doneButtonTitle saveCapturedMedia:(bool)saveCapturedMedia saveEditedPhotos:(bool)saveEditedPhotos; +- (instancetype)initWithContext:(id)context image:(UIImage *)image metadata:(PGCameraShotMetadata *)metadata recipientName:(NSString *)recipientName saveCapturedMedia:(bool)saveCapturedMedia saveEditedPhotos:(bool)saveEditedPhotos defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset; +- (instancetype)initWithContext:(id)context image:(UIImage *)image metadata:(PGCameraShotMetadata *)metadata recipientName:(NSString *)recipientName backButtonTitle:(NSString *)backButtonTitle doneButtonTitle:(NSString *)doneButtonTitle saveCapturedMedia:(bool)saveCapturedMedia saveEditedPhotos:(bool)saveEditedPhotos defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset; @end diff --git a/submodules/LegacyComponents/LegacyComponents/TGCameraPhotoPreviewController.m b/submodules/LegacyComponents/LegacyComponents/TGCameraPhotoPreviewController.m index aa650c39ee..459c80f6a5 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGCameraPhotoPreviewController.m +++ b/submodules/LegacyComponents/LegacyComponents/TGCameraPhotoPreviewController.m @@ -80,6 +80,8 @@ bool _saveEditedPhotos; id _context; + + TGMediaVideoConversionPreset _defaultVideoPreset; } @property (nonatomic, weak) TGPhotoEditorController *editorController; @@ -88,12 +90,12 @@ @implementation TGCameraPhotoPreviewController -- (instancetype)initWithContext:(id)context image:(UIImage *)image metadata:(PGCameraShotMetadata *)metadata recipientName:(NSString *)recipientName saveCapturedMedia:(bool)saveCapturedMedia saveEditedPhotos:(bool)saveEditedPhotos +- (instancetype)initWithContext:(id)context image:(UIImage *)image metadata:(PGCameraShotMetadata *)metadata recipientName:(NSString *)recipientName saveCapturedMedia:(bool)saveCapturedMedia saveEditedPhotos:(bool)saveEditedPhotos defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset { - return [self initWithContext:context image:image metadata:metadata recipientName:recipientName backButtonTitle:TGLocalized(@"Camera.Retake") doneButtonTitle:TGLocalized(@"MediaPicker.Send") saveCapturedMedia:saveCapturedMedia saveEditedPhotos:saveEditedPhotos]; + return [self initWithContext:context image:image metadata:metadata recipientName:recipientName backButtonTitle:TGLocalized(@"Camera.Retake") doneButtonTitle:TGLocalized(@"MediaPicker.Send") saveCapturedMedia:saveCapturedMedia saveEditedPhotos:saveEditedPhotos defaultVideoPreset:defaultVideoPreset]; } -- (instancetype)initWithContext:(id)context image:(UIImage *)image metadata:(PGCameraShotMetadata *)metadata recipientName:(NSString *)recipientName backButtonTitle:(NSString *)backButtonTitle doneButtonTitle:(NSString *)doneButtonTitle saveCapturedMedia:(bool)saveCapturedMedia saveEditedPhotos:(bool)saveEditedPhotos +- (instancetype)initWithContext:(id)context image:(UIImage *)image metadata:(PGCameraShotMetadata *)metadata recipientName:(NSString *)recipientName backButtonTitle:(NSString *)backButtonTitle doneButtonTitle:(NSString *)doneButtonTitle saveCapturedMedia:(bool)saveCapturedMedia saveEditedPhotos:(bool)saveEditedPhotos defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset { self = [super initWithContext:context]; if (self != nil) @@ -103,6 +105,7 @@ _metadata = metadata; _imageSize = image.size; _recipientName = recipientName; + _defaultVideoPreset = defaultVideoPreset; _editingContext = [[TGMediaEditingContext alloc] init]; @@ -884,7 +887,7 @@ PGPhotoEditorValues *editorValues = (PGPhotoEditorValues *)[_editingContext adjustmentsForItem:_image]; NSString *caption = [_editingContext captionForItem:_image]; - TGPhotoEditorController *controller = [[TGPhotoEditorController alloc] initWithContext:_context item:editableMediaItem intent:TGPhotoEditorControllerFromCameraIntent adjustments:editorValues caption:caption screenImage:screenImage availableTabs:_portraitToolbarView.currentTabs selectedTab:tab]; + TGPhotoEditorController *controller = [[TGPhotoEditorController alloc] initWithContext:_context item:editableMediaItem intent:TGPhotoEditorControllerFromCameraIntent adjustments:editorValues caption:caption screenImage:screenImage availableTabs:_portraitToolbarView.currentTabs selectedTab:tab defaultVideoPreset:_defaultVideoPreset]; controller.editingContext = _editingContext; self.editorController = controller; controller.metadata = _metadata; diff --git a/submodules/LegacyComponents/LegacyComponents/TGClipboardGalleryMixin.h b/submodules/LegacyComponents/LegacyComponents/TGClipboardGalleryMixin.h index 91029a936f..68a366f226 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGClipboardGalleryMixin.h +++ b/submodules/LegacyComponents/LegacyComponents/TGClipboardGalleryMixin.h @@ -2,6 +2,7 @@ #import #import +#import @class TGClipboardGalleryPhotoItem; @@ -19,7 +20,7 @@ @property (nonatomic, copy) void (^editorOpened)(void); @property (nonatomic, copy) void (^editorClosed)(void); -- (instancetype)initWithContext:(id)context image:(UIImage *)image images:(NSArray *)images parentController:(TGViewController *)parentController thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaptions hasTimer:(bool)hasTimer recipientName:(NSString *)recipientName; +- (instancetype)initWithContext:(id)context image:(UIImage *)image images:(NSArray *)images parentController:(TGViewController *)parentController thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaptions hasTimer:(bool)hasTimer recipientName:(NSString *)recipientName defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset; - (void)present; diff --git a/submodules/LegacyComponents/LegacyComponents/TGClipboardGalleryMixin.m b/submodules/LegacyComponents/LegacyComponents/TGClipboardGalleryMixin.m index 0e7688207a..cc49874cf6 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGClipboardGalleryMixin.m +++ b/submodules/LegacyComponents/LegacyComponents/TGClipboardGalleryMixin.m @@ -35,7 +35,7 @@ @implementation TGClipboardGalleryMixin -- (instancetype)initWithContext:(id)context image:(UIImage *)image images:(NSArray *)images parentController:(TGViewController *)parentController thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaptions hasTimer:(bool)hasTimer recipientName:(NSString *)recipientName +- (instancetype)initWithContext:(id)context image:(UIImage *)image images:(NSArray *)images parentController:(TGViewController *)parentController thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaptions hasTimer:(bool)hasTimer recipientName:(NSString *)recipientName defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset { self = [super init]; if (self != nil) @@ -61,7 +61,7 @@ } }]; - TGClipboardGalleryModel *model = [[TGClipboardGalleryModel alloc] initWithContext:_context images:images focusIndex:focusIndex selectionContext:selectionContext editingContext:editingContext hasCaptions:hasCaptions hasTimer:hasTimer hasSelectionPanel:false recipientName:recipientName]; + TGClipboardGalleryModel *model = [[TGClipboardGalleryModel alloc] initWithContext:_context images:images focusIndex:focusIndex selectionContext:selectionContext editingContext:editingContext hasCaptions:hasCaptions hasTimer:hasTimer hasSelectionPanel:false recipientName:recipientName defaultVideoPreset:defaultVideoPreset]; _galleryModel = model; model.controller = modernGallery; model.suggestionContext = suggestionContext; diff --git a/submodules/LegacyComponents/LegacyComponents/TGClipboardGalleryModel.h b/submodules/LegacyComponents/LegacyComponents/TGClipboardGalleryModel.h index f2a5356d91..68a8809fc6 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGClipboardGalleryModel.h +++ b/submodules/LegacyComponents/LegacyComponents/TGClipboardGalleryModel.h @@ -6,6 +6,7 @@ #import #import +#import @interface TGClipboardGalleryModel : TGModernGalleryModel @@ -26,6 +27,6 @@ @property (nonatomic, readonly) TGMediaSelectionContext *selectionContext; @property (nonatomic, strong) TGSuggestionContext *suggestionContext; -- (instancetype)initWithContext:(id)context images:(NSArray *)images focusIndex:(NSUInteger)focusIndex selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext hasCaptions:(bool)hasCaptions hasTimer:(bool)hasTimer hasSelectionPanel:(bool)hasSelectionPanel recipientName:(NSString *)recipientName; +- (instancetype)initWithContext:(id)context images:(NSArray *)images focusIndex:(NSUInteger)focusIndex selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext hasCaptions:(bool)hasCaptions hasTimer:(bool)hasTimer hasSelectionPanel:(bool)hasSelectionPanel recipientName:(NSString *)recipientName defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset; @end diff --git a/submodules/LegacyComponents/LegacyComponents/TGClipboardGalleryModel.m b/submodules/LegacyComponents/LegacyComponents/TGClipboardGalleryModel.m index 32761d6193..df1b4eb441 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGClipboardGalleryModel.m +++ b/submodules/LegacyComponents/LegacyComponents/TGClipboardGalleryModel.m @@ -26,6 +26,7 @@ TGMediaEditingContext *_editingContext; id _context; + TGMediaVideoConversionPreset _defaultVideoPreset; } @property (nonatomic, weak) TGPhotoEditorController *editorController; @@ -34,12 +35,13 @@ @implementation TGClipboardGalleryModel -- (instancetype)initWithContext:(id)context images:(NSArray *)images focusIndex:(NSUInteger)focusIndex selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext hasCaptions:(bool)hasCaptions hasTimer:(bool)hasTimer hasSelectionPanel:(bool)hasSelectionPanel recipientName:(NSString *)recipientName +- (instancetype)initWithContext:(id)context images:(NSArray *)images focusIndex:(NSUInteger)focusIndex selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext hasCaptions:(bool)hasCaptions hasTimer:(bool)hasTimer hasSelectionPanel:(bool)hasSelectionPanel recipientName:(NSString *)recipientName defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset { self = [super init]; if (self != nil) { _context = context; + _defaultVideoPreset = defaultVideoPreset; NSMutableArray *items = [[NSMutableArray alloc] init]; TGClipboardGalleryPhotoItem *focusItem = nil; @@ -77,7 +79,7 @@ }; } - _interfaceView = [[TGMediaPickerGalleryInterfaceView alloc] initWithContext:_context focusItem:focusItem selectionContext:selectionContext editingContext:editingContext hasSelectionPanel:hasSelectionPanel hasCameraButton:false recipientName:recipientName]; + _interfaceView = [[TGMediaPickerGalleryInterfaceView alloc] initWithContext:_context focusItem:focusItem selectionContext:selectionContext editingContext:editingContext hasSelectionPanel:hasSelectionPanel hasCameraButton:false recipientName:recipientName defaultVideoPreset:defaultVideoPreset]; _interfaceView.hasCaptions = hasCaptions; _interfaceView.hasTimer = hasTimer; [_interfaceView setEditorTabPressed:^(TGPhotoEditorTab tab) @@ -320,7 +322,7 @@ } TGPhotoEditorControllerIntent intent = isVideo ? TGPhotoEditorControllerVideoIntent : TGPhotoEditorControllerGenericIntent; - TGPhotoEditorController *controller = [[TGPhotoEditorController alloc] initWithContext:_context item:item.editableMediaItem intent:intent adjustments:editorValues caption:caption screenImage:screenImage availableTabs:_interfaceView.currentTabs selectedTab:tab]; + TGPhotoEditorController *controller = [[TGPhotoEditorController alloc] initWithContext:_context item:item.editableMediaItem intent:intent adjustments:editorValues caption:caption screenImage:screenImage availableTabs:_interfaceView.currentTabs selectedTab:tab defaultVideoPreset:_defaultVideoPreset]; controller.editingContext = _editingContext; self.editorController = controller; controller.suggestionContext = self.suggestionContext; diff --git a/submodules/LegacyComponents/LegacyComponents/TGClipboardMenu.h b/submodules/LegacyComponents/LegacyComponents/TGClipboardMenu.h index 3fa226683c..d7fa71c3bb 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGClipboardMenu.h +++ b/submodules/LegacyComponents/LegacyComponents/TGClipboardMenu.h @@ -1,6 +1,7 @@ #import #import +#import @class TGViewController; @class TGMenuSheetController; @@ -12,7 +13,7 @@ @interface TGClipboardMenu : NSObject -+ (TGMenuSheetController *)presentInParentController:(TGViewController *)parentController context:(id)context images:(NSArray *)images hasCaption:(bool)hasCaption hasTimer:(bool)hasTimer recipientName:(NSString *)recipientName completed:(void (^)(TGMediaSelectionContext *selectionContext, TGMediaEditingContext *editingContext, id currentItem))completed dismissed:(void (^)(void))dismissed sourceView:(UIView *)sourceView sourceRect:(CGRect (^)(void))sourceRect; ++ (TGMenuSheetController *)presentInParentController:(TGViewController *)parentController context:(id)context images:(NSArray *)images hasCaption:(bool)hasCaption hasTimer:(bool)hasTimer recipientName:(NSString *)recipientName defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset completed:(void (^)(TGMediaSelectionContext *selectionContext, TGMediaEditingContext *editingContext, id currentItem))completed dismissed:(void (^)(void))dismissed sourceView:(UIView *)sourceView sourceRect:(CGRect (^)(void))sourceRect; + (NSArray *)resultSignalsForSelectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext currentItem:(id)currentItem descriptionGenerator:(id (^)(id, NSString *, NSArray *, NSString *))descriptionGenerator; diff --git a/submodules/LegacyComponents/LegacyComponents/TGClipboardMenu.m b/submodules/LegacyComponents/LegacyComponents/TGClipboardMenu.m index 7a3b0c3169..eeae1b04e7 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGClipboardMenu.m +++ b/submodules/LegacyComponents/LegacyComponents/TGClipboardMenu.m @@ -9,7 +9,7 @@ @implementation TGClipboardMenu -+ (TGMenuSheetController *)presentInParentController:(TGViewController *)parentController context:(id)context images:(NSArray *)images hasCaption:(bool)hasCaption hasTimer:(bool)hasTimer recipientName:(NSString *)recipientName completed:(void (^)(TGMediaSelectionContext *selectionContext, TGMediaEditingContext *editingContext, id currentItem))completed dismissed:(void (^)(void))dismissed sourceView:(UIView *)sourceView sourceRect:(CGRect (^)(void))sourceRect ++ (TGMenuSheetController *)presentInParentController:(TGViewController *)parentController context:(id)context images:(NSArray *)images hasCaption:(bool)hasCaption hasTimer:(bool)hasTimer recipientName:(NSString *)recipientName defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset completed:(void (^)(TGMediaSelectionContext *selectionContext, TGMediaEditingContext *editingContext, id currentItem))completed dismissed:(void (^)(void))dismissed sourceView:(UIView *)sourceView sourceRect:(CGRect (^)(void))sourceRect { bool centered = false; if (sourceRect == nil) @@ -46,6 +46,7 @@ previewItem.allowCaptions = hasCaption; previewItem.hasTimer = hasTimer; previewItem.recipientName = recipientName; + previewItem.defaultVideoPreset = defaultVideoPreset; previewItem.sendPressed = ^(UIImage *currentItem) { __strong TGClipboardPreviewItemView *strongPreviewItem = weakPreviewItem; diff --git a/submodules/LegacyComponents/LegacyComponents/TGClipboardPreviewItemView.h b/submodules/LegacyComponents/LegacyComponents/TGClipboardPreviewItemView.h index 1283089e83..c40305a54d 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGClipboardPreviewItemView.h +++ b/submodules/LegacyComponents/LegacyComponents/TGClipboardPreviewItemView.h @@ -11,6 +11,7 @@ @property (nonatomic, assign) bool allowCaptions; @property (nonatomic, assign) bool hasTimer; @property (nonatomic, strong) NSString *recipientName; +@property (nonatomic, assign) TGMediaVideoConversionPreset defaultVideoPreset; @property (nonatomic, readonly) TGMediaSelectionContext *selectionContext; @property (nonatomic, readonly) TGMediaEditingContext *editingContext; diff --git a/submodules/LegacyComponents/LegacyComponents/TGClipboardPreviewItemView.m b/submodules/LegacyComponents/LegacyComponents/TGClipboardPreviewItemView.m index 8d05d42cb2..e888889272 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGClipboardPreviewItemView.m +++ b/submodules/LegacyComponents/LegacyComponents/TGClipboardPreviewItemView.m @@ -266,7 +266,7 @@ const CGFloat TGClipboardPreviewEdgeInset = 8.0f; if ([cell isKindOfClass:[TGClipboardPreviewCell class]]) thumbnailImage = cell.imageView.image; - TGClipboardGalleryMixin *mixin = [[TGClipboardGalleryMixin alloc] initWithContext:_context image:image images:_images parentController:self.parentController thumbnailImage:thumbnailImage selectionContext:_selectionContext editingContext:_editingContext suggestionContext:self.suggestionContext hasCaptions:self.allowCaptions hasTimer:self.hasTimer recipientName:self.recipientName]; + TGClipboardGalleryMixin *mixin = [[TGClipboardGalleryMixin alloc] initWithContext:_context image:image images:_images parentController:self.parentController thumbnailImage:thumbnailImage selectionContext:_selectionContext editingContext:_editingContext suggestionContext:self.suggestionContext hasCaptions:self.allowCaptions hasTimer:self.hasTimer recipientName:self.recipientName defaultVideoPreset:self.defaultVideoPreset]; [self _setupGalleryMixin:mixin]; diff --git a/submodules/LegacyComponents/LegacyComponents/TGMediaAssetsController.h b/submodules/LegacyComponents/LegacyComponents/TGMediaAssetsController.h index 348bab118a..da0a4f2cad 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGMediaAssetsController.h +++ b/submodules/LegacyComponents/LegacyComponents/TGMediaAssetsController.h @@ -6,6 +6,8 @@ #import +#import + @class TGMediaAssetsPickerController; @class TGViewController; @@ -91,8 +93,8 @@ typedef enum - (void)dismiss; -+ (instancetype)controllerWithContext:(id)context assetGroup:(TGMediaAssetGroup *)assetGroup intent:(TGMediaAssetsControllerIntent)intent recipientName:(NSString *)recipientName saveEditedPhotos:(bool)saveEditedPhotos allowGrouping:(bool)allowGrouping selectionLimit:(int)selectionLimit; -+ (instancetype)controllerWithContext:(id)context assetGroup:(TGMediaAssetGroup *)assetGroup intent:(TGMediaAssetsControllerIntent)intent recipientName:(NSString *)recipientName saveEditedPhotos:(bool)saveEditedPhotos allowGrouping:(bool)allowGrouping inhibitSelection:(bool)inhibitSelection selectionLimit:(int)selectionLimit; ++ (instancetype)controllerWithContext:(id)context assetGroup:(TGMediaAssetGroup *)assetGroup intent:(TGMediaAssetsControllerIntent)intent recipientName:(NSString *)recipientName defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset saveEditedPhotos:(bool)saveEditedPhotos allowGrouping:(bool)allowGrouping selectionLimit:(int)selectionLimit; ++ (instancetype)controllerWithContext:(id)context assetGroup:(TGMediaAssetGroup *)assetGroup intent:(TGMediaAssetsControllerIntent)intent recipientName:(NSString *)recipientName defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset saveEditedPhotos:(bool)saveEditedPhotos allowGrouping:(bool)allowGrouping inhibitSelection:(bool)inhibitSelection selectionLimit:(int)selectionLimit; + (TGMediaAssetType)assetTypeForIntent:(TGMediaAssetsControllerIntent)intent; diff --git a/submodules/LegacyComponents/LegacyComponents/TGMediaAssetsController.m b/submodules/LegacyComponents/LegacyComponents/TGMediaAssetsController.m index 8c6fd58736..12b5bad676 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGMediaAssetsController.m +++ b/submodules/LegacyComponents/LegacyComponents/TGMediaAssetsController.m @@ -58,12 +58,12 @@ @implementation TGMediaAssetsController -+ (instancetype)controllerWithContext:(id)context assetGroup:(TGMediaAssetGroup *)assetGroup intent:(TGMediaAssetsControllerIntent)intent recipientName:(NSString *)recipientName saveEditedPhotos:(bool)saveEditedPhotos allowGrouping:(bool)allowGrouping selectionLimit:(int)selectionLimit ++ (instancetype)controllerWithContext:(id)context assetGroup:(TGMediaAssetGroup *)assetGroup intent:(TGMediaAssetsControllerIntent)intent recipientName:(NSString *)recipientName defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset saveEditedPhotos:(bool)saveEditedPhotos allowGrouping:(bool)allowGrouping selectionLimit:(int)selectionLimit { - return [self controllerWithContext:context assetGroup:assetGroup intent:intent recipientName:recipientName saveEditedPhotos:saveEditedPhotos allowGrouping:allowGrouping inhibitSelection:false selectionLimit:selectionLimit]; + return [self controllerWithContext:context assetGroup:assetGroup intent:intent recipientName:recipientName defaultVideoPreset:defaultVideoPreset saveEditedPhotos:saveEditedPhotos allowGrouping:allowGrouping inhibitSelection:false selectionLimit:selectionLimit]; } -+ (instancetype)controllerWithContext:(id)context assetGroup:(TGMediaAssetGroup *)assetGroup intent:(TGMediaAssetsControllerIntent)intent recipientName:(NSString *)recipientName saveEditedPhotos:(bool)saveEditedPhotos allowGrouping:(bool)allowGrouping inhibitSelection:(bool)inhibitSelection selectionLimit:(int)selectionLimit ++ (instancetype)controllerWithContext:(id)context assetGroup:(TGMediaAssetGroup *)assetGroup intent:(TGMediaAssetsControllerIntent)intent recipientName:(NSString *)recipientName defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset saveEditedPhotos:(bool)saveEditedPhotos allowGrouping:(bool)allowGrouping inhibitSelection:(bool)inhibitSelection selectionLimit:(int)selectionLimit { if (intent != TGMediaAssetsControllerSendMediaIntent) allowGrouping = false; @@ -106,7 +106,7 @@ if ([group isKindOfClass:[TGMediaAssetGroup class]]) { - pickerController = [[TGMediaAssetsPickerController alloc] initWithContext:strongController->_context assetsLibrary:strongController.assetsLibrary assetGroup:group intent:intent selectionContext:inhibitSelection ? nil : strongController->_selectionContext editingContext:strongController->_editingContext saveEditedPhotos:strongController->_saveEditedPhotos]; + pickerController = [[TGMediaAssetsPickerController alloc] initWithContext:strongController->_context assetsLibrary:strongController.assetsLibrary assetGroup:group intent:intent selectionContext:inhibitSelection ? nil : strongController->_selectionContext editingContext:strongController->_editingContext saveEditedPhotos:strongController->_saveEditedPhotos defaultVideoPreset:defaultVideoPreset]; pickerController.pallete = strongController.pallete; } pickerController.suggestionContext = strongController.suggestionContext; @@ -118,6 +118,7 @@ pickerController.liveVideoUploadEnabled = strongController.liveVideoUploadEnabled; pickerController.catchToolbarView = catchToolbarView; pickerController.recipientName = recipientName; + pickerController.defaultVideoPreset = defaultVideoPreset; pickerController.hasTimer = strongController.hasTimer; pickerController.onlyCrop = strongController.onlyCrop; pickerController.hasSilentPosting = strongController.hasSilentPosting; @@ -128,7 +129,7 @@ }; [groupsController loadViewIfNeeded]; - TGMediaAssetsPickerController *pickerController = [[TGMediaAssetsPickerController alloc] initWithContext:context assetsLibrary:assetsController.assetsLibrary assetGroup:assetGroup intent:intent selectionContext:inhibitSelection ? nil : assetsController->_selectionContext editingContext:assetsController->_editingContext saveEditedPhotos:saveEditedPhotos]; + TGMediaAssetsPickerController *pickerController = [[TGMediaAssetsPickerController alloc] initWithContext:context assetsLibrary:assetsController.assetsLibrary assetGroup:assetGroup intent:intent selectionContext:inhibitSelection ? nil : assetsController->_selectionContext editingContext:assetsController->_editingContext saveEditedPhotos:saveEditedPhotos defaultVideoPreset:defaultVideoPreset]; pickerController.pallete = assetsController.pallete; pickerController.catchToolbarView = catchToolbarView; diff --git a/submodules/LegacyComponents/LegacyComponents/TGMediaAssetsPickerController.h b/submodules/LegacyComponents/LegacyComponents/TGMediaAssetsPickerController.h index 6933723a00..0834e8793c 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGMediaAssetsPickerController.h +++ b/submodules/LegacyComponents/LegacyComponents/TGMediaAssetsPickerController.h @@ -1,6 +1,7 @@ #import #import #import +#import @class TGMediaAssetsPreheatMixin; @class TGMediaPickerModernGalleryMixin; @@ -14,6 +15,6 @@ @property (nonatomic, assign) bool liveVideoUploadEnabled; @property (nonatomic, readonly) TGMediaAssetGroup *assetGroup; -- (instancetype)initWithContext:(id)context assetsLibrary:(TGMediaAssetsLibrary *)assetsLibrary assetGroup:(TGMediaAssetGroup *)assetGroup intent:(TGMediaAssetsControllerIntent)intent selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext saveEditedPhotos:(bool)saveEditedPhotos; +- (instancetype)initWithContext:(id)context assetsLibrary:(TGMediaAssetsLibrary *)assetsLibrary assetGroup:(TGMediaAssetGroup *)assetGroup intent:(TGMediaAssetsControllerIntent)intent selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext saveEditedPhotos:(bool)saveEditedPhotos defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset; @end diff --git a/submodules/LegacyComponents/LegacyComponents/TGMediaAssetsPickerController.m b/submodules/LegacyComponents/LegacyComponents/TGMediaAssetsPickerController.m index 965c013b24..9b71a6fb5c 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGMediaAssetsPickerController.m +++ b/submodules/LegacyComponents/LegacyComponents/TGMediaAssetsPickerController.m @@ -46,13 +46,15 @@ id _context; bool _saveEditedPhotos; + + TGMediaVideoConversionPreset _defaultVideoPreset; } @end @implementation TGMediaAssetsPickerController -- (instancetype)initWithContext:(id)context assetsLibrary:(TGMediaAssetsLibrary *)assetsLibrary assetGroup:(TGMediaAssetGroup *)assetGroup intent:(TGMediaAssetsControllerIntent)intent selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext saveEditedPhotos:(bool)saveEditedPhotos +- (instancetype)initWithContext:(id)context assetsLibrary:(TGMediaAssetsLibrary *)assetsLibrary assetGroup:(TGMediaAssetGroup *)assetGroup intent:(TGMediaAssetsControllerIntent)intent selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext saveEditedPhotos:(bool)saveEditedPhotos defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset { bool hasSelection = false; bool hasEditing = false; @@ -88,6 +90,7 @@ _assetsLibrary = assetsLibrary; _assetGroup = assetGroup; _intent = intent; + _defaultVideoPreset = defaultVideoPreset; [self setTitle:_assetGroup.title]; @@ -323,7 +326,7 @@ - (TGMediaPickerModernGalleryMixin *)_galleryMixinForContext:(id)context item:(id)item thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities inhibitDocumentCaptions:(bool)inhibitDocumentCaptions asFile:(bool)asFile { - return [[TGMediaPickerModernGalleryMixin alloc] initWithContext:context item:item fetchResult:_fetchResult parentController:self thumbnailImage:thumbnailImage selectionContext:selectionContext editingContext:editingContext suggestionContext:suggestionContext hasCaptions:hasCaptions allowCaptionEntities:allowCaptionEntities hasTimer:self.hasTimer onlyCrop:self.onlyCrop inhibitDocumentCaptions:inhibitDocumentCaptions inhibitMute:self.inhibitMute asFile:asFile itemsLimit:0 recipientName:self.recipientName hasSilentPosting:self.hasSilentPosting hasSchedule:self.hasSchedule reminder:self.reminder]; + return [[TGMediaPickerModernGalleryMixin alloc] initWithContext:context item:item fetchResult:_fetchResult parentController:self thumbnailImage:thumbnailImage selectionContext:selectionContext editingContext:editingContext suggestionContext:suggestionContext hasCaptions:hasCaptions allowCaptionEntities:allowCaptionEntities hasTimer:self.hasTimer onlyCrop:self.onlyCrop inhibitDocumentCaptions:inhibitDocumentCaptions inhibitMute:self.inhibitMute asFile:asFile itemsLimit:0 recipientName:self.recipientName defaultVideoPreset:self.defaultVideoPreset hasSilentPosting:self.hasSilentPosting hasSchedule:self.hasSchedule reminder:self.reminder]; } - (TGMediaPickerModernGalleryMixin *)galleryMixinForIndexPath:(NSIndexPath *)indexPath previewMode:(bool)previewMode outAsset:(TGMediaAsset **)outAsset @@ -395,7 +398,7 @@ if (_intent == TGMediaAssetsControllerSetSignupProfilePhotoIntent) { intent = TGPhotoEditorControllerSignupAvatarIntent; } - TGPhotoEditorController *controller = [[TGPhotoEditorController alloc] initWithContext:_context item:asset intent:intent adjustments:nil caption:nil screenImage:thumbnailImage availableTabs:[TGPhotoEditorController defaultTabsForAvatarIntent] selectedTab:TGPhotoEditorCropTab]; + TGPhotoEditorController *controller = [[TGPhotoEditorController alloc] initWithContext:_context item:asset intent:intent adjustments:nil caption:nil screenImage:thumbnailImage availableTabs:[TGPhotoEditorController defaultTabsForAvatarIntent] selectedTab:TGPhotoEditorCropTab defaultVideoPreset:_defaultVideoPreset]; controller.editingContext = self.editingContext; controller.didFinishRenderingFullSizeImage = ^(UIImage *resultImage) { diff --git a/submodules/LegacyComponents/LegacyComponents/TGMediaAvatarMenuMixin.m b/submodules/LegacyComponents/LegacyComponents/TGMediaAvatarMenuMixin.m index ed292c996e..98cf3c2ec2 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGMediaAvatarMenuMixin.m +++ b/submodules/LegacyComponents/LegacyComponents/TGMediaAvatarMenuMixin.m @@ -445,7 +445,7 @@ if (strongSelf == nil) return nil; - TGMediaAssetsController *controller = [TGMediaAssetsController controllerWithContext:context assetGroup:group intent:strongSelf->_signup ? TGMediaAssetsControllerSetSignupProfilePhotoIntent : TGMediaAssetsControllerSetProfilePhotoIntent recipientName:nil saveEditedPhotos:strongSelf->_saveEditedPhotos allowGrouping:false selectionLimit:10]; + TGMediaAssetsController *controller = [TGMediaAssetsController controllerWithContext:context assetGroup:group intent:strongSelf->_signup ? TGMediaAssetsControllerSetSignupProfilePhotoIntent : TGMediaAssetsControllerSetProfilePhotoIntent recipientName:nil defaultVideoPreset:TGMediaVideoConversionPresetCompressedDefault saveEditedPhotos:strongSelf->_saveEditedPhotos allowGrouping:false selectionLimit:10]; __weak TGMediaAssetsController *weakController = controller; controller.avatarCompletionBlock = ^(UIImage *resultImage) { diff --git a/submodules/LegacyComponents/LegacyComponents/TGMediaPickerController.h b/submodules/LegacyComponents/LegacyComponents/TGMediaPickerController.h index 8cd104554b..5351e3fd2d 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGMediaPickerController.h +++ b/submodules/LegacyComponents/LegacyComponents/TGMediaPickerController.h @@ -2,6 +2,8 @@ #import +#import + @class TGMediaPickerLayoutMetrics; @class TGMediaSelectionContext; @class TGMediaEditingContext; @@ -27,6 +29,7 @@ @property (nonatomic, assign) bool onlyCrop; @property (nonatomic, assign) bool inhibitMute; @property (nonatomic, strong) NSString *recipientName; +@property (nonatomic, assign) TGMediaVideoConversionPreset defaultVideoPreset; @property (nonatomic, assign) bool hasSilentPosting; @property (nonatomic, assign) bool hasSchedule; @property (nonatomic, assign) bool reminder; diff --git a/submodules/LegacyComponents/LegacyComponents/TGMediaPickerController.m b/submodules/LegacyComponents/LegacyComponents/TGMediaPickerController.m index de1ef07824..ee45ef34fe 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGMediaPickerController.m +++ b/submodules/LegacyComponents/LegacyComponents/TGMediaPickerController.m @@ -36,6 +36,7 @@ { _selectionContext = selectionContext; _editingContext = editingContext; + _defaultVideoPreset = TGMediaVideoConversionPresetCompressedDefault; } return self; } diff --git a/submodules/LegacyComponents/LegacyComponents/TGMediaPickerGalleryInterfaceView.h b/submodules/LegacyComponents/LegacyComponents/TGMediaPickerGalleryInterfaceView.h index 062b5e8e0e..405a5d519e 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGMediaPickerGalleryInterfaceView.h +++ b/submodules/LegacyComponents/LegacyComponents/TGMediaPickerGalleryInterfaceView.h @@ -4,6 +4,7 @@ #import #import +#import @class TGMediaSelectionContext; @class TGMediaEditingContext; @@ -37,7 +38,7 @@ @property (nonatomic, readonly) UIView *timerButton; -- (instancetype)initWithContext:(id)context focusItem:(id)focusItem selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext hasSelectionPanel:(bool)hasSelectionPanel hasCameraButton:(bool)hasCameraButton recipientName:(NSString *)recipientName; +- (instancetype)initWithContext:(id)context focusItem:(id)focusItem selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext hasSelectionPanel:(bool)hasSelectionPanel hasCameraButton:(bool)hasCameraButton recipientName:(NSString *)recipientName defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset; - (void)setSelectedItemsModel:(TGMediaPickerGallerySelectedItemsModel *)selectedItemsModel; - (void)setEditorTabPressed:(void (^)(TGPhotoEditorTab tab))editorTabPressed; diff --git a/submodules/LegacyComponents/LegacyComponents/TGMediaPickerGalleryInterfaceView.m b/submodules/LegacyComponents/LegacyComponents/TGMediaPickerGalleryInterfaceView.m index 7bcdea25b5..6512cca1f2 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGMediaPickerGalleryInterfaceView.m +++ b/submodules/LegacyComponents/LegacyComponents/TGMediaPickerGalleryInterfaceView.m @@ -92,6 +92,8 @@ id _context; bool _ignoreSelectionUpdates; + + TGMediaVideoConversionPreset _defaultVideoPreset; } @property (nonatomic, strong) ASHandle *actionHandle; @@ -103,7 +105,7 @@ @synthesize safeAreaInset = _safeAreaInset; -- (instancetype)initWithContext:(id)context focusItem:(id)focusItem selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext hasSelectionPanel:(bool)hasSelectionPanel hasCameraButton:(bool)hasCameraButton recipientName:(NSString *)recipientName +- (instancetype)initWithContext:(id)context focusItem:(id)focusItem selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext hasSelectionPanel:(bool)hasSelectionPanel hasCameraButton:(bool)hasCameraButton recipientName:(NSString *)recipientName defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset { self = [super initWithFrame:CGRectZero]; if (self != nil) @@ -116,6 +118,8 @@ _hasSwipeGesture = true; + _defaultVideoPreset = defaultVideoPreset; + _itemHeaderViews = [[NSMutableArray alloc] init]; _itemFooterViews = [[NSMutableArray alloc] init]; @@ -850,11 +854,7 @@ } else { - NSNumber *presetValue = [[NSUserDefaults standardUserDefaults] objectForKey:@"TG_preferredVideoPreset_v0"]; - if (presetValue != nil) - preset = (TGMediaVideoConversionPreset)[presetValue integerValue]; - else - preset = TGMediaVideoConversionPresetCompressedMedium; + preset = _defaultVideoPreset; } TGMediaVideoConversionPreset bestPreset = [TGMediaVideoConverter bestAvailablePresetForDimensions:dimensions]; diff --git a/submodules/LegacyComponents/LegacyComponents/TGMediaPickerGalleryModel.h b/submodules/LegacyComponents/LegacyComponents/TGMediaPickerGalleryModel.h index 40d8da8921..565fdf7b56 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGMediaPickerGalleryModel.h +++ b/submodules/LegacyComponents/LegacyComponents/TGMediaPickerGalleryModel.h @@ -7,6 +7,7 @@ #import #import +#import @class TGModernGalleryController; @class TGMediaPickerGallerySelectedItemsModel; @@ -45,6 +46,6 @@ @property (nonatomic, readonly) TGMediaSelectionContext *selectionContext; @property (nonatomic, strong) TGSuggestionContext *suggestionContext; -- (instancetype)initWithContext:(id)context items:(NSArray *)items focusItem:(id)focusItem selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities hasTimer:(bool)hasTimer onlyCrop:(bool)onlyCrop inhibitDocumentCaptions:(bool)inhibitDocumentCaptions hasSelectionPanel:(bool)hasSelectionPanel hasCamera:(bool)hasCamera recipientName:(NSString *)recipientName; +- (instancetype)initWithContext:(id)context items:(NSArray *)items focusItem:(id)focusItem selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities hasTimer:(bool)hasTimer onlyCrop:(bool)onlyCrop inhibitDocumentCaptions:(bool)inhibitDocumentCaptions hasSelectionPanel:(bool)hasSelectionPanel hasCamera:(bool)hasCamera recipientName:(NSString *)recipientName defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset; @end diff --git a/submodules/LegacyComponents/LegacyComponents/TGMediaPickerGalleryModel.m b/submodules/LegacyComponents/LegacyComponents/TGMediaPickerGalleryModel.m index 445e471e2d..6d8de38086 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGMediaPickerGalleryModel.m +++ b/submodules/LegacyComponents/LegacyComponents/TGMediaPickerGalleryModel.m @@ -38,6 +38,7 @@ bool _inhibitDocumentCaptions; NSString *_recipientName; bool _hasCamera; + TGMediaVideoConversionPreset _defaultVideoPreset; } @property (nonatomic, weak) TGPhotoEditorController *editorController; @@ -46,7 +47,7 @@ @implementation TGMediaPickerGalleryModel -- (instancetype)initWithContext:(id)context items:(NSArray *)items focusItem:(id)focusItem selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities hasTimer:(bool)hasTimer onlyCrop:(bool)onlyCrop inhibitDocumentCaptions:(bool)inhibitDocumentCaptions hasSelectionPanel:(bool)hasSelectionPanel hasCamera:(bool)hasCamera recipientName:(NSString *)recipientName +- (instancetype)initWithContext:(id)context items:(NSArray *)items focusItem:(id)focusItem selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities hasTimer:(bool)hasTimer onlyCrop:(bool)onlyCrop inhibitDocumentCaptions:(bool)inhibitDocumentCaptions hasSelectionPanel:(bool)hasSelectionPanel hasCamera:(bool)hasCamera recipientName:(NSString *)recipientName defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset { self = [super init]; if (self != nil) @@ -66,6 +67,7 @@ _hasSelectionPanel = hasSelectionPanel; _inhibitDocumentCaptions = inhibitDocumentCaptions; _recipientName = recipientName; + _defaultVideoPreset = defaultVideoPreset; _hasCamera = hasCamera; __weak TGMediaPickerGalleryModel *weakSelf = self; @@ -182,7 +184,7 @@ if (_interfaceView == nil) { __weak TGMediaPickerGalleryModel *weakSelf = self; - _interfaceView = [[TGMediaPickerGalleryInterfaceView alloc] initWithContext:_context focusItem:_initialFocusItem selectionContext:_selectionContext editingContext:_editingContext hasSelectionPanel:_hasSelectionPanel hasCameraButton:_hasCamera recipientName:_recipientName]; + _interfaceView = [[TGMediaPickerGalleryInterfaceView alloc] initWithContext:_context focusItem:_initialFocusItem selectionContext:_selectionContext editingContext:_editingContext hasSelectionPanel:_hasSelectionPanel hasCameraButton:_hasCamera recipientName:_recipientName defaultVideoPreset:_defaultVideoPreset]; [_interfaceView setSuggestionContext:_suggestionContext]; _interfaceView.hasCaptions = _hasCaptions; _interfaceView.allowCaptionEntities = _allowCaptionEntities; @@ -385,7 +387,7 @@ self.storeOriginalImageForItem(item.editableMediaItem, screenImage); TGPhotoEditorControllerIntent intent = isVideo ? TGPhotoEditorControllerVideoIntent : TGPhotoEditorControllerGenericIntent; - TGPhotoEditorController *controller = [[TGPhotoEditorController alloc] initWithContext:_context item:item.editableMediaItem intent:intent adjustments:editorValues caption:caption screenImage:screenImage availableTabs:_interfaceView.currentTabs selectedTab:tab]; + TGPhotoEditorController *controller = [[TGPhotoEditorController alloc] initWithContext:_context item:item.editableMediaItem intent:intent adjustments:editorValues caption:caption screenImage:screenImage availableTabs:_interfaceView.currentTabs selectedTab:tab defaultVideoPreset:_defaultVideoPreset]; controller.editingContext = _editingContext; self.editorController = controller; controller.suggestionContext = self.suggestionContext; diff --git a/submodules/LegacyComponents/LegacyComponents/TGMediaPickerModernGalleryMixin.h b/submodules/LegacyComponents/LegacyComponents/TGMediaPickerModernGalleryMixin.h index f35fd05706..cef013441f 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGMediaPickerModernGalleryMixin.h +++ b/submodules/LegacyComponents/LegacyComponents/TGMediaPickerModernGalleryMixin.h @@ -29,9 +29,9 @@ @property (nonatomic, copy) void (^presentScheduleController)(void (^)(int32_t)); -- (instancetype)initWithContext:(id)context item:(id)item fetchResult:(TGMediaAssetFetchResult *)fetchResult parentController:(TGViewController *)parentController thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities hasTimer:(bool)hasTimer onlyCrop:(bool)onlyCrop inhibitDocumentCaptions:(bool)inhibitDocumentCaptions inhibitMute:(bool)inhibitMute asFile:(bool)asFile itemsLimit:(NSUInteger)itemsLimit recipientName:(NSString *)recipientName hasSilentPosting:(bool)hasSilentPosting hasSchedule:(bool)hasSchedule reminder:(bool)reminder; +- (instancetype)initWithContext:(id)context item:(id)item fetchResult:(TGMediaAssetFetchResult *)fetchResult parentController:(TGViewController *)parentController thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities hasTimer:(bool)hasTimer onlyCrop:(bool)onlyCrop inhibitDocumentCaptions:(bool)inhibitDocumentCaptions inhibitMute:(bool)inhibitMute asFile:(bool)asFile itemsLimit:(NSUInteger)itemsLimit recipientName:(NSString *)recipientName defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset hasSilentPosting:(bool)hasSilentPosting hasSchedule:(bool)hasSchedule reminder:(bool)reminder; -- (instancetype)initWithContext:(id)context item:(id)item momentList:(TGMediaAssetMomentList *)momentList parentController:(TGViewController *)parentController thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities hasTimer:(bool)hasTimer onlyCrop:(bool)onlyCrop inhibitDocumentCaptions:(bool)inhibitDocumentCaptions inhibitMute:(bool)inhibitMute asFile:(bool)asFile itemsLimit:(NSUInteger)itemsLimit hasSilentPosting:(bool)hasSilentPosting hasSchedule:(bool)hasSchedule reminder:(bool)reminder; +- (instancetype)initWithContext:(id)context item:(id)item momentList:(TGMediaAssetMomentList *)momentList parentController:(TGViewController *)parentController thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities hasTimer:(bool)hasTimer onlyCrop:(bool)onlyCrop inhibitDocumentCaptions:(bool)inhibitDocumentCaptions inhibitMute:(bool)inhibitMute asFile:(bool)asFile itemsLimit:(NSUInteger)itemsLimit defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset hasSilentPosting:(bool)hasSilentPosting hasSchedule:(bool)hasSchedule reminder:(bool)reminder; - (void)present; - (void)updateWithFetchResult:(TGMediaAssetFetchResult *)fetchResult; diff --git a/submodules/LegacyComponents/LegacyComponents/TGMediaPickerModernGalleryMixin.m b/submodules/LegacyComponents/LegacyComponents/TGMediaPickerModernGalleryMixin.m index 3ba245c3b8..755e57ee21 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGMediaPickerModernGalleryMixin.m +++ b/submodules/LegacyComponents/LegacyComponents/TGMediaPickerModernGalleryMixin.m @@ -41,17 +41,17 @@ @implementation TGMediaPickerModernGalleryMixin -- (instancetype)initWithContext:(id)context item:(id)item fetchResult:(TGMediaAssetFetchResult *)fetchResult parentController:(TGViewController *)parentController thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities hasTimer:(bool)hasTimer onlyCrop:(bool)onlyCrop inhibitDocumentCaptions:(bool)inhibitDocumentCaptions inhibitMute:(bool)inhibitMute asFile:(bool)asFile itemsLimit:(NSUInteger)itemsLimit recipientName:(NSString *)recipientName hasSilentPosting:(bool)hasSilentPosting hasSchedule:(bool)hasSchedule reminder:(bool)reminder +- (instancetype)initWithContext:(id)context item:(id)item fetchResult:(TGMediaAssetFetchResult *)fetchResult parentController:(TGViewController *)parentController thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities hasTimer:(bool)hasTimer onlyCrop:(bool)onlyCrop inhibitDocumentCaptions:(bool)inhibitDocumentCaptions inhibitMute:(bool)inhibitMute asFile:(bool)asFile itemsLimit:(NSUInteger)itemsLimit recipientName:(NSString *)recipientName defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset hasSilentPosting:(bool)hasSilentPosting hasSchedule:(bool)hasSchedule reminder:(bool)reminder { - return [self initWithContext:context item:item fetchResult:fetchResult momentList:nil parentController:parentController thumbnailImage:thumbnailImage selectionContext:selectionContext editingContext:editingContext suggestionContext:suggestionContext hasCaptions:hasCaptions allowCaptionEntities:allowCaptionEntities hasTimer:hasTimer onlyCrop:onlyCrop inhibitDocumentCaptions:inhibitDocumentCaptions inhibitMute:inhibitMute asFile:asFile itemsLimit:itemsLimit recipientName:recipientName hasSilentPosting:hasSilentPosting hasSchedule:hasSchedule reminder:reminder]; + return [self initWithContext:context item:item fetchResult:fetchResult momentList:nil parentController:parentController thumbnailImage:thumbnailImage selectionContext:selectionContext editingContext:editingContext suggestionContext:suggestionContext hasCaptions:hasCaptions allowCaptionEntities:allowCaptionEntities hasTimer:hasTimer onlyCrop:onlyCrop inhibitDocumentCaptions:inhibitDocumentCaptions inhibitMute:inhibitMute asFile:asFile itemsLimit:itemsLimit recipientName:recipientName defaultVideoPreset:defaultVideoPreset hasSilentPosting:hasSilentPosting hasSchedule:hasSchedule reminder:reminder]; } -- (instancetype)initWithContext:(id)context item:(id)item momentList:(TGMediaAssetMomentList *)momentList parentController:(TGViewController *)parentController thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities hasTimer:(bool)hasTimer onlyCrop:(bool)onlyCrop inhibitDocumentCaptions:(bool)inhibitDocumentCaptions inhibitMute:(bool)inhibitMute asFile:(bool)asFile itemsLimit:(NSUInteger)itemsLimit hasSilentPosting:(bool)hasSilentPosting hasSchedule:(bool)hasSchedule reminder:(bool)reminder +- (instancetype)initWithContext:(id)context item:(id)item momentList:(TGMediaAssetMomentList *)momentList parentController:(TGViewController *)parentController thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities hasTimer:(bool)hasTimer onlyCrop:(bool)onlyCrop inhibitDocumentCaptions:(bool)inhibitDocumentCaptions inhibitMute:(bool)inhibitMute asFile:(bool)asFile itemsLimit:(NSUInteger)itemsLimit defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset hasSilentPosting:(bool)hasSilentPosting hasSchedule:(bool)hasSchedule reminder:(bool)reminder { - return [self initWithContext:context item:item fetchResult:nil momentList:momentList parentController:parentController thumbnailImage:thumbnailImage selectionContext:selectionContext editingContext:editingContext suggestionContext:suggestionContext hasCaptions:hasCaptions allowCaptionEntities:allowCaptionEntities hasTimer:hasTimer onlyCrop:onlyCrop inhibitDocumentCaptions:inhibitDocumentCaptions inhibitMute:inhibitMute asFile:asFile itemsLimit:itemsLimit recipientName:nil hasSilentPosting:hasSilentPosting hasSchedule:hasSchedule reminder:reminder]; + return [self initWithContext:context item:item fetchResult:nil momentList:momentList parentController:parentController thumbnailImage:thumbnailImage selectionContext:selectionContext editingContext:editingContext suggestionContext:suggestionContext hasCaptions:hasCaptions allowCaptionEntities:allowCaptionEntities hasTimer:hasTimer onlyCrop:onlyCrop inhibitDocumentCaptions:inhibitDocumentCaptions inhibitMute:inhibitMute asFile:asFile itemsLimit:itemsLimit recipientName:nil defaultVideoPreset:defaultVideoPreset hasSilentPosting:hasSilentPosting hasSchedule:hasSchedule reminder:reminder]; } -- (instancetype)initWithContext:(id)context item:(id)item fetchResult:(TGMediaAssetFetchResult *)fetchResult momentList:(TGMediaAssetMomentList *)momentList parentController:(TGViewController *)parentController thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities hasTimer:(bool)hasTimer onlyCrop:(bool)onlyCrop inhibitDocumentCaptions:(bool)inhibitDocumentCaptions inhibitMute:(bool)inhibitMute asFile:(bool)asFile itemsLimit:(NSUInteger)itemsLimit recipientName:(NSString *)recipientName hasSilentPosting:(bool)hasSilentPosting hasSchedule:(bool)hasSchedule reminder:(bool)reminder +- (instancetype)initWithContext:(id)context item:(id)item fetchResult:(TGMediaAssetFetchResult *)fetchResult momentList:(TGMediaAssetMomentList *)momentList parentController:(TGViewController *)parentController thumbnailImage:(UIImage *)thumbnailImage selectionContext:(TGMediaSelectionContext *)selectionContext editingContext:(TGMediaEditingContext *)editingContext suggestionContext:(TGSuggestionContext *)suggestionContext hasCaptions:(bool)hasCaptions allowCaptionEntities:(bool)allowCaptionEntities hasTimer:(bool)hasTimer onlyCrop:(bool)onlyCrop inhibitDocumentCaptions:(bool)inhibitDocumentCaptions inhibitMute:(bool)inhibitMute asFile:(bool)asFile itemsLimit:(NSUInteger)itemsLimit recipientName:(NSString *)recipientName defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset hasSilentPosting:(bool)hasSilentPosting hasSchedule:(bool)hasSchedule reminder:(bool)reminder { self = [super init]; if (self != nil) @@ -83,7 +83,7 @@ NSArray *galleryItems = fetchResult != nil ? [self prepareGalleryItemsForFetchResult:fetchResult selectionContext:selectionContext editingContext:editingContext asFile:asFile enumerationBlock:enumerationBlock] : [self prepareGalleryItemsForMomentList:momentList selectionContext:selectionContext editingContext:editingContext asFile:asFile enumerationBlock:enumerationBlock]; - TGMediaPickerGalleryModel *model = [[TGMediaPickerGalleryModel alloc] initWithContext:[_windowManager context] items:galleryItems focusItem:focusItem selectionContext:selectionContext editingContext:editingContext hasCaptions:hasCaptions allowCaptionEntities:allowCaptionEntities hasTimer:hasTimer onlyCrop:onlyCrop inhibitDocumentCaptions:inhibitDocumentCaptions hasSelectionPanel:true hasCamera:false recipientName:recipientName]; + TGMediaPickerGalleryModel *model = [[TGMediaPickerGalleryModel alloc] initWithContext:[_windowManager context] items:galleryItems focusItem:focusItem selectionContext:selectionContext editingContext:editingContext hasCaptions:hasCaptions allowCaptionEntities:allowCaptionEntities hasTimer:hasTimer onlyCrop:onlyCrop inhibitDocumentCaptions:inhibitDocumentCaptions hasSelectionPanel:true hasCamera:false recipientName:recipientName defaultVideoPreset:defaultVideoPreset]; _galleryModel = model; model.inhibitMute = inhibitMute; model.controller = modernGallery; diff --git a/submodules/LegacyComponents/LegacyComponents/TGPassportAttachMenu.m b/submodules/LegacyComponents/LegacyComponents/TGPassportAttachMenu.m index fe894de053..cdf22f0e98 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGPassportAttachMenu.m +++ b/submodules/LegacyComponents/LegacyComponents/TGPassportAttachMenu.m @@ -227,7 +227,7 @@ TGMediaAssetsControllerIntent assetsIntent = (intent == TGPassportAttachIntentMultiple) ? TGMediaAssetsControllerPassportMultipleIntent : TGMediaAssetsControllerPassportIntent; [strongParentController presentWithContext:^UIViewController *(id context) { - TGMediaAssetsController *controller = [TGMediaAssetsController controllerWithContext:context assetGroup:group intent:assetsIntent recipientName:nil saveEditedPhotos:false allowGrouping:false selectionLimit:10]; + TGMediaAssetsController *controller = [TGMediaAssetsController controllerWithContext:context assetGroup:group intent:assetsIntent recipientName:nil defaultVideoPreset:TGMediaVideoConversionPresetCompressedDefault saveEditedPhotos:false allowGrouping:false selectionLimit:10]; controller.onlyCrop = true; __weak TGMediaAssetsController *weakController = controller; controller.singleCompletionBlock = ^(id currentItem, TGMediaEditingContext *editingContext) { diff --git a/submodules/LegacyComponents/LegacyComponents/TGPhotoEditorController.h b/submodules/LegacyComponents/LegacyComponents/TGPhotoEditorController.h index ae25ee29ad..6d41e41855 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGPhotoEditorController.h +++ b/submodules/LegacyComponents/LegacyComponents/TGPhotoEditorController.h @@ -51,7 +51,7 @@ typedef enum { @property (nonatomic, assign) bool dontHideStatusBar; @property (nonatomic, strong) PGCameraShotMetadata *metadata; -- (instancetype)initWithContext:(id)context item:(id)item intent:(TGPhotoEditorControllerIntent)intent adjustments:(id)adjustments caption:(NSString *)caption screenImage:(UIImage *)screenImage availableTabs:(TGPhotoEditorTab)availableTabs selectedTab:(TGPhotoEditorTab)selectedTab; +- (instancetype)initWithContext:(id)context item:(id)item intent:(TGPhotoEditorControllerIntent)intent adjustments:(id)adjustments caption:(NSString *)caption screenImage:(UIImage *)screenImage availableTabs:(TGPhotoEditorTab)availableTabs selectedTab:(TGPhotoEditorTab)selectedTab defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset; - (void)dismissEditor; - (void)applyEditor; diff --git a/submodules/LegacyComponents/LegacyComponents/TGPhotoEditorController.m b/submodules/LegacyComponents/LegacyComponents/TGPhotoEditorController.m index 0233810df4..5688ff7883 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGPhotoEditorController.m +++ b/submodules/LegacyComponents/LegacyComponents/TGPhotoEditorController.m @@ -88,6 +88,8 @@ TGMessageImageViewOverlayView *_progressView; id _context; + + TGMediaVideoConversionPreset _defaultVideoPreset; } @property (nonatomic, weak) UIImage *fullSizeImage; @@ -98,7 +100,7 @@ @synthesize actionHandle = _actionHandle; -- (instancetype)initWithContext:(id)context item:(id)item intent:(TGPhotoEditorControllerIntent)intent adjustments:(id)adjustments caption:(NSString *)caption screenImage:(UIImage *)screenImage availableTabs:(TGPhotoEditorTab)availableTabs selectedTab:(TGPhotoEditorTab)selectedTab +- (instancetype)initWithContext:(id)context item:(id)item intent:(TGPhotoEditorControllerIntent)intent adjustments:(id)adjustments caption:(NSString *)caption screenImage:(UIImage *)screenImage availableTabs:(TGPhotoEditorTab)availableTabs selectedTab:(TGPhotoEditorTab)selectedTab defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset { self = [super initWithContext:context]; if (self != nil) @@ -120,6 +122,8 @@ _initialAdjustments = adjustments; _screenImage = screenImage; + _defaultVideoPreset = defaultVideoPreset; + _queue = [[SQueue alloc] init]; _photoEditor = [[PGPhotoEditor alloc] initWithOriginalSize:_item.originalSize adjustments:adjustments forVideo:(intent == TGPhotoEditorControllerVideoIntent) enableStickers:(intent & TGPhotoEditorControllerSignupAvatarIntent) == 0]; if ([self presentedForAvatarCreation]) @@ -1114,7 +1118,7 @@ { _ignoreDefaultPreviewViewTransitionIn = true; - TGPhotoQualityController *qualityController = [[TGPhotoQualityController alloc] initWithContext:_context photoEditor:_photoEditor previewView:_previewView]; + TGPhotoQualityController *qualityController = [[TGPhotoQualityController alloc] initWithContext:_context photoEditor:_photoEditor previewView:_previewView defaultPreset:_defaultVideoPreset]; qualityController.item = _item; qualityController.toolbarLandscapeSize = TGPhotoEditorToolbarSize; qualityController.beginTransitionIn = ^UIView *(CGRect *referenceFrame, UIView **parentView, bool *noTransitionView) diff --git a/submodules/LegacyComponents/LegacyComponents/TGPhotoQualityController.h b/submodules/LegacyComponents/LegacyComponents/TGPhotoQualityController.h index 0a33e72154..c8eb807858 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGPhotoQualityController.h +++ b/submodules/LegacyComponents/LegacyComponents/TGPhotoQualityController.h @@ -10,6 +10,6 @@ @property (nonatomic, readonly) TGMediaVideoConversionPreset preset; -- (instancetype)initWithContext:(id)context photoEditor:(PGPhotoEditor *)photoEditor previewView:(TGPhotoEditorPreviewView *)previewView; +- (instancetype)initWithContext:(id)context photoEditor:(PGPhotoEditor *)photoEditor previewView:(TGPhotoEditorPreviewView *)previewView defaultPreset:(TGMediaVideoConversionPreset)defaultPreset; @end diff --git a/submodules/LegacyComponents/LegacyComponents/TGPhotoQualityController.m b/submodules/LegacyComponents/LegacyComponents/TGPhotoQualityController.m index 5df162adfc..03cab474bf 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGPhotoQualityController.m +++ b/submodules/LegacyComponents/LegacyComponents/TGPhotoQualityController.m @@ -69,7 +69,7 @@ const NSTimeInterval TGPhotoQualityPreviewDuration = 15.0f; @implementation TGPhotoQualityController -- (instancetype)initWithContext:(id)context photoEditor:(PGPhotoEditor *)photoEditor previewView:(TGPhotoEditorPreviewView *)previewView +- (instancetype)initWithContext:(id)context photoEditor:(PGPhotoEditor *)photoEditor previewView:(TGPhotoEditorPreviewView *)previewView defaultPreset:(TGMediaVideoConversionPreset)defaultPreset { self = [super initWithContext:context]; if (self != nil) @@ -89,11 +89,7 @@ const NSTimeInterval TGPhotoQualityPreviewDuration = 15.0f; } else { - NSNumber *presetValue = [[NSUserDefaults standardUserDefaults] objectForKey:@"TG_preferredVideoPreset_v0"]; - if (presetValue != nil) - value = [presetValue integerValue]; - else - value = TGMediaVideoConversionPresetCompressedMedium; + value = defaultPreset; } _disposable = [[SMetaDisposable alloc] init]; diff --git a/submodules/LegacyComponents/LegacyComponents/TGPhotoVideoEditor.h b/submodules/LegacyComponents/LegacyComponents/TGPhotoVideoEditor.h index ff8cfd650c..2be5281b6b 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGPhotoVideoEditor.h +++ b/submodules/LegacyComponents/LegacyComponents/TGPhotoVideoEditor.h @@ -2,6 +2,6 @@ @interface TGPhotoVideoEditor : NSObject -+ (void)presentWithContext:(id)context controller:(TGViewController *)controller caption:(NSString *)caption entities:(NSArray *)entities withItem:(id)item recipientName:(NSString *)recipientName completion:(void (^)(id, TGMediaEditingContext *))completion; ++ (void)presentWithContext:(id)context controller:(TGViewController *)controller caption:(NSString *)caption entities:(NSArray *)entities withItem:(id)item recipientName:(NSString *)recipientName defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset completion:(void (^)(id, TGMediaEditingContext *))completion; @end diff --git a/submodules/LegacyComponents/LegacyComponents/TGPhotoVideoEditor.m b/submodules/LegacyComponents/LegacyComponents/TGPhotoVideoEditor.m index ee6a2bc03d..6ca62fab90 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGPhotoVideoEditor.m +++ b/submodules/LegacyComponents/LegacyComponents/TGPhotoVideoEditor.m @@ -10,7 +10,7 @@ @implementation TGPhotoVideoEditor -+ (void)presentWithContext:(id)context controller:(TGViewController *)controller caption:(NSString *)caption entities:(NSArray *)entities withItem:(id)item recipientName:(NSString *)recipientName completion:(void (^)(id, TGMediaEditingContext *))completion ++ (void)presentWithContext:(id)context controller:(TGViewController *)controller caption:(NSString *)caption entities:(NSArray *)entities withItem:(id)item recipientName:(NSString *)recipientName defaultVideoPreset:(TGMediaVideoConversionPreset)defaultVideoPreset completion:(void (^)(id, TGMediaEditingContext *))completion { id windowManager = [context makeOverlayWindowManager]; id windowContext = [windowManager context]; @@ -29,7 +29,7 @@ galleryItem = [[TGMediaPickerGalleryPhotoItem alloc] initWithAsset:item]; galleryItem.editingContext = editingContext; - TGMediaPickerGalleryModel *model = [[TGMediaPickerGalleryModel alloc] initWithContext:windowContext items:@[galleryItem] focusItem:galleryItem selectionContext:nil editingContext:editingContext hasCaptions:true allowCaptionEntities:true hasTimer:false onlyCrop:false inhibitDocumentCaptions:false hasSelectionPanel:false hasCamera:false recipientName:recipientName]; + TGMediaPickerGalleryModel *model = [[TGMediaPickerGalleryModel alloc] initWithContext:windowContext items:@[galleryItem] focusItem:galleryItem selectionContext:nil editingContext:editingContext hasCaptions:true allowCaptionEntities:true hasTimer:false onlyCrop:false inhibitDocumentCaptions:false hasSelectionPanel:false hasCamera:false recipientName:recipientName defaultVideoPreset:defaultVideoPreset]; model.controller = galleryController; //model.suggestionContext = self.suggestionContext; diff --git a/submodules/LegacyMediaPickerUI/Sources/LegacyAttachmentMenu.swift b/submodules/LegacyMediaPickerUI/Sources/LegacyAttachmentMenu.swift index 1f8f946163..6b9f656964 100644 --- a/submodules/LegacyMediaPickerUI/Sources/LegacyAttachmentMenu.swift +++ b/submodules/LegacyMediaPickerUI/Sources/LegacyAttachmentMenu.swift @@ -11,6 +11,47 @@ import DeviceAccess import AccountContext import LegacyUI +public func defaultVideoPresetForContext(_ context: AccountContext) -> TGMediaVideoConversionPreset { + var networkType: NetworkType = .wifi + let _ = (context.account.networkType + |> take(1)).start(next: { value in + networkType = value + }) + + let autodownloadSettings = context.sharedContext.currentAutodownloadSettings.with { $0 } + let presetSettings: AutodownloadPresetSettings + switch networkType { + case .wifi: + presetSettings = autodownloadSettings.highPreset + default: + presetSettings = autodownloadSettings.mediumPreset + } + + let effectiveValue: Int + if presetSettings.videoUploadMaxbitrate == 0 { + effectiveValue = 0 + } else { + effectiveValue = Int(presetSettings.videoUploadMaxbitrate) * 5 / 100 + } + + switch effectiveValue { + case 0: + return TGMediaVideoConversionPresetCompressedMedium + case 1: + return TGMediaVideoConversionPresetCompressedVeryLow + case 2: + return TGMediaVideoConversionPresetCompressedLow + case 3: + return TGMediaVideoConversionPresetCompressedMedium + case 4: + return TGMediaVideoConversionPresetCompressedHigh + case 5: + return TGMediaVideoConversionPresetCompressedVeryLow + default: + return TGMediaVideoConversionPresetCompressedMedium + } +} + public struct LegacyAttachmentMenuMediaEditing: OptionSet { public var rawValue: Int32 @@ -62,6 +103,7 @@ public func legacyAttachmentMenu(context: AccountContext, peer: Peer, editMediaO carouselItemView = carouselItem carouselItem.suggestionContext = legacySuggestionContext(context: context, peerId: peer.id) carouselItem.recipientName = peer.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder) + carouselItem.defaultVideoPreset = defaultVideoPresetForContext(context) carouselItem.cameraPressed = { [weak controller] cameraView in if let controller = controller { DeviceAccess.authorizeAccess(to: .camera, presentationData: context.sharedContext.currentPresentationData.with { $0 }, present: context.sharedContext.presentGlobalController, openSettings: context.sharedContext.applicationBindings.openSettings, { value in @@ -218,7 +260,7 @@ public func presentLegacyPasteMenu(context: AccountContext, peer: Peer, saveEdit legacyController.enableSizeClassSignal = true - let controller = TGClipboardMenu.present(inParentController: emptyController, context: legacyController.context, images: images, hasCaption: true, hasTimer: hasTimer, recipientName: recipientName, completed: { selectionContext, editingContext, currentItem in + let controller = TGClipboardMenu.present(inParentController: emptyController, context: legacyController.context, images: images, hasCaption: true, hasTimer: hasTimer, recipientName: recipientName, defaultVideoPreset: defaultVideoPresetForContext(context), completed: { selectionContext, editingContext, currentItem in let signals = TGClipboardMenu.resultSignals(for: selectionContext, editingContext: editingContext, currentItem: currentItem, descriptionGenerator: legacyAssetPickerItemGenerator()) sendMessagesWithSignals(signals) }, dismissed: { [weak legacyController] in diff --git a/submodules/LegacyMediaPickerUI/Sources/LegacyMediaPickers.swift b/submodules/LegacyMediaPickerUI/Sources/LegacyMediaPickers.swift index 137dda19cb..3d9560ee8a 100644 --- a/submodules/LegacyMediaPickerUI/Sources/LegacyMediaPickers.swift +++ b/submodules/LegacyMediaPickerUI/Sources/LegacyMediaPickers.swift @@ -56,6 +56,7 @@ public func legacyAssetPicker(context: AccountContext, presentationData: Present return Signal { subscriber in let intent = fileMode ? TGMediaAssetsControllerSendFileIntent : TGMediaAssetsControllerSendMediaIntent + let defaultVideoPreset = defaultVideoPresetForContext(context) DeviceAccess.authorizeAccess(to: .mediaLibrary(.send), presentationData: presentationData, present: context.sharedContext.presentGlobalController, openSettings: context.sharedContext.applicationBindings.openSettings, { value in if !value { @@ -70,7 +71,7 @@ public func legacyAssetPicker(context: AccountContext, presentationData: Present } else { Queue.mainQueue().async { subscriber.putNext({ context in - let controller = TGMediaAssetsController(context: context, assetGroup: group, intent: intent, recipientName: peer?.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder), saveEditedPhotos: !isSecretChat && saveEditedPhotos, allowGrouping: allowGrouping, inhibitSelection: editingMedia, selectionLimit: Int32(selectionLimit)) + let controller = TGMediaAssetsController(context: context, assetGroup: group, intent: intent, recipientName: peer?.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder), defaultVideoPreset: defaultVideoPreset, saveEditedPhotos: !isSecretChat && saveEditedPhotos, allowGrouping: allowGrouping, inhibitSelection: editingMedia, selectionLimit: Int32(selectionLimit)) return controller! }) subscriber.putCompletion() @@ -79,7 +80,7 @@ public func legacyAssetPicker(context: AccountContext, presentationData: Present }) } else { subscriber.putNext({ context in - let controller = TGMediaAssetsController(context: context, assetGroup: nil, intent: intent, recipientName: peer?.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder), saveEditedPhotos: !isSecretChat && saveEditedPhotos, allowGrouping: allowGrouping, selectionLimit: Int32(selectionLimit)) + let controller = TGMediaAssetsController(context: context, assetGroup: nil, intent: intent, recipientName: peer?.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder), defaultVideoPreset: defaultVideoPreset, saveEditedPhotos: !isSecretChat && saveEditedPhotos, allowGrouping: allowGrouping, selectionLimit: Int32(selectionLimit)) return controller! }) subscriber.putCompletion() diff --git a/submodules/LegacyMediaPickerUI/Sources/LegacyWallpaperPicker.swift b/submodules/LegacyMediaPickerUI/Sources/LegacyWallpaperPicker.swift index 05968635c7..54d110d7f2 100644 --- a/submodules/LegacyMediaPickerUI/Sources/LegacyWallpaperPicker.swift +++ b/submodules/LegacyMediaPickerUI/Sources/LegacyWallpaperPicker.swift @@ -24,7 +24,7 @@ public func legacyWallpaperPicker(context: AccountContext, presentationData: Pre } else { Queue.mainQueue().async { subscriber.putNext({ context in - let controller = TGMediaAssetsController(context: context, assetGroup: group, intent: intent, recipientName: nil, saveEditedPhotos: false, allowGrouping: false, selectionLimit: 1) + let controller = TGMediaAssetsController(context: context, assetGroup: group, intent: intent, recipientName: nil, defaultVideoPreset: TGMediaVideoConversionPresetCompressedDefault, saveEditedPhotos: false, allowGrouping: false, selectionLimit: 1) return controller! }) subscriber.putCompletion() @@ -33,7 +33,7 @@ public func legacyWallpaperPicker(context: AccountContext, presentationData: Pre }) } else { subscriber.putNext({ context in - let controller = TGMediaAssetsController(context: context, assetGroup: nil, intent: intent, recipientName: nil, saveEditedPhotos: false, allowGrouping: false, selectionLimit: 1) + let controller = TGMediaAssetsController(context: context, assetGroup: nil, intent: intent, recipientName: nil, defaultVideoPreset: TGMediaVideoConversionPresetCompressedDefault, saveEditedPhotos: false, allowGrouping: false, selectionLimit: 1) return controller! }) subscriber.putCompletion() diff --git a/submodules/PassportUI/Sources/SecureIdDocumentFormControllerNode.swift b/submodules/PassportUI/Sources/SecureIdDocumentFormControllerNode.swift index e8782a86e6..e0f44699b3 100644 --- a/submodules/PassportUI/Sources/SecureIdDocumentFormControllerNode.swift +++ b/submodules/PassportUI/Sources/SecureIdDocumentFormControllerNode.swift @@ -3037,7 +3037,7 @@ final class SecureIdDocumentFormControllerNode: FormControllerNode (UIView?, UIView?)), addToTransitionSurface: (UIView) -> Void) { + override func animateIn(from node: (ASDisplayNode, CGRect, () -> (UIView?, UIView?)), addToTransitionSurface: (UIView) -> Void) { var transformedFrame = node.0.view.convert(node.0.view.bounds, to: self.imageNode.view) let transformedSuperFrame = node.0.view.convert(node.0.view.bounds, to: self.imageNode.view.superview) let transformedSelfFrame = node.0.view.convert(node.0.view.bounds, to: self.view) let transformedCopyViewFinalFrame = self.imageNode.view.convert(self.imageNode.view.bounds, to: self.view) - let copyView = node.1().0! + let copyView = node.2().0! self.view.insertSubview(copyView, belowSubview: self.scrollNode.view) copyView.frame = transformedSelfFrame @@ -157,7 +157,7 @@ final class SecureIdDocumentGalleryItemNode: ZoomableContentGalleryItemNode { self.imageNode.layer.animateBounds(from: transformedFrame, to: self.imageNode.layer.bounds, duration: 0.25, timingFunction: kCAMediaTimingFunctionSpring) } - override func animateOut(to node: (ASDisplayNode, () -> (UIView?, UIView?)), addToTransitionSurface: (UIView) -> Void, completion: @escaping () -> Void) { + override func animateOut(to node: (ASDisplayNode, CGRect, () -> (UIView?, UIView?)), addToTransitionSurface: (UIView) -> Void, completion: @escaping () -> Void) { var transformedFrame = node.0.view.convert(node.0.view.bounds, to: self.imageNode.view) let transformedSuperFrame = node.0.view.convert(node.0.view.bounds, to: self.imageNode.view.superview) let transformedSelfFrame = node.0.view.convert(node.0.view.bounds, to: self.view) @@ -167,7 +167,7 @@ final class SecureIdDocumentGalleryItemNode: ZoomableContentGalleryItemNode { var boundsCompleted = false var copyCompleted = false - let copyView = node.1().0! + let copyView = node.2().0! self.view.insertSubview(copyView, belowSubview: self.scrollNode.view) copyView.frame = transformedSelfFrame diff --git a/submodules/PeerAvatarGalleryUI/Sources/PeerAvatarImageGalleryItem.swift b/submodules/PeerAvatarGalleryUI/Sources/PeerAvatarImageGalleryItem.swift index d8510f4029..4789f0c18f 100644 --- a/submodules/PeerAvatarGalleryUI/Sources/PeerAvatarImageGalleryItem.swift +++ b/submodules/PeerAvatarGalleryUI/Sources/PeerAvatarImageGalleryItem.swift @@ -229,13 +229,13 @@ final class PeerAvatarImageGalleryItemNode: ZoomableContentGalleryItemNode { } } - override func animateIn(from node: (ASDisplayNode, () -> (UIView?, UIView?)), addToTransitionSurface: (UIView) -> Void) { + override func animateIn(from node: (ASDisplayNode, CGRect, () -> (UIView?, UIView?)), addToTransitionSurface: (UIView) -> Void) { var transformedFrame = node.0.view.convert(node.0.view.bounds, to: self.imageNode.view) let transformedSuperFrame = node.0.view.convert(node.0.view.bounds, to: self.imageNode.view.superview) let transformedSelfFrame = node.0.view.convert(node.0.view.bounds, to: self.view) let transformedCopyViewFinalFrame = self.imageNode.view.convert(self.imageNode.view.bounds, to: self.view) - let copyView = node.1().0! + let copyView = node.2().0! self.view.insertSubview(copyView, belowSubview: self.scrollNode.view) copyView.frame = transformedSelfFrame @@ -269,7 +269,7 @@ final class PeerAvatarImageGalleryItemNode: ZoomableContentGalleryItemNode { self.statusNodeContainer.layer.animateScale(from: 0.5, to: 1.0, duration: 0.25, timingFunction: kCAMediaTimingFunctionSpring) } - override func animateOut(to node: (ASDisplayNode, () -> (UIView?, UIView?)), addToTransitionSurface: (UIView) -> Void, completion: @escaping () -> Void) { + override func animateOut(to node: (ASDisplayNode, CGRect, () -> (UIView?, UIView?)), addToTransitionSurface: (UIView) -> Void, completion: @escaping () -> Void) { var transformedFrame = node.0.view.convert(node.0.view.bounds, to: self.imageNode.view) let transformedSuperFrame = node.0.view.convert(node.0.view.bounds, to: self.imageNode.view.superview) let transformedSelfFrame = node.0.view.convert(node.0.view.bounds, to: self.view) @@ -279,7 +279,7 @@ final class PeerAvatarImageGalleryItemNode: ZoomableContentGalleryItemNode { var boundsCompleted = false var copyCompleted = false - let copyView = node.1().0! + let copyView = node.2().0! self.view.insertSubview(copyView, belowSubview: self.scrollNode.view) copyView.frame = transformedSelfFrame diff --git a/submodules/PeerInfoUI/Sources/ChannelAdminController.swift b/submodules/PeerInfoUI/Sources/ChannelAdminController.swift index f1d61a9f7a..91ad93de86 100644 --- a/submodules/PeerInfoUI/Sources/ChannelAdminController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelAdminController.swift @@ -1063,12 +1063,17 @@ public func channelAdminController(context: AccountContext, peerId: PeerId, admi return current.withUpdatedUpdating(true) } updateRightsDisposable.set((context.peerChannelMemberCategoriesContextsManager.updateMemberAdminRights(account: context.account, peerId: peerId, memberId: adminId, adminRights: TelegramChatAdminRights(flags: updateFlags), rank: updateRank) |> deliverOnMainQueue).start(error: { error in - if case let .addMemberError(error) = error, case .restricted = error, let admin = adminView.peers[adminView.peerId] { - var text = presentationData.strings.Privacy_GroupsAndChannels_InviteToChannelError(admin.compactDisplayTitle, admin.compactDisplayTitle).0 - if case .group = channel.info { - text = presentationData.strings.Privacy_GroupsAndChannels_InviteToGroupError(admin.compactDisplayTitle, admin.compactDisplayTitle).0 + if case let .addMemberError(error) = error, let admin = adminView.peers[adminView.peerId] { + if case .restricted = error { + var text = presentationData.strings.Privacy_GroupsAndChannels_InviteToChannelError(admin.compactDisplayTitle, admin.compactDisplayTitle).0 + if case .group = channel.info { + text = presentationData.strings.Privacy_GroupsAndChannels_InviteToGroupError(admin.compactDisplayTitle, admin.compactDisplayTitle).0 + } + presentControllerImpl?(textAlertController(context: context, title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})]), nil) + } else if case .tooMuchJoined = error { + let text = presentationData.strings.Invite_ChannelsTooMuch + 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) } dismissImpl?() }, completed: { diff --git a/submodules/PeerInfoUI/Sources/ChannelInfoController.swift b/submodules/PeerInfoUI/Sources/ChannelInfoController.swift index 1400cd4437..a227e4aefc 100644 --- a/submodules/PeerInfoUI/Sources/ChannelInfoController.swift +++ b/submodules/PeerInfoUI/Sources/ChannelInfoController.swift @@ -1124,7 +1124,7 @@ public func channelInfoController(context: AccountContext, peerId: PeerId) -> Vi } avatarGalleryTransitionArguments = { [weak controller] entry in if let controller = controller { - var result: ((ASDisplayNode, () -> (UIView?, UIView?)), CGRect)? + var result: ((ASDisplayNode, CGRect, () -> (UIView?, UIView?)), CGRect)? controller.forEachItemNode { itemNode in if let itemNode = itemNode as? ItemListAvatarAndNameInfoItemNode { result = itemNode.avatarTransitionNode() diff --git a/submodules/PeerInfoUI/Sources/GroupInfoController.swift b/submodules/PeerInfoUI/Sources/GroupInfoController.swift index d667e09bbf..f99bfe27ec 100644 --- a/submodules/PeerInfoUI/Sources/GroupInfoController.swift +++ b/submodules/PeerInfoUI/Sources/GroupInfoController.swift @@ -1755,6 +1755,26 @@ public func groupInfoController(context: AccountContext, peerId originalPeerId: presentControllerImpl?(textAlertController(context: context, title: nil, text: presentationData.strings.Privacy_GroupsAndChannels_InviteToGroupError(peer.compactDisplayTitle, peer.compactDisplayTitle).0, actions: [TextAlertAction(type: .genericAction, title: presentationData.strings.Common_OK, action: {})]), nil) }) + updateState { state in + var temporaryParticipants = state.temporaryParticipants + for i in 0 ..< temporaryParticipants.count { + if temporaryParticipants[i].peer.id == memberId { + temporaryParticipants.remove(at: i) + break + } + } + var successfullyAddedParticipantIds = state.successfullyAddedParticipantIds + successfullyAddedParticipantIds.remove(memberId) + + return state.withUpdatedTemporaryParticipants(temporaryParticipants).withUpdatedSuccessfullyAddedParticipantIds(successfullyAddedParticipantIds) + } + return .complete() + case .tooManyChannels: + let _ = (context.account.postbox.loadedPeerWithId(memberId) + |> deliverOnMainQueue).start(next: { peer in + presentControllerImpl?(textAlertController(context: context, title: nil, text: presentationData.strings.Invite_ChannelsTooMuch, actions: [TextAlertAction(type: .genericAction, title: presentationData.strings.Common_OK, action: {})]), nil) + }) + updateState { state in var temporaryParticipants = state.temporaryParticipants for i in 0 ..< temporaryParticipants.count { @@ -2467,7 +2487,7 @@ public func groupInfoController(context: AccountContext, peerId originalPeerId: avatarGalleryTransitionArguments = { [weak controller] entry in if let controller = controller { - var result: ((ASDisplayNode, () -> (UIView?, UIView?)), CGRect)? + var result: ((ASDisplayNode, CGRect, () -> (UIView?, UIView?)), CGRect)? controller.forEachItemNode { itemNode in if let itemNode = itemNode as? ItemListAvatarAndNameInfoItemNode { result = itemNode.avatarTransitionNode() diff --git a/submodules/PeerInfoUI/Sources/GroupStickerPackSetupController.swift b/submodules/PeerInfoUI/Sources/GroupStickerPackSetupController.swift index 1f4b4d5abe..de91e5b228 100644 --- a/submodules/PeerInfoUI/Sources/GroupStickerPackSetupController.swift +++ b/submodules/PeerInfoUI/Sources/GroupStickerPackSetupController.swift @@ -490,7 +490,8 @@ public func groupStickerPackSetupController(context: AccountContext, peerId: Pee } presentStickerPackController = { [weak controller] info in dismissInputImpl?() - presentControllerImpl?(StickerPackScreen(context: context, stickerPacks: [.id(id: info.id.id, accessHash: info.accessHash)], parentNavigationController: controller?.navigationController as? NavigationController), nil) + let packReference: StickerPackReference = .id(id: info.id.id, accessHash: info.accessHash) + presentControllerImpl?(StickerPackScreen(context: context, mainStickerPack: packReference, stickerPacks: [packReference], parentNavigationController: controller?.navigationController as? NavigationController), nil) } navigateToChatControllerImpl = { [weak controller] peerId in if let controller = controller, let navigationController = controller.navigationController as? NavigationController { diff --git a/submodules/PeerInfoUI/Sources/UserInfoController.swift b/submodules/PeerInfoUI/Sources/UserInfoController.swift index 09956b3a07..296b609297 100644 --- a/submodules/PeerInfoUI/Sources/UserInfoController.swift +++ b/submodules/PeerInfoUI/Sources/UserInfoController.swift @@ -1463,7 +1463,7 @@ public func userInfoController(context: AccountContext, peerId: PeerId, mode: Pe } avatarGalleryTransitionArguments = { [weak controller] entry in if let controller = controller { - var result: ((ASDisplayNode, () -> (UIView?, UIView?)), CGRect)? + var result: ((ASDisplayNode, CGRect, () -> (UIView?, UIView?)), CGRect)? controller.forEachItemNode { itemNode in if let itemNode = itemNode as? ItemListAvatarAndNameInfoItemNode { result = itemNode.avatarTransitionNode() diff --git a/submodules/Postbox/Sources/MessageHistoryTable.swift b/submodules/Postbox/Sources/MessageHistoryTable.swift index 5dc3bea560..feac0da947 100644 --- a/submodules/Postbox/Sources/MessageHistoryTable.swift +++ b/submodules/Postbox/Sources/MessageHistoryTable.swift @@ -1380,7 +1380,7 @@ final class MessageHistoryTable: Table { } } - self.valueBox.remove(self.table, key: self.key(index), secure: false) + self.valueBox.remove(self.table, key: self.key(index), secure: true) let updatedIndex = message.index diff --git a/submodules/Postbox/Sources/MessageHistoryTextIndexTable.swift b/submodules/Postbox/Sources/MessageHistoryTextIndexTable.swift index ca8efff04c..710a4caf36 100644 --- a/submodules/Postbox/Sources/MessageHistoryTextIndexTable.swift +++ b/submodules/Postbox/Sources/MessageHistoryTextIndexTable.swift @@ -66,7 +66,7 @@ final class MessageHistoryTextIndexTable { } func remove(messageId: MessageId) { - self.valueBox.fullTextRemove(self.table, itemId: itemId(messageId)) + self.valueBox.fullTextRemove(self.table, itemId: itemId(messageId), secure: true) } func search(peerId: PeerId?, text: String, tags: MessageTags?) -> [MessageId] { diff --git a/submodules/Postbox/Sources/SqliteValueBox.swift b/submodules/Postbox/Sources/SqliteValueBox.swift index 3c9777f952..dcaa340bb2 100644 --- a/submodules/Postbox/Sources/SqliteValueBox.swift +++ b/submodules/Postbox/Sources/SqliteValueBox.swift @@ -1764,8 +1764,14 @@ public final class SqliteValueBox: ValueBox { statement.reset() } - public func fullTextRemove(_ table: ValueBoxFullTextTable, itemId: String) { + public func fullTextRemove(_ table: ValueBoxFullTextTable, itemId: String, secure: Bool) { if let _ = self.fullTextTables[table.id] { + if secure != self.secureDeleteEnabled { + self.secureDeleteEnabled = secure + let result = database.execute("PRAGMA secure_delete=\(secure ? 1 : 0)") + precondition(result) + } + guard let itemIdData = itemId.data(using: .utf8) else { return } diff --git a/submodules/Postbox/Sources/ValueBox.swift b/submodules/Postbox/Sources/ValueBox.swift index 5e1d8eefab..00297c3708 100644 --- a/submodules/Postbox/Sources/ValueBox.swift +++ b/submodules/Postbox/Sources/ValueBox.swift @@ -82,7 +82,7 @@ public protocol ValueBox { func removeRange(_ table: ValueBoxTable, start: ValueBoxKey, end: ValueBoxKey) func fullTextSet(_ table: ValueBoxFullTextTable, collectionId: String, itemId: String, contents: String, tags: String) func fullTextMatch(_ table: ValueBoxFullTextTable, collectionId: String?, query: String, tags: String?, values: (String, String) -> Bool) - func fullTextRemove(_ table: ValueBoxFullTextTable, itemId: String) + func fullTextRemove(_ table: ValueBoxFullTextTable, itemId: String, secure: Bool) func removeAllFromTable(_ table: ValueBoxTable) func removeTable(_ table: ValueBoxTable) func renameTable(_ table: ValueBoxTable, to toTable: ValueBoxTable) diff --git a/submodules/SettingsUI/Sources/Data and Storage/AutodownloadMediaCategoryController.swift b/submodules/SettingsUI/Sources/Data and Storage/AutodownloadMediaCategoryController.swift index 3591b7c92b..222efd9093 100644 --- a/submodules/SettingsUI/Sources/Data and Storage/AutodownloadMediaCategoryController.swift +++ b/submodules/SettingsUI/Sources/Data and Storage/AutodownloadMediaCategoryController.swift @@ -447,7 +447,7 @@ func autodownloadMediaCategoryController(context: AccountContext, connectionType case .wifi: preset = .high } - let settings = AutodownloadPresetSettings(disabled: false, photoSizeMax: categories.photo.sizeLimit, videoSizeMax: categories.video.sizeLimit, fileSizeMax: categories.file.sizeLimit, preloadLargeVideo: categories.video.predownload, lessDataForPhoneCalls: false) + let settings = AutodownloadPresetSettings(disabled: false, photoSizeMax: categories.photo.sizeLimit, videoSizeMax: categories.video.sizeLimit, fileSizeMax: categories.file.sizeLimit, preloadLargeVideo: categories.video.predownload, lessDataForPhoneCalls: false, videoUploadMaxbitrate: 0) return saveAutodownloadSettings(account: context.account, preset: preset, settings: settings) } return .complete() diff --git a/submodules/SettingsUI/Sources/EditSettingsController.swift b/submodules/SettingsUI/Sources/EditSettingsController.swift index 074c7619a4..38a0100565 100644 --- a/submodules/SettingsUI/Sources/EditSettingsController.swift +++ b/submodules/SettingsUI/Sources/EditSettingsController.swift @@ -458,7 +458,7 @@ func editSettingsController(context: AccountContext, currentName: ItemListAvatar } avatarGalleryTransitionArguments = { [weak controller] entry in if let controller = controller { - var result: ((ASDisplayNode, () -> (UIView?, UIView?)), CGRect)? + var result: ((ASDisplayNode, CGRect, () -> (UIView?, UIView?)), CGRect)? controller.forEachItemNode { itemNode in if let itemNode = itemNode as? ItemListAvatarAndNameInfoItemNode { result = itemNode.avatarTransitionNode() diff --git a/submodules/SettingsUI/Sources/Search/SettingsSearchableItems.swift b/submodules/SettingsUI/Sources/Search/SettingsSearchableItems.swift index 81ad75a0ad..57c1ad9d21 100644 --- a/submodules/SettingsUI/Sources/Search/SettingsSearchableItems.swift +++ b/submodules/SettingsUI/Sources/Search/SettingsSearchableItems.swift @@ -527,7 +527,7 @@ private func privacySearchableItems(context: AccountContext, privacySettings: Ac }), SettingsSearchableItem(id: .privacy(7), title: passcodeTitle, alternate: passcodeAlternate, icon: icon, breadcrumbs: [strings.Settings_PrivacySettings], present: { context, _, present in let _ = passcodeOptionsAccessController(context: context, pushController: { c in - + present(.push, c) }, completion: { animated in let controller = passcodeOptionsController(context: context) if animated { @@ -537,7 +537,7 @@ private func privacySearchableItems(context: AccountContext, privacySettings: Ac } }).start(next: { controller in if let controller = controller { - present(.modal, controller) + present(.push, controller) } }) }), diff --git a/submodules/SettingsUI/Sources/SettingsController.swift b/submodules/SettingsUI/Sources/SettingsController.swift index 25a1a6613c..3730316c72 100644 --- a/submodules/SettingsUI/Sources/SettingsController.swift +++ b/submodules/SettingsUI/Sources/SettingsController.swift @@ -1547,7 +1547,7 @@ public func settingsController(context: AccountContext, accountManager: AccountM } avatarGalleryTransitionArguments = { [weak controller] entry in if let controller = controller { - var result: ((ASDisplayNode, () -> (UIView?, UIView?)), CGRect)? + var result: ((ASDisplayNode, CGRect, () -> (UIView?, UIView?)), CGRect)? controller.forEachItemNode { itemNode in if let itemNode = itemNode as? ItemListAvatarAndNameInfoItemNode { result = itemNode.avatarTransitionNode() diff --git a/submodules/SettingsUI/Sources/Stickers/ArchivedStickerPacksController.swift b/submodules/SettingsUI/Sources/Stickers/ArchivedStickerPacksController.swift index 225021adf7..80a9eea859 100644 --- a/submodules/SettingsUI/Sources/Stickers/ArchivedStickerPacksController.swift +++ b/submodules/SettingsUI/Sources/Stickers/ArchivedStickerPacksController.swift @@ -430,7 +430,8 @@ public func archivedStickerPacksController(context: AccountContext, mode: Archiv } presentStickerPackController = { [weak controller] info in - presentControllerImpl?(StickerPackScreen(context: context, stickerPacks: [.id(id: info.id.id, accessHash: info.accessHash)], parentNavigationController: controller?.navigationController as? NavigationController), nil) + let packReference: StickerPackReference = .id(id: info.id.id, accessHash: info.accessHash) + presentControllerImpl?(StickerPackScreen(context: context, mainStickerPack: packReference, stickerPacks: [packReference], parentNavigationController: controller?.navigationController as? NavigationController), nil) } return controller diff --git a/submodules/SettingsUI/Sources/Stickers/FeaturedStickerPacksController.swift b/submodules/SettingsUI/Sources/Stickers/FeaturedStickerPacksController.swift index 9a13cc3f0c..68743f7b34 100644 --- a/submodules/SettingsUI/Sources/Stickers/FeaturedStickerPacksController.swift +++ b/submodules/SettingsUI/Sources/Stickers/FeaturedStickerPacksController.swift @@ -264,7 +264,8 @@ public func featuredStickerPacksController(context: AccountContext) -> ViewContr } presentStickerPackController = { [weak controller] info in - presentControllerImpl?(StickerPackScreen(context: context, stickerPacks: [.id(id: info.id.id, accessHash: info.accessHash)], parentNavigationController: controller?.navigationController as? NavigationController), nil) + let packReference: StickerPackReference = .id(id: info.id.id, accessHash: info.accessHash) + presentControllerImpl?(StickerPackScreen(context: context, mainStickerPack: packReference, stickerPacks: [packReference], parentNavigationController: controller?.navigationController as? NavigationController), nil) } return controller diff --git a/submodules/SettingsUI/Sources/Stickers/InstalledStickerPacksController.swift b/submodules/SettingsUI/Sources/Stickers/InstalledStickerPacksController.swift index 12cd2245c8..933537b4cd 100644 --- a/submodules/SettingsUI/Sources/Stickers/InstalledStickerPacksController.swift +++ b/submodules/SettingsUI/Sources/Stickers/InstalledStickerPacksController.swift @@ -783,22 +783,25 @@ public func installedStickerPacksController(context: AccountContext, mode: Insta guard let stickerPacksView = view.views[.itemCollectionInfos(namespaces: [namespaceForMode(mode)])] as? ItemCollectionInfosView, let entries = stickerPacksView.entriesByNamespace[namespaceForMode(mode)] else { return } + var mainStickerPack: StickerPackReference? var packs: [StickerPackReference] = [] - var selectedIndex: Int = 0 - var foundSelected = false for entry in entries { if let listInfo = entry.info as? StickerPackCollectionInfo { + let packReference: StickerPackReference = .id(id: listInfo.id.id, accessHash: listInfo.accessHash) if listInfo.id == info.id { - foundSelected = true - selectedIndex = packs.count + mainStickerPack = packReference } - packs.append(.id(id: listInfo.id.id, accessHash: listInfo.accessHash)) + packs.append(packReference) } } - if !foundSelected { - packs.insert(.id(id: info.id.id, accessHash: info.accessHash), at: 0) + if mainStickerPack == nil { + let packReference: StickerPackReference = .id(id: info.id.id, accessHash: info.accessHash) + mainStickerPack = packReference + packs.insert(packReference, at: 0) + } + if let mainStickerPack = mainStickerPack { + presentControllerImpl?(StickerPackScreen(context: context, mainStickerPack: mainStickerPack, stickerPacks: packs, parentNavigationController: controller?.navigationController as? NavigationController), nil) } - presentControllerImpl?(StickerPackScreen(context: context, stickerPacks: packs, selectedStickerPackIndex: selectedIndex, parentNavigationController: controller?.navigationController as? NavigationController), nil) }) } pushControllerImpl = { [weak controller] c in diff --git a/submodules/StickerPackPreviewUI/Sources/StickerPackPreviewController.swift b/submodules/StickerPackPreviewUI/Sources/StickerPackPreviewController.swift index be7a8e945b..f2c7181e6a 100644 --- a/submodules/StickerPackPreviewUI/Sources/StickerPackPreviewController.swift +++ b/submodules/StickerPackPreviewUI/Sources/StickerPackPreviewController.swift @@ -26,11 +26,6 @@ public final class StickerPackPreviewController: ViewController, StandalonePrese private var animatedIn = false private var dismissed = false - private let _ready = Promise() - override public var ready: Promise { - return self._ready - } - private let context: AccountContext private let mode: StickerPackPreviewControllerMode private weak var parentNavigationController: NavigationController? @@ -79,15 +74,7 @@ public final class StickerPackPreviewController: ViewController, StandalonePrese self.statusBar.statusBarStyle = .Ignore - #if false && DEBUG - self.stickerPackContents.set(.single(.fetching) - |> then( - loadedStickerPack(postbox: context.account.postbox, network: context.account.network, reference: stickerPack, forceActualized: true) - |> delay(1.0, queue: .mainQueue()) - )) - #else self.stickerPackContents.set(loadedStickerPack(postbox: context.account.postbox, network: context.account.network, reference: stickerPack, forceActualized: true)) - #endif self.presentationDataDisposable = (context.sharedContext.presentationData |> deliverOnMainQueue).start(next: { [weak self] presentationData in @@ -122,7 +109,7 @@ public final class StickerPackPreviewController: ViewController, StandalonePrese } } } - self.displayNode = StickerPackPreviewControllerNode(controller: self, context: self.context, openShare: openShareImpl, openMention: { [weak self] mention in + self.displayNode = StickerPackPreviewControllerNode(context: self.context, openShare: openShareImpl, openMention: { [weak self] mention in guard let strongSelf = self else { return } diff --git a/submodules/StickerPackPreviewUI/Sources/StickerPackPreviewControllerNode.swift b/submodules/StickerPackPreviewUI/Sources/StickerPackPreviewControllerNode.swift index 1411cb7806..12a2bb9989 100644 --- a/submodules/StickerPackPreviewUI/Sources/StickerPackPreviewControllerNode.swift +++ b/submodules/StickerPackPreviewUI/Sources/StickerPackPreviewControllerNode.swift @@ -45,7 +45,6 @@ private struct StickerPackPreviewGridTransaction { } final class StickerPackPreviewControllerNode: ViewControllerTracingNode, UIScrollViewDelegate { - private weak var controller: StickerPackPreviewController? private let context: AccountContext private let openShare: (() -> Void)? private var presentationData: PresentationData @@ -60,11 +59,10 @@ final class StickerPackPreviewControllerNode: ViewControllerTracingNode, UIScrol private let contentContainerNode: ASDisplayNode private let contentBackgroundNode: ASImageNode private let contentGridNode: GridNode - private let actionsSeparatorNode: ASDisplayNode - private let actionsBackgroundNode: ASDisplayNode - private let installActionButtonNode: HighlightTrackingButtonNode - private var installActionButtonIsRemove = false - private let shareActionButtonNode: HighlightTrackingButtonNode + private let installActionButtonNode: ASButtonNode + private let installActionSeparatorNode: ASDisplayNode + private let shareActionButtonNode: ASButtonNode + private let shareActionSeparatorNode: ASDisplayNode private let contentTitleNode: ImmediateTextNode private let contentSeparatorNode: ASDisplayNode @@ -89,8 +87,7 @@ final class StickerPackPreviewControllerNode: ViewControllerTracingNode, UIScrol private var hapticFeedback: HapticFeedback? - init(controller: StickerPackPreviewController, context: AccountContext, openShare: (() -> Void)?, openMention: @escaping (String) -> Void) { - self.controller = controller + init(context: AccountContext, openShare: (() -> Void)?, openMention: @escaping (String) -> Void) { self.context = context self.openShare = openShare self.presentationData = context.sharedContext.currentPresentationData.with { $0 } @@ -131,9 +128,13 @@ final class StickerPackPreviewControllerNode: ViewControllerTracingNode, UIScrol self.contentSeparatorNode = ASDisplayNode() self.contentSeparatorNode.isLayerBacked = true - self.actionsSeparatorNode = ASDisplayNode() - self.actionsSeparatorNode.isLayerBacked = true - self.actionsBackgroundNode = ASDisplayNode() + self.installActionSeparatorNode = ASDisplayNode() + self.installActionSeparatorNode.isLayerBacked = true + self.installActionSeparatorNode.displaysAsynchronously = false + + self.shareActionSeparatorNode = ASDisplayNode() + self.shareActionSeparatorNode.isLayerBacked = true + self.shareActionSeparatorNode.displaysAsynchronously = false super.init() @@ -148,49 +149,25 @@ final class StickerPackPreviewControllerNode: ViewControllerTracingNode, UIScrol self.wrappingScrollNode.view.delegate = self self.addSubnode(self.wrappingScrollNode) + self.wrappingScrollNode.addSubnode(self.cancelButtonNode) + self.cancelButtonNode.addTarget(self, action: #selector(self.cancelButtonPressed), forControlEvents: .touchUpInside) + self.installActionButtonNode.addTarget(self, action: #selector(self.installActionButtonPressed), forControlEvents: .touchUpInside) - self.installActionButtonNode.highligthedChanged = { [weak self] highlighted in - if let strongSelf = self { - if highlighted { - strongSelf.installActionButtonNode.layer.removeAnimation(forKey: "opacity") - strongSelf.installActionButtonNode.alpha = 0.8 - } else { - strongSelf.installActionButtonNode.alpha = 1.0 - strongSelf.installActionButtonNode.layer.animateAlpha(from: 0.8, to: 1.0, duration: 0.3) - } - } - } - self.shareActionButtonNode.addTarget(self, action: #selector(self.sharePressed), forControlEvents: .touchUpInside) - self.shareActionButtonNode.highligthedChanged = { [weak self] highlighted in - if let strongSelf = self { - if highlighted { - strongSelf.shareActionButtonNode.layer.removeAnimation(forKey: "opacity") - strongSelf.shareActionButtonNode.alpha = 0.8 - } else { - strongSelf.shareActionButtonNode.alpha = 1.0 - strongSelf.shareActionButtonNode.layer.animateAlpha(from: 0.8, to: 1.0, duration: 0.3) - } - } - } - self.wrappingScrollNode.clipsToBounds = false self.wrappingScrollNode.addSubnode(self.contentBackgroundNode) self.wrappingScrollNode.addSubnode(self.contentContainerNode) self.contentContainerNode.addSubnode(self.contentGridNode) - - self.wrappingScrollNode.addSubnode(self.actionsBackgroundNode) - self.wrappingScrollNode.addSubnode(self.actionsSeparatorNode) - self.wrappingScrollNode.addSubnode(self.installActionButtonNode) - self.wrappingScrollNode.addSubnode(self.shareActionButtonNode) - + self.contentContainerNode.addSubnode(self.installActionSeparatorNode) + self.contentContainerNode.addSubnode(self.installActionButtonNode) + if openShare != nil { + self.contentContainerNode.addSubnode(self.shareActionSeparatorNode) + self.contentContainerNode.addSubnode(self.shareActionButtonNode) + } self.wrappingScrollNode.addSubnode(self.contentTitleNode) self.wrappingScrollNode.addSubnode(self.contentSeparatorNode) - self.wrappingScrollNode.addSubnode(self.cancelButtonNode) - self.cancelButtonNode.addTarget(self, action: #selector(self.cancelButtonPressed), forControlEvents: .touchUpInside) - self.contentGridNode.presentationLayoutUpdated = { [weak self] presentationLayout, transition in self?.gridPresentationLayoutUpdated(presentationLayout, transition: transition) } @@ -286,28 +263,53 @@ final class StickerPackPreviewControllerNode: ViewControllerTracingNode, UIScrol context.clear(CGRect(origin: CGPoint(), size: size)) context.setFillColor(theme.actionSheet.opaqueItemBackgroundColor.cgColor) context.fill(CGRect(origin: CGPoint(), size: CGSize(width: size.width, height: size.height))) - })?.stretchableImage(withLeftCapWidth: 1, topCapHeight: 1) + })?.stretchableImage(withLeftCapWidth: 16, topCapHeight: 1) - let roundedBackground = generateStretchableFilledCircleImage(radius: 10.0, color: presentationData.theme.actionSheet.opaqueItemBackgroundColor) + let highlightedSolidBackground = generateImage(CGSize(width: 1.0, height: 1.0), rotatedContext: { size, context in + context.clear(CGRect(origin: CGPoint(), size: size)) + context.setFillColor(theme.actionSheet.opaqueItemHighlightedBackgroundColor.cgColor) + context.fill(CGRect(origin: CGPoint(), size: CGSize(width: size.width, height: size.height))) + })?.stretchableImage(withLeftCapWidth: 16, topCapHeight: 1) + + let halfRoundedBackground = generateImage(CGSize(width: 32.0, height: 32.0), rotatedContext: { size, context in + context.clear(CGRect(origin: CGPoint(), size: size)) + context.setFillColor(theme.actionSheet.opaqueItemBackgroundColor.cgColor) + context.fillEllipse(in: CGRect(origin: CGPoint(), size: CGSize(width: size.width, height: size.height))) + context.fill(CGRect(origin: CGPoint(), size: CGSize(width: size.width, height: size.height / 2.0))) + })?.stretchableImage(withLeftCapWidth: 16, topCapHeight: 1) + + let highlightedHalfRoundedBackground = generateImage(CGSize(width: 32.0, height: 32.0), rotatedContext: { size, context in + context.clear(CGRect(origin: CGPoint(), size: size)) + context.setFillColor(theme.actionSheet.opaqueItemHighlightedBackgroundColor.cgColor) + context.fillEllipse(in: CGRect(origin: CGPoint(), size: CGSize(width: size.width, height: size.height))) + context.fill(CGRect(origin: CGPoint(), size: CGSize(width: size.width, height: size.height / 2.0))) + })?.stretchableImage(withLeftCapWidth: 16, topCapHeight: 1) + + let roundedBackground = generateStretchableFilledCircleImage(radius: 16.0, color: presentationData.theme.actionSheet.opaqueItemBackgroundColor) + let highlightedRoundedBackground = generateStretchableFilledCircleImage(radius: 16.0, color: presentationData.theme.actionSheet.opaqueItemHighlightedBackgroundColor) self.contentBackgroundNode.image = roundedBackground - if !self.installActionButtonIsRemove { - let roundedAccentBackground = generateImage(CGSize(width: 50.0, height: 50.0), rotatedContext: { size, context in - context.clear(CGRect(origin: CGPoint(), size: size)) - context.setFillColor(self.presentationData.theme.list.itemCheckColors.fillColor.cgColor) - context.fillEllipse(in: CGRect(origin: CGPoint(), size: CGSize(width: size.width, height: size.height))) - })?.stretchableImage(withLeftCapWidth: 25, topCapHeight: 25) - self.installActionButtonNode.setBackgroundImage(roundedAccentBackground, for: []) + self.cancelButtonNode.setBackgroundImage(roundedBackground, for: .normal) + self.cancelButtonNode.setBackgroundImage(highlightedRoundedBackground, for: .highlighted) + + if self.shareActionButtonNode.supernode != nil { + self.installActionButtonNode.setBackgroundImage(solidBackground, for: .normal) + self.installActionButtonNode.setBackgroundImage(highlightedSolidBackground, for: .highlighted) + } else { + self.installActionButtonNode.setBackgroundImage(halfRoundedBackground, for: .normal) + self.installActionButtonNode.setBackgroundImage(highlightedHalfRoundedBackground, for: .highlighted) } - self.shareActionButtonNode.setTitle(presentationData.strings.Conversation_ContextMenuShare.uppercased(), with: Font.semibold(17.0), with: presentationData.theme.actionSheet.controlAccentColor, for: .normal) + self.shareActionButtonNode.setBackgroundImage(halfRoundedBackground, for: .normal) + self.shareActionButtonNode.setBackgroundImage(highlightedHalfRoundedBackground, for: .highlighted) + self.shareActionButtonNode.setTitle(presentationData.strings.Conversation_ContextMenuShare, with: Font.regular(20.0), with: presentationData.theme.actionSheet.controlAccentColor, for: .normal) self.contentSeparatorNode.backgroundColor = presentationData.theme.actionSheet.opaqueItemSeparatorColor - self.actionsSeparatorNode.backgroundColor = presentationData.theme.actionSheet.opaqueItemSeparatorColor - self.actionsBackgroundNode.backgroundColor = presentationData.theme.actionSheet.opaqueItemBackgroundColor + self.installActionSeparatorNode.backgroundColor = presentationData.theme.actionSheet.opaqueItemSeparatorColor + self.shareActionSeparatorNode.backgroundColor = presentationData.theme.actionSheet.opaqueItemSeparatorColor - self.cancelButtonNode.setTitle(presentationData.strings.Common_Cancel.uppercased(), with: Font.semibold(17.0), with: presentationData.theme.actionSheet.standardActionTextColor, for: .normal) + self.cancelButtonNode.setTitle(presentationData.strings.Common_Cancel, with: Font.medium(20.0), with: presentationData.theme.actionSheet.standardActionTextColor, for: .normal) self.contentTitleNode.linkHighlightColor = presentationData.theme.actionSheet.controlAccentColor.withAlphaComponent(0.5) @@ -322,7 +324,7 @@ final class StickerPackPreviewControllerNode: ViewControllerTracingNode, UIScrol transition.updateFrame(node: self.wrappingScrollNode, frame: CGRect(origin: CGPoint(), size: layout.size)) var insets = layout.insets(options: [.statusBar]) - insets.top = 10.0 + insets.top + insets.top = max(10.0, insets.top) let cleanInsets = layout.insets(options: [.statusBar]) let hasShareButton = self.shareActionButtonNode.supernode != nil @@ -330,30 +332,23 @@ final class StickerPackPreviewControllerNode: ViewControllerTracingNode, UIScrol var bottomInset: CGFloat = 10.0 + cleanInsets.bottom if insets.bottom > 0 { - bottomInset -= 0.0 + bottomInset -= 12.0 } - let buttonHeight: CGFloat = 50.0 - let actionAreaTopInset: CGFloat = 15.0 - let buttonSpacing: CGFloat = 10.0 + let buttonHeight: CGFloat = 57.0 let sectionSpacing: CGFloat = 8.0 - let titleAreaHeight: CGFloat = 54.0 + let titleAreaHeight: CGFloat = 51.0 - let width = horizontalContainerFillingSizeForLayout(layout: layout, sideInset: 0.0) + let width = horizontalContainerFillingSizeForLayout(layout: layout, sideInset: 10.0 + layout.safeInsets.left) - let sideInset: CGFloat = 0.0 + let sideInset = floor((layout.size.width - width) / 2.0) - //transition.updateFrame(node: self.cancelButtonNode, frame: CGRect(origin: CGPoint(x: sideInset, y: layout.size.height - bottomInset - buttonHeight), size: CGSize(width: width, height: buttonHeight))) + transition.updateFrame(node: self.cancelButtonNode, frame: CGRect(origin: CGPoint(x: sideInset, y: layout.size.height - bottomInset - buttonHeight), size: CGSize(width: width, height: buttonHeight))) - var actionAreaHeight = bottomInset + buttonHeight + actionAreaTopInset - - transition.updateFrame(node: self.actionsBackgroundNode, frame: CGRect(origin: CGPoint(x: 0.0, y: layout.size.height - actionAreaHeight), size: CGSize(width: layout.size.width, height: actionAreaHeight))) - transition.updateFrame(node: self.actionsSeparatorNode, frame: CGRect(origin: CGPoint(x: 0.0, y: layout.size.height - actionAreaHeight), size: CGSize(width: layout.size.width, height: UIScreenPixel))) - - let maximumContentHeight = layout.size.height - insets.top + let maximumContentHeight = layout.size.height - insets.top - bottomInset - buttonHeight - sectionSpacing let contentContainerFrame = CGRect(origin: CGPoint(x: sideInset, y: insets.top), size: CGSize(width: width, height: maximumContentHeight)) - let contentFrame = contentContainerFrame.insetBy(dx: 0.0, dy: 0.0) + let contentFrame = contentContainerFrame.insetBy(dx: 12.0, dy: 0.0) var transaction: StickerPackPreviewGridTransaction? @@ -384,7 +379,7 @@ final class StickerPackPreviewControllerNode: ViewControllerTracingNode, UIScrol if self.currentItems.isEmpty && !updatedItems.isEmpty { let entities = generateTextEntities(info.title, enabledTypes: [.mention]) - let font = Font.semibold(17.0) + let font = Font.medium(20.0) self.contentTitleNode.attributedText = stringWithAppliedEntities(info.title, entities: entities, baseColor: self.presentationData.theme.actionSheet.primaryTextColor, linkColor: self.presentationData.theme.actionSheet.controlAccentColor, baseFont: font, linkFont: font, boldFont: font, italicFont: font, boldItalicFont: font, fixedFont: font, blockQuoteFont: font) animateIn = true } @@ -394,7 +389,7 @@ final class StickerPackPreviewControllerNode: ViewControllerTracingNode, UIScrol } let titleSize = self.contentTitleNode.updateLayout(CGSize(width: contentContainerFrame.size.width - 24.0, height: CGFloat.greatestFiniteMagnitude)) - let titleFrame = CGRect(origin: CGPoint(x: contentContainerFrame.minX + floor((contentContainerFrame.size.width - titleSize.width) / 2.0), y: self.contentBackgroundNode.frame.minY + floor((titleAreaHeight - titleSize.height) / 2.0)), size: titleSize) + let titleFrame = CGRect(origin: CGPoint(x: contentContainerFrame.minX + floor((contentContainerFrame.size.width - titleSize.width) / 2.0), y: self.contentBackgroundNode.frame.minY + 15.0), size: titleSize) let deltaTitlePosition = CGPoint(x: titleFrame.midX - self.contentTitleNode.frame.midX, y: titleFrame.midY - self.contentTitleNode.frame.midY) self.contentTitleNode.frame = titleFrame transition.animatePosition(node: self.contentTitleNode, from: CGPoint(x: titleFrame.midX + deltaTitlePosition.x, y: titleFrame.midY + deltaTitlePosition.y)) @@ -406,40 +401,38 @@ final class StickerPackPreviewControllerNode: ViewControllerTracingNode, UIScrol let itemWidth = floor(contentFrame.size.width / CGFloat(itemsPerRow)) let rowCount = itemCount / itemsPerRow + (itemCount % itemsPerRow != 0 ? 1 : 0) - let minimallyRevealedRowCount: CGFloat = 4.5 + let minimallyRevealedRowCount: CGFloat = 3.5 let initiallyRevealedRowCount = min(minimallyRevealedRowCount, CGFloat(rowCount)) - let topInset = max(0.0, contentFrame.size.height - initiallyRevealedRowCount * itemWidth - titleAreaHeight - actionAreaHeight) + let topInset = max(0.0, contentFrame.size.height - initiallyRevealedRowCount * itemWidth - titleAreaHeight - buttonHeight) + let bottomGridInset = hasShareButton ? buttonHeight * 2.0 : buttonHeight transition.updateFrame(node: self.contentContainerNode, frame: contentContainerFrame) if let activityIndicator = self.activityIndicator { let indicatorSize = activityIndicator.calculateSizeThatFits(layout.size) - transition.updateFrame(node: activityIndicator, frame: CGRect(origin: CGPoint(x: contentFrame.minX + floor((contentFrame.width - indicatorSize.width) / 2.0), y: contentFrame.maxY - indicatorSize.height - 54.0), size: indicatorSize)) + transition.updateFrame(node: activityIndicator, frame: CGRect(origin: CGPoint(x: contentFrame.minX + floor((contentFrame.width - indicatorSize.width) / 2.0), y: contentFrame.maxY - indicatorSize.height - 30.0), size: indicatorSize)) } - var actionsOffset: CGFloat = layout.size.height - bottomInset - transition.updateFrame(node: self.installActionButtonNode, frame: CGRect(origin: CGPoint(x: 16.0, y: actionsOffset - buttonHeight), size: CGSize(width: contentContainerFrame.size.width - 16.0 * 2.0, height: buttonHeight))) - actionsOffset -= buttonHeight + let installButtonOffset = hasShareButton ? buttonHeight * 2.0 : buttonHeight + transition.updateFrame(node: self.installActionButtonNode, frame: CGRect(origin: CGPoint(x: 0.0, y: contentContainerFrame.size.height - installButtonOffset), size: CGSize(width: contentContainerFrame.size.width, height: buttonHeight))) + transition.updateFrame(node: self.installActionSeparatorNode, frame: CGRect(origin: CGPoint(x: 0.0, y: contentContainerFrame.size.height - installButtonOffset - UIScreenPixel), size: CGSize(width: contentContainerFrame.size.width, height: UIScreenPixel))) - //transition.updateFrame(node: self.installActionSeparatorNode, frame: CGRect(origin: CGPoint(x: 0.0, y: contentContainerFrame.size.height - installButtonOffset - UIScreenPixel - bottomAreaHeight), size: CGSize(width: contentContainerFrame.size.width, height: UIScreenPixel))) + transition.updateFrame(node: self.shareActionButtonNode, frame: CGRect(origin: CGPoint(x: 0.0, y: contentContainerFrame.size.height - buttonHeight), size: CGSize(width: contentContainerFrame.size.width, height: buttonHeight))) + transition.updateFrame(node: self.shareActionSeparatorNode, frame: CGRect(origin: CGPoint(x: 0.0, y: contentContainerFrame.size.height - buttonHeight - UIScreenPixel), size: CGSize(width: contentContainerFrame.size.width, height: UIScreenPixel))) - //transition.updateFrame(node: self.shareActionButtonNode, frame: CGRect(origin: CGPoint(x: 0.0, y: contentContainerFrame.size.height - buttonHeight - bottomAreaHeight), size: CGSize(width: contentContainerFrame.size.width, height: buttonHeight))) + let gridSize = CGSize(width: contentFrame.size.width, height: max(32.0, contentFrame.size.height - titleAreaHeight)) - //transition.updateFrame(node: self.shareActionSeparatorNode, frame: CGRect(origin: CGPoint(x: 0.0, y: contentContainerFrame.size.height - buttonHeight - UIScreenPixel - bottomAreaHeight), size: CGSize(width: contentContainerFrame.size.width, height: UIScreenPixel))) - - let gridSize = CGSize(width: contentFrame.size.width, height: max(32.0, contentFrame.size.height - titleAreaHeight - actionAreaHeight)) - - self.contentGridNode.transaction(GridNodeTransaction(deleteItems: transaction?.deletions ?? [], insertItems: transaction?.insertions ?? [], updateItems: transaction?.updates ?? [], scrollToItem: nil, updateLayout: GridNodeUpdateLayout(layout: GridNodeLayout(size: gridSize, insets: UIEdgeInsets(top: topInset, left: 0.0, bottom: 0.0, right: 0.0), preloadSize: 80.0, type: .fixed(itemSize: CGSize(width: itemWidth, height: itemWidth), fillWidth: nil, lineSpacing: 0.0, itemSpacing: nil)), transition: transition), itemTransition: .immediate, stationaryItems: .none, updateFirstIndexInSectionOffset: nil), completion: { _ in }) + self.contentGridNode.transaction(GridNodeTransaction(deleteItems: transaction?.deletions ?? [], insertItems: transaction?.insertions ?? [], updateItems: transaction?.updates ?? [], scrollToItem: nil, updateLayout: GridNodeUpdateLayout(layout: GridNodeLayout(size: gridSize, insets: UIEdgeInsets(top: topInset, left: 0.0, bottom: bottomGridInset, right: 0.0), preloadSize: 80.0, type: .fixed(itemSize: CGSize(width: itemWidth, height: itemWidth), fillWidth: nil, lineSpacing: 0.0, itemSpacing: nil)), transition: transition), itemTransition: .immediate, stationaryItems: .none, updateFirstIndexInSectionOffset: nil), completion: { _ in }) transition.updateFrame(node: self.contentGridNode, frame: CGRect(origin: CGPoint(x: floor((contentContainerFrame.size.width - contentFrame.size.width) / 2.0), y: titleAreaHeight), size: gridSize)) if animateIn { self.contentGridNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2) - self.installActionButtonNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2) - self.shareActionButtonNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2) - self.actionsSeparatorNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2) - self.actionsBackgroundNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2) + self.installActionButtonNode.titleNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2) + self.installActionSeparatorNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2) + self.shareActionButtonNode.titleNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2) + self.shareActionSeparatorNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2) } if let _ = self.stickerPack, self.stickerPackUpdated { @@ -450,30 +443,26 @@ final class StickerPackPreviewControllerNode: ViewControllerTracingNode, UIScrol private func gridPresentationLayoutUpdated(_ presentationLayout: GridNodeCurrentPresentationLayout, transition: ContainedViewLayoutTransition) { if let (layout, _) = self.containerLayout { var insets = layout.insets(options: [.statusBar]) - insets.top = 10.0 + insets.top + insets.top = max(10.0, insets.top) let cleanInsets = layout.insets(options: [.statusBar]) var bottomInset: CGFloat = 10.0 + cleanInsets.bottom if insets.bottom > 0 { - bottomInset -= 0.0 + bottomInset -= 12.0 } - let buttonHeight: CGFloat = 50.0 - let actionAreaTopInset: CGFloat = 15.0 - let buttonSpacing: CGFloat = 10.0 + let buttonHeight: CGFloat = 57.0 let sectionSpacing: CGFloat = 8.0 - let titleAreaHeight: CGFloat = 54.0 + let titleAreaHeight: CGFloat = 51.0 - let width = horizontalContainerFillingSizeForLayout(layout: layout, sideInset: 0.0) + let width = horizontalContainerFillingSizeForLayout(layout: layout, sideInset: 10.0 + layout.safeInsets.left) - let sideInset: CGFloat = 0.0 + let sideInset = floor((layout.size.width - width) / 2.0) - var actionAreaHeight = bottomInset + buttonHeight + actionAreaTopInset - - let maximumContentHeight = layout.size.height - insets.top + let maximumContentHeight = layout.size.height - insets.top - bottomInset - buttonHeight - sectionSpacing let contentFrame = CGRect(origin: CGPoint(x: sideInset, y: insets.top), size: CGSize(width: width, height: maximumContentHeight)) - var backgroundFrame = CGRect(origin: CGPoint(x: contentFrame.minX, y: contentFrame.minY - presentationLayout.contentOffset.y), size: CGSize(width: contentFrame.size.width, height: contentFrame.size.height + 500.0)) + var backgroundFrame = CGRect(origin: CGPoint(x: contentFrame.minX, y: contentFrame.minY - presentationLayout.contentOffset.y), size: contentFrame.size) if backgroundFrame.minY < contentFrame.minY { backgroundFrame.origin.y = contentFrame.minY } @@ -489,29 +478,23 @@ final class StickerPackPreviewControllerNode: ViewControllerTracingNode, UIScrol compactFrame = false } if compactFrame { - backgroundFrame = CGRect(origin: CGPoint(x: contentFrame.minX, y: contentFrame.maxY - buttonHeight - 64.0), size: CGSize(width: contentFrame.size.width, height: buttonHeight + 64.0)) + backgroundFrame = CGRect(origin: CGPoint(x: contentFrame.minX, y: contentFrame.maxY - buttonHeight - 32.0), size: CGSize(width: contentFrame.size.width, height: buttonHeight + 32.0)) } let backgroundDeltaY = backgroundFrame.minY - self.contentBackgroundNode.frame.minY transition.updateFrame(node: self.contentBackgroundNode, frame: backgroundFrame) transition.animatePositionAdditive(node: self.contentGridNode, offset: CGPoint(x: 0.0, y: -backgroundDeltaY)) let titleSize = self.contentTitleNode.bounds.size - let titleFrame = CGRect(origin: CGPoint(x: contentFrame.minX + floor((contentFrame.size.width - titleSize.width) / 2.0), y: backgroundFrame.minY + floor((titleAreaHeight - titleSize.height) / 2.0)), size: titleSize) + let titleFrame = CGRect(origin: CGPoint(x: contentFrame.minX + floor((contentFrame.size.width - titleSize.width) / 2.0), y: backgroundFrame.minY + 15.0), size: titleSize) transition.updateFrame(node: self.contentTitleNode, frame: titleFrame) transition.updateFrame(node: self.contentSeparatorNode, frame: CGRect(origin: CGPoint(x: contentFrame.minX, y: backgroundFrame.minY + titleAreaHeight), size: CGSize(width: contentFrame.size.width, height: UIScreenPixel))) - var modalStyleOverlayTransitionFactor: CGFloat = 0.0 - if !compactFrame && presentationLayout.contentOffset.y >= 0.0 { + if !compactFrame && CGFloat(0.0).isLessThanOrEqualTo(presentationLayout.contentOffset.y) { self.contentSeparatorNode.alpha = 1.0 } else { self.contentSeparatorNode.alpha = 0.0 } - let activationDistance: CGFloat = 100.0 - let offsetFactor = (activationDistance - min(max(0.0, -presentationLayout.contentOffset.y), activationDistance)) / activationDistance - - self.controller?.updateModalStyleOverlayTransitionFactor(offsetFactor, transition: transition) - //self.controller?.updateModalStyleOverlayTransitionFactor(offsetFactor.isZero ? 0.0 : 1.0, transition: .animated(duration: 0.4, curve: .spring)) } } @@ -528,7 +511,7 @@ final class StickerPackPreviewControllerNode: ViewControllerTracingNode, UIScrol @objc func installActionButtonPressed() { let dismissOnAction: Bool if let initiallyInstalled = self.stickerPackInitiallyInstalled, initiallyInstalled { - dismissOnAction = true + dismissOnAction = false } else { dismissOnAction = true } @@ -598,22 +581,19 @@ final class StickerPackPreviewControllerNode: ViewControllerTracingNode, UIScrol if let _ = self.containerLayout { self.dequeueUpdateStickerPack() } - switch stickerPack { case .none, .fetching: - self.actionsSeparatorNode.alpha = 0.0 + self.installActionSeparatorNode.alpha = 0.0 + self.shareActionSeparatorNode.alpha = 0.0 self.shareActionButtonNode.alpha = 0.0 - self.actionsBackgroundNode.alpha = 0.0 self.installActionButtonNode.alpha = 0.0 - self.installActionButtonNode.setTitle("", with: Font.semibold(17.0), with: self.presentationData.theme.list.itemCheckColors.foregroundColor, for: .normal) - self.installActionButtonIsRemove = true - self.installActionButtonNode.setBackgroundImage(nil, for: []) + self.installActionButtonNode.setTitle("", with: Font.medium(20.0), with: self.presentationData.theme.actionSheet.standardActionTextColor, for: .normal) case let .result(info, _, installed): if self.stickerPackInitiallyInstalled == nil { self.stickerPackInitiallyInstalled = installed } - self.actionsSeparatorNode.alpha = 1.0 - self.actionsBackgroundNode.alpha = 1.0 + self.installActionSeparatorNode.alpha = 1.0 + self.shareActionSeparatorNode.alpha = 1.0 self.shareActionButtonNode.alpha = 1.0 self.installActionButtonNode.alpha = 1.0 if installed { @@ -623,9 +603,7 @@ final class StickerPackPreviewControllerNode: ViewControllerTracingNode, UIScrol } else { text = self.presentationData.strings.StickerPack_RemoveMaskCount(info.count) } - self.installActionButtonNode.setTitle(text.uppercased(), with: Font.semibold(17.0), with: self.presentationData.theme.list.itemDestructiveColor, for: .normal) - self.installActionButtonIsRemove = true - self.installActionButtonNode.setBackgroundImage(nil, for: []) + self.installActionButtonNode.setTitle(text, with: Font.regular(20.0), with: self.presentationData.theme.actionSheet.destructiveActionTextColor, for: .normal) } else { let text: String if info.id.namespace == Namespaces.ItemCollection.CloudStickerPacks { @@ -633,14 +611,7 @@ final class StickerPackPreviewControllerNode: ViewControllerTracingNode, UIScrol } else { text = self.presentationData.strings.StickerPack_AddMaskCount(info.count) } - self.installActionButtonNode.setTitle(text.uppercased(), with: Font.semibold(17.0), with: self.presentationData.theme.list.itemCheckColors.foregroundColor, for: .normal) - self.installActionButtonIsRemove = false - let roundedAccentBackground = generateImage(CGSize(width: 50.0, height: 50.0), rotatedContext: { size, context in - context.clear(CGRect(origin: CGPoint(), size: size)) - context.setFillColor(self.presentationData.theme.list.itemCheckColors.fillColor.cgColor) - context.fillEllipse(in: CGRect(origin: CGPoint(), size: CGSize(width: size.width, height: size.height))) - })?.stretchableImage(withLeftCapWidth: 25, topCapHeight: 25) - self.installActionButtonNode.setBackgroundImage(roundedAccentBackground, for: []) + self.installActionButtonNode.setTitle(text, with: Font.regular(20.0), with: self.presentationData.theme.actionSheet.controlAccentColor, for: .normal) } } } @@ -676,32 +647,7 @@ final class StickerPackPreviewControllerNode: ViewControllerTracingNode, UIScrol return self.dimNode.view } } - - let result = super.hitTest(point, with: event) - - var currentParent: UIView? = result - var enableScrolling = true - while true { - if currentParent == nil { - break - } - if let scrollView = currentParent as? UIScrollView { - if scrollView === self.wrappingScrollNode.view { - break - } - if scrollView.disablesInteractiveModalDismiss { - enableScrolling = false - break - } else { - if scrollView.isDecelerating && scrollView.contentOffset.y < -scrollView.contentInset.top { - return self.wrappingScrollNode.view - } - } - } - currentParent = currentParent?.superview - } - - return result + return super.hitTest(point, with: event) } func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) { diff --git a/submodules/StickerPackPreviewUI/Sources/StickerPackScreen.swift b/submodules/StickerPackPreviewUI/Sources/StickerPackScreen.swift index f4d921ec1b..0ee8479c3b 100644 --- a/submodules/StickerPackPreviewUI/Sources/StickerPackScreen.swift +++ b/submodules/StickerPackPreviewUI/Sources/StickerPackScreen.swift @@ -764,7 +764,7 @@ private final class StickerPackScreenNode: ViewControllerTracingNode { } } -public final class StickerPackScreen: ViewController { +public final class StickerPackScreenImpl: ViewController { private let context: AccountContext private let stickerPacks: [StickerPackReference] private let initialSelectedStickerPackIndex: Int @@ -841,3 +841,9 @@ public final class StickerPackScreen: ViewController { self.controllerNode.containerLayoutUpdated(layout, transition: transition) } } + +public func StickerPackScreen(context: AccountContext, mainStickerPack: StickerPackReference, stickerPacks: [StickerPackReference], parentNavigationController: NavigationController? = nil, sendSticker: ((FileMediaReference, ASDisplayNode, CGRect) -> Bool)? = nil) -> ViewController { + let controller = StickerPackPreviewController(context: context, stickerPack: mainStickerPack, mode: .default, parentNavigationController: parentNavigationController) + controller.sendSticker = sendSticker + return controller +} diff --git a/submodules/SyncCore/Sources/AutodownloadSettings.swift b/submodules/SyncCore/Sources/AutodownloadSettings.swift index 3724217966..a8f2af62e2 100644 --- a/submodules/SyncCore/Sources/AutodownloadSettings.swift +++ b/submodules/SyncCore/Sources/AutodownloadSettings.swift @@ -13,14 +13,16 @@ public struct AutodownloadPresetSettings: PostboxCoding, Equatable { public let fileSizeMax: Int32 public let preloadLargeVideo: Bool public let lessDataForPhoneCalls: Bool + public let videoUploadMaxbitrate: Int32 - public init(disabled: Bool, photoSizeMax: Int32, videoSizeMax: Int32, fileSizeMax: Int32, preloadLargeVideo: Bool, lessDataForPhoneCalls: Bool) { + public init(disabled: Bool, photoSizeMax: Int32, videoSizeMax: Int32, fileSizeMax: Int32, preloadLargeVideo: Bool, lessDataForPhoneCalls: Bool, videoUploadMaxbitrate: Int32) { self.disabled = disabled self.photoSizeMax = photoSizeMax self.videoSizeMax = videoSizeMax self.fileSizeMax = fileSizeMax self.preloadLargeVideo = preloadLargeVideo self.lessDataForPhoneCalls = lessDataForPhoneCalls + self.videoUploadMaxbitrate = videoUploadMaxbitrate } public init(decoder: PostboxDecoder) { @@ -30,6 +32,7 @@ public struct AutodownloadPresetSettings: PostboxCoding, Equatable { self.fileSizeMax = decoder.decodeInt32ForKey("fileSizeMax", orElse: 0) self.preloadLargeVideo = decoder.decodeInt32ForKey("preloadLargeVideo", orElse: 0) != 0 self.lessDataForPhoneCalls = decoder.decodeInt32ForKey("lessDataForPhoneCalls", orElse: 0) != 0 + self.videoUploadMaxbitrate = decoder.decodeInt32ForKey("videoUploadMaxbitrate", orElse: 0) } public func encode(_ encoder: PostboxEncoder) { @@ -39,6 +42,7 @@ public struct AutodownloadPresetSettings: PostboxCoding, Equatable { encoder.encodeInt32(self.fileSizeMax, forKey: "fileSizeMax") encoder.encodeInt32(self.preloadLargeVideo ? 1 : 0, forKey: "preloadLargeVideo") encoder.encodeInt32(self.lessDataForPhoneCalls ? 1 : 0, forKey: "lessDataForPhoneCalls") + encoder.encodeInt32(self.videoUploadMaxbitrate, forKey: "videoUploadMaxbitrate") } } @@ -48,9 +52,10 @@ public struct AutodownloadSettings: PreferencesEntry, Equatable { public let highPreset: AutodownloadPresetSettings public static var defaultSettings: AutodownloadSettings { - return AutodownloadSettings(lowPreset: AutodownloadPresetSettings(disabled: false, photoSizeMax: 1 * 1024 * 1024, videoSizeMax: 0, fileSizeMax: 0, preloadLargeVideo: false, lessDataForPhoneCalls: true), - mediumPreset: AutodownloadPresetSettings(disabled: false, photoSizeMax: 1 * 1024 * 1024, videoSizeMax: Int32(2.5 * 1024 * 1024), fileSizeMax: 1 * 1024 * 1024, preloadLargeVideo: false, lessDataForPhoneCalls: false), - highPreset: AutodownloadPresetSettings(disabled: false, photoSizeMax: 1 * 1024 * 1024, videoSizeMax: 10 * 1024 * 1024, fileSizeMax: 3 * 1024 * 1024, preloadLargeVideo: false, lessDataForPhoneCalls: false)) + return AutodownloadSettings( + lowPreset: AutodownloadPresetSettings(disabled: false, photoSizeMax: 1 * 1024 * 1024, videoSizeMax: 0, fileSizeMax: 0, preloadLargeVideo: false, lessDataForPhoneCalls: true, videoUploadMaxbitrate: 0), + mediumPreset: AutodownloadPresetSettings(disabled: false, photoSizeMax: 1 * 1024 * 1024, videoSizeMax: Int32(2.5 * 1024 * 1024), fileSizeMax: 1 * 1024 * 1024, preloadLargeVideo: false, lessDataForPhoneCalls: false, videoUploadMaxbitrate: 0), + highPreset: AutodownloadPresetSettings(disabled: false, photoSizeMax: 1 * 1024 * 1024, videoSizeMax: 10 * 1024 * 1024, fileSizeMax: 3 * 1024 * 1024, preloadLargeVideo: false, lessDataForPhoneCalls: false, videoUploadMaxbitrate: 0)) } public init(lowPreset: AutodownloadPresetSettings, mediumPreset: AutodownloadPresetSettings, highPreset: AutodownloadPresetSettings) { diff --git a/submodules/TelegramApi/Sources/Api0.swift b/submodules/TelegramApi/Sources/Api0.swift index d316fd251e..58d8f497df 100644 --- a/submodules/TelegramApi/Sources/Api0.swift +++ b/submodules/TelegramApi/Sources/Api0.swift @@ -71,7 +71,8 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[1202287072] = { return Api.StatsURL.parse_statsURL($0) } dict[1516793212] = { return Api.ChatInvite.parse_chatInviteAlready($0) } dict[-540871282] = { return Api.ChatInvite.parse_chatInvite($0) } - dict[-767099577] = { return Api.AutoDownloadSettings.parse_autoDownloadSettings($0) } + dict[-532532493] = { return Api.AutoDownloadSettings.parse_autoDownloadSettings($0) } + dict[-767099577] = { return Api.AutoDownloadSettings.parse_autoDownloadSettingsLegacy($0) } dict[1678812626] = { return Api.StickerSetCovered.parse_stickerSetCovered($0) } dict[872932635] = { return Api.StickerSetCovered.parse_stickerSetMultiCovered($0) } dict[1189204285] = { return Api.RecentMeUrl.parse_recentMeUrlUnknown($0) } diff --git a/submodules/TelegramApi/Sources/Api1.swift b/submodules/TelegramApi/Sources/Api1.swift index 3864c7cbc9..4f1d259c20 100644 --- a/submodules/TelegramApi/Sources/Api1.swift +++ b/submodules/TelegramApi/Sources/Api1.swift @@ -1908,11 +1908,22 @@ public extension Api { } public enum AutoDownloadSettings: TypeConstructorDescription { - case autoDownloadSettings(flags: Int32, photoSizeMax: Int32, videoSizeMax: Int32, fileSizeMax: Int32) + case autoDownloadSettings(flags: Int32, photoSizeMax: Int32, videoSizeMax: Int32, fileSizeMax: Int32, videoUploadMaxbitrate: Int32) + case autoDownloadSettingsLegacy(flags: Int32, photoSizeMax: Int32, videoSizeMax: Int32, fileSizeMax: Int32) public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { switch self { - case .autoDownloadSettings(let flags, let photoSizeMax, let videoSizeMax, let fileSizeMax): + case .autoDownloadSettings(let flags, let photoSizeMax, let videoSizeMax, let fileSizeMax, let videoUploadMaxbitrate): + if boxed { + buffer.appendInt32(-532532493) + } + serializeInt32(flags, buffer: buffer, boxed: false) + serializeInt32(photoSizeMax, buffer: buffer, boxed: false) + serializeInt32(videoSizeMax, buffer: buffer, boxed: false) + serializeInt32(fileSizeMax, buffer: buffer, boxed: false) + serializeInt32(videoUploadMaxbitrate, buffer: buffer, boxed: false) + break + case .autoDownloadSettingsLegacy(let flags, let photoSizeMax, let videoSizeMax, let fileSizeMax): if boxed { buffer.appendInt32(-767099577) } @@ -1926,12 +1937,37 @@ public extension Api { public func descriptionFields() -> (String, [(String, Any)]) { switch self { - case .autoDownloadSettings(let flags, let photoSizeMax, let videoSizeMax, let fileSizeMax): - return ("autoDownloadSettings", [("flags", flags), ("photoSizeMax", photoSizeMax), ("videoSizeMax", videoSizeMax), ("fileSizeMax", fileSizeMax)]) + case .autoDownloadSettings(let flags, let photoSizeMax, let videoSizeMax, let fileSizeMax, let videoUploadMaxbitrate): + return ("autoDownloadSettings", [("flags", flags), ("photoSizeMax", photoSizeMax), ("videoSizeMax", videoSizeMax), ("fileSizeMax", fileSizeMax), ("videoUploadMaxbitrate", videoUploadMaxbitrate)]) + case .autoDownloadSettingsLegacy(let flags, let photoSizeMax, let videoSizeMax, let fileSizeMax): + return ("autoDownloadSettingsLegacy", [("flags", flags), ("photoSizeMax", photoSizeMax), ("videoSizeMax", videoSizeMax), ("fileSizeMax", fileSizeMax)]) } } public static func parse_autoDownloadSettings(_ reader: BufferReader) -> AutoDownloadSettings? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Int32? + _2 = reader.readInt32() + var _3: Int32? + _3 = reader.readInt32() + var _4: Int32? + _4 = reader.readInt32() + var _5: Int32? + _5 = reader.readInt32() + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = _3 != nil + let _c4 = _4 != nil + let _c5 = _5 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 { + return Api.AutoDownloadSettings.autoDownloadSettings(flags: _1!, photoSizeMax: _2!, videoSizeMax: _3!, fileSizeMax: _4!, videoUploadMaxbitrate: _5!) + } + else { + return nil + } + } + public static func parse_autoDownloadSettingsLegacy(_ reader: BufferReader) -> AutoDownloadSettings? { var _1: Int32? _1 = reader.readInt32() var _2: Int32? @@ -1945,7 +1981,7 @@ public extension Api { let _c3 = _3 != nil let _c4 = _4 != nil if _c1 && _c2 && _c3 && _c4 { - return Api.AutoDownloadSettings.autoDownloadSettings(flags: _1!, photoSizeMax: _2!, videoSizeMax: _3!, fileSizeMax: _4!) + return Api.AutoDownloadSettings.autoDownloadSettingsLegacy(flags: _1!, photoSizeMax: _2!, videoSizeMax: _3!, fileSizeMax: _4!) } else { return nil diff --git a/submodules/TelegramCore/Sources/AddPeerMember.swift b/submodules/TelegramCore/Sources/AddPeerMember.swift index 5b3b6cac71..138d4b3029 100644 --- a/submodules/TelegramCore/Sources/AddPeerMember.swift +++ b/submodules/TelegramCore/Sources/AddPeerMember.swift @@ -10,6 +10,7 @@ public enum AddGroupMemberError { case generic case groupFull case privacy + case tooManyChannels } public func addGroupMember(account: Account, peerId: PeerId, memberId: PeerId) -> Signal { @@ -19,12 +20,14 @@ public func addGroupMember(account: Account, peerId: PeerId, memberId: PeerId) - return account.network.request(Api.functions.messages.addChatUser(chatId: group.id.id, userId: inputUser, fwdLimit: 100)) |> mapError { error -> AddGroupMemberError in switch error.errorDescription { - case "USERS_TOO_MUCH": - return .groupFull - case "USER_PRIVACY_RESTRICTED": - return .privacy - default: - return .generic + case "USERS_TOO_MUCH": + return .groupFull + case "USER_PRIVACY_RESTRICTED": + return .privacy + case "USER_CHANNELS_TOO_MUCH": + return .tooManyChannels + default: + return .generic } } |> mapToSignal { result -> Signal in diff --git a/submodules/TelegramCore/Sources/AutodownloadSettings.swift b/submodules/TelegramCore/Sources/AutodownloadSettings.swift index 141a6ac9d1..b86130c742 100644 --- a/submodules/TelegramCore/Sources/AutodownloadSettings.swift +++ b/submodules/TelegramCore/Sources/AutodownloadSettings.swift @@ -22,8 +22,10 @@ public func updateAutodownloadSettingsInteractively(accountManager: AccountManag extension AutodownloadPresetSettings { init(apiAutodownloadSettings: Api.AutoDownloadSettings) { switch apiAutodownloadSettings { - case let .autoDownloadSettings(flags, photoSizeMax, videoSizeMax, fileSizeMax): - self.init(disabled: (flags & (1 << 0)) != 0, photoSizeMax: photoSizeMax, videoSizeMax: videoSizeMax, fileSizeMax: fileSizeMax, preloadLargeVideo: (flags & (1 << 1)) != 0, lessDataForPhoneCalls: (flags & (1 << 3)) != 0) + case let .autoDownloadSettings(flags, photoSizeMax, videoSizeMax, fileSizeMax, videoUploadMaxbitrate): + self.init(disabled: (flags & (1 << 0)) != 0, photoSizeMax: photoSizeMax, videoSizeMax: videoSizeMax, fileSizeMax: fileSizeMax, preloadLargeVideo: (flags & (1 << 1)) != 0, lessDataForPhoneCalls: (flags & (1 << 3)) != 0, videoUploadMaxbitrate: videoUploadMaxbitrate) + case let .autoDownloadSettingsLegacy(flags, photoSizeMax, videoSizeMax, fileSizeMax): + self.init(disabled: (flags & (1 << 0)) != 0, photoSizeMax: photoSizeMax, videoSizeMax: videoSizeMax, fileSizeMax: fileSizeMax, preloadLargeVideo: (flags & (1 << 1)) != 0, lessDataForPhoneCalls: (flags & (1 << 3)) != 0, videoUploadMaxbitrate: 0) } } } @@ -48,6 +50,6 @@ func apiAutodownloadPresetSettings(_ autodownloadPresetSettings: AutodownloadPre if autodownloadPresetSettings.lessDataForPhoneCalls { flags |= (1 << 3) } - return .autoDownloadSettings(flags: flags, photoSizeMax: autodownloadPresetSettings.photoSizeMax, videoSizeMax: autodownloadPresetSettings.videoSizeMax, fileSizeMax: autodownloadPresetSettings.fileSizeMax) + return .autoDownloadSettings(flags: flags, photoSizeMax: autodownloadPresetSettings.photoSizeMax, videoSizeMax: autodownloadPresetSettings.videoSizeMax, fileSizeMax: autodownloadPresetSettings.fileSizeMax, videoUploadMaxbitrate: autodownloadPresetSettings.videoUploadMaxbitrate) } diff --git a/submodules/TelegramCore/Sources/PeerAdmins.swift b/submodules/TelegramCore/Sources/PeerAdmins.swift index d5bc504a0c..416a0596e0 100644 --- a/submodules/TelegramCore/Sources/PeerAdmins.swift +++ b/submodules/TelegramCore/Sources/PeerAdmins.swift @@ -195,6 +195,8 @@ public func updateChannelAdminRights(account: Account, peerId: PeerId, adminId: ) } else if error.errorDescription == "USER_PRIVACY_RESTRICTED" { return .fail(.addMemberError(.restricted)) + } else if error.errorDescription == "USER_CHANNELS_TOO_MUCH" { + return .fail(.addMemberError(.tooMuchJoined)) } return .fail(.generic) } diff --git a/submodules/TelegramPresentationData/Sources/PresentationData.swift b/submodules/TelegramPresentationData/Sources/PresentationData.swift index de306cb977..5c83f79bea 100644 --- a/submodules/TelegramPresentationData/Sources/PresentationData.swift +++ b/submodules/TelegramPresentationData/Sources/PresentationData.swift @@ -165,14 +165,16 @@ private func currentPersonNameSortOrder() -> PresentationPersonNameOrder { public final class InitialPresentationDataAndSettings { public let presentationData: PresentationData public let automaticMediaDownloadSettings: MediaAutoDownloadSettings + public let autodownloadSettings: AutodownloadSettings public let callListSettings: CallListSettings public let inAppNotificationSettings: InAppNotificationSettings public let mediaInputSettings: MediaInputSettings public let experimentalUISettings: ExperimentalUISettings - public init(presentationData: PresentationData, automaticMediaDownloadSettings: MediaAutoDownloadSettings, callListSettings: CallListSettings, inAppNotificationSettings: InAppNotificationSettings, mediaInputSettings: MediaInputSettings, experimentalUISettings: ExperimentalUISettings) { + public init(presentationData: PresentationData, automaticMediaDownloadSettings: MediaAutoDownloadSettings, autodownloadSettings: AutodownloadSettings, callListSettings: CallListSettings, inAppNotificationSettings: InAppNotificationSettings, mediaInputSettings: MediaInputSettings, experimentalUISettings: ExperimentalUISettings) { self.presentationData = presentationData self.automaticMediaDownloadSettings = automaticMediaDownloadSettings + self.autodownloadSettings = autodownloadSettings self.callListSettings = callListSettings self.inAppNotificationSettings = inAppNotificationSettings self.mediaInputSettings = mediaInputSettings @@ -203,6 +205,13 @@ public func currentPresentationDataAndSettings(accountManager: AccountManager, s automaticMediaDownloadSettings = MediaAutoDownloadSettings.defaultSettings } + let autodownloadSettings: AutodownloadSettings + if let value = transaction.getSharedData(SharedDataKeys.autodownloadSettings) as? AutodownloadSettings { + autodownloadSettings = value + } else { + autodownloadSettings = .defaultSettings + } + let callListSettings: CallListSettings if let value = transaction.getSharedData(ApplicationSpecificSharedDataKeys.callListSettings) as? CallListSettings { callListSettings = value @@ -253,7 +262,7 @@ public func currentPresentationDataAndSettings(accountManager: AccountManager, s } let nameDisplayOrder = contactSettings.nameDisplayOrder let nameSortOrder = currentPersonNameSortOrder() - return InitialPresentationDataAndSettings(presentationData: PresentationData(strings: stringsValue, theme: theme, autoNightModeTriggered: autoNightModeTriggered, chatWallpaper: effectiveChatWallpaper, fontSize: resolveFontSize(settings: themeSettings), dateTimeFormat: dateTimeFormat, nameDisplayOrder: nameDisplayOrder, nameSortOrder: nameSortOrder, disableAnimations: themeSettings.disableAnimations, largeEmoji: themeSettings.largeEmoji), automaticMediaDownloadSettings: automaticMediaDownloadSettings, callListSettings: callListSettings, inAppNotificationSettings: inAppNotificationSettings, mediaInputSettings: mediaInputSettings, experimentalUISettings: experimentalUISettings) + return InitialPresentationDataAndSettings(presentationData: PresentationData(strings: stringsValue, theme: theme, autoNightModeTriggered: autoNightModeTriggered, chatWallpaper: effectiveChatWallpaper, fontSize: resolveFontSize(settings: themeSettings), dateTimeFormat: dateTimeFormat, nameDisplayOrder: nameDisplayOrder, nameSortOrder: nameSortOrder, disableAnimations: themeSettings.disableAnimations, largeEmoji: themeSettings.largeEmoji), automaticMediaDownloadSettings: automaticMediaDownloadSettings, autodownloadSettings: autodownloadSettings, callListSettings: callListSettings, inAppNotificationSettings: inAppNotificationSettings, mediaInputSettings: mediaInputSettings, experimentalUISettings: experimentalUISettings) } } diff --git a/submodules/TelegramPresentationData/Sources/Resources/PresentationResourceKey.swift b/submodules/TelegramPresentationData/Sources/Resources/PresentationResourceKey.swift index 12fdc82903..a1b0744fad 100644 --- a/submodules/TelegramPresentationData/Sources/Resources/PresentationResourceKey.swift +++ b/submodules/TelegramPresentationData/Sources/Resources/PresentationResourceKey.swift @@ -228,4 +228,10 @@ public enum PresentationResourceParameterKey: Hashable { case chatMediaPartialCheck(CGFloat) case chatFreeFullCheck(CGFloat, Bool) case chatFreePartialCheck(CGFloat, Bool) + + case chatListBadgeBackgroundActive(CGFloat) + case chatListBadgeBackgroundInactive(CGFloat) + case chatListBadgeBackgroundMention(CGFloat) + case chatListBadgeBackgroundInactiveMention(CGFloat) + case chatListBadgeBackgroundPinned(CGFloat) } diff --git a/submodules/TelegramPresentationData/Sources/Resources/PresentationResourcesChatList.swift b/submodules/TelegramPresentationData/Sources/Resources/PresentationResourcesChatList.swift index 77dd16f219..12aca8462b 100644 --- a/submodules/TelegramPresentationData/Sources/Resources/PresentationResourcesChatList.swift +++ b/submodules/TelegramPresentationData/Sources/Resources/PresentationResourcesChatList.swift @@ -19,8 +19,8 @@ private func generateStatusCheckImage(theme: PresentationTheme, single: Bool) -> }) } -private func generateBadgeBackgroundImage(theme: PresentationTheme, active: Bool, icon: UIImage? = nil) -> UIImage? { - return generateImage(CGSize(width: 20.0, height: 20.0), contextGenerator: { size, context in +private func generateBadgeBackgroundImage(theme: PresentationTheme, diameter: CGFloat, active: Bool, icon: UIImage? = nil) -> UIImage? { + return generateImage(CGSize(width: diameter, height: diameter), contextGenerator: { size, context in context.clear(CGRect(origin: CGPoint(), size: size)) if active { context.setFillColor(theme.chatList.unreadBadgeActiveBackgroundColor.cgColor) @@ -31,7 +31,7 @@ private func generateBadgeBackgroundImage(theme: PresentationTheme, active: Bool if let icon = icon, let cgImage = icon.cgImage { context.draw(cgImage, in: CGRect(origin: CGPoint(x: floor((size.width - icon.size.width) / 2.0), y: floor((size.height - icon.size.height) / 2.0)), size: icon.size)) } - })?.stretchableImage(withLeftCapWidth: 10, topCapHeight: 10) + })?.stretchableImage(withLeftCapWidth: Int(diameter / 2.0), topCapHeight: Int(diameter / 2.0)) } private func generateClockFrameImage(color: UIColor) -> UIImage? { @@ -169,32 +169,32 @@ public struct PresentationResourcesChatList { }) } - public static func badgeBackgroundActive(_ theme: PresentationTheme) -> UIImage? { - return theme.image(PresentationResourceKey.chatListBadgeBackgroundActive.rawValue, { theme in - return generateBadgeBackgroundImage(theme: theme, active: true) + public static func badgeBackgroundActive(_ theme: PresentationTheme, diameter: CGFloat) -> UIImage? { + return theme.image(PresentationResourceParameterKey.chatListBadgeBackgroundActive(diameter), { theme in + return generateBadgeBackgroundImage(theme: theme, diameter: diameter, active: true) }) } - public static func badgeBackgroundInactive(_ theme: PresentationTheme) -> UIImage? { - return theme.image(PresentationResourceKey.chatListBadgeBackgroundInactive.rawValue, { theme in - return generateBadgeBackgroundImage(theme: theme, active: false) + public static func badgeBackgroundInactive(_ theme: PresentationTheme, diameter: CGFloat) -> UIImage? { + return theme.image(PresentationResourceParameterKey.chatListBadgeBackgroundInactive(diameter), { theme in + return generateBadgeBackgroundImage(theme: theme, diameter: diameter, active: false) }) } - public static func badgeBackgroundMention(_ theme: PresentationTheme) -> UIImage? { - return theme.image(PresentationResourceKey.chatListBadgeBackgroundMention.rawValue, { theme in - return generateBadgeBackgroundImage(theme: theme, active: true, icon: generateTintedImage(image: UIImage(bundleImageName: "Chat List/MentionBadgeIcon"), color: theme.chatList.unreadBadgeActiveTextColor)) + public static func badgeBackgroundMention(_ theme: PresentationTheme, diameter: CGFloat) -> UIImage? { + return theme.image(PresentationResourceParameterKey.chatListBadgeBackgroundMention(diameter), { theme in + return generateBadgeBackgroundImage(theme: theme, diameter: diameter, active: true, icon: generateTintedImage(image: UIImage(bundleImageName: "Chat List/MentionBadgeIcon"), color: theme.chatList.unreadBadgeActiveTextColor)) }) } - public static func badgeBackgroundInactiveMention(_ theme: PresentationTheme) -> UIImage? { - return theme.image(PresentationResourceKey.chatListBadgeBackgroundInactiveMention.rawValue, { theme in - return generateBadgeBackgroundImage(theme: theme, active: false, icon: generateTintedImage(image: UIImage(bundleImageName: "Chat List/MentionBadgeIcon"), color: theme.chatList.unreadBadgeInactiveTextColor)) + public static func badgeBackgroundInactiveMention(_ theme: PresentationTheme, diameter: CGFloat) -> UIImage? { + return theme.image(PresentationResourceParameterKey.chatListBadgeBackgroundInactiveMention(diameter), { theme in + return generateBadgeBackgroundImage(theme: theme, diameter: diameter, active: false, icon: generateTintedImage(image: UIImage(bundleImageName: "Chat List/MentionBadgeIcon"), color: theme.chatList.unreadBadgeInactiveTextColor)) }) } - public static func badgeBackgroundPinned(_ theme: PresentationTheme) -> UIImage? { - return theme.image(PresentationResourceKey.chatListBadgeBackgroundPinned.rawValue, { theme in + public static func badgeBackgroundPinned(_ theme: PresentationTheme, diameter: CGFloat) -> UIImage? { + return theme.image(PresentationResourceParameterKey.chatListBadgeBackgroundPinned(diameter), { theme in return generateTintedImage(image: UIImage(bundleImageName: "Chat List/PeerPinnedIcon"), color: theme.chatList.pinnedBadgeColor) }) } diff --git a/submodules/TelegramUI/TelegramUI/ApplicationContext.swift b/submodules/TelegramUI/TelegramUI/ApplicationContext.swift index b4475e127c..42ab9f51d8 100644 --- a/submodules/TelegramUI/TelegramUI/ApplicationContext.swift +++ b/submodules/TelegramUI/TelegramUI/ApplicationContext.swift @@ -58,6 +58,16 @@ final class UnauthorizedApplicationContext { return .never } }) + + DeviceAccess.authorizeAccess(to: .cellularData, presentationData: sharedContext.currentPresentationData.with { $0 }, present: { [weak self] c, a in + if let strongSelf = self { + (strongSelf.rootController.viewControllers.last as? ViewController)?.present(c, in: .window(.root)) + } + }, openSettings: { + sharedContext.applicationBindings.openSettings() + }, { result in + ApplicationSpecificNotice.setPermissionWarning(accountManager: sharedContext.accountManager, permission: .cellularData, value: 0) + }) } } diff --git a/submodules/TelegramUI/TelegramUI/ChatChannelSubscriberInputPanelNode.swift b/submodules/TelegramUI/TelegramUI/ChatChannelSubscriberInputPanelNode.swift index f4734e7a13..33a435c828 100644 --- a/submodules/TelegramUI/TelegramUI/ChatChannelSubscriberInputPanelNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatChannelSubscriberInputPanelNode.swift @@ -175,7 +175,7 @@ final class ChatChannelSubscriberInputPanelNode: ChatInputPanelNode { self.presentationInterfaceState = interfaceState if previousState?.theme !== interfaceState.theme { - self.badgeBackground.image = PresentationResourcesChatList.badgeBackgroundActive(interfaceState.theme) + self.badgeBackground.image = PresentationResourcesChatList.badgeBackgroundActive(interfaceState.theme, diameter: 20.0) } if previousState?.peerDiscussionId != interfaceState.peerDiscussionId { diff --git a/submodules/TelegramUI/TelegramUI/ChatController.swift b/submodules/TelegramUI/TelegramUI/ChatController.swift index 692c163f7e..67f264c07e 100644 --- a/submodules/TelegramUI/TelegramUI/ChatController.swift +++ b/submodules/TelegramUI/TelegramUI/ChatController.swift @@ -438,7 +438,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G }, present: { c, a in self?.present(c, in: .window(.root), with: a, blockInteraction: true) }, transitionNode: { messageId, media in - var selectedNode: (ASDisplayNode, () -> (UIView?, UIView?))? + var selectedNode: (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? if let strongSelf = self { strongSelf.chatDisplayNode.historyNode.forEachItemNode { itemNode in if let itemNode = itemNode as? ChatMessageItemView { @@ -7401,7 +7401,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G if let (message, content) = result { switch content { case let .media(media): - var selectedTransitionNode: (ASDisplayNode, () -> (UIView?, UIView?))? + var selectedTransitionNode: (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? self.chatDisplayNode.historyNode.forEachItemNode { itemNode in if let itemNode = itemNode as? ChatMessageItemView { if let result = itemNode.transitionNode(id: message.id, media: media) { @@ -7472,7 +7472,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G self.present(gallery, in: .window(.root), with: GalleryControllerPresentationArguments(animated: false, transitionArguments: { [weak self] messageId, media in if let strongSelf = self { - var selectedTransitionNode: (ASDisplayNode, () -> (UIView?, UIView?))? + var selectedTransitionNode: (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? strongSelf.chatDisplayNode.historyNode.forEachItemNode { itemNode in if let itemNode = itemNode as? ChatMessageItemView { if let result = itemNode.transitionNode(id: messageId, media: media) { @@ -7586,7 +7586,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G self.chatDisplayNode.dismissInput() self.present(gallery, in: .window(.root), with: GalleryControllerPresentationArguments(transitionArguments: { [weak self] messageId, media in if let strongSelf = self { - var transitionNode: (ASDisplayNode, () -> (UIView?, UIView?))? + var transitionNode: (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? strongSelf.chatDisplayNode.historyNode.forEachItemNode { itemNode in if let itemNode = itemNode as? ChatMessageItemView { if let result = itemNode.transitionNode(id: messageId, media: media) { @@ -8077,7 +8077,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G } public func getTransitionInfo(messageId: MessageId, media: Media) -> ((UIView) -> Void, ASDisplayNode, () -> (UIView?, UIView?))? { - var selectedNode: (ASDisplayNode, () -> (UIView?, UIView?))? + var selectedNode: (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? self.chatDisplayNode.historyNode.forEachItemNode { itemNode in if let itemNode = itemNode as? ChatMessageItemView { if let result = itemNode.transitionNode(id: messageId, media: media) { @@ -8085,7 +8085,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G } } } - if let (node, get) = selectedNode { + if let (node, contentBounds, get) = selectedNode { return ({ [weak self] view in guard let strongSelf = self else { return diff --git a/submodules/TelegramUI/TelegramUI/ChatHistorySearchContainerNode.swift b/submodules/TelegramUI/TelegramUI/ChatHistorySearchContainerNode.swift index 3edfa84d36..754796778f 100644 --- a/submodules/TelegramUI/TelegramUI/ChatHistorySearchContainerNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatHistorySearchContainerNode.swift @@ -368,8 +368,8 @@ final class ChatHistorySearchContainerNode: SearchDisplayControllerContentNode { } } - func transitionNodeForGallery(messageId: MessageId, media: Media) -> (ASDisplayNode, () -> (UIView?, UIView?))? { - var transitionNode: (ASDisplayNode, () -> (UIView?, UIView?))? + func transitionNodeForGallery(messageId: MessageId, media: Media) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? { + var transitionNode: (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? self.listNode.forEachItemNode { itemNode in if let itemNode = itemNode as? ChatMessageItemView { if let result = itemNode.transitionNode(id: messageId, media: media) { diff --git a/submodules/TelegramUI/TelegramUI/ChatMediaInputNode.swift b/submodules/TelegramUI/TelegramUI/ChatMediaInputNode.swift index 9447c84f48..fb60abc52b 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMediaInputNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMediaInputNode.swift @@ -738,7 +738,8 @@ final class ChatMediaInputNode: ChatInputNode { return } strongSelf.view.window?.endEditing(true) - let controller = StickerPackScreen(context: strongSelf.context, stickerPacks: [.id(id: info.id.id, accessHash: info.accessHash)], parentNavigationController: strongSelf.controllerInteraction.navigationController(), sendSticker: { fileReference, sourceNode, sourceRect in + let packReference: StickerPackReference = .id(id: info.id.id, accessHash: info.accessHash) + let controller = StickerPackScreen(context: strongSelf.context, mainStickerPack: packReference, stickerPacks: [packReference], parentNavigationController: strongSelf.controllerInteraction.navigationController(), sendSticker: { fileReference, sourceNode, sourceRect in if let strongSelf = self { return strongSelf.controllerInteraction.sendSticker(fileReference, false, sourceNode, sourceRect) } else { @@ -974,7 +975,7 @@ final class ChatMediaInputNode: ChatInputNode { switch attribute { case let .Sticker(_, packReference, _): if let packReference = packReference { - let controller = StickerPackScreen(context: strongSelf.context, stickerPacks: [packReference], parentNavigationController: strongSelf.controllerInteraction.navigationController(), sendSticker: { file, sourceNode, sourceRect in + let controller = StickerPackScreen(context: strongSelf.context, mainStickerPack: packReference, stickerPacks: [packReference], parentNavigationController: strongSelf.controllerInteraction.navigationController(), sendSticker: { file, sourceNode, sourceRect in if let strongSelf = self { return strongSelf.controllerInteraction.sendSticker(file, false, sourceNode, sourceRect) } else { @@ -1088,7 +1089,7 @@ final class ChatMediaInputNode: ChatInputNode { switch attribute { case let .Sticker(_, packReference, _): if let packReference = packReference { - let controller = StickerPackScreen(context: strongSelf.context, stickerPacks: [packReference], parentNavigationController: strongSelf.controllerInteraction.navigationController(), sendSticker: { file, sourceNode, sourceRect in + let controller = StickerPackScreen(context: strongSelf.context, mainStickerPack: packReference, stickerPacks: [packReference], parentNavigationController: strongSelf.controllerInteraction.navigationController(), sendSticker: { file, sourceNode, sourceRect in if let strongSelf = self { return strongSelf.controllerInteraction.sendSticker(file, false, sourceNode, sourceRect) } else { diff --git a/submodules/TelegramUI/TelegramUI/ChatMediaInputTrendingPane.swift b/submodules/TelegramUI/TelegramUI/ChatMediaInputTrendingPane.swift index c0a0393750..3b421468b1 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMediaInputTrendingPane.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMediaInputTrendingPane.swift @@ -192,7 +192,8 @@ final class ChatMediaInputTrendingPane: ChatMediaInputPane { }, openPack: { [weak self] info in if let strongSelf = self, let info = info as? StickerPackCollectionInfo { strongSelf.view.window?.endEditing(true) - let controller = StickerPackScreen(context: strongSelf.context, stickerPacks: [.id(id: info.id.id, accessHash: info.accessHash)], parentNavigationController: strongSelf.controllerInteraction.navigationController(), sendSticker: { fileReference, sourceNode, sourceRect in + let packReference: StickerPackReference = .id(id: info.id.id, accessHash: info.accessHash) + let controller = StickerPackScreen(context: strongSelf.context, mainStickerPack: packReference, stickerPacks: [packReference], parentNavigationController: strongSelf.controllerInteraction.navigationController(), sendSticker: { fileReference, sourceNode, sourceRect in if let strongSelf = self { return strongSelf.controllerInteraction.sendSticker(fileReference, false, sourceNode, sourceRect) } else { diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageActionItemNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageActionItemNode.swift index f39d214451..b09a154646 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageActionItemNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageActionItemNode.swift @@ -50,9 +50,9 @@ class ChatMessageActionBubbleContentNode: ChatMessageBubbleContentNode { super.didLoad() } - override func transitionNode(messageId: MessageId, media: Media) -> (ASDisplayNode, () -> (UIView?, UIView?))? { + override func transitionNode(messageId: MessageId, media: Media) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? { if let imageNode = self.imageNode, self.item?.message.id == messageId { - return (imageNode, { [weak imageNode] in + return (imageNode, imageNode.bounds, { [weak imageNode] in return (imageNode?.view.snapshotContentTree(unhide: true), nil) }) } else { diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageAttachedContentNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageAttachedContentNode.swift index 63d8c5de30..907ee9dee2 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageAttachedContentNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageAttachedContentNode.swift @@ -960,13 +960,13 @@ final class ChatMessageAttachedContentNode: ASDisplayNode { return false } - func transitionNode(media: Media) -> (ASDisplayNode, () -> (UIView?, UIView?))? { + func transitionNode(media: Media) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? { if let contentImageNode = self.contentImageNode, let image = self.media as? TelegramMediaImage, image.isEqual(to: media) { - return (contentImageNode, { [weak contentImageNode] in + return (contentImageNode, contentImageNode.bounds, { [weak contentImageNode] in return (contentImageNode?.view.snapshotContentTree(unhide: true), nil) }) } else if let contentImageNode = self.contentImageNode, let file = self.media as? TelegramMediaFile, file.isEqual(to: media) { - return (contentImageNode, { [weak contentImageNode] in + return (contentImageNode, contentImageNode.bounds, { [weak contentImageNode] in return (contentImageNode?.view.snapshotContentTree(unhide: true), nil) }) } diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageBubbleContentNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageBubbleContentNode.swift index 27b0638d0b..f13a99335d 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageBubbleContentNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageBubbleContentNode.swift @@ -138,7 +138,7 @@ class ChatMessageBubbleContentNode: ASDisplayNode { }) } - func transitionNode(messageId: MessageId, media: Media) -> (ASDisplayNode, () -> (UIView?, UIView?))? { + func transitionNode(messageId: MessageId, media: Media) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? { return nil } diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageBubbleItemNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageBubbleItemNode.swift index 2930d6c6db..9a3a8a8bb3 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageBubbleItemNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageBubbleItemNode.swift @@ -2508,12 +2508,12 @@ class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePrevewItemNode return super.hitTest(point, with: event) } - override func transitionNode(id: MessageId, media: Media) -> (ASDisplayNode, () -> (UIView?, UIView?))? { + override func transitionNode(id: MessageId, media: Media) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? { for contentNode in self.contentNodes { if let result = contentNode.transitionNode(messageId: id, media: media) { if self.contentNodes.count == 1 && self.contentNodes.first is ChatMessageMediaBubbleContentNode && self.nameNode == nil && self.adminBadgeNode == nil && self.forwardInfoNode == nil && self.replyInfoNode == nil { - return (result.0, { [weak self] in - guard let strongSelf = self, let resultView = result.1().0 else { + return (result.0, result.1, { [weak self] in + guard let strongSelf = self, let resultView = result.2().0 else { return (nil, nil) } if strongSelf.backgroundNode.supernode != nil, let backgroundView = strongSelf.backgroundNode.view.snapshotContentTree(unhide: true) { diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageEventLogPreviousDescriptionContentNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageEventLogPreviousDescriptionContentNode.swift index 2a2a51fff0..ae9077c843 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageEventLogPreviousDescriptionContentNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageEventLogPreviousDescriptionContentNode.swift @@ -99,7 +99,7 @@ final class ChatMessageEventLogPreviousDescriptionContentNode: ChatMessageBubble return self.contentNode.updateHiddenMedia(media) } - override func transitionNode(messageId: MessageId, media: Media) -> (ASDisplayNode, () -> (UIView?, UIView?))? { + override func transitionNode(messageId: MessageId, media: Media) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? { if self.item?.message.id != messageId { return nil } diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageEventLogPreviousLinkContentNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageEventLogPreviousLinkContentNode.swift index 975026d312..5f788aa00c 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageEventLogPreviousLinkContentNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageEventLogPreviousLinkContentNode.swift @@ -94,7 +94,7 @@ final class ChatMessageEventLogPreviousLinkContentNode: ChatMessageBubbleContent return self.contentNode.updateHiddenMedia(media) } - override func transitionNode(messageId: MessageId, media: Media) -> (ASDisplayNode, () -> (UIView?, UIView?))? { + override func transitionNode(messageId: MessageId, media: Media) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? { if self.item?.message.id != messageId { return nil } diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageEventLogPreviousMessageContentNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageEventLogPreviousMessageContentNode.swift index bb9ea516dd..7058604a8c 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageEventLogPreviousMessageContentNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageEventLogPreviousMessageContentNode.swift @@ -101,7 +101,7 @@ final class ChatMessageEventLogPreviousMessageContentNode: ChatMessageBubbleCont return self.contentNode.updateHiddenMedia(media) } - override func transitionNode(messageId: MessageId, media: Media) -> (ASDisplayNode, () -> (UIView?, UIView?))? { + override func transitionNode(messageId: MessageId, media: Media) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? { if self.item?.message.id != messageId { return nil } diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageFileBubbleContentNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageFileBubbleContentNode.swift index c837e89d56..24366c0374 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageFileBubbleContentNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageFileBubbleContentNode.swift @@ -95,7 +95,7 @@ class ChatMessageFileBubbleContentNode: ChatMessageBubbleContentNode { } } - override func transitionNode(messageId: MessageId, media: Media) -> (ASDisplayNode, () -> (UIView?, UIView?))? { + override func transitionNode(messageId: MessageId, media: Media) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? { if self.item?.message.id == messageId { return self.interactiveFileNode.transitionNode(media: media) } else { diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageGameBubbleContentNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageGameBubbleContentNode.swift index ce6f6e2a96..4b2c542f75 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageGameBubbleContentNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageGameBubbleContentNode.swift @@ -127,7 +127,7 @@ final class ChatMessageGameBubbleContentNode: ChatMessageBubbleContentNode { return self.contentNode.updateHiddenMedia(media) } - override func transitionNode(messageId: MessageId, media: Media) -> (ASDisplayNode, () -> (UIView?, UIView?))? { + override func transitionNode(messageId: MessageId, media: Media) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? { if self.item?.message.id != messageId { return nil } diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageInteractiveFileNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageInteractiveFileNode.swift index 36a9c012c0..938b34cd74 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageInteractiveFileNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageInteractiveFileNode.swift @@ -912,9 +912,9 @@ final class ChatMessageInteractiveFileNode: ASDisplayNode { } } - func transitionNode(media: Media) -> (ASDisplayNode, () -> (UIView?, UIView?))? { + func transitionNode(media: Media) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? { if let iconNode = self.iconNode, let file = self.file, file.isEqual(to: media) { - return (iconNode, { [weak iconNode] in + return (iconNode, iconNode.bounds, { [weak iconNode] in return (iconNode?.view.snapshotContentTree(unhide: true), nil) }) } else { diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageInteractiveMediaNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageInteractiveMediaNode.swift index 54a8e8c452..f7cedeb5c9 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageInteractiveMediaNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageInteractiveMediaNode.swift @@ -1028,6 +1028,10 @@ final class ChatMessageInteractiveMediaNode: ASDisplayNode, GalleryItemTransitio if let file = self.media as? TelegramMediaFile, file.isAnimated { muted = false + + if case .Fetching = fetchStatus, message.flags.isSending, file.resource is CloudDocumentMediaResource { + fetchStatus = .Local + } } if message.flags.contains(.Unsent) { @@ -1321,8 +1325,14 @@ final class ChatMessageInteractiveMediaNode: ASDisplayNode, GalleryItemTransitio } } - func transitionNode() -> (ASDisplayNode, () -> (UIView?, UIView?))? { - return (self, { [weak self] in + func transitionNode() -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? { + let bounds: CGRect + if let currentImageArguments = self.currentImageArguments { + bounds = currentImageArguments.imageRect + } else { + bounds = self.bounds + } + return (self, bounds, { [weak self] in var badgeNodeHidden: Bool? if let badgeNode = self?.badgeNode { badgeNodeHidden = badgeNode.isHidden diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageInvoiceBubbleContentNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageInvoiceBubbleContentNode.swift index 0964c03b96..f908a4c8d4 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageInvoiceBubbleContentNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageInvoiceBubbleContentNode.swift @@ -130,7 +130,7 @@ final class ChatMessageInvoiceBubbleContentNode: ChatMessageBubbleContentNode { return self.contentNode.updateHiddenMedia(media) } - override func transitionNode(messageId: MessageId, media: Media) -> (ASDisplayNode, () -> (UIView?, UIView?))? { + override func transitionNode(messageId: MessageId, media: Media) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? { if self.item?.message.id != messageId { return nil } diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageItemView.swift b/submodules/TelegramUI/TelegramUI/ChatMessageItemView.swift index 84141ce0d7..8f84499aa4 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageItemView.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageItemView.swift @@ -698,7 +698,7 @@ public class ChatMessageItemView: ListViewItemNode { } } - func transitionNode(id: MessageId, media: Media) -> (ASDisplayNode, () -> (UIView?, UIView?))? { + func transitionNode(id: MessageId, media: Media) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? { return nil } diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageMapBubbleContentNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageMapBubbleContentNode.swift index 237ade7493..0bc7c5b130 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageMapBubbleContentNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageMapBubbleContentNode.swift @@ -432,10 +432,10 @@ class ChatMessageMapBubbleContentNode: ChatMessageBubbleContentNode { self.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, removeOnCompletion: false) } - override func transitionNode(messageId: MessageId, media: Media) -> (ASDisplayNode, () -> (UIView?, UIView?))? { + override func transitionNode(messageId: MessageId, media: Media) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? { if self.item?.message.id == messageId, let currentMedia = self.media, currentMedia.isEqual(to: media) { let imageNode = self.imageNode - return (self.imageNode, { [weak imageNode] in + return (self.imageNode, self.imageNode.bounds, { [weak imageNode] in return (imageNode?.view.snapshotContentTree(unhide: true), nil) }) } diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageMediaBubbleContentNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageMediaBubbleContentNode.swift index 5448edda4e..e60d732459 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageMediaBubbleContentNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageMediaBubbleContentNode.swift @@ -297,7 +297,7 @@ class ChatMessageMediaBubbleContentNode: ChatMessageBubbleContentNode { } } - override func transitionNode(messageId: MessageId, media: Media) -> (ASDisplayNode, () -> (UIView?, UIView?))? { + override func transitionNode(messageId: MessageId, media: Media) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? { if self.item?.message.id == messageId, let currentMedia = self.media, currentMedia.isSemanticallyEqual(to: media) { return self.interactiveImageNode.transitionNode() } diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageWebpageBubbleContentNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageWebpageBubbleContentNode.swift index 5edef04901..964a80d785 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageWebpageBubbleContentNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageWebpageBubbleContentNode.swift @@ -488,7 +488,7 @@ final class ChatMessageWebpageBubbleContentNode: ChatMessageBubbleContentNode { } } - override func transitionNode(messageId: MessageId, media: Media) -> (ASDisplayNode, () -> (UIView?, UIView?))? { + override func transitionNode(messageId: MessageId, media: Media) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? { if self.item?.message.id != messageId { return nil } diff --git a/submodules/TelegramUI/TelegramUI/ChatRecentActionsControllerNode.swift b/submodules/TelegramUI/TelegramUI/ChatRecentActionsControllerNode.swift index 0fbc4d6c6a..a3cc4c128b 100644 --- a/submodules/TelegramUI/TelegramUI/ChatRecentActionsControllerNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatRecentActionsControllerNode.swift @@ -146,7 +146,7 @@ final class ChatRecentActionsControllerNode: ViewControllerTracingNode { switch entry.entry.event.action { case let .changeStickerPack(_, new): if let new = new { - strongSelf.presentController(StickerPackScreen(context: strongSelf.context, stickerPacks: [new], parentNavigationController: strongSelf.getNavigationController()), nil) + strongSelf.presentController(StickerPackScreen(context: strongSelf.context, mainStickerPack: new, stickerPacks: [new], parentNavigationController: strongSelf.getNavigationController()), nil) return true } default: @@ -161,7 +161,7 @@ final class ChatRecentActionsControllerNode: ViewControllerTracingNode { }, present: { c, a in self?.presentController(c, a) }, transitionNode: { messageId, media in - var selectedNode: (ASDisplayNode, () -> (UIView?, UIView?))? + var selectedNode: (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? if let strongSelf = self { strongSelf.listNode.forEachItemNode { itemNode in if let itemNode = itemNode as? ChatMessageItemView { @@ -700,6 +700,9 @@ final class ChatRecentActionsControllerNode: ViewControllerTracingNode { if !channel.hasPermission(.banMembers) { canBan = false } + if case .broadcast = channel.info { + canBan = false + } } for member in adminsState.list { if member.peer.id == author.id { @@ -779,7 +782,8 @@ final class ChatRecentActionsControllerNode: ViewControllerTracingNode { strongSelf.context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: navigationController, context: strongSelf.context, chatLocation: .peer(peerId), subject: .message(messageId))) } case let .stickerPack(name): - strongSelf.presentController(StickerPackScreen(context: strongSelf.context, stickerPacks: [.name(name)], parentNavigationController: strongSelf.getNavigationController()), nil) + let packReference: StickerPackReference = .name(name) + strongSelf.presentController(StickerPackScreen(context: strongSelf.context, mainStickerPack: packReference, stickerPacks: [packReference], parentNavigationController: strongSelf.getNavigationController()), nil) case let .instantView(webpage, anchor): strongSelf.pushController(InstantPageController(context: strongSelf.context, webPage: webpage, sourcePeerType: .channel, anchor: anchor)) case let .join(link): diff --git a/submodules/TelegramUI/TelegramUI/GridMessageItem.swift b/submodules/TelegramUI/TelegramUI/GridMessageItem.swift index d0166ceadd..a396526820 100644 --- a/submodules/TelegramUI/TelegramUI/GridMessageItem.swift +++ b/submodules/TelegramUI/TelegramUI/GridMessageItem.swift @@ -379,10 +379,10 @@ final class GridMessageItemNode: GridItemNode { } } - func transitionNode(id: MessageId, media: Media) -> (ASDisplayNode, () -> (UIView?, UIView?))? { + func transitionNode(id: MessageId, media: Media) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? { if self.messageId == id { let imageNode = self.imageNode - return (self.imageNode, { [weak self, weak imageNode] in + return (self.imageNode, self.imageNode.bounds, { [weak self, weak imageNode] in var statusNodeHidden = false var accessoryHidden = false if let strongSelf = self { diff --git a/submodules/TelegramUI/TelegramUI/HorizontalListContextResultsChatInputContextPanelNode.swift b/submodules/TelegramUI/TelegramUI/HorizontalListContextResultsChatInputContextPanelNode.swift index afd567ad9d..d241bb0663 100644 --- a/submodules/TelegramUI/TelegramUI/HorizontalListContextResultsChatInputContextPanelNode.swift +++ b/submodules/TelegramUI/TelegramUI/HorizontalListContextResultsChatInputContextPanelNode.swift @@ -151,7 +151,7 @@ final class HorizontalListContextResultsChatInputContextPanelNode: ChatInputCont } menuItems.append(PeekControllerMenuItem(title: strongSelf.strings.StickerPack_ViewPack, color: .accent, action: { _, _ in if let strongSelf = self { - let controller = StickerPackScreen(context: strongSelf.context, stickerPacks: [packReference], parentNavigationController: strongSelf.interfaceInteraction?.getNavigationController(), sendSticker: { file, sourceNode, sourceRect in + let controller = StickerPackScreen(context: strongSelf.context, mainStickerPack: packReference, stickerPacks: [packReference], parentNavigationController: strongSelf.interfaceInteraction?.getNavigationController(), sendSticker: { file, sourceNode, sourceRect in if let strongSelf = self { return strongSelf.interfaceInteraction?.sendSticker(file, sourceNode, sourceRect) ?? false } else { diff --git a/submodules/TelegramUI/TelegramUI/HorizontalStickersChatContextPanelNode.swift b/submodules/TelegramUI/TelegramUI/HorizontalStickersChatContextPanelNode.swift index de1bf67574..6cfd6880a6 100755 --- a/submodules/TelegramUI/TelegramUI/HorizontalStickersChatContextPanelNode.swift +++ b/submodules/TelegramUI/TelegramUI/HorizontalStickersChatContextPanelNode.swift @@ -191,7 +191,7 @@ final class HorizontalStickersChatContextPanelNode: ChatInputContextPanelNode { switch attribute { case let .Sticker(_, packReference, _): if let packReference = packReference { - let controller = StickerPackScreen(context: strongSelf.context, stickerPacks: [packReference], parentNavigationController: controllerInteraction.navigationController(), sendSticker: { file, sourceNode, sourceRect in + let controller = StickerPackScreen(context: strongSelf.context, mainStickerPack: packReference, stickerPacks: [packReference], parentNavigationController: controllerInteraction.navigationController(), sendSticker: { file, sourceNode, sourceRect in if let strongSelf = self, let controllerInteraction = strongSelf.controllerInteraction { return controllerInteraction.sendSticker(file, true, sourceNode, sourceRect) } else { @@ -318,6 +318,7 @@ final class HorizontalStickersChatContextPanelNode: ChatInputContextPanelNode { } override func animateOut(completion: @escaping () -> Void) { + self.layer.allowsGroupOpacity = true self.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.3, removeOnCompletion: false, completion: { _ in completion() }) diff --git a/submodules/TelegramUI/TelegramUI/LegacyCamera.swift b/submodules/TelegramUI/TelegramUI/LegacyCamera.swift index 8c6af7aefd..f2d54b53f7 100644 --- a/submodules/TelegramUI/TelegramUI/LegacyCamera.swift +++ b/submodules/TelegramUI/TelegramUI/LegacyCamera.swift @@ -20,7 +20,7 @@ func presentedLegacyCamera(context: AccountContext, peer: Peer, cameraView: TGAt legacyController.deferScreenEdgeGestures = [.top] let isSecretChat = peer.id.namespace == Namespaces.Peer.SecretChat - + let controller: TGCameraController if let cameraView = cameraView, let previewView = cameraView.previewView() { controller = TGCameraController(context: legacyController.context, saveEditedPhotos: saveCapturedPhotos && !isSecretChat, saveCapturedMedia: saveCapturedPhotos && !isSecretChat, camera: previewView.camera, previewView: previewView, intent: TGCameraControllerGenericIntent) @@ -28,6 +28,7 @@ func presentedLegacyCamera(context: AccountContext, peer: Peer, cameraView: TGAt } else { controller = TGCameraController() } + controller.defaultVideoPreset = defaultVideoPresetForContext(context) controller.presentScheduleController = { done in presentSchedulePicker { time in diff --git a/submodules/TelegramUI/TelegramUI/ListMessageFileItemNode.swift b/submodules/TelegramUI/TelegramUI/ListMessageFileItemNode.swift index 030f40ed65..b6e759f72f 100644 --- a/submodules/TelegramUI/TelegramUI/ListMessageFileItemNode.swift +++ b/submodules/TelegramUI/TelegramUI/ListMessageFileItemNode.swift @@ -741,10 +741,10 @@ final class ListMessageFileItemNode: ListMessageNode { } } - override func transitionNode(id: MessageId, media: Media) -> (ASDisplayNode, () -> (UIView?, UIView?))? { + override func transitionNode(id: MessageId, media: Media) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? { if let item = self.item, item.message.id == id, self.iconImageNode.supernode != nil { let iconImageNode = self.iconImageNode - return (self.iconImageNode, { [weak iconImageNode] in + return (self.iconImageNode, self.iconImageNode.bounds, { [weak iconImageNode] in return (iconImageNode?.view.snapshotContentTree(unhide: true), nil) }) } diff --git a/submodules/TelegramUI/TelegramUI/ListMessageNode.swift b/submodules/TelegramUI/TelegramUI/ListMessageNode.swift index ad9ff1b29b..f110ca203e 100644 --- a/submodules/TelegramUI/TelegramUI/ListMessageNode.swift +++ b/submodules/TelegramUI/TelegramUI/ListMessageNode.swift @@ -27,7 +27,7 @@ class ListMessageNode: ListViewItemNode { } } - func transitionNode(id: MessageId, media: Media) -> (ASDisplayNode, () -> (UIView?, UIView?))? { + func transitionNode(id: MessageId, media: Media) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? { return nil } diff --git a/submodules/TelegramUI/TelegramUI/ListMessageSnippetItemNode.swift b/submodules/TelegramUI/TelegramUI/ListMessageSnippetItemNode.swift index 55a3757745..d5154e082a 100644 --- a/submodules/TelegramUI/TelegramUI/ListMessageSnippetItemNode.swift +++ b/submodules/TelegramUI/TelegramUI/ListMessageSnippetItemNode.swift @@ -467,10 +467,10 @@ final class ListMessageSnippetItemNode: ListMessageNode { } } - override func transitionNode(id: MessageId, media: Media) -> (ASDisplayNode, () -> (UIView?, UIView?))? { + override func transitionNode(id: MessageId, media: Media) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? { if let item = self.item, item.message.id == id, self.iconImageNode.supernode != nil { let iconImageNode = self.iconImageNode - return (self.iconImageNode, { [weak iconImageNode] in + return (self.iconImageNode, self.iconImageNode.bounds, { [weak iconImageNode] in return (iconImageNode?.view.snapshotContentTree(unhide: true), nil) }) } diff --git a/submodules/TelegramUI/TelegramUI/OpenChatMessage.swift b/submodules/TelegramUI/TelegramUI/OpenChatMessage.swift index 62bc293ab0..b8bdff1ac2 100644 --- a/submodules/TelegramUI/TelegramUI/OpenChatMessage.swift +++ b/submodules/TelegramUI/TelegramUI/OpenChatMessage.swift @@ -270,7 +270,7 @@ func openChatMessageImpl(_ params: OpenChatMessageParams) -> Bool { params.dismissInput() params.present(gallery, InstantPageGalleryControllerPresentationArguments(transitionArguments: { entry in - var selectedTransitionNode: (ASDisplayNode, () -> (UIView?, UIView?))? + var selectedTransitionNode: (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? if entry.index == centralIndex { selectedTransitionNode = params.transitionNode(params.message.id, galleryMedia) } @@ -304,13 +304,7 @@ func openChatMessageImpl(_ params: OpenChatMessageParams) -> Bool { params.navigationController?.pushViewController(controller) return true case let .stickerPack(reference): - if true { - let controller = StickerPackScreen(context: params.context, stickerPacks: [reference], selectedStickerPackIndex: 0, sendSticker: params.sendSticker) - params.dismissInput() - params.present(controller, nil) - return true - } - let controller = StickerPackScreen(context: params.context, stickerPacks: [reference], parentNavigationController: params.navigationController, sendSticker: params.sendSticker) + let controller = StickerPackScreen(context: params.context, mainStickerPack: reference, stickerPacks: [reference], sendSticker: params.sendSticker) params.dismissInput() params.present(controller, nil) return true diff --git a/submodules/TelegramUI/TelegramUI/OpenResolvedUrl.swift b/submodules/TelegramUI/TelegramUI/OpenResolvedUrl.swift index 865ac810b8..631210f487 100644 --- a/submodules/TelegramUI/TelegramUI/OpenResolvedUrl.swift +++ b/submodules/TelegramUI/TelegramUI/OpenResolvedUrl.swift @@ -89,12 +89,11 @@ func openResolvedUrlImpl(_ resolvedUrl: ResolvedUrl, context: AccountContext, ur openPeer(peerId, .chat(textInputState: nil, subject: .message(messageId))) case let .stickerPack(name): dismissInput() - if true { + if false { + var mainStickerPack: StickerPackReference? var stickerPacks: [StickerPackReference] = [] - var initialIndex: Int = 0 if let message = contentContext as? Message { let dataDetector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType([.link]).rawValue) - var foundMain = false if let matches = dataDetector?.matches(in: message.text, options: [], range: NSRange(message.text.startIndex ..< message.text.endIndex, in: message.text)) { for match in matches { guard let stringRange = Range(match.range, in: message.text) else { @@ -104,29 +103,28 @@ func openResolvedUrlImpl(_ resolvedUrl: ResolvedUrl, context: AccountContext, ur if let resultName = parseStickerPackUrl(urlText) { stickerPacks.append(.name(resultName)) if resultName == name { - foundMain = true - initialIndex = stickerPacks.count - 1 + mainStickerPack = .name(resultName) } } } - if !foundMain { + if mainStickerPack == nil { + mainStickerPack = .name(name) stickerPacks.insert(.name(name), at: 0) - initialIndex = 0 } } else { + mainStickerPack = .name(name) stickerPacks = [.name(name)] - initialIndex = 0 } } else { + mainStickerPack = .name(name) stickerPacks = [.name(name)] - initialIndex = 0 } - if !stickerPacks.isEmpty { - let controller = StickerPackScreen(context: context, stickerPacks: stickerPacks, selectedStickerPackIndex: initialIndex, sendSticker: sendSticker) + if let mainStickerPack = mainStickerPack, !stickerPacks.isEmpty { + let controller = StickerPackScreen(context: context, mainStickerPack: mainStickerPack, stickerPacks: stickerPacks, sendSticker: sendSticker) present(controller, nil) } } else { - let controller = StickerPackScreen(context: context, stickerPacks: [.name(name)], parentNavigationController: navigationController, sendSticker: sendSticker) + let controller = StickerPackScreen(context: context, mainStickerPack: .name(name), stickerPacks: [.name(name)], parentNavigationController: navigationController, sendSticker: sendSticker) present(controller, nil) } case let .instantView(webpage, anchor): diff --git a/submodules/TelegramUI/TelegramUI/PeerMediaCollectionControllerNode.swift b/submodules/TelegramUI/TelegramUI/PeerMediaCollectionControllerNode.swift index 37a4f202db..42b7f08b9a 100644 --- a/submodules/TelegramUI/TelegramUI/PeerMediaCollectionControllerNode.swift +++ b/submodules/TelegramUI/TelegramUI/PeerMediaCollectionControllerNode.swift @@ -508,14 +508,14 @@ class PeerMediaCollectionControllerNode: ASDisplayNode { return nil } - func transitionNodeForGallery(messageId: MessageId, media: Media) -> (ASDisplayNode, () -> (UIView?, UIView?))? { + func transitionNodeForGallery(messageId: MessageId, media: Media) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? { if let searchContentNode = self.searchDisplayController?.contentNode as? ChatHistorySearchContainerNode { if let transitionNode = searchContentNode.transitionNodeForGallery(messageId: messageId, media: media) { return transitionNode } } - var transitionNode: (ASDisplayNode, () -> (UIView?, UIView?))? + var transitionNode: (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? self.historyNode.forEachItemNode { itemNode in if let itemNode = itemNode as? ChatMessageItemView { if let result = itemNode.transitionNode(id: messageId, media: media) { diff --git a/submodules/TelegramUI/TelegramUI/SharedAccountContext.swift b/submodules/TelegramUI/TelegramUI/SharedAccountContext.swift index 0ac70353b0..ecefac629f 100644 --- a/submodules/TelegramUI/TelegramUI/SharedAccountContext.swift +++ b/submodules/TelegramUI/TelegramUI/SharedAccountContext.swift @@ -129,6 +129,10 @@ public final class SharedAccountContextImpl: SharedAccountContext { return self._automaticMediaDownloadSettings.get() } + public let currentAutodownloadSettings: Atomic + private let _autodownloadSettings = Promise() + private var currentAutodownloadSettingsDisposable = MetaDisposable() + public let currentMediaInputSettings: Atomic private var mediaInputSettingsDisposable: Disposable? @@ -179,6 +183,7 @@ public final class SharedAccountContextImpl: SharedAccountContext { self._currentPresentationData = Atomic(value: initialPresentationDataAndSettings.presentationData) self.currentAutomaticMediaDownloadSettings = Atomic(value: initialPresentationDataAndSettings.automaticMediaDownloadSettings) + self.currentAutodownloadSettings = Atomic(value: initialPresentationDataAndSettings.autodownloadSettings) self.currentMediaInputSettings = Atomic(value: initialPresentationDataAndSettings.mediaInputSettings) self.currentInAppNotificationSettings = Atomic(value: initialPresentationDataAndSettings.inAppNotificationSettings) @@ -198,6 +203,14 @@ public final class SharedAccountContextImpl: SharedAccountContext { self.mediaManager = MediaManagerImpl(accountManager: accountManager, inForeground: applicationBindings.applicationInForeground, presentationData: presentationData) + self._autodownloadSettings.set(.single(initialPresentationDataAndSettings.autodownloadSettings) + |> then(accountManager.sharedData(keys: [SharedDataKeys.autodownloadSettings]) + |> map { sharedData in + let autodownloadSettings: AutodownloadSettings = sharedData.entries[SharedDataKeys.autodownloadSettings] as? AutodownloadSettings ?? .defaultSettings + return autodownloadSettings + } + )) + self.presentationDataDisposable.set((self.presentationData |> deliverOnMainQueue).start(next: { [weak self] next in if let strongSelf = self { @@ -269,6 +282,12 @@ public final class SharedAccountContextImpl: SharedAccountContext { } })) + self.currentAutodownloadSettingsDisposable.set(self._autodownloadSettings.get().start(next: { [weak self] next in + if let strongSelf = self { + let _ = strongSelf.currentAutodownloadSettings.swap(next) + } + })) + let startTime = CFAbsoluteTimeGetCurrent() let differenceDisposable = MetaDisposable() @@ -653,6 +672,7 @@ public final class SharedAccountContextImpl: SharedAccountContext { self.registeredNotificationTokensDisposable.dispose() self.presentationDataDisposable.dispose() self.automaticMediaDownloadSettingsDisposable.dispose() + self.currentAutodownloadSettingsDisposable.dispose() self.inAppNotificationSettingsDisposable?.dispose() self.mediaInputSettingsDisposable?.dispose() self.callDisposable?.dispose() diff --git a/submodules/TelegramUI/TelegramUI/StickerPaneSearchContentNode.swift b/submodules/TelegramUI/TelegramUI/StickerPaneSearchContentNode.swift index 78f0fa5e5b..7d4cb872a6 100644 --- a/submodules/TelegramUI/TelegramUI/StickerPaneSearchContentNode.swift +++ b/submodules/TelegramUI/TelegramUI/StickerPaneSearchContentNode.swift @@ -217,8 +217,8 @@ final class StickerPaneSearchContentNode: ASDisplayNode, PaneSearchContentNode { self.interaction = StickerPaneSearchInteraction(open: { [weak self] info in if let strongSelf = self { strongSelf.view.window?.endEditing(true) - - let controller = StickerPackScreen(context: strongSelf.context, stickerPacks: [.id(id: info.id.id, accessHash: info.accessHash)], parentNavigationController: strongSelf.controllerInteraction.navigationController(), sendSticker: { [weak self] fileReference, sourceNode, sourceRect in + let packReference: StickerPackReference = .id(id: info.id.id, accessHash: info.accessHash) + let controller = StickerPackScreen(context: strongSelf.context, mainStickerPack: packReference, stickerPacks: [packReference], parentNavigationController: strongSelf.controllerInteraction.navigationController(), sendSticker: { [weak self] fileReference, sourceNode, sourceRect in if let strongSelf = self { return strongSelf.controllerInteraction.sendSticker(fileReference, false, sourceNode, sourceRect) } else { diff --git a/submodules/TelegramUI/TelegramUI/StickersChatInputContextPanelNode.swift b/submodules/TelegramUI/TelegramUI/StickersChatInputContextPanelNode.swift index 68dfedb9e8..0075a48ca7 100644 --- a/submodules/TelegramUI/TelegramUI/StickersChatInputContextPanelNode.swift +++ b/submodules/TelegramUI/TelegramUI/StickersChatInputContextPanelNode.swift @@ -148,7 +148,7 @@ final class StickersChatInputContextPanelNode: ChatInputContextPanelNode { switch attribute { case let .Sticker(_, packReference, _): if let packReference = packReference { - let controller = StickerPackScreen(context: strongSelf.context, stickerPacks: [packReference], parentNavigationController: controllerInteraction.navigationController(), sendSticker: { file, sourceNode, sourceRect in + let controller = StickerPackScreen(context: strongSelf.context, mainStickerPack: packReference, stickerPacks: [packReference], parentNavigationController: controllerInteraction.navigationController(), sendSticker: { file, sourceNode, sourceRect in if let strongSelf = self, let controllerInteraction = strongSelf.controllerInteraction { return controllerInteraction.sendSticker(file, true, sourceNode, sourceRect) } else { diff --git a/submodules/TelegramUI/TelegramUI/TextLinkHandling.swift b/submodules/TelegramUI/TelegramUI/TextLinkHandling.swift index 369e56d0ac..cc46c4172e 100644 --- a/submodules/TelegramUI/TelegramUI/TextLinkHandling.swift +++ b/submodules/TelegramUI/TelegramUI/TextLinkHandling.swift @@ -58,7 +58,8 @@ func handleTextLinkActionImpl(context: AccountContext, peerId: PeerId?, navigate context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: navigationController, context: context, chatLocation: .peer(peerId), subject: .message(messageId))) } case let .stickerPack(name): - controller.present(StickerPackScreen(context: context, stickerPacks: [.name(name)], parentNavigationController: controller.navigationController as? NavigationController), in: .window(.root)) + let packReference: StickerPackReference = .name(name) + controller.present(StickerPackScreen(context: context, mainStickerPack: packReference, stickerPacks: [packReference], parentNavigationController: controller.navigationController as? NavigationController), in: .window(.root)) case let .instantView(webpage, anchor): (controller.navigationController as? NavigationController)?.pushViewController(InstantPageController(context: context, webPage: webpage, sourcePeerType: .group, anchor: anchor)) case let .join(link): diff --git a/submodules/WebSearchUI/Sources/LegacyWebSearchEditor.swift b/submodules/WebSearchUI/Sources/LegacyWebSearchEditor.swift index 5fb3ac16d1..09b4732606 100644 --- a/submodules/WebSearchUI/Sources/LegacyWebSearchEditor.swift +++ b/submodules/WebSearchUI/Sources/LegacyWebSearchEditor.swift @@ -35,7 +35,7 @@ func presentLegacyWebSearchEditor(context: AccountContext, theme: PresentationTh let legacyController = LegacyController(presentation: .custom, theme: theme, initialLayout: initialLayout) legacyController.statusBar.statusBarStyle = theme.rootController.statusBarStyle.style - let controller = TGPhotoEditorController(context: legacyController.context, item: item, intent: TGPhotoEditorControllerAvatarIntent, adjustments: nil, caption: nil, screenImage: screenImage ?? UIImage(), availableTabs: TGPhotoEditorController.defaultTabsForAvatarIntent(), selectedTab: .cropTab)! + let controller = TGPhotoEditorController(context: legacyController.context, item: item, intent: TGPhotoEditorControllerAvatarIntent, adjustments: nil, caption: nil, screenImage: screenImage ?? UIImage(), availableTabs: TGPhotoEditorController.defaultTabsForAvatarIntent(), selectedTab: .cropTab, defaultVideoPreset: TGMediaVideoConversionPresetCompressedDefault)! legacyController.bind(controller: controller) controller.editingContext = TGMediaEditingContext() diff --git a/submodules/WebSearchUI/Sources/LegacyWebSearchGallery.swift b/submodules/WebSearchUI/Sources/LegacyWebSearchGallery.swift index 7eaf2e7ba7..79f061802a 100644 --- a/submodules/WebSearchUI/Sources/LegacyWebSearchGallery.swift +++ b/submodules/WebSearchUI/Sources/LegacyWebSearchGallery.swift @@ -323,7 +323,7 @@ func presentLegacyWebSearchGallery(context: AccountContext, peer: Peer?, present let (items, focusItem) = galleryItems(account: context.account, results: results, current: current, selectionContext: selectionContext, editingContext: editingContext) - let model = TGMediaPickerGalleryModel(context: legacyController.context, items: items, focus: focusItem, selectionContext: selectionContext, editingContext: editingContext, hasCaptions: false, allowCaptionEntities: true, hasTimer: false, onlyCrop: false, inhibitDocumentCaptions: false, hasSelectionPanel: false, hasCamera: false, recipientName: peer?.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder))! + let model = TGMediaPickerGalleryModel(context: legacyController.context, items: items, focus: focusItem, selectionContext: selectionContext, editingContext: editingContext, hasCaptions: false, allowCaptionEntities: true, hasTimer: false, onlyCrop: false, inhibitDocumentCaptions: false, hasSelectionPanel: false, hasCamera: false, recipientName: peer?.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder), defaultVideoPreset: TGMediaVideoConversionPresetCompressedDefault)! if let peer = peer { model.suggestionContext = legacySuggestionContext(context: context, peerId: peer.id) } diff --git a/submodules/WebSearchUI/Sources/WebSearchControllerNode.swift b/submodules/WebSearchUI/Sources/WebSearchControllerNode.swift index 00edc86d92..c180b8a1ef 100644 --- a/submodules/WebSearchUI/Sources/WebSearchControllerNode.swift +++ b/submodules/WebSearchUI/Sources/WebSearchControllerNode.swift @@ -711,7 +711,7 @@ class WebSearchControllerNode: ASDisplayNode { } } if let transitionNode = transitionNode { - return GalleryTransitionArguments(transitionNode: (transitionNode, { [weak transitionNode] in + return GalleryTransitionArguments(transitionNode: (transitionNode, transitionNode.bounds, { [weak transitionNode] in return (transitionNode?.transitionView().snapshotContentTree(unhide: true), nil) }), addToTransitionSurface: { view in if let strongSelf = self { diff --git a/submodules/WebSearchUI/Sources/WebSearchVideoGalleryItem.swift b/submodules/WebSearchUI/Sources/WebSearchVideoGalleryItem.swift index ee199f8778..498a758306 100644 --- a/submodules/WebSearchUI/Sources/WebSearchVideoGalleryItem.swift +++ b/submodules/WebSearchUI/Sources/WebSearchVideoGalleryItem.swift @@ -284,7 +284,7 @@ final class WebSearchVideoGalleryItemNode: ZoomableContentGalleryItemNode { } } - override func animateIn(from node: (ASDisplayNode, () -> (UIView?, UIView?)), addToTransitionSurface: (UIView) -> Void) { + override func animateIn(from node: (ASDisplayNode, CGRect, () -> (UIView?, UIView?)), addToTransitionSurface: (UIView) -> Void) { guard let videoNode = self.videoNode else { return } @@ -307,8 +307,8 @@ final class WebSearchVideoGalleryItemNode: ZoomableContentGalleryItemNode { let transformedSelfFrame = node.0.view.convert(node.0.view.bounds, to: self.view) let transformedCopyViewFinalFrame = videoNode.view.convert(videoNode.view.bounds, to: self.view) - let surfaceCopyView = node.1().0! - let copyView = node.1().0! + let surfaceCopyView = node.2().0! + let copyView = node.2().0! addToTransitionSurface(surfaceCopyView) @@ -361,7 +361,7 @@ final class WebSearchVideoGalleryItemNode: ZoomableContentGalleryItemNode { } } - override func animateOut(to node: (ASDisplayNode, () -> (UIView?, UIView?)), addToTransitionSurface: (UIView) -> Void, completion: @escaping () -> Void) { + override func animateOut(to node: (ASDisplayNode, CGRect, () -> (UIView?, UIView?)), addToTransitionSurface: (UIView) -> Void, completion: @escaping () -> Void) { guard let videoNode = self.videoNode else { completion() return @@ -376,8 +376,8 @@ final class WebSearchVideoGalleryItemNode: ZoomableContentGalleryItemNode { var boundsCompleted = false var copyCompleted = false - let copyView = node.1().0! - let surfaceCopyView = node.1().0! + let copyView = node.2().0! + let surfaceCopyView = node.2().0! addToTransitionSurface(surfaceCopyView)