From ca8f59565b5218ac4ee1c1fcbd440f47bcfa8668 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Sat, 4 Mar 2023 20:17:12 +0400 Subject: [PATCH] Various fixes --- .../Sources/ChatListController.swift | 6 +--- .../Sources/DrawingStickerEntity.swift | 34 ++++++++++++------- .../Sources/ApiUtils/TelegramGroup.swift | 8 ++++- .../ChatMessageAnimatedStickerItemNode.swift | 13 +++---- .../Sources/PeerInfo/PeerInfoScreen.swift | 13 ++++--- .../Sources/ChatTextInputAttributes.swift | 23 ++++++++++--- 6 files changed, 59 insertions(+), 38 deletions(-) diff --git a/submodules/ChatListUI/Sources/ChatListController.swift b/submodules/ChatListUI/Sources/ChatListController.swift index b1ae5efa2e..28da92f370 100644 --- a/submodules/ChatListUI/Sources/ChatListController.swift +++ b/submodules/ChatListUI/Sources/ChatListController.swift @@ -2749,11 +2749,7 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController tabsIsEmpty = true } - var displaySearchFilters = true - if chatListView.0.entries.count < 10 { - displaySearchFilters = false - } - + let displaySearchFilters = true if !tabsIsEmpty, let snapshotView = strongSelf.tabContainerNode.view.snapshotView(afterScreenUpdates: false) { snapshotView.frame = strongSelf.tabContainerNode.frame strongSelf.tabContainerNode.view.superview?.addSubview(snapshotView) diff --git a/submodules/DrawingUI/Sources/DrawingStickerEntity.swift b/submodules/DrawingUI/Sources/DrawingStickerEntity.swift index 1d22294a9d..e2d18a2079 100644 --- a/submodules/DrawingUI/Sources/DrawingStickerEntity.swift +++ b/submodules/DrawingUI/Sources/DrawingStickerEntity.swift @@ -292,7 +292,6 @@ final class DrawingStickerEntityView: DrawingEntityView { let sideSize: CGFloat = size.width let boundingSize = CGSize(width: sideSize, height: sideSize) - let imageSize = self.dimensions.aspectFitted(boundingSize) self.imageNode.asyncLayout()(TransformImageArguments(corners: ImageCorners(), imageSize: imageSize, boundingSize: imageSize, intrinsicInsets: UIEdgeInsets()))() self.imageNode.frame = CGRect(origin: CGPoint(x: floor((size.width - imageSize.width) / 2.0), y: (size.height - imageSize.height) / 2.0), size: imageSize) @@ -317,21 +316,32 @@ final class DrawingStickerEntityView: DrawingEntityView { self.bounds = CGRect(origin: .zero, size: self.dimensions.aspectFitted(size)) self.transform = CGAffineTransformScale(CGAffineTransformMakeRotation(self.stickerEntity.rotation), self.stickerEntity.scale, self.stickerEntity.scale) - var transform = CATransform3DIdentity + let staticTransform = CATransform3DMakeScale(self.stickerEntity.mirrored ? -1.0 : 1.0, 1.0, 1.0) - if self.stickerEntity.mirrored { - transform = CATransform3DRotate(transform, .pi, 0.0, 1.0, 0.0) - transform.m34 = -1.0 / self.imageNode.frame.width - } - if animated { - UIView.animate(withDuration: 0.25, delay: 0.0) { - self.imageNode.transform = transform - self.animationNode?.transform = transform + let isCurrentlyMirrored = ((self.imageNode.layer.value(forKeyPath: "transform.scale.y") as? NSNumber)?.floatValue ?? 1.0) < 0.0 + var animationSourceTransform = CATransform3DIdentity + var animationTargetTransform = CATransform3DIdentity + if isCurrentlyMirrored { + animationSourceTransform = CATransform3DRotate(animationSourceTransform, .pi, 0.0, 1.0, 0.0) + animationSourceTransform.m34 = -1.0 / self.imageNode.frame.width } + if self.stickerEntity.mirrored { + animationTargetTransform = CATransform3DRotate(animationTargetTransform, .pi, 0.0, 1.0, 0.0) + animationTargetTransform.m34 = -1.0 / self.imageNode.frame.width + } + self.imageNode.transform = animationSourceTransform + self.animationNode?.transform = animationSourceTransform + UIView.animate(withDuration: 0.25, animations: { + self.imageNode.transform = animationTargetTransform + self.animationNode?.transform = animationTargetTransform + }, completion: { finished in + self.imageNode.transform = staticTransform + self.animationNode?.transform = staticTransform + }) } else { - self.imageNode.transform = transform - self.animationNode?.transform = transform + self.imageNode.transform = staticTransform + self.animationNode?.transform = staticTransform } super.update(animated: animated) diff --git a/submodules/TelegramCore/Sources/ApiUtils/TelegramGroup.swift b/submodules/TelegramCore/Sources/ApiUtils/TelegramGroup.swift index 912d167749..d0a85c23cd 100644 --- a/submodules/TelegramCore/Sources/ApiUtils/TelegramGroup.swift +++ b/submodules/TelegramCore/Sources/ApiUtils/TelegramGroup.swift @@ -14,6 +14,13 @@ public extension TelegramGroup { func hasPermission(_ permission: Permission) -> Bool { switch permission { case .sendSomething: + switch self.role { + case .creator, .admin: + return true + default: + break + } + let flags: TelegramChatBannedRightsFlags = [ .banSendText, .banSendInstantVideos, @@ -25,7 +32,6 @@ public extension TelegramGroup { .banSendFiles, .banSendInline ] - if let defaultBannedRights = self.defaultBannedRights, defaultBannedRights.flags.intersection(flags) == flags { return false } diff --git a/submodules/TelegramUI/Sources/ChatMessageAnimatedStickerItemNode.swift b/submodules/TelegramUI/Sources/ChatMessageAnimatedStickerItemNode.swift index 39f74693a8..54139e219f 100644 --- a/submodules/TelegramUI/Sources/ChatMessageAnimatedStickerItemNode.swift +++ b/submodules/TelegramUI/Sources/ChatMessageAnimatedStickerItemNode.swift @@ -638,6 +638,10 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView { if self.emojiString != emojiString { self.emojiString = emojiString } else if self.emojiFile?.id != emojiFile?.id { + if self.emojiFile != nil { + self.didSetUpAnimationNode = false + item.controllerInteraction.seenOneTimeAnimatedMedia.remove(item.message.id) + } self.emojiFile = emojiFile if let emojiFile = emojiFile { var dimensions = emojiFile.dimensions ?? PixelDimensions(width: 512, height: 512) @@ -728,7 +732,7 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView { } } if let animationNode = self.animationNode as? AnimatedStickerNode { - if self.isPlaying != isPlaying { + if self.isPlaying != isPlaying || (isPlaying && !self.didSetUpAnimationNode) { self.isPlaying = isPlaying if isPlaying && self.setupTimestamp == nil { @@ -736,13 +740,6 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView { } animationNode.visibility = isPlaying - /*if self.didSetUpAnimationNode && alreadySeen { - if let emojiFile = self.emojiFile, emojiFile.resource is LocalFileReferenceMediaResource { - } else { - animationNode.seekTo(.start) - } - }*/ - if self.isPlaying && !self.didSetUpAnimationNode { self.didSetUpAnimationNode = true diff --git a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift index fbd52c822c..55faa61fce 100644 --- a/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift +++ b/submodules/TelegramUI/Sources/PeerInfo/PeerInfoScreen.swift @@ -1691,12 +1691,6 @@ private func editingItems(data: PeerInfoScreenData?, state: PeerInfoState, chatL interaction.editingOpenReactionsSetup() })) } - - if !isPublic, case .known(nil) = cachedData.linkedDiscussionPeerId, !channel.flags.contains(.isForum){ - items[.peerPublicSettings]!.append(PeerInfoScreenDisclosureItem(id: ItemPreHistory, label: .text(cachedData.flags.contains(.preHistoryEnabled) ? presentationData.strings.GroupInfo_GroupHistoryVisible : presentationData.strings.GroupInfo_GroupHistoryHidden), text: presentationData.strings.GroupInfo_GroupHistoryShort, icon: UIImage(bundleImageName: "Chat/Info/GroupDiscussionIcon"), action: { - interaction.editingOpenPreHistorySetup() - })) - } } else { if isCreator || (channel.adminRights?.rights.contains(.canChangeInfo) == true) { let label: String @@ -1718,6 +1712,12 @@ private func editingItems(data: PeerInfoScreenData?, state: PeerInfoState, chatL } } + if (isCreator || (channel.adminRights != nil && channel.hasPermission(.banMembers))) && cachedData.peerGeoLocation == nil, !isPublic, case .known(nil) = cachedData.linkedDiscussionPeerId, !channel.flags.contains(.isForum) { + items[.peerPublicSettings]!.append(PeerInfoScreenDisclosureItem(id: ItemPreHistory, label: .text(cachedData.flags.contains(.preHistoryEnabled) ? presentationData.strings.GroupInfo_GroupHistoryVisible : presentationData.strings.GroupInfo_GroupHistoryHidden), text: presentationData.strings.GroupInfo_GroupHistoryShort, icon: UIImage(bundleImageName: "Chat/Info/GroupDiscussionIcon"), action: { + interaction.editingOpenPreHistorySetup() + })) + } + if cachedData.flags.contains(.canSetStickerSet) && canEditPeerInfo(context: context, peer: channel, chatLocation: chatLocation, threadData: data.threadData) { items[.peerDataSettings]!.append(PeerInfoScreenDisclosureItem(id: ItemStickerPack, label: .text(cachedData.stickerPack?.title ?? presentationData.strings.GroupInfo_SharedMediaNone), text: presentationData.strings.Stickers_GroupStickers, icon: UIImage(bundleImageName: "Settings/Menu/Stickers"), action: { interaction.editingOpenStickerPackSetup() @@ -1850,7 +1850,6 @@ private func editingItems(data: PeerInfoScreenData?, state: PeerInfoState, chatL interaction.editingOpenPreHistorySetup() })) - let label: String if let cachedData = data.cachedData as? CachedGroupData, case let .known(allowedReactions) = cachedData.allowedReactions { switch allowedReactions { diff --git a/submodules/TextFormat/Sources/ChatTextInputAttributes.swift b/submodules/TextFormat/Sources/ChatTextInputAttributes.swift index 711273b010..99e151c834 100644 --- a/submodules/TextFormat/Sources/ChatTextInputAttributes.swift +++ b/submodules/TextFormat/Sources/ChatTextInputAttributes.swift @@ -376,6 +376,19 @@ private func refreshTextMentions(text: NSString, initialAttributedText: NSAttrib } } +private let textUrlEdgeCharacters: CharacterSet = { + var set: CharacterSet = .alphanumerics + set.formUnion(.symbols) + set.formUnion(.punctuationCharacters) + return set +}() + +private let textUrlCharacters: CharacterSet = { + var set: CharacterSet = textUrlEdgeCharacters + set.formUnion(.whitespacesAndNewlines) + return set +}() + private func refreshTextUrls(text: NSString, initialAttributedText: NSAttributedString, attributedText: NSMutableAttributedString, fullRange: NSRange) { var textUrlRanges: [(NSRange, ChatTextInputTextUrlAttribute)] = [] initialAttributedText.enumerateAttribute(ChatTextInputAttributes.textUrl, in: fullRange, options: [], using: { value, range, _ in @@ -392,7 +405,7 @@ private func refreshTextUrls(text: NSString, initialAttributedText: NSAttributed var validLower = range.lowerBound inner1: for i in range.lowerBound ..< range.upperBound { if let c = UnicodeScalar(text.character(at: i)) { - if alphanumericCharacters.contains(c) || c == " " as UnicodeScalar { + if textUrlCharacters.contains(c) { validLower = i break inner1 } @@ -403,7 +416,7 @@ private func refreshTextUrls(text: NSString, initialAttributedText: NSAttributed var validUpper = range.upperBound inner2: for i in (validLower ..< range.upperBound).reversed() { if let c = UnicodeScalar(text.character(at: i)) { - if alphanumericCharacters.contains(c) || c == " " as UnicodeScalar { + if textUrlCharacters.contains(c) { validUpper = i + 1 break inner2 } @@ -415,7 +428,7 @@ private func refreshTextUrls(text: NSString, initialAttributedText: NSAttributed let minLower = (i == 0) ? fullRange.lowerBound : textUrlRanges[i - 1].0.upperBound inner3: for i in (minLower ..< validLower).reversed() { if let c = UnicodeScalar(text.character(at: i)) { - if alphanumericCharacters.contains(c) { + if textUrlEdgeCharacters.contains(c) { validLower = i } else { break inner3 @@ -428,7 +441,7 @@ private func refreshTextUrls(text: NSString, initialAttributedText: NSAttributed let maxUpper = (i == textUrlRanges.count - 1) ? fullRange.upperBound : textUrlRanges[i + 1].0.lowerBound inner3: for i in validUpper ..< maxUpper { if let c = UnicodeScalar(text.character(at: i)) { - if alphanumericCharacters.contains(c) { + if textUrlEdgeCharacters.contains(c) { validUpper = i + 1 } else { break inner3 @@ -450,7 +463,7 @@ private func refreshTextUrls(text: NSString, initialAttributedText: NSAttributed var combine = true inner: for j in textUrlRanges[i].0.upperBound ..< textUrlRanges[i + 1].0.lowerBound { if let c = UnicodeScalar(text.character(at: j)) { - if alphanumericCharacters.contains(c) || c == " " as UnicodeScalar { + if textUrlCharacters.contains(c) { } else { combine = false break inner