From 5d97a0c65c1e9b45fb4609801a06aa0e13c94194 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Fri, 10 Dec 2021 18:42:29 +0400 Subject: [PATCH] Cherry-pick more fixes --- .../Telegram-iOS/en.lproj/Localizable.strings | 2 + .../Sources/ChatListSearchContainerNode.swift | 18 ++- .../Sources/Items/ChatImageGalleryItem.swift | 6 +- .../Sources/ImageContentAnalysis.swift | 8 +- .../SearchBarNode/Sources/SearchBarNode.swift | 13 ++- .../Sources/SearchDisplayController.swift | 5 +- .../Themes/ThemeGridSearchContentNode.swift | 2 +- .../Search/Archive.imageset/Contents.json | 12 ++ .../Search/Archive.imageset/archive_18.pdf | 109 ++++++++++++++++++ .../TelegramUI/Sources/ChatController.swift | 3 + .../ChatMessageSelectionInputPanelNode.swift | 6 + .../ChatSearchNavigationContentNode.swift | 2 +- .../Sources/PeerInfo/PeerInfoScreen.swift | 4 +- .../Sources/PeerMessagesMediaPlaylist.swift | 2 +- .../StickerPaneTrendingListGridItem.swift | 2 +- 15 files changed, 176 insertions(+), 18 deletions(-) create mode 100644 submodules/TelegramUI/Images.xcassets/Chat List/Search/Archive.imageset/Contents.json create mode 100644 submodules/TelegramUI/Images.xcassets/Chat List/Search/Archive.imageset/archive_18.pdf diff --git a/Telegram/Telegram-iOS/en.lproj/Localizable.strings b/Telegram/Telegram-iOS/en.lproj/Localizable.strings index ff955dabf5..869636a7da 100644 --- a/Telegram/Telegram-iOS/en.lproj/Localizable.strings +++ b/Telegram/Telegram-iOS/en.lproj/Localizable.strings @@ -7131,3 +7131,5 @@ Sorry for the inconvenience."; "Conversation.LargeEmojiDisabledInfo" = "You have disabled large emoji, so they appear small and have no effects in chat."; "Conversation.LargeEmojiEnable" = "Enable Large Emoji"; "Conversation.LargeEmojiEnabled" = "Large emoji enabled."; + +"ChatList.Archive" = "Archive"; diff --git a/submodules/ChatListUI/Sources/ChatListSearchContainerNode.swift b/submodules/ChatListUI/Sources/ChatListSearchContainerNode.swift index b66f3235ef..4da7046071 100644 --- a/submodules/ChatListUI/Sources/ChatListSearchContainerNode.swift +++ b/submodules/ChatListUI/Sources/ChatListSearchContainerNode.swift @@ -31,6 +31,7 @@ import UndoUI import TextFormat private enum ChatListTokenId: Int32 { + case archive case filter case peer case date @@ -457,13 +458,17 @@ public final class ChatListSearchContainerNode: SearchDisplayControllerContentNo private func updateSearchOptions(_ options: ChatListSearchOptions?, clearQuery: Bool = false) { var options = options + var tokens: [SearchBarToken] = [] + if self.groupId == .archive { + tokens.append(SearchBarToken(id: ChatListTokenId.archive.rawValue, icon: UIImage(bundleImageName: "Chat List/Search/Archive"), title: self.presentationData.strings.ChatList_Archive, permanent: true)) + } + if options?.isEmpty ?? true { options = nil } self.searchOptionsValue = options self.searchOptions.set(.single(options)) - var tokens: [SearchBarToken] = [] if let (peerId, isGroup, peerName) = options?.peer { let image: UIImage? if isGroup { @@ -473,11 +478,11 @@ public final class ChatListSearchContainerNode: SearchDisplayControllerContentNo } else { image = UIImage(bundleImageName: "Chat List/Search/User") } - tokens.append(SearchBarToken(id: ChatListTokenId.peer.rawValue, icon:image, title: peerName)) + tokens.append(SearchBarToken(id: ChatListTokenId.peer.rawValue, icon: image, title: peerName, permanent: false)) } if let (_, _, dateTitle) = options?.date { - tokens.append(SearchBarToken(id: ChatListTokenId.date.rawValue, icon: UIImage(bundleImageName: "Chat List/Search/Calendar"), title: dateTitle)) + tokens.append(SearchBarToken(id: ChatListTokenId.date.rawValue, icon: UIImage(bundleImageName: "Chat List/Search/Calendar"), title: dateTitle, permanent: false)) self.suggestedDates.set(.single([])) } @@ -524,7 +529,12 @@ public final class ChatListSearchContainerNode: SearchDisplayControllerContentNo self.paneContainerNode.requestSelectPane(key) self.updateSearchOptions(nil) self.searchTextUpdated(text: query ?? "") - self.setQuery?(nil, [], query ?? "") + + var tokens: [SearchBarToken] = [] + if self.groupId == .archive { + tokens.append(SearchBarToken(id: ChatListTokenId.archive.rawValue, icon: UIImage(bundleImageName: "Chat List/Search/Archive"), title: self.presentationData.strings.ChatList_Archive, permanent: true)) + } + self.setQuery?(nil, tokens, query ?? "") } override public func containerLayoutUpdated(_ layout: ContainerViewLayout, navigationBarHeight: CGFloat, transition: ContainedViewLayoutTransition) { diff --git a/submodules/GalleryUI/Sources/Items/ChatImageGalleryItem.swift b/submodules/GalleryUI/Sources/Items/ChatImageGalleryItem.swift index 2ec9e63f32..2cb36c9ae2 100644 --- a/submodules/GalleryUI/Sources/Items/ChatImageGalleryItem.swift +++ b/submodules/GalleryUI/Sources/Items/ChatImageGalleryItem.swift @@ -322,8 +322,10 @@ final class ChatImageGalleryItemNode: ZoomableContentGalleryItemNode { strongSelf.recognizedContentNode?.removeFromSupernode() if !results.isEmpty { let size = strongSelf.imageNode.bounds.size - let recognizedContentNode = RecognizedContentContainer(size: size, recognitions: results, presentationData: strongSelf.context.sharedContext.currentPresentationData.with { $0 }, present: { c, a in - strongSelf.galleryController()?.presentInGlobalOverlay(c, with: a) + let recognizedContentNode = RecognizedContentContainer(size: size, recognitions: results, presentationData: strongSelf.context.sharedContext.currentPresentationData.with { $0 }, present: { [weak self] c, a in + if let strongSelf = self { + strongSelf.galleryController()?.presentInGlobalOverlay(c, with: a) + } }, performAction: { [weak self] string, action in guard let strongSelf = self else { return diff --git a/submodules/ImageContentAnalysis/Sources/ImageContentAnalysis.swift b/submodules/ImageContentAnalysis/Sources/ImageContentAnalysis.swift index 13b5e5ca05..eb0bf757a8 100644 --- a/submodules/ImageContentAnalysis/Sources/ImageContentAnalysis.swift +++ b/submodules/ImageContentAnalysis/Sources/ImageContentAnalysis.swift @@ -302,6 +302,7 @@ private func recognizeContent(in image: UIImage) -> Signal<[RecognizedContent], let _ = barcodeResult.swap(mappedResults) completion() } + barcodeRequest.preferBackgroundProcessing = true requests.append(barcodeRequest) if #available(iOS 13.0, *) { @@ -310,6 +311,7 @@ private func recognizeContent(in image: UIImage) -> Signal<[RecognizedContent], let _ = textResult.swap(mappedResults) completion() } + textRequest.preferBackgroundProcessing = true textRequest.usesLanguageCorrection = true requests.append(textRequest) } else { @@ -320,7 +322,11 @@ private func recognizeContent(in image: UIImage) -> Signal<[RecognizedContent], try? handler.perform(requests) return ActionDisposable { - + if #available(iOS 13.0, *) { + for request in requests { + request.cancel() + } + } } } } else { diff --git a/submodules/SearchBarNode/Sources/SearchBarNode.swift b/submodules/SearchBarNode/Sources/SearchBarNode.swift index 2756d839c7..9dec26f70d 100644 --- a/submodules/SearchBarNode/Sources/SearchBarNode.swift +++ b/submodules/SearchBarNode/Sources/SearchBarNode.swift @@ -43,12 +43,14 @@ public struct SearchBarToken { public let icon: UIImage? public let title: String public let style: Style? + public let permanent: Bool - public init(id: AnyHashable, icon: UIImage?, title: String, style: Style? = nil) { + public init(id: AnyHashable, icon: UIImage?, title: String, style: Style? = nil, permanent: Bool) { self.id = id self.icon = icon self.title = title self.style = style + self.permanent = permanent } } @@ -106,6 +108,7 @@ private final class TokenNode: ASDisplayNode { } @objc private func tapGesture() { + self.tapped?() } @@ -264,7 +267,7 @@ private class SearchBarTextField: UITextField, UIScrollViewDelegate { if i < self.tokens.count - 1 && isSelected { hasSelected = true } - let isCollapsed = !isSelected && (i < self.tokens.count - 1 || hasSelected) + let isCollapsed = !isSelected && (token.permanent || (i < self.tokens.count - 1 || hasSelected)) tokenNode.update(theme: self.theme, token: token, isSelected: isSelected, isCollapsed: isCollapsed) } var removeKeys: [AnyHashable] = [] @@ -863,8 +866,10 @@ public class SearchBarNode: ASDisplayNode, UITextFieldDelegate { return false } if let index = strongSelf.textField.selectedTokenIndex { - strongSelf.tokens.remove(at: index) - strongSelf.tokensUpdated?(strongSelf.tokens) + if !strongSelf.tokens[index].permanent { + strongSelf.tokens.remove(at: index) + strongSelf.tokensUpdated?(strongSelf.tokens) + } return true } else if strongSelf.text.isEmpty { strongSelf.clearPressed() diff --git a/submodules/SearchUI/Sources/SearchDisplayController.swift b/submodules/SearchUI/Sources/SearchDisplayController.swift index 341bebff44..ed4dc6974f 100644 --- a/submodules/SearchUI/Sources/SearchDisplayController.swift +++ b/submodules/SearchUI/Sources/SearchDisplayController.swift @@ -70,15 +70,18 @@ public final class SearchDisplayController { self.contentNode.dismissInput = { [weak self] in self?.searchBar.deactivate(clear: false) } + + var isFirstTime = true self.contentNode.setQuery = { [weak self] prefix, tokens, query in if let strongSelf = self { strongSelf.searchBar.prefixString = prefix let previousTokens = strongSelf.searchBar.tokens strongSelf.searchBar.tokens = tokens strongSelf.searchBar.text = query - if previousTokens.count < tokens.count { + if previousTokens.count < tokens.count && !isFirstTime { strongSelf.searchBar.selectLastToken() } + isFirstTime = false } } if let placeholder = placeholder { diff --git a/submodules/SettingsUI/Sources/Themes/ThemeGridSearchContentNode.swift b/submodules/SettingsUI/Sources/Themes/ThemeGridSearchContentNode.swift index bbdd356531..540ec13610 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeGridSearchContentNode.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeGridSearchContentNode.swift @@ -681,7 +681,7 @@ final class ThemeGridSearchContentNode: SearchDisplayControllerContentNode { foregroundColor = .white strokeColor = color.displayColor } - tokens = [SearchBarToken(id: 0, icon: UIImage(bundleImageName: "Settings/WallpaperSearchColorIcon"), title: color.localizedString(strings: self.presentationData.strings), style: SearchBarToken.Style(backgroundColor: backgroundColor, foregroundColor: foregroundColor, strokeColor: strokeColor))] + tokens = [SearchBarToken(id: 0, icon: UIImage(bundleImageName: "Settings/WallpaperSearchColorIcon"), title: color.localizedString(strings: self.presentationData.strings), style: SearchBarToken.Style(backgroundColor: backgroundColor, foregroundColor: foregroundColor, strokeColor: strokeColor), permanent: false)] text = query placeholder = self.presentationData.strings.Wallpaper_SearchShort } diff --git a/submodules/TelegramUI/Images.xcassets/Chat List/Search/Archive.imageset/Contents.json b/submodules/TelegramUI/Images.xcassets/Chat List/Search/Archive.imageset/Contents.json new file mode 100644 index 0000000000..b5c9067a42 --- /dev/null +++ b/submodules/TelegramUI/Images.xcassets/Chat List/Search/Archive.imageset/Contents.json @@ -0,0 +1,12 @@ +{ + "images" : [ + { + "filename" : "archive_18.pdf", + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/submodules/TelegramUI/Images.xcassets/Chat List/Search/Archive.imageset/archive_18.pdf b/submodules/TelegramUI/Images.xcassets/Chat List/Search/Archive.imageset/archive_18.pdf new file mode 100644 index 0000000000..ef7c2a13f2 --- /dev/null +++ b/submodules/TelegramUI/Images.xcassets/Chat List/Search/Archive.imageset/archive_18.pdf @@ -0,0 +1,109 @@ +%PDF-1.7 + +1 0 obj + << >> +endobj + +2 0 obj + << /Length 3 0 R >> +stream +/DeviceRGB CS +/DeviceRGB cs +q +1.000000 0.000000 -0.000000 1.000000 3.000000 11.625000 cm +0.000000 0.000000 0.000000 scn +0.000000 1.500000 m +0.000000 1.848739 -0.000000 2.023109 0.038333 2.166172 c +0.142359 2.554400 0.445600 2.857641 0.833829 2.961667 c +0.976891 3.000000 1.151261 3.000000 1.500000 3.000000 c +10.500000 3.000000 l +10.848740 3.000000 11.023109 3.000000 11.166171 2.961667 c +11.554400 2.857641 11.857641 2.554400 11.961666 2.166172 c +12.000000 2.023109 12.000000 1.848739 12.000000 1.500000 c +12.000000 1.500000 l +12.000000 1.151261 12.000000 0.976891 11.961666 0.833829 c +11.857641 0.445600 11.554400 0.142359 11.166171 0.038333 c +11.023109 0.000000 10.848740 0.000000 10.500000 0.000000 c +1.500000 0.000000 l +1.151261 0.000000 0.976891 0.000000 0.833829 0.038333 c +0.445600 0.142359 0.142359 0.445600 0.038333 0.833829 c +-0.000000 0.976891 0.000000 1.151261 0.000000 1.500000 c +0.000000 1.500000 l +h +f +n +Q +q +1.000000 0.000000 -0.000000 1.000000 3.750000 3.375000 cm +0.000000 0.000000 0.000000 scn +0.000000 3.200033 m +0.000000 7.625000 l +10.500000 7.625000 l +10.500000 3.200035 l +10.500000 2.079930 10.500000 1.519877 10.282013 1.092054 c +10.090266 0.715730 9.784306 0.409769 9.407981 0.218022 c +8.980158 0.000035 8.420105 0.000035 7.300000 0.000035 c +3.200000 0.000035 l +2.079895 0.000035 1.519843 0.000035 1.092019 0.218022 c +0.715695 0.409769 0.409734 0.715730 0.217987 1.092054 c +0.000000 1.519877 0.000000 2.079929 0.000000 3.200033 c +h +3.000000 6.500000 m +2.723858 6.500000 2.500000 6.276142 2.500000 6.000000 c +2.500000 5.723858 2.723858 5.500000 3.000000 5.500000 c +7.500000 5.500000 l +7.776143 5.500000 8.000000 5.723858 8.000000 6.000000 c +8.000000 6.276142 7.776143 6.500000 7.500000 6.500000 c +3.000000 6.500000 l +h +f* +n +Q + +endstream +endobj + +3 0 obj + 1750 +endobj + +4 0 obj + << /Annots [] + /Type /Page + /MediaBox [ 0.000000 0.000000 18.000000 18.000000 ] + /Resources 1 0 R + /Contents 2 0 R + /Parent 5 0 R + >> +endobj + +5 0 obj + << /Kids [ 4 0 R ] + /Count 1 + /Type /Pages + >> +endobj + +6 0 obj + << /Pages 5 0 R + /Type /Catalog + >> +endobj + +xref +0 7 +0000000000 65535 f +0000000010 00000 n +0000000034 00000 n +0000001840 00000 n +0000001863 00000 n +0000002036 00000 n +0000002110 00000 n +trailer +<< /ID [ (some) (id) ] + /Root 6 0 R + /Size 7 +>> +startxref +2169 +%%EOF \ No newline at end of file diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index 1f516390b6..732143bd41 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -4859,6 +4859,9 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G allPeers?.insert(currentAccountPeer, at: 0) } } + if allPeers?.count == 1 { + allPeers = nil + } strongSelf.updateChatPresentationInterfaceState(animated: true, interactive: false, { return $0.updatedSendAsPeers(allPeers) }) diff --git a/submodules/TelegramUI/Sources/ChatMessageSelectionInputPanelNode.swift b/submodules/TelegramUI/Sources/ChatMessageSelectionInputPanelNode.swift index e01f11d8c1..4d04335615 100644 --- a/submodules/TelegramUI/Sources/ChatMessageSelectionInputPanelNode.swift +++ b/submodules/TelegramUI/Sources/ChatMessageSelectionInputPanelNode.swift @@ -132,6 +132,9 @@ final class ChatMessageSelectionInputPanelNode: ChatInputPanelNode { } @objc func forwardButtonPressed() { + if let _ = self.presentationInterfaceState?.renderedPeer?.peer as? TelegramSecretChat { + return + } if let actions = self.actions, actions.isCopyProtected { self.interfaceInteraction?.displayCopyProtectionTip(self.forwardButton, false) } else { @@ -140,6 +143,9 @@ final class ChatMessageSelectionInputPanelNode: ChatInputPanelNode { } @objc func shareButtonPressed() { + if let _ = self.presentationInterfaceState?.renderedPeer?.peer as? TelegramSecretChat { + return + } if let actions = self.actions, actions.isCopyProtected { self.interfaceInteraction?.displayCopyProtectionTip(self.shareButton, true) } else { diff --git a/submodules/TelegramUI/Sources/ChatSearchNavigationContentNode.swift b/submodules/TelegramUI/Sources/ChatSearchNavigationContentNode.swift index f2dce4fdbf..4c2aaf455e 100644 --- a/submodules/TelegramUI/Sources/ChatSearchNavigationContentNode.swift +++ b/submodules/TelegramUI/Sources/ChatSearchNavigationContentNode.swift @@ -112,7 +112,7 @@ final class ChatSearchNavigationContentNode: NavigationBarContentNode { self.searchBar.prefixString = NSAttributedString(string: strings.Conversation_SearchByName_Prefix, font: searchBarFont, textColor: theme.rootController.navigationSearchBar.inputTextColor) self.searchBar.placeholderString = nil case let .member(peer): - self.searchBar.tokens = [SearchBarToken(id: peer.id, icon: UIImage(bundleImageName: "Chat List/Search/User"), title: EnginePeer(peer).compactDisplayTitle)] + self.searchBar.tokens = [SearchBarToken(id: peer.id, icon: UIImage(bundleImageName: "Chat List/Search/User"), title: EnginePeer(peer).compactDisplayTitle, permanent: false)] self.searchBar.prefixString = nil self.searchBar.placeholderString = nil } diff --git a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift index 2b76086919..6c0a042b41 100644 --- a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift +++ b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift @@ -6424,7 +6424,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewDelegate } strongSelf.deleteMessages(messageIds: nil) }, shareMessages: { [weak self] in - guard let strongSelf = self, let messageIds = strongSelf.state.selectedMessageIds, !messageIds.isEmpty else { + guard let strongSelf = self, let messageIds = strongSelf.state.selectedMessageIds, !messageIds.isEmpty, strongSelf.peerId.namespace != Namespaces.Peer.SecretChat else { return } let _ = (strongSelf.context.account.postbox.transaction { transaction -> [Message] in @@ -6448,7 +6448,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewDelegate } }) }, forwardMessages: { [weak self] in - guard let strongSelf = self else { + guard let strongSelf = self, strongSelf.peerId.namespace != Namespaces.Peer.SecretChat else { return } strongSelf.forwardMessages(messageIds: nil) diff --git a/submodules/TelegramUI/Sources/PeerMessagesMediaPlaylist.swift b/submodules/TelegramUI/Sources/PeerMessagesMediaPlaylist.swift index 44839c6c05..996269fd3a 100644 --- a/submodules/TelegramUI/Sources/PeerMessagesMediaPlaylist.swift +++ b/submodules/TelegramUI/Sources/PeerMessagesMediaPlaylist.swift @@ -114,7 +114,7 @@ final class MessageMediaPlaylistItem: SharedMediaPlaylistItem { albumArt = SharedMediaPlaybackAlbumArt(thumbnailResource: ExternalMusicAlbumArtResource(title: updatedTitle ?? "", performer: updatedPerformer ?? "", isThumbnail: true), fullSizeResource: ExternalMusicAlbumArtResource(title: updatedTitle ?? "", performer: updatedPerformer ?? "", isThumbnail: false)) } - return SharedMediaPlaybackDisplayData.music(title: updatedTitle, performer: updatedPerformer, albumArt: albumArt, long: duration > 60 * 20) + return SharedMediaPlaybackDisplayData.music(title: updatedTitle, performer: updatedPerformer, albumArt: albumArt, long: CGFloat(duration) > 10.0 * 60.0) } case let .Video(_, _, flags): if flags.contains(.instantRoundVideo) { diff --git a/submodules/TelegramUI/Sources/StickerPaneTrendingListGridItem.swift b/submodules/TelegramUI/Sources/StickerPaneTrendingListGridItem.swift index f023e78890..a6616e5e59 100644 --- a/submodules/TelegramUI/Sources/StickerPaneTrendingListGridItem.swift +++ b/submodules/TelegramUI/Sources/StickerPaneTrendingListGridItem.swift @@ -528,7 +528,7 @@ class StickerPaneTrendingListGridItemNode: GridItemNode { let titleFrame = CGRect(origin: CGPoint(x: params.leftInset + leftInset, y: topOffset), size: titleLayout.size) let dismissButtonSize = CGSize(width: 12.0, height: 12.0) - self.dismissButtonNode.frame = CGRect(origin: CGPoint(x: params.width - params.rightInset - rightInset - dismissButtonSize.width, y: topOffset - 1.0), size: dismissButtonSize) + self.dismissButtonNode.frame = CGRect(origin: CGPoint(x: params.width - params.rightInset - rightInset - dismissButtonSize.width + 1.0, y: topOffset - 1.0), size: dismissButtonSize) self.dismissButtonNode.isHidden = item.dismiss == nil self.titleNode.frame = titleFrame }