From b261e67c34f1ddef7292334bfb0e76d0ebcce6e7 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Tue, 19 Mar 2024 14:49:20 +0400 Subject: [PATCH] Various improvements --- .../Node/ChatListStorageInfoItem.swift | 9 +++ .../TelegramEngine/Data/PeersData.swift | 29 --------- .../Stickers/CachedStickerPack.swift | 14 ++--- .../Stickers/ImportStickers.swift | 5 ++ .../Sources/ChatEntityKeyboardInputNode.swift | 2 +- .../Sources/EmojiPagerContentSignals.swift | 32 +++++++++- .../StickerPackEditTitleController.swift | 61 ++++++++++++------- .../TelegramUI/Sources/ChatController.swift | 1 + 8 files changed, 90 insertions(+), 63 deletions(-) diff --git a/submodules/ChatListUI/Sources/Node/ChatListStorageInfoItem.swift b/submodules/ChatListUI/Sources/Node/ChatListStorageInfoItem.swift index 568ae0aab1..c3edb90eb6 100644 --- a/submodules/ChatListUI/Sources/Node/ChatListStorageInfoItem.swift +++ b/submodules/ChatListUI/Sources/Node/ChatListStorageInfoItem.swift @@ -395,7 +395,16 @@ class ChatListStorageInfoItemNode: ItemListRevealOptionsItemNode { } let arrowIsHidden = strongSelf.arrowNode.isHidden + var hasCloseButton = false if case .xmasPremiumGift = item.notice { + hasCloseButton = true + } else if case .setupBirthday = item.notice { + hasCloseButton = true + } else if case .birthdayPremiumGift = item.notice { + hasCloseButton = true + } + + if hasCloseButton { strongSelf.arrowNode.isHidden = true let closeButton: HighlightableButtonNode diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Data/PeersData.swift b/submodules/TelegramCore/Sources/TelegramEngine/Data/PeersData.swift index f9eead7cbb..4c6d859e38 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Data/PeersData.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Data/PeersData.swift @@ -1760,34 +1760,5 @@ public extension TelegramEngine.EngineData.Item { } } } - - public struct Birthday: TelegramEngineDataItem, TelegramEngineMapKeyDataItem, PostboxViewDataItem { - public typealias Result = TelegramBirthday? - - fileprivate var id: EnginePeer.Id - public var mapKey: EnginePeer.Id { - return self.id - } - - public init(id: EnginePeer.Id) { - self.id = id - } - - var key: PostboxViewKey { - return .cachedPeerData(peerId: self.id) - } - - func extract(view: PostboxView) -> Result { - guard let view = view as? CachedPeerDataView else { - preconditionFailure() - } - if let cachedData = view.cachedPeerData as? CachedUserData { - return cachedData.birthday - } else { - return nil - } - } - } - } } diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Stickers/CachedStickerPack.swift b/submodules/TelegramCore/Sources/TelegramEngine/Stickers/CachedStickerPack.swift index 8e556c97fd..90644ade6b 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Stickers/CachedStickerPack.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Stickers/CachedStickerPack.swift @@ -10,13 +10,13 @@ public enum CachedStickerPackResult { } func cacheStickerPack(transaction: Transaction, info: StickerPackCollectionInfo, items: [StickerPackItem], reference: StickerPackReference? = nil) { - if let entry = CodableEntry(CachedStickerPack(info: info, items: items, hash: info.hash)) { - transaction.putItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(info.id)), entry: entry) - } - if let entry = CodableEntry(CachedStickerPack(info: info, items: items, hash: info.hash)) { - transaction.putItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(shortName: info.shortName.lowercased())), entry: entry) + guard let entry = CodableEntry(CachedStickerPack(info: info, items: items, hash: info.hash)) else { + return } + transaction.putItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(info.id)), entry: entry) + transaction.putItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(shortName: info.shortName.lowercased())), entry: entry) + if let reference = reference { var namespace: Int32? var id: ItemCollectionId.Id? @@ -57,9 +57,7 @@ func cacheStickerPack(transaction: Transaction, info: StickerPackCollectionInfo, id = info.id.id } if let namespace = namespace, let id = id { - if let entry = CodableEntry(CachedStickerPack(info: info, items: items, hash: info.hash)) { - transaction.putItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(ItemCollectionId(namespace: namespace, id: id))), entry: entry) - } + transaction.putItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(ItemCollectionId(namespace: namespace, id: id))), entry: entry) } } } diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Stickers/ImportStickers.swift b/submodules/TelegramCore/Sources/TelegramEngine/Stickers/ImportStickers.swift index e37fca3718..307914d26f 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Stickers/ImportStickers.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Stickers/ImportStickers.swift @@ -270,6 +270,11 @@ func _internal_deleteStickerSet(account: Account, packReference: StickerPackRefe } |> mapToSignal { _ in return account.postbox.transaction { transaction in + if let (info, _, _) = cachedStickerPack(transaction: transaction, reference: packReference) { + transaction.removeItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(info.id))) + transaction.removeItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(shortName: info.shortName.lowercased()))) + } + if case let .id(id, _) = packReference { transaction.removeItemCollection(collectionId: ItemCollectionId(namespace: Namespaces.ItemCollection.CloudStickerPacks, id: id)) } diff --git a/submodules/TelegramUI/Components/ChatEntityKeyboardInputNode/Sources/ChatEntityKeyboardInputNode.swift b/submodules/TelegramUI/Components/ChatEntityKeyboardInputNode/Sources/ChatEntityKeyboardInputNode.swift index ce68a301e5..272d5700c3 100644 --- a/submodules/TelegramUI/Components/ChatEntityKeyboardInputNode/Sources/ChatEntityKeyboardInputNode.swift +++ b/submodules/TelegramUI/Components/ChatEntityKeyboardInputNode/Sources/ChatEntityKeyboardInputNode.swift @@ -1149,7 +1149,7 @@ public final class ChatEntityKeyboardInputNode: ChatInputNode { return } guard let file = item.itemFile else { - if groupId == AnyHashable("recent"), case .icon(.add) = item.content { + if case .icon(.add) = item.content { interaction.openStickerEditor() } return diff --git a/submodules/TelegramUI/Components/EntityKeyboard/Sources/EmojiPagerContentSignals.swift b/submodules/TelegramUI/Components/EntityKeyboard/Sources/EmojiPagerContentSignals.swift index 4195137f15..5efd0709c8 100644 --- a/submodules/TelegramUI/Components/EntityKeyboard/Sources/EmojiPagerContentSignals.swift +++ b/submodules/TelegramUI/Components/EntityKeyboard/Sources/EmojiPagerContentSignals.swift @@ -1828,6 +1828,7 @@ public extension EmojiPagerContentComponent { } } + var addedCreateStickerButton = false if let recentStickers = recentStickers { let groupId = "recent" for item in recentStickers.items { @@ -1861,7 +1862,7 @@ public extension EmojiPagerContentComponent { } } - if !forceHasPremium, let groupIndex = itemGroupIndexById[groupId] { + if hasEdit && !addedCreateStickerButton, let groupIndex = itemGroupIndexById[groupId] { let resultItem = EmojiPagerContentComponent.Item( animationData: nil, content: .icon(.add), @@ -1871,6 +1872,7 @@ public extension EmojiPagerContentComponent { tintMode: .none ) itemGroups[groupIndex].items.insert(resultItem, at: 0) + addedCreateStickerButton = true } } @@ -1879,6 +1881,7 @@ public extension EmojiPagerContentComponent { avatarPeer = peerSpecificPack.peer var processedIds = Set() + let groupId = "peerSpecific" for item in peerSpecificPack.items { if isPremiumDisabled && item.file.isPremiumSticker { continue @@ -1903,7 +1906,6 @@ public extension EmojiPagerContentComponent { tintMode: tintMode ) - let groupId = "peerSpecific" if let groupIndex = itemGroupIndexById[groupId] { itemGroups[groupIndex].items.append(resultItem) } else { @@ -1911,6 +1913,19 @@ public extension EmojiPagerContentComponent { itemGroups.append(ItemGroup(supergroupId: groupId, id: groupId, title: peerSpecificPack.peer.compactDisplayTitle, subtitle: nil, actionButtonTitle: nil, isPremiumLocked: false, isFeatured: false, displayPremiumBadges: false, hasEdit: false, headerItem: nil, items: [resultItem])) } } + + if hasEdit && !addedCreateStickerButton, let groupIndex = itemGroupIndexById[groupId] { + let resultItem = EmojiPagerContentComponent.Item( + animationData: nil, + content: .icon(.add), + itemFile: nil, + subgroupId: nil, + icon: .none, + tintMode: .none + ) + itemGroups[groupIndex].items.insert(resultItem, at: 0) + addedCreateStickerButton = true + } } for entry in view.entries { @@ -1971,6 +1986,19 @@ public extension EmojiPagerContentComponent { } } itemGroups.append(ItemGroup(supergroupId: groupId, id: groupId, title: title, subtitle: nil, actionButtonTitle: nil, isPremiumLocked: false, isFeatured: false, displayPremiumBadges: true, hasEdit: hasEdit && groupHasEdit, headerItem: headerItem, items: [resultItem])) + + if hasEdit && !addedCreateStickerButton, let groupIndex = itemGroupIndexById[groupId] { + let resultItem = EmojiPagerContentComponent.Item( + animationData: nil, + content: .icon(.add), + itemFile: nil, + subgroupId: nil, + icon: .none, + tintMode: .none + ) + itemGroups[groupIndex].items.insert(resultItem, at: 0) + addedCreateStickerButton = true + } } } diff --git a/submodules/TelegramUI/Components/Stickers/StickerPackEditTitleController/Sources/StickerPackEditTitleController.swift b/submodules/TelegramUI/Components/Stickers/StickerPackEditTitleController/Sources/StickerPackEditTitleController.swift index e4b9e0746f..e8a0ae4137 100644 --- a/submodules/TelegramUI/Components/Stickers/StickerPackEditTitleController/Sources/StickerPackEditTitleController.swift +++ b/submodules/TelegramUI/Components/Stickers/StickerPackEditTitleController/Sources/StickerPackEditTitleController.swift @@ -95,7 +95,7 @@ private class TextField: UITextField, UIScrollViewDelegate { override func deleteBackward() { super.deleteBackward() - if let scrollView = self.scrollView { + if let scrollView = self.scrollView, self.fixEditingRect { if scrollView.contentSize.width <= scrollView.frame.width && scrollView.contentOffset.x > -scrollView.contentInset.left { scrollView.contentOffset = CGPoint(x: max(scrollView.contentOffset.x - 5.0, -scrollView.contentInset.left), y: 0.0) self.updatePrefixPosition() @@ -116,6 +116,9 @@ private class TextField: UITextField, UIScrollViewDelegate { var fixAutoScroll: CGPoint? func scrollViewDidScroll(_ scrollView: UIScrollView) { + guard self.fixEditingRect else { + return + } if let fixAutoScroll = self.fixAutoScroll { self.scrollView?.setContentOffset(fixAutoScroll, animated: true) self.scrollView?.setContentOffset(fixAutoScroll, animated: false) @@ -161,28 +164,37 @@ private class TextField: UITextField, UIScrollViewDelegate { } override func textRect(forBounds bounds: CGRect) -> CGRect { - if bounds.size.width.isZero { - return CGRect(origin: CGPoint(), size: CGSize()) - } - var rect = bounds.insetBy(dx: 0.0, dy: 4.0) - if #available(iOS 14.0, *) { - } else { - rect.origin.y += 1.0 - } - if !self.prefixWidth.isZero && self.scrollView?.superview == nil { - var offset = self.prefixWidth - if let scrollView = self.scrollView { - offset = scrollView.contentOffset.x * -1.0 + if self.fixEditingRect { + if bounds.size.width.isZero { + return CGRect(origin: CGPoint(), size: CGSize()) } - rect.origin.x += offset - rect.size.width -= offset - } - rect.size.width = max(rect.size.width, 10.0) - return rect + var rect = bounds.insetBy(dx: 0.0, dy: 4.0) + if #available(iOS 14.0, *) { + } else { + rect.origin.y += 1.0 + } + if !self.prefixWidth.isZero && self.scrollView?.superview == nil { + var offset = self.prefixWidth + if let scrollView = self.scrollView { + offset = scrollView.contentOffset.x * -1.0 + } + rect.origin.x += offset + rect.size.width -= offset + } + rect.size.width = max(rect.size.width, 10.0) + return rect + } else { + return super.textRect(forBounds: bounds) + } } + var fixEditingRect = false override func editingRect(forBounds bounds: CGRect) -> CGRect { - return self.textRect(forBounds: bounds) + if self.fixEditingRect { + return self.textRect(forBounds: bounds) + } else { + return super.editingRect(forBounds: bounds) + } } override func layoutSubviews() { @@ -196,12 +208,14 @@ private class TextField: UITextField, UIScrollViewDelegate { let textRect = self.textRect(forBounds: bounds) let labelSize = self.placeholderLabel.updateLayout(textRect.size) - self.placeholderLabel.frame = CGRect(origin: CGPoint(x: textRect.minX + 3.0, y: floorToScreenPixels((bounds.height - labelSize.height) / 2.0)), size: labelSize) + self.placeholderLabel.frame = CGRect(origin: CGPoint(x: textRect.minX + (self.fixEditingRect ? 3.0 : 0.0), y: floorToScreenPixels((bounds.height - labelSize.height) / 2.0)), size: labelSize) let prefixSize = self.prefixLabel.updateLayout(CGSize(width: floor(bounds.size.width * 0.7), height: bounds.size.height)) let prefixBounds = bounds.insetBy(dx: 4.0, dy: 4.0) self.prefixLabel.frame = CGRect(origin: CGPoint(x: self.prefixPosition ?? prefixBounds.minX, y: floorToScreenPixels((bounds.height - prefixSize.height) / 2.0)), size: prefixSize) - self.updatePrefixWidth(prefixSize.width + 3.0) + if self.fixEditingRect { + self.updatePrefixWidth(prefixSize.width + 3.0) + } } } @@ -276,7 +290,8 @@ private final class ImportStickerPackTitleInputFieldNode: ASDisplayNode, UITextF self.textInputNode.autocorrectionType = .default self.textInputNode.tintColor = theme.actionSheet.controlAccentColor self.textInputNode.textColor = theme.actionSheet.inputTextColor - + self.textInputNode.fixEditingRect = hasClearButton + self.clearButton = HighlightableButtonNode() self.clearButton.imageNode.displaysAsynchronously = false self.clearButton.imageNode.displayWithoutProcessing = true @@ -325,7 +340,7 @@ private final class ImportStickerPackTitleInputFieldNode: ASDisplayNode, UITextF let backgroundFrame = CGRect(origin: CGPoint(x: backgroundInsets.left, y: backgroundInsets.top), size: CGSize(width: width - backgroundInsets.left - backgroundInsets.right, height: panelHeight - backgroundInsets.top - backgroundInsets.bottom)) transition.updateFrame(node: self.backgroundNode, frame: backgroundFrame) - transition.updateFrame(view: self.textInputNode, frame: CGRect(origin: CGPoint(x: backgroundFrame.minX + inputInsets.left, y: backgroundFrame.minY), size: CGSize(width: backgroundFrame.size.width - inputInsets.left - inputInsets.right - 22.0, height: backgroundFrame.size.height))) + transition.updateFrame(view: self.textInputNode, frame: CGRect(origin: CGPoint(x: backgroundFrame.minX + inputInsets.left, y: backgroundFrame.minY), size: CGSize(width: backgroundFrame.size.width - inputInsets.left - inputInsets.right - (self.clearButton.supernode != nil ? 22.0 : 0.0), height: backgroundFrame.size.height))) if let image = self.clearButton.image(for: []) { transition.updateFrame(node: self.clearButton, frame: CGRect(origin: CGPoint(x: backgroundFrame.maxX - 8.0 - image.size.width, y: backgroundFrame.minY + floor((backgroundFrame.size.height - image.size.height) / 2.0)), size: image.size)) diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index 48e27e6be3..d38aba93f7 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -11771,6 +11771,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G } switch action { case .info: + let context = self.context var replaceImpl: ((ViewController) -> Void)? let controller = context.sharedContext.makePremiumDemoController(context: context, subject: .fasterDownload, action: { let controller = context.sharedContext.makePremiumIntroController(context: context, source: .fasterDownload, forceDark: false, dismissed: nil)