From 00516523a4bf832cd7ff109facb195c8e9d20d82 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Thu, 26 Sep 2024 17:18:16 +0400 Subject: [PATCH] Various fixes --- .../MultilineTextWithEntitiesComponent.swift | 2 +- .../ChatItemGalleryFooterContentNode.swift | 9 ++--- .../TelegramEngine/Payments/StarGifts.swift | 16 +++++++++ .../Sources/GiftOptionsScreen.swift | 2 +- .../Sources/GiftSetupScreen.swift | 2 +- .../Sources/GiftViewScreen.swift | 33 ++++++++++++------- 6 files changed, 46 insertions(+), 18 deletions(-) diff --git a/submodules/Components/MultilineTextWithEntitiesComponent/Sources/MultilineTextWithEntitiesComponent.swift b/submodules/Components/MultilineTextWithEntitiesComponent/Sources/MultilineTextWithEntitiesComponent.swift index a0f9198def..f6e54bbac5 100644 --- a/submodules/Components/MultilineTextWithEntitiesComponent/Sources/MultilineTextWithEntitiesComponent.swift +++ b/submodules/Components/MultilineTextWithEntitiesComponent/Sources/MultilineTextWithEntitiesComponent.swift @@ -170,7 +170,7 @@ public final class MultilineTextWithEntitiesComponent: Component { self.textNode.highlightAttributeAction = component.highlightAction self.textNode.tapAttributeAction = component.tapAction self.textNode.longTapAttributeAction = component.longTapAction - + if case let .curve(duration, _) = transition.animation, let previousText = previousText, previousText != attributedString.string { if let snapshotView = self.snapshotContentTree() { snapshotView.center = self.center diff --git a/submodules/GalleryUI/Sources/ChatItemGalleryFooterContentNode.swift b/submodules/GalleryUI/Sources/ChatItemGalleryFooterContentNode.swift index d47d42bd3f..082471eebc 100644 --- a/submodules/GalleryUI/Sources/ChatItemGalleryFooterContentNode.swift +++ b/submodules/GalleryUI/Sources/ChatItemGalleryFooterContentNode.swift @@ -123,8 +123,6 @@ class CaptionScrollWrapperNode: ASDisplayNode { } } - - final class ChatItemGalleryFooterContentNode: GalleryFooterContentNode, ASScrollViewDelegate { private let context: AccountContext private var presentationData: PresentationData @@ -1106,8 +1104,11 @@ final class ChatItemGalleryFooterContentNode: GalleryFooterContentNode, ASScroll let dustNode = InvisibleInkDustNode(textNode: spoilerTextNode, enableAnimations: self.context.sharedContext.energyUsageSettings.fullTranslucency) self.dustNode = dustNode - spoilerTextNode.supernode?.insertSubnode(dustNode, aboveSubnode: spoilerTextNode) - + if let textSelectionNode = self.textSelectionNode { + spoilerTextNode.supernode?.insertSubnode(dustNode, aboveSubnode: textSelectionNode) + } else { + spoilerTextNode.supernode?.insertSubnode(dustNode, aboveSubnode: spoilerTextNode) + } } if let dustNode = self.dustNode { dustNode.update(size: textFrame.size, color: .white, textColor: .white, rects: textLayout.spoilers.map { $0.1.offsetBy(dx: 3.0, dy: 3.0).insetBy(dx: 0.0, dy: 1.0) }, wordRects: textLayout.spoilerWords.map { $0.1.offsetBy(dx: 3.0, dy: 3.0).insetBy(dx: 0.0, dy: 1.0) }) diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Payments/StarGifts.swift b/submodules/TelegramCore/Sources/TelegramEngine/Payments/StarGifts.swift index da2930b8c2..1aaffb2ea5 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Payments/StarGifts.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Payments/StarGifts.swift @@ -207,6 +207,22 @@ func _internal_convertStarGift(account: Account, messageId: EngineMessage.Id) -> |> `catch` { _ -> Signal in return .single(nil) } + |> mapToSignal { result in + if let result, case .boolTrue = result { + return account.postbox.transaction { transaction -> Void in + transaction.updatePeerCachedData(peerIds: Set([account.peerId]), update: { _, cachedData -> CachedPeerData? in + if let cachedData = cachedData as? CachedUserData, let starGiftsCount = cachedData.starGiftsCount { + var updatedData = cachedData + updatedData = updatedData.withUpdatedStarGiftsCount(max(0, starGiftsCount - 1)) + return updatedData + } else { + return cachedData + } + }) + } + } + return .complete() + } |> ignoreValues } } diff --git a/submodules/TelegramUI/Components/Gifts/GiftOptionsScreen/Sources/GiftOptionsScreen.swift b/submodules/TelegramUI/Components/Gifts/GiftOptionsScreen/Sources/GiftOptionsScreen.swift index 31acafe4dd..0a91ed47cc 100644 --- a/submodules/TelegramUI/Components/Gifts/GiftOptionsScreen/Sources/GiftOptionsScreen.swift +++ b/submodules/TelegramUI/Components/Gifts/GiftOptionsScreen/Sources/GiftOptionsScreen.swift @@ -369,7 +369,7 @@ final class GiftOptionsScreenComponent: Component { } var controllers = navigationController.viewControllers - controllers = controllers.filter { !($0 is GiftOptionsScreen) } + controllers = controllers.filter { !($0 is GiftOptionsScreen) && !($0 is PeerInfoScreen) && !($0 is ContactSelectionController) } var foundController = false for controller in controllers.reversed() { if let chatController = controller as? ChatController, case .peer(id: component.peerId) = chatController.chatLocation { diff --git a/submodules/TelegramUI/Components/Gifts/GiftSetupScreen/Sources/GiftSetupScreen.swift b/submodules/TelegramUI/Components/Gifts/GiftSetupScreen/Sources/GiftSetupScreen.swift index e73031098a..ac85c06f65 100644 --- a/submodules/TelegramUI/Components/Gifts/GiftSetupScreen/Sources/GiftSetupScreen.swift +++ b/submodules/TelegramUI/Components/Gifts/GiftSetupScreen/Sources/GiftSetupScreen.swift @@ -214,7 +214,7 @@ final class GiftSetupScreenComponent: Component { } var controllers = navigationController.viewControllers - controllers = controllers.filter { !($0 is GiftSetupScreen) && !($0 is GiftOptionsScreenProtocol) } + controllers = controllers.filter { !($0 is GiftSetupScreen) && !($0 is GiftOptionsScreenProtocol) && !($0 is PeerInfoScreen) && !($0 is ContactSelectionController) } var foundController = false for controller in controllers.reversed() { if let chatController = controller as? ChatController, case .peer(id: component.peerId) = chatController.chatLocation { diff --git a/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftViewScreen.swift b/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftViewScreen.swift index 885086b89a..617b9dd772 100644 --- a/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftViewScreen.swift +++ b/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftViewScreen.swift @@ -70,6 +70,7 @@ private final class GiftViewSheetContent: CombinedComponent { var initialized = false var peerMap: [EnginePeer.Id: EnginePeer] = [:] + var starGiftsMap: [Int64: StarGift] = [:] var cachedCloseImage: (UIImage, PresentationTheme)? var cachedChevronImage: (UIImage, PresentationTheme)? @@ -86,14 +87,15 @@ private final class GiftViewSheetContent: CombinedComponent { if let fromPeerId = arguments.fromPeerId { peerIds.append(fromPeerId) } - self.disposable = (context.engine.data.get( - EngineDataMap( + + self.disposable = combineLatest(queue: Queue.mainQueue(), + context.engine.data.get(EngineDataMap( peerIds.map { peerId -> TelegramEngine.EngineData.Item.Peer.Peer in return TelegramEngine.EngineData.Item.Peer.Peer(id: peerId) } - ) - ) - |> deliverOnMainQueue).startStrict(next: { [weak self] peers in + )), + context.engine.payments.cachedStarGifts() + ).startStrict(next: { [weak self] peers, starGifts in if let strongSelf = self { var peersMap: [EnginePeer.Id: EnginePeer] = [:] for peerId in peerIds { @@ -103,6 +105,14 @@ private final class GiftViewSheetContent: CombinedComponent { } strongSelf.peerMap = peersMap + var starGiftsMap: [Int64: StarGift] = [:] + if let starGifts { + for gift in starGifts { + starGiftsMap[gift.id] = gift + } + } + strongSelf.starGiftsMap = starGiftsMap + strongSelf.initialized = true strongSelf.updated(transition: .immediate) @@ -170,33 +180,30 @@ private final class GiftViewSheetContent: CombinedComponent { let convertStars: Int64 let text: String? let entities: [MessageTextEntity]? - let limitNumber: Int32? let limitTotal: Int32? var incoming = false var savedToProfile = false var converted = false + var giftId: Int64 = 0 if let arguments = component.subject.arguments { animationFile = arguments.gift.file stars = arguments.gift.price text = arguments.text entities = arguments.entities - limitNumber = arguments.gift.availability?.remains limitTotal = arguments.gift.availability?.total convertStars = arguments.convertStars incoming = arguments.incoming || arguments.peerId == component.context.account.peerId savedToProfile = arguments.savedToProfile converted = arguments.converted + giftId = arguments.gift.id } else { animationFile = nil stars = 0 text = nil entities = nil - limitNumber = nil limitTotal = nil convertStars = 0 } - let _ = entities - let _ = limitNumber var descriptionText: String if incoming { @@ -326,11 +333,15 @@ private final class GiftViewSheetContent: CombinedComponent { )) if let limitTotal { + var remains: Int32 = 0 + if let gift = state.starGiftsMap[giftId], let availability = gift.availability { + remains = availability.remains + } tableItems.append(.init( id: "availability", title: "Availability", component: AnyComponent( - MultilineTextComponent(text: .plain(NSAttributedString(string: "1 of \(limitTotal)", font: tableFont, textColor: tableTextColor))) + MultilineTextComponent(text: .plain(NSAttributedString(string: "\(remains) of \(limitTotal)", font: tableFont, textColor: tableTextColor))) ) )) }