From c77dd504f23e822f290e298bbd898c1edd581357 Mon Sep 17 00:00:00 2001 From: overtake <> Date: Tue, 23 Jul 2019 14:41:48 +0200 Subject: [PATCH 01/16] no message --- submodules/TelegramCore/TelegramCore/ApplyUpdateMessage.swift | 2 +- .../TelegramCore/TelegramCore/ChannelAdminEventLogs.swift | 3 ++- submodules/TelegramCore/TelegramCore/TelegramMediaFile.swift | 4 +++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/submodules/TelegramCore/TelegramCore/ApplyUpdateMessage.swift b/submodules/TelegramCore/TelegramCore/ApplyUpdateMessage.swift index 17feefe1c0..851095631b 100644 --- a/submodules/TelegramCore/TelegramCore/ApplyUpdateMessage.swift +++ b/submodules/TelegramCore/TelegramCore/ApplyUpdateMessage.swift @@ -191,7 +191,7 @@ func applyUpdateMessage(postbox: Postbox, stateManager: AccountStateManager, mes } - return .update(StoreMessage(id: updatedId, globallyUniqueId: nil, groupingKey: currentMessage.groupingKey, timestamp: updatedTimestamp ?? currentMessage.timestamp, flags: [], tags: tags, globalTags: globalTags, localTags: currentMessage.localTags, forwardInfo: forwardInfo, authorId: currentMessage.author?.id, text: text, attributes: attributes, media: media)) + return .update(StoreMessage(id: updatedId, globallyUniqueId: currentMessage.globallyUniqueId, groupingKey: currentMessage.groupingKey, timestamp: updatedTimestamp ?? currentMessage.timestamp, flags: [], tags: tags, globalTags: globalTags, localTags: currentMessage.localTags, forwardInfo: forwardInfo, authorId: currentMessage.author?.id, text: text, attributes: attributes, media: media)) }) for file in sentStickers { transaction.addOrMoveToFirstPositionOrderedItemListItem(collectionId: Namespaces.OrderedItemList.CloudRecentStickers, item: OrderedItemListEntry(id: RecentMediaItemId(file.fileId).rawValue, contents: RecentMediaItem(file)), removeTailIfCountExceeds: 20) diff --git a/submodules/TelegramCore/TelegramCore/ChannelAdminEventLogs.swift b/submodules/TelegramCore/TelegramCore/ChannelAdminEventLogs.swift index a169b27cc7..6adb0f1371 100644 --- a/submodules/TelegramCore/TelegramCore/ChannelAdminEventLogs.swift +++ b/submodules/TelegramCore/TelegramCore/ChannelAdminEventLogs.swift @@ -48,6 +48,7 @@ public enum AdminLogEventAction { case changePhoto(prev: [TelegramMediaImageRepresentation], new: [TelegramMediaImageRepresentation]) case toggleInvites(Bool) case toggleSignatures(Bool) + case toggleSlowMode(prev: Int32, newValue: Int32) case updatePinned(Message?) case editMessage(prev: Message, new: Message) case deleteMessage(Message) @@ -219,7 +220,7 @@ public func channelAdminLogEvents(postbox: Postbox, network: Network, peerId: Pe case let .channelAdminLogEventActionChangeLocation(prevValue, newValue): action = .changeGeoLocation(previous: PeerGeoLocation(apiLocation: prevValue), updated: PeerGeoLocation(apiLocation: newValue)) case let .channelAdminLogEventActionToggleSlowMode(prevValue, newValue): - break + action = .toggleSlowMode(prev: prevValue, newValue: newValue) } let peerId = PeerId(namespace: Namespaces.Peer.CloudUser, id: userId) if let action = action { diff --git a/submodules/TelegramCore/TelegramCore/TelegramMediaFile.swift b/submodules/TelegramCore/TelegramCore/TelegramMediaFile.swift index 143062cdfe..f0122003a7 100644 --- a/submodules/TelegramCore/TelegramCore/TelegramMediaFile.swift +++ b/submodules/TelegramCore/TelegramCore/TelegramMediaFile.swift @@ -330,7 +330,9 @@ public final class TelegramMediaFile: Media, Equatable { public var isSticker: Bool { for attribute in self.attributes { if case .Sticker = attribute { - return !isAnimatedSticker + if let s = self.size, s < 200 * 1024 { + return !isAnimatedSticker + } } } return false From 78c29f54bff123ffd1ae4c103fed0be1f6eee937 Mon Sep 17 00:00:00 2001 From: overtake <> Date: Fri, 26 Jul 2019 13:14:10 +0200 Subject: [PATCH 02/16] signal: struct -> final class --- submodules/SSignalKit/SwiftSignalKit/Signal.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/submodules/SSignalKit/SwiftSignalKit/Signal.swift b/submodules/SSignalKit/SwiftSignalKit/Signal.swift index 1bedb501ce..cdde287573 100644 --- a/submodules/SSignalKit/SwiftSignalKit/Signal.swift +++ b/submodules/SSignalKit/SwiftSignalKit/Signal.swift @@ -38,7 +38,7 @@ private final class SubscriberDisposable : Disposable { } } -public struct Signal { +public final class Signal { private let generator: (Subscriber) -> Disposable public init(_ generator: @escaping(Subscriber) -> Disposable) { From 1f83851c8d3b1e3a3f1d0824ec4b2cc5be464aae Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Tue, 30 Jul 2019 11:55:19 +0300 Subject: [PATCH 03/16] Fixed monochrome theme badge colors --- .../Sources/DefaultDarkPresentationTheme.swift | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/submodules/TelegramPresentationData/Sources/DefaultDarkPresentationTheme.swift b/submodules/TelegramPresentationData/Sources/DefaultDarkPresentationTheme.swift index 065478e63d..aa7ca199b8 100644 --- a/submodules/TelegramPresentationData/Sources/DefaultDarkPresentationTheme.swift +++ b/submodules/TelegramPresentationData/Sources/DefaultDarkPresentationTheme.swift @@ -6,19 +6,22 @@ private func makeDarkPresentationTheme(accentColor: UIColor, preview: Bool) -> P let constructiveColor: UIColor = UIColor(rgb: 0x08a723) let secretColor: UIColor = UIColor(rgb: 0x00b12c) + let badgeFillColor: UIColor let badgeTextColor: UIColor let outgoingBubbleFillColor: UIColor let outgoingBubbleHighlightedFillColor: UIColor let outgoingScamColor: UIColor if accentColor.rgb == UIColor.white.rgb { + badgeFillColor = .white badgeTextColor = .black outgoingBubbleFillColor = UIColor(rgb: 0x313131) outgoingBubbleHighlightedFillColor = UIColor(rgb: 0x464646) outgoingScamColor = destructiveColor } else { - outgoingBubbleFillColor = accentColor + badgeFillColor = destructiveColor badgeTextColor = .white + outgoingBubbleFillColor = accentColor outgoingBubbleHighlightedFillColor = accentColor.withMultipliedBrightnessBy(1.421) outgoingScamColor = .white } @@ -30,9 +33,9 @@ private func makeDarkPresentationTheme(accentColor: UIColor, preview: Bool) -> P selectedIconColor: accentColor, textColor: UIColor(rgb: 0x828282), selectedTextColor: accentColor, - badgeBackgroundColor: destructiveColor, + badgeBackgroundColor: badgeFillColor, badgeStrokeColor: UIColor(rgb: 0x1c1c1d), - badgeTextColor: UIColor(rgb: 0xffffff) + badgeTextColor: badgeTextColor ) let rootNavigationBar = PresentationThemeRootNavigationBar( @@ -44,9 +47,9 @@ private func makeDarkPresentationTheme(accentColor: UIColor, preview: Bool) -> P accentTextColor: accentColor, backgroundColor: UIColor(rgb: 0x1c1c1d), separatorColor: UIColor(rgb: 0x3d3d40), - badgeBackgroundColor: destructiveColor, + badgeBackgroundColor: badgeFillColor, badgeStrokeColor: UIColor(rgb: 0x1c1c1d), - badgeTextColor: UIColor(rgb: 0xffffff) + badgeTextColor: badgeTextColor ) let navigationSearchBar = PresentationThemeNavigationSearchBar( @@ -252,7 +255,7 @@ private func makeDarkPresentationTheme(accentColor: UIColor, preview: Bool) -> P foregroundColor: .white, badgeBackgroundColor: accentColor, badgeStrokeColor: accentColor, - badgeTextColor: .white + badgeTextColor: badgeTextColor ) let chat = PresentationThemeChat( From a9119e69bbab3cc00e4db4b2e1d701249d925c7c Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Tue, 30 Jul 2019 11:59:35 +0300 Subject: [PATCH 04/16] Fixed phone label screen title --- submodules/TelegramUI/TelegramUI/PhoneLabelController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/submodules/TelegramUI/TelegramUI/PhoneLabelController.swift b/submodules/TelegramUI/TelegramUI/PhoneLabelController.swift index f22b84e79b..77af1cdd18 100644 --- a/submodules/TelegramUI/TelegramUI/PhoneLabelController.swift +++ b/submodules/TelegramUI/TelegramUI/PhoneLabelController.swift @@ -114,7 +114,7 @@ public func phoneLabelController(context: AccountContext, currentLabel: String, arguments.complete() }) - let controllerState = ItemListControllerState(theme: presentationData.theme, title: .text(presentationData.strings.Notifications_TextTone), leftNavigationButton: leftNavigationButton, rightNavigationButton: rightNavigationButton, backNavigationButton: ItemListBackButton(title: presentationData.strings.Common_Back)) + let controllerState = ItemListControllerState(theme: presentationData.theme, title: .text(presentationData.strings.PhoneLabel_Title), leftNavigationButton: leftNavigationButton, rightNavigationButton: rightNavigationButton, backNavigationButton: ItemListBackButton(title: presentationData.strings.Common_Back)) let listState = ItemListNodeState(entries: phoneLabelEntries(presentationData: presentationData, state: state), style: .blocks) return (controllerState, (listState, arguments)) From 43694a7cdb8f305fb2f31520d85afd19db7c5d0f Mon Sep 17 00:00:00 2001 From: overtake <> Date: Tue, 30 Jul 2019 11:36:34 +0200 Subject: [PATCH 05/16] - changed default cache media settings to 7 days. --- submodules/TelegramCore/TelegramCore/CacheStorageSettings.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/submodules/TelegramCore/TelegramCore/CacheStorageSettings.swift b/submodules/TelegramCore/TelegramCore/CacheStorageSettings.swift index 0bb345caaf..94bec9c653 100644 --- a/submodules/TelegramCore/TelegramCore/CacheStorageSettings.swift +++ b/submodules/TelegramCore/TelegramCore/CacheStorageSettings.swift @@ -11,7 +11,7 @@ public struct CacheStorageSettings: PreferencesEntry, Equatable { public let defaultCacheStorageTimeout: Int32 public static var defaultSettings: CacheStorageSettings { - return CacheStorageSettings(defaultCacheStorageTimeout: Int32.max) + return CacheStorageSettings(defaultCacheStorageTimeout: 7 * 60 * 60 * 24) } init(defaultCacheStorageTimeout: Int32) { From e1aa23e714c0eca05d9ba129fc0132cff84cf6fc Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Tue, 30 Jul 2019 13:48:34 +0300 Subject: [PATCH 06/16] Various UI fixes --- submodules/RLottie/Sources/LottieInstance.mm | 2 +- .../TelegramUI/AnimatedStickerNode.swift | 14 +++++++++++--- .../TelegramUI/ChannelAdminController.swift | 10 +++++++--- .../ChatMessageAnimatedStickerItemNode.swift | 18 +++++++++++++----- ...tSendMessageActionSheetControllerNode.swift | 11 ++++++++++- .../GlobalExperimentalSettings.swift | 1 - 6 files changed, 42 insertions(+), 14 deletions(-) diff --git a/submodules/RLottie/Sources/LottieInstance.mm b/submodules/RLottie/Sources/LottieInstance.mm index 0b567f0dd6..e1859ef694 100644 --- a/submodules/RLottie/Sources/LottieInstance.mm +++ b/submodules/RLottie/Sources/LottieInstance.mm @@ -31,7 +31,7 @@ _dimensions = CGSizeMake(width, height); - if ((_frameRate > 60) || _animation->duration() > 4.5) { + if ((_frameRate > 60) || _animation->duration() > 7.0) { return nil; } } diff --git a/submodules/TelegramUI/TelegramUI/AnimatedStickerNode.swift b/submodules/TelegramUI/TelegramUI/AnimatedStickerNode.swift index 733e2374a5..a4a56c95d3 100644 --- a/submodules/TelegramUI/TelegramUI/AnimatedStickerNode.swift +++ b/submodules/TelegramUI/TelegramUI/AnimatedStickerNode.swift @@ -82,12 +82,14 @@ private final class AnimatedStickerFrame { let type: AnimationRendererFrameType let width: Int let height: Int + let isLastFrame: Bool - init(data: Data, type: AnimationRendererFrameType, width: Int, height: Int) { + init(data: Data, type: AnimationRendererFrameType, width: Int, height: Int, isLastFrame: Bool) { self.data = data self.type = type self.width = width self.height = height + self.isLastFrame = isLastFrame } } @@ -162,6 +164,7 @@ private final class AnimatedStickerCachedFrameSource: AnimatedStickerFrameSource func takeFrame() -> AnimatedStickerFrame { var frameData: Data? + var isLastFrame = false let dataLength = self.data.count let decodeBufferLength = self.decodeBuffer.count @@ -192,6 +195,7 @@ private final class AnimatedStickerCachedFrameSource: AnimatedStickerFrameSource self.offset += Int(frameLength) if self.offset == dataLength { + isLastFrame = true self.offset = self.initialOffset self.frameBuffer.withUnsafeMutableBytes { (bytes: UnsafeMutablePointer) -> Void in memset(bytes, 0, frameBufferLength) @@ -199,7 +203,7 @@ private final class AnimatedStickerCachedFrameSource: AnimatedStickerFrameSource } } - return AnimatedStickerFrame(data: frameData!, type: .yuva, width: self.width, height: self.height) + return AnimatedStickerFrame(data: frameData!, type: .yuva, width: self.width, height: self.height, isLastFrame: isLastFrame) } } @@ -243,7 +247,7 @@ private final class AnimatedStickerDirectFrameSource: AnimatedStickerFrameSource memset(bytes, 0, self.width * self.height * 4) self.animation.renderFrame(with: Int32(frameIndex), into: bytes, width: Int32(self.width), height: Int32(self.height)) } - return AnimatedStickerFrame(data: frameData, type: .argb, width: self.width, height: self.height) + return AnimatedStickerFrame(data: frameData, type: .argb, width: self.width, height: self.height, isLastFrame: frameIndex == self.frameCount) } } @@ -434,6 +438,10 @@ final class AnimatedStickerNode: ASDisplayNode { strongSelf.started() } }) + if case .once = strongSelf.playbackMode, frame.isLastFrame { + strongSelf.stop() + strongSelf.isPlaying = false + } } } frameQueue.with { frameQueue in diff --git a/submodules/TelegramUI/TelegramUI/ChannelAdminController.swift b/submodules/TelegramUI/TelegramUI/ChannelAdminController.swift index d61b285553..f2f180eacb 100644 --- a/submodules/TelegramUI/TelegramUI/ChannelAdminController.swift +++ b/submodules/TelegramUI/TelegramUI/ChannelAdminController.swift @@ -892,7 +892,7 @@ public func channelAdminController(context: AccountContext, peerId: PeerId, admi return current } - if let updateRank = updateRank, updateRank.count > rankMaxLength { + if let updateRank = updateRank, updateRank.count > rankMaxLength || updateRank.containsEmoji { errorImpl?() return } @@ -928,6 +928,10 @@ public func channelAdminController(context: AccountContext, peerId: PeerId, admi } let effectiveRank = updateRank ?? currentRank + if effectiveRank?.containsEmoji ?? false { + errorImpl?() + return + } if let updateFlags = updateFlags { updateState { current in @@ -961,7 +965,7 @@ public func channelAdminController(context: AccountContext, peerId: PeerId, admi return current } - if let updateRank = updateRank, updateRank.count > rankMaxLength { + if let updateRank = updateRank, updateRank.count > rankMaxLength || updateRank.containsEmoji { errorImpl?() return } @@ -1014,7 +1018,7 @@ public func channelAdminController(context: AccountContext, peerId: PeerId, admi return current } - if let updateRank = updateRank, updateRank.count > rankMaxLength { + if let updateRank = updateRank, updateRank.count > rankMaxLength || updateRank.containsEmoji { errorImpl?() return } diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageAnimatedStickerItemNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageAnimatedStickerItemNode.swift index fda6d0d21d..0eab5d0e7d 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageAnimatedStickerItemNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageAnimatedStickerItemNode.swift @@ -153,11 +153,11 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView { return } - let isPlaying = self.visibilityStatus && item.controllerInteraction.stickerSettings.loopAnimatedStickers + let isPlaying = self.visibilityStatus if self.isPlaying != isPlaying { self.isPlaying = isPlaying self.animationNode.visibility = isPlaying - if let item = self.item, isPlaying, !self.didSetUpAnimationNode { + if self.isPlaying && !self.didSetUpAnimationNode { self.didSetUpAnimationNode = true var telegramFile: TelegramMediaFile? for media in item.message.media { @@ -166,11 +166,19 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView { break } } - + if let telegramFile = telegramFile { - self.animationNode.setup(account: item.context.account, resource: telegramFile.resource, width: 384, height: 384, mode: .cached) + var playbackMode: AnimatedStickerPlaybackMode = .loop + if !item.controllerInteraction.stickerSettings.loopAnimatedStickers { + playbackMode = .once + } + self.animationNode.setup(account: item.context.account, resource: telegramFile.resource, width: 384, height: 384, playbackMode: playbackMode, mode: .cached) } else if let emojiResource = self.emojiResource { - self.animationNode.setup(account: item.context.account, resource: emojiResource, width: 384, height: 384, mode: .cached) + var playbackMode: AnimatedStickerPlaybackMode = .loop + if item.context.sharedContext.immediateExperimentalUISettings.playAnimatedEmojiOnce { + playbackMode = .once + } + self.animationNode.setup(account: item.context.account, resource: emojiResource, width: 384, height: 384, playbackMode: playbackMode, mode: .cached) } } } diff --git a/submodules/TelegramUI/TelegramUI/ChatSendMessageActionSheetControllerNode.swift b/submodules/TelegramUI/TelegramUI/ChatSendMessageActionSheetControllerNode.swift index 6ac1668cf7..43b3567ceb 100644 --- a/submodules/TelegramUI/TelegramUI/ChatSendMessageActionSheetControllerNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatSendMessageActionSheetControllerNode.swift @@ -1,6 +1,7 @@ import Foundation import UIKit import AsyncDisplayKit +import SwiftSignalKit import Display import Postbox import TelegramCore @@ -44,7 +45,6 @@ private final class ActionSheetItemNode: ASDisplayNode { super.init() - self.addSubnode(self.separatorNode) self.addSubnode(self.highlightedBackgroundNode) self.addSubnode(self.titleNode) self.addSubnode(self.iconNode) @@ -389,6 +389,15 @@ final class ChatSendMessageActionSheetControllerNode: ViewControllerTracingNode, completedEffect = true intermediateCompletion() }) + + Queue.mainQueue().after(0.7) { + completedAlpha = true + completedButton = true + completedBubble = true + completedEffect = true + intermediateCompletion() + } + self.dimNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.3, removeOnCompletion: false) self.contentContainerNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, removeOnCompletion: false, completion: { _ in }) diff --git a/submodules/TelegramUI/TelegramUI/GlobalExperimentalSettings.swift b/submodules/TelegramUI/TelegramUI/GlobalExperimentalSettings.swift index 54dfa899e6..143bfa6a53 100644 --- a/submodules/TelegramUI/TelegramUI/GlobalExperimentalSettings.swift +++ b/submodules/TelegramUI/TelegramUI/GlobalExperimentalSettings.swift @@ -3,5 +3,4 @@ import Foundation public struct GlobalExperimentalSettings { public static var isAppStoreBuild: Bool = false public static var enableFeed: Bool = false - public static var animatedStickers: Bool = false } From 0f50b4ee6dd321a39595806a534277eae0e7fd70 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Tue, 30 Jul 2019 14:00:01 +0300 Subject: [PATCH 07/16] Play animated emoji on tap --- .../TelegramUI/AnimatedStickerNode.swift | 6 ++++ .../ChatMessageAnimatedStickerItemNode.swift | 36 +++++++++++-------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/submodules/TelegramUI/TelegramUI/AnimatedStickerNode.swift b/submodules/TelegramUI/TelegramUI/AnimatedStickerNode.swift index a4a56c95d3..168b692774 100644 --- a/submodules/TelegramUI/TelegramUI/AnimatedStickerNode.swift +++ b/submodules/TelegramUI/TelegramUI/AnimatedStickerNode.swift @@ -458,6 +458,12 @@ final class AnimatedStickerNode: ASDisplayNode { self.timer.swap(nil)?.invalidate() } + func playIfNeeded() { + if !self.isPlaying { + self.play() + } + } + func updateLayout(size: CGSize) { self.renderer?.frame = CGRect(origin: CGPoint(), size: size) } diff --git a/submodules/TelegramUI/TelegramUI/ChatMessageAnimatedStickerItemNode.swift b/submodules/TelegramUI/TelegramUI/ChatMessageAnimatedStickerItemNode.swift index 0eab5d0e7d..5b2fc88f74 100644 --- a/submodules/TelegramUI/TelegramUI/ChatMessageAnimatedStickerItemNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatMessageAnimatedStickerItemNode.swift @@ -654,26 +654,32 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView { if let item = self.item, self.imageNode.frame.contains(location) { if self.telegramFile != nil { let _ = item.controllerInteraction.openMessage(item.message, .default) - } else if let emoji = self.emojiResource, emoji.name == "heart" { - let hapticFeedback: HapticFeedback - if let currentHapticFeedback = self.hapticFeedback { - hapticFeedback = currentHapticFeedback - } else { - hapticFeedback = HapticFeedback() - self.hapticFeedback = hapticFeedback + } else if let emoji = self.emojiResource { + if item.context.sharedContext.immediateExperimentalUISettings.playAnimatedEmojiOnce { + self.animationNode.playIfNeeded() } - hapticFeedback.prepareImpact() - hapticFeedback.impact(.heavy) - Queue.mainQueue().after(0.2) { - hapticFeedback.impact(.medium) - Queue.mainQueue().after(0.68) { + + if emoji.name == "heart" { + let hapticFeedback: HapticFeedback + if let currentHapticFeedback = self.hapticFeedback { + hapticFeedback = currentHapticFeedback + } else { + hapticFeedback = HapticFeedback() + self.hapticFeedback = hapticFeedback + } + hapticFeedback.prepareImpact() + hapticFeedback.impact(.heavy) + Queue.mainQueue().after(0.2) { hapticFeedback.impact(.medium) - Queue.mainQueue().after(0.2) { + Queue.mainQueue().after(0.74) { hapticFeedback.impact(.medium) - Queue.mainQueue().after(0.68) { + Queue.mainQueue().after(0.2) { hapticFeedback.impact(.medium) - Queue.mainQueue().after(0.2) { + Queue.mainQueue().after(0.74) { hapticFeedback.impact(.medium) + Queue.mainQueue().after(0.2) { + hapticFeedback.impact(.medium) + } } } } From f778a52cb58e313736999bf4c5c5a1222ff45a33 Mon Sep 17 00:00:00 2001 From: Peter <> Date: Tue, 30 Jul 2019 16:47:53 +0300 Subject: [PATCH 08/16] Fix scrubbing node hitTest --- submodules/MediaPlayer/Sources/MediaPlayerScrubbingNode.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/submodules/MediaPlayer/Sources/MediaPlayerScrubbingNode.swift b/submodules/MediaPlayer/Sources/MediaPlayerScrubbingNode.swift index d7de8daf3e..03b4838a63 100644 --- a/submodules/MediaPlayer/Sources/MediaPlayerScrubbingNode.swift +++ b/submodules/MediaPlayer/Sources/MediaPlayerScrubbingNode.swift @@ -698,13 +698,13 @@ public final class MediaPlayerScrubbingNode: ASDisplayNode { override public func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? { switch self.contentNodes { case let .standard(node): - if let handleNodeContainer = node.handleNodeContainer, handleNodeContainer.isUserInteractionEnabled { + if let handleNodeContainer = node.handleNodeContainer, handleNodeContainer.isUserInteractionEnabled, handleNodeContainer.frame.insetBy(dx: 0.0, dy: -5.0).contains(point) { return handleNodeContainer.view } else { return nil } case let .custom(node): - if let handleNodeContainer = node.handleNodeContainer, handleNodeContainer.isUserInteractionEnabled { + if let handleNodeContainer = node.handleNodeContainer, handleNodeContainer.isUserInteractionEnabled, handleNodeContainer.frame.insetBy(dx: 0.0, dy: -5.0).contains(point) { return handleNodeContainer.view } else { return nil From a499f59758b12a53390733d48105b9c6eedb0eaa Mon Sep 17 00:00:00 2001 From: Peter <> Date: Tue, 30 Jul 2019 16:48:12 +0300 Subject: [PATCH 09/16] Add secretMediaDuration: Int32? --- .../AutoremoveTimeoutMessageAttribute.swift | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/submodules/TelegramCore/TelegramCore/AutoremoveTimeoutMessageAttribute.swift b/submodules/TelegramCore/TelegramCore/AutoremoveTimeoutMessageAttribute.swift index 5674fe59f2..c0a4f6eea9 100644 --- a/submodules/TelegramCore/TelegramCore/AutoremoveTimeoutMessageAttribute.swift +++ b/submodules/TelegramCore/TelegramCore/AutoremoveTimeoutMessageAttribute.swift @@ -71,4 +71,31 @@ public extension Message { return false } + + public var secretMediaDuration: Int32? { + var found = false + for attribute in self.attributes { + if let attribute = attribute as? AutoremoveTimeoutMessageAttribute { + found = true + break + } + } + + if !found { + return nil + } + + for media in self.media { + switch media { + case _ as TelegramMediaImage: + return nil + case let file as TelegramMediaFile: + return file.duration + default: + break + } + } + + return nil + } } From 10b1ec24672241dccfe3d11f45119fc9a31c1834 Mon Sep 17 00:00:00 2001 From: Peter <> Date: Tue, 30 Jul 2019 16:48:47 +0300 Subject: [PATCH 10/16] Option to delete whole message groups --- .../DeleteMessagesInteractively.swift | 19 ++++++++++++++++++- .../TelegramUI/ChatController.swift | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/submodules/TelegramCore/TelegramCore/DeleteMessagesInteractively.swift b/submodules/TelegramCore/TelegramCore/DeleteMessagesInteractively.swift index 656e883e7c..4341dab5aa 100644 --- a/submodules/TelegramCore/TelegramCore/DeleteMessagesInteractively.swift +++ b/submodules/TelegramCore/TelegramCore/DeleteMessagesInteractively.swift @@ -20,8 +20,25 @@ public enum InteractiveMessagesDeletionType: Int32 { case forEveryone = 1 } -public func deleteMessagesInteractively(postbox: Postbox, messageIds: [MessageId], type: InteractiveMessagesDeletionType) -> Signal { +public func deleteMessagesInteractively(postbox: Postbox, messageIds initialMessageIds: [MessageId], type: InteractiveMessagesDeletionType, deleteAllInGroup: Bool = false) -> Signal { return postbox.transaction { transaction -> Void in + var messageIds: [MessageId] = [] + if deleteAllInGroup { + for id in initialMessageIds { + if let group = transaction.getMessageGroup(id) ?? transaction.getMessageForwardedGroup(id) { + for message in group { + if !messageIds.contains(message.id) { + messageIds.append(message.id) + } + } + } else { + messageIds.append(id) + } + } + } else { + messageIds = initialMessageIds + } + var messageIdsByPeerId: [PeerId: [MessageId]] = [:] for id in messageIds { if messageIdsByPeerId[id.peerId] == nil { diff --git a/submodules/TelegramUI/TelegramUI/ChatController.swift b/submodules/TelegramUI/TelegramUI/ChatController.swift index ca63d082e3..5d487e8f9a 100644 --- a/submodules/TelegramUI/TelegramUI/ChatController.swift +++ b/submodules/TelegramUI/TelegramUI/ChatController.swift @@ -2680,7 +2680,7 @@ public final class ChatController: TelegramController, GalleryHiddenMediaTarget, if isAction && (actions.options == .deleteGlobally || actions.options == .deleteLocally) { let _ = deleteMessagesInteractively(postbox: strongSelf.context.account.postbox, messageIds: Array(messageIds), type: actions.options == .deleteLocally ? .forLocalPeer : .forEveryone).start() } else if (messages.first?.flags.isSending ?? false) { - let _ = deleteMessagesInteractively(postbox: strongSelf.context.account.postbox, messageIds: Array(messageIds), type: .forEveryone).start() + let _ = deleteMessagesInteractively(postbox: strongSelf.context.account.postbox, messageIds: Array(messageIds), type: .forEveryone, deleteAllInGroup: true).start() } else { strongSelf.presentDeleteMessageOptions(messageIds: messageIds, options: actions.options) } From 3565d295146e85e60ee5c597f6f750134edcea12 Mon Sep 17 00:00:00 2001 From: Peter <> Date: Tue, 30 Jul 2019 16:49:20 +0300 Subject: [PATCH 11/16] Fix unnecessary text input animation --- submodules/TelegramUI/TelegramUI/ChatControllerNode.swift | 4 ++-- .../TelegramUI/ChatInterfaceStateInputPanels.swift | 1 + .../TelegramUI/TelegramUI/ChatTextInputPanelNode.swift | 8 ++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/submodules/TelegramUI/TelegramUI/ChatControllerNode.swift b/submodules/TelegramUI/TelegramUI/ChatControllerNode.swift index 2910d52c28..bfcdb88dca 100644 --- a/submodules/TelegramUI/TelegramUI/ChatControllerNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatControllerNode.swift @@ -274,9 +274,9 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate { self?.interfaceInteraction?.presentController(controller, nil) }) self.textInputPanelNode?.storedInputLanguage = chatPresentationInterfaceState.interfaceState.inputLanguage - self.textInputPanelNode?.updateHeight = { [weak self] in + self.textInputPanelNode?.updateHeight = { [weak self] animated in if let strongSelf = self, let _ = strongSelf.inputPanelNode as? ChatTextInputPanelNode, !strongSelf.ignoreUpdateHeight { - strongSelf.requestLayout(.animated(duration: 0.1, curve: .easeInOut)) + strongSelf.requestLayout(animated ? .animated(duration: 0.1, curve: .easeInOut) : .immediate) } } diff --git a/submodules/TelegramUI/TelegramUI/ChatInterfaceStateInputPanels.swift b/submodules/TelegramUI/TelegramUI/ChatInterfaceStateInputPanels.swift index d3de4c634a..7466f47a4c 100644 --- a/submodules/TelegramUI/TelegramUI/ChatInterfaceStateInputPanels.swift +++ b/submodules/TelegramUI/TelegramUI/ChatInterfaceStateInputPanels.swift @@ -222,6 +222,7 @@ func inputPanelForChatPresentationIntefaceState(_ chatPresentationInterfaceState let panel = ChatTextInputPanelNode(presentationInterfaceState: chatPresentationInterfaceState, presentController: { [weak interfaceInteraction] controller in interfaceInteraction?.presentController(controller, nil) }) + panel.interfaceInteraction = interfaceInteraction panel.context = context return panel diff --git a/submodules/TelegramUI/TelegramUI/ChatTextInputPanelNode.swift b/submodules/TelegramUI/TelegramUI/ChatTextInputPanelNode.swift index d6b3972a63..2532044104 100644 --- a/submodules/TelegramUI/TelegramUI/ChatTextInputPanelNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatTextInputPanelNode.swift @@ -223,7 +223,7 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate { var displayAttachmentMenu: () -> Void = { } var sendMessage: () -> Void = { } var paste: (ChatTextInputPanelPasteData) -> Void = { _ in } - var updateHeight: () -> Void = { } + var updateHeight: (Bool) -> Void = { _ in } var updateActivity: () -> Void = { } @@ -1199,7 +1199,7 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate { } self.updateActionButtons(hasText: inputHasText, hideMicButton: hideMicButton, animated: animated) - self.updateTextHeight() + self.updateTextHeight(animated: animated) } private func updateActionButtons(hasText: Bool, hideMicButton: Bool, animated: Bool) { @@ -1345,12 +1345,12 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate { self.actionButtons.updateAccessibility() } - private func updateTextHeight() { + private func updateTextHeight(animated: Bool) { if let (width, leftInset, rightInset, maxHeight, metrics) = self.validLayout { let (_, textFieldHeight) = self.calculateTextFieldMetrics(width: width - leftInset - rightInset, maxHeight: maxHeight, metrics: metrics) let panelHeight = self.panelHeight(textFieldHeight: textFieldHeight, metrics: metrics) if !self.bounds.size.height.isEqual(to: panelHeight) { - self.updateHeight() + self.updateHeight(animated) } } } From 8df0a6969e9c8816f16e2486db8d6acbaac2efc1 Mon Sep 17 00:00:00 2001 From: Peter <> Date: Tue, 30 Jul 2019 16:49:41 +0300 Subject: [PATCH 12/16] Extend secret media autoremove timeout to media duration --- .../MarkMessageContentAsConsumedInteractively.swift | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/submodules/TelegramCore/TelegramCore/MarkMessageContentAsConsumedInteractively.swift b/submodules/TelegramCore/TelegramCore/MarkMessageContentAsConsumedInteractively.swift index 51c91c09a4..fd0e9c3030 100644 --- a/submodules/TelegramCore/TelegramCore/MarkMessageContentAsConsumedInteractively.swift +++ b/submodules/TelegramCore/TelegramCore/MarkMessageContentAsConsumedInteractively.swift @@ -57,10 +57,14 @@ public func markMessageContentAsConsumedInteractively(postbox: Postbox, messageI for i in 0 ..< updatedAttributes.count { if let attribute = updatedAttributes[i] as? AutoremoveTimeoutMessageAttribute { if attribute.countdownBeginTime == nil || attribute.countdownBeginTime == 0 { - updatedAttributes[i] = AutoremoveTimeoutMessageAttribute(timeout: attribute.timeout, countdownBeginTime: timestamp) + var timeout = attribute.timeout + if let duration = message.secretMediaDuration { + timeout = max(timeout, duration) + } + updatedAttributes[i] = AutoremoveTimeoutMessageAttribute(timeout: timeout, countdownBeginTime: timestamp) updateMessage = true - transaction.addTimestampBasedMessageAttribute(tag: 0, timestamp: timestamp + attribute.timeout, messageId: messageId) + transaction.addTimestampBasedMessageAttribute(tag: 0, timestamp: timestamp + timeout, messageId: messageId) if messageId.peerId.namespace == Namespaces.Peer.SecretChat { var layer: SecretChatLayer? From 61c2bfd8ffc1d1062add5e84ca107d1d72229e01 Mon Sep 17 00:00:00 2001 From: Peter <> Date: Tue, 30 Jul 2019 16:50:14 +0300 Subject: [PATCH 13/16] Block repeated passport attachment callback --- .../LegacySecureIdAttachmentMenu.swift | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/submodules/TelegramUI/TelegramUI/LegacySecureIdAttachmentMenu.swift b/submodules/TelegramUI/TelegramUI/LegacySecureIdAttachmentMenu.swift index 5f738ac0ce..17d89a1883 100644 --- a/submodules/TelegramUI/TelegramUI/LegacySecureIdAttachmentMenu.swift +++ b/submodules/TelegramUI/TelegramUI/LegacySecureIdAttachmentMenu.swift @@ -51,8 +51,25 @@ func presentLegacySecureIdAttachmentMenu(context: AccountContext, present: @esca mappedIntent = TGPassportAttachIntentSelfie } + var uploadStarted = false + guard let attachMenu = TGPassportAttachMenu.present(with: legacyController.context, parentController: emptyController, menuController: nil, title: "", intent: mappedIntent, uploadAction: { signal, completed in if let signal = signal { + if uploadStarted { + completed?() + return + } + uploadStarted = true + let statusController = OverlayStatusController(theme: presentationData.theme, strings: presentationData.strings, type: .loading(cancelled: nil)) + let statusDisposable = (Signal { subscriber in + present(statusController) + return ActionDisposable { + statusController.dismiss() + } + } + |> runOn(.mainQueue()) + |> delay(0.1, queue: .mainQueue())).start() + let _ = (processedLegacySecureIdAttachmentItems(postbox: context.account.postbox, signal: signal) |> mapToSignal { resources -> Signal<([TelegramMediaResource], SecureIdRecognizedDocumentData?), NoError> in switch type { @@ -70,6 +87,7 @@ func presentLegacySecureIdAttachmentMenu(context: AccountContext, present: @esca } |> deliverOnMainQueue).start(next: { resourcesAndData in completion(resourcesAndData.0, resourcesAndData.1) + statusDisposable.dispose() completed?() }) } else { From 137938b1cfcb248a7864a7370e0c8bf251c043f2 Mon Sep 17 00:00:00 2001 From: Peter <> Date: Tue, 30 Jul 2019 16:50:34 +0300 Subject: [PATCH 14/16] Expose more stickers to legacy UI --- submodules/TelegramUI/TelegramUI/LegacyComponentsStickers.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/submodules/TelegramUI/TelegramUI/LegacyComponentsStickers.swift b/submodules/TelegramUI/TelegramUI/LegacyComponentsStickers.swift index 36754b751d..67cba82663 100644 --- a/submodules/TelegramUI/TelegramUI/LegacyComponentsStickers.swift +++ b/submodules/TelegramUI/TelegramUI/LegacyComponentsStickers.swift @@ -31,7 +31,7 @@ func stickerFromLegacyDocument(_ documentAttachment: TGDocumentMediaAttachment) func legacyComponentsStickers(postbox: Postbox, namespace: Int32) -> SSignal { return SSignal { subscriber in - let disposable = (postbox.itemCollectionsView(orderedItemListCollectionIds: [], namespaces: [namespace], aroundIndex: nil, count: 1000)).start(next: { view in + let disposable = (postbox.itemCollectionsView(orderedItemListCollectionIds: [], namespaces: [namespace], aroundIndex: nil, count: 200 * 200)).start(next: { view in var stickerPackDocuments: [ItemCollectionId: [Any]] = [:] for entry in view.entries { From 31866487d25c0f5f93d10936b2498b19d957f8f4 Mon Sep 17 00:00:00 2001 From: Peter <> Date: Tue, 30 Jul 2019 16:50:57 +0300 Subject: [PATCH 15/16] Pass through current found remote peers while updating search results --- .../TelegramUI/ChatListSearchContainerNode.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/submodules/TelegramUI/TelegramUI/ChatListSearchContainerNode.swift b/submodules/TelegramUI/TelegramUI/ChatListSearchContainerNode.swift index 5e40158776..546a05ce87 100644 --- a/submodules/TelegramUI/TelegramUI/ChatListSearchContainerNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatListSearchContainerNode.swift @@ -611,10 +611,13 @@ final class ChatListSearchContainerNode: SearchDisplayControllerContentNode { } self.recentListNode.isHidden = filter.contains(.excludeRecent) + let currentRemotePeers = Atomic<([FoundPeer], [FoundPeer])?>(value: nil) + let presentationDataPromise = self.presentationDataPromise let foundItems = self.searchQuery.get() |> mapToSignal { query -> Signal<([ChatListSearchEntry], Bool)?, NoError> in guard let query = query, !query.isEmpty else { + let _ = currentRemotePeers.swap(nil) return .single(nil) } @@ -651,8 +654,9 @@ final class ChatListSearchContainerNode: SearchDisplayControllerContentNode { } let foundRemotePeers: Signal<([FoundPeer], [FoundPeer], Bool), NoError> + let currentRemotePeersValue = currentRemotePeers.with { $0 } ?? ([], []) foundRemotePeers = ( - .single(([], [], true)) + .single((currentRemotePeersValue.0, currentRemotePeersValue.1, true)) |> then( searchPeers(account: context.account, query: query) |> map { ($0.0, $0.1, false) } @@ -717,6 +721,8 @@ final class ChatListSearchContainerNode: SearchDisplayControllerContentNode { let isSearching = foundRemotePeers.2 || foundRemoteMessages.1 var index = 0 + let _ = currentRemotePeers.swap((foundRemotePeers.0, foundRemotePeers.1)) + let filteredPeer:(Peer, Peer) -> Bool = { peer, accountPeer in guard !filter.contains(.excludeSavedMessages) || peer.id != accountPeer.id else { return false } guard !filter.contains(.excludeSecretChats) || peer.id.namespace != Namespaces.Peer.SecretChat else { return false } From da238e4b335aa3d4023b577aa87878abaf83ee53 Mon Sep 17 00:00:00 2001 From: Peter <> Date: Tue, 30 Jul 2019 16:54:49 +0300 Subject: [PATCH 16/16] Update allowed slowmode intervals --- submodules/TelegramUI/TelegramUI/ChatSlowmodeItem.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/submodules/TelegramUI/TelegramUI/ChatSlowmodeItem.swift b/submodules/TelegramUI/TelegramUI/ChatSlowmodeItem.swift index 8ffc4dc7c0..6cc629952f 100644 --- a/submodules/TelegramUI/TelegramUI/ChatSlowmodeItem.swift +++ b/submodules/TelegramUI/TelegramUI/ChatSlowmodeItem.swift @@ -66,7 +66,7 @@ private func generateKnobImage() -> UIImage? { }) } -private let allowedValues: [Int32] = [0, 30, 60 * 1, 60 * 5, 60 * 15, 60 * 30, 60 * 60] +private let allowedValues: [Int32] = [0, 10, 30, 60, 300, 900, 3600] class ChatSlowmodeItemNode: ListViewItemNode { private let backgroundNode: ASDisplayNode