From d574fb7a113fda8611a819d705fa1935967e2c34 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Thu, 13 Nov 2025 16:10:30 +0400 Subject: [PATCH] Various fixes --- .../Sources/MediaPickerScreen.swift | 13 ++----- .../State/AccountStateManagementUtils.swift | 2 +- .../Payments/StarGiftsAuctions.swift | 35 +++++++++++++++---- .../Sources/GiftAuctionBidScreen.swift | 24 ++++--------- .../Sources/GlassBarButtonComponent.swift | 2 +- 5 files changed, 40 insertions(+), 36 deletions(-) diff --git a/submodules/MediaPickerUI/Sources/MediaPickerScreen.swift b/submodules/MediaPickerUI/Sources/MediaPickerScreen.swift index d6b75900dc..b59c8fe046 100644 --- a/submodules/MediaPickerUI/Sources/MediaPickerScreen.swift +++ b/submodules/MediaPickerUI/Sources/MediaPickerScreen.swift @@ -205,7 +205,6 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att private let titleView: MediaPickerTitleView private let cancelButtonNode: WebAppCancelButtonNode - private var glassContainerView = GlassBackgroundContainerView() private var cancelButton: ComponentView? private var rightButton: ComponentView? private let moreButtonPlayOnce = ActionSlot() @@ -2573,14 +2572,6 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att transition.updateAlpha(layer: self.controllerNode.topEdgeEffectView.layer, alpha: self.controllerNode.scrolledExactlyToTop && self.controllerNode.currentDisplayMode == .all ? 0.0 : 1.0) self.controllerNode.topEdgeEffectView.update(content: topEdgeColor, blur: true, alpha: 0.8, rect: topEdgeEffectFrame, edge: .top, edgeSize: topEdgeEffectFrame.height, transition: ComponentTransition(transition)) - if self.cancelButton != nil { - if self.glassContainerView.superview == nil { - self.view.addSubview(self.glassContainerView) - } - self.glassContainerView.frame = CGRect(origin: .zero, size: CGSize(width: layout.size.width, height: 72.0)) - self.glassContainerView.update(size: self.glassContainerView.frame.size, isDark: self.presentationData.theme.overallDarkAppearance, transition: .immediate) - } - if let cancelButton = self.cancelButton { if cancelButton.view == nil { buttonTransition = .immediate @@ -2608,7 +2599,7 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att let cancelButtonFrame = CGRect(origin: CGPoint(x: barButtonSideInset + layout.safeInsets.left, y: barButtonSideInset), size: cancelButtonSize) if let view = cancelButton.view { if view.superview == nil { - self.glassContainerView.contentView.addSubview(view) + self.view.addSubview(view) } view.bounds = CGRect(origin: .zero, size: cancelButtonFrame.size) view.center = cancelButtonFrame.center @@ -2643,7 +2634,7 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att let moreButtonFrame = CGRect(origin: CGPoint(x: layout.size.width - moreButtonSize.width - barButtonSideInset - layout.safeInsets.right, y: barButtonSideInset), size: moreButtonSize) if let view = moreButton.view { if view.superview == nil { - self.glassContainerView.contentView.addSubview(view) + self.view.addSubview(view) } view.bounds = CGRect(origin: .zero, size: moreButtonFrame.size) view.center = moreButtonFrame.center diff --git a/submodules/TelegramCore/Sources/State/AccountStateManagementUtils.swift b/submodules/TelegramCore/Sources/State/AccountStateManagementUtils.swift index cd6d2c01e8..4c82390309 100644 --- a/submodules/TelegramCore/Sources/State/AccountStateManagementUtils.swift +++ b/submodules/TelegramCore/Sources/State/AccountStateManagementUtils.swift @@ -1901,7 +1901,7 @@ private func finalStateWithUpdatesAndServerTime(accountPeerId: PeerId, postbox: case let .updateMonoForumNoPaidException(flags, channelId, savedPeerId): updatedState.updateMonoForumNoPaidException(peerId: PeerId(namespace: Namespaces.Peer.CloudChannel, id: PeerId.Id._internalFromInt64Value(channelId)), threadId: savedPeerId.peerId.toInt64(), isFree: (flags & (1 << 0)) != 0) case let .updateStarGiftAuctionState(giftId, state): - if let state = GiftAuctionContext.State.AuctionState(apiAuctionState: state) { + if let state = GiftAuctionContext.State.AuctionState(apiAuctionState: state, peers: updatedState.peers) { updatedState.updateStarGiftAuctionState(giftId: giftId, state: state) } case let .updateStarGiftAuctionUserState(giftId, userState): diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Payments/StarGiftsAuctions.swift b/submodules/TelegramCore/Sources/TelegramEngine/Payments/StarGiftsAuctions.swift index e09fdbbd38..7ecea01e38 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Payments/StarGiftsAuctions.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Payments/StarGiftsAuctions.swift @@ -37,7 +37,7 @@ private func _internal_getStarGiftAuctionState(postbox: Postbox, network: Networ } return ( gift: gift, - state: GiftAuctionContext.State.AuctionState(apiAuctionState: state), + state: GiftAuctionContext.State.AuctionState(apiAuctionState: state, transaction: transaction), myState: GiftAuctionContext.State.MyState(apiAuctionUserState: userState), timeout: timeout ) @@ -55,7 +55,7 @@ public final class GiftAuctionContext { } public enum AuctionState: Equatable { - case ongoing(version: Int32, startDate: Int32, endDate: Int32, minBidAmount: Int64, bidLevels: [BidLevel], topBidders: [EnginePeer.Id], nextRoundDate: Int32, giftsLeft: Int32, currentRound: Int32, totalRounds: Int32) + case ongoing(version: Int32, startDate: Int32, endDate: Int32, minBidAmount: Int64, bidLevels: [BidLevel], topBidders: [EnginePeer], nextRoundDate: Int32, giftsLeft: Int32, currentRound: Int32, totalRounds: Int32) case finished(startDate: Int32, endDate: Int32, averagePrice: Int64) } @@ -208,10 +208,33 @@ extension GiftAuctionContext.State.BidLevel { } extension GiftAuctionContext.State.AuctionState { - init?(apiAuctionState: Api.StarGiftAuctionState) { + init?(apiAuctionState: Api.StarGiftAuctionState, peers: [PeerId: Peer]) { switch apiAuctionState { - case let .starGiftAuctionState(version, startDate, endDate, minBidAmount, bidLevels, topBidders, nextRoundAt, giftsLeft, currentRound, totalRounds): - self = .ongoing(version: version, startDate: startDate, endDate: endDate, minBidAmount: minBidAmount, bidLevels: bidLevels.map(GiftAuctionContext.State.BidLevel.init(apiBidLevel:)), topBidders: topBidders.map { EnginePeer.Id(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value($0)) }, nextRoundDate: nextRoundAt, giftsLeft: giftsLeft, currentRound: currentRound, totalRounds: totalRounds) + case let .starGiftAuctionState(version, startDate, endDate, minBidAmount, bidLevels, topBiddersPeerIds, nextRoundAt, giftsLeft, currentRound, totalRounds): + var topBidders: [EnginePeer] = [] + for peerId in topBiddersPeerIds { + if let peer = peers[PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(peerId))] { + topBidders.append(EnginePeer(peer)) + } + } + self = .ongoing(version: version, startDate: startDate, endDate: endDate, minBidAmount: minBidAmount, bidLevels: bidLevels.map(GiftAuctionContext.State.BidLevel.init(apiBidLevel:)), topBidders: topBidders, nextRoundDate: nextRoundAt, giftsLeft: giftsLeft, currentRound: currentRound, totalRounds: totalRounds) + case let .starGiftAuctionStateFinished(startDate, endDate, averagePrice): + self = .finished(startDate: startDate, endDate: endDate, averagePrice: averagePrice) + case .starGiftAuctionStateNotModified: + return nil + } + } + + init?(apiAuctionState: Api.StarGiftAuctionState, transaction: Transaction) { + switch apiAuctionState { + case let .starGiftAuctionState(version, startDate, endDate, minBidAmount, bidLevels, topBiddersPeerIds, nextRoundAt, giftsLeft, currentRound, totalRounds): + var topBidders: [EnginePeer] = [] + for peerId in topBiddersPeerIds { + if let peer = transaction.getPeer(PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(peerId))) { + topBidders.append(EnginePeer(peer)) + } + } + self = .ongoing(version: version, startDate: startDate, endDate: endDate, minBidAmount: minBidAmount, bidLevels: bidLevels.map(GiftAuctionContext.State.BidLevel.init(apiBidLevel:)), topBidders: topBidders, nextRoundDate: nextRoundAt, giftsLeft: giftsLeft, currentRound: currentRound, totalRounds: totalRounds) case let .starGiftAuctionStateFinished(startDate, endDate, averagePrice): self = .finished(startDate: startDate, endDate: endDate, averagePrice: averagePrice) case .starGiftAuctionStateNotModified: @@ -314,7 +337,7 @@ func _internal_getActiveGiftAuctions(account: Account, hash: Int64) -> Signal<[G auctionContexts.append(GiftAuctionContext( account: account, gift: gift, - initialAuctionState: GiftAuctionContext.State.AuctionState(apiAuctionState: auctionState), + initialAuctionState: GiftAuctionContext.State.AuctionState(apiAuctionState: auctionState, transaction: transaction), initialMyState: GiftAuctionContext.State.MyState(apiAuctionUserState: userState), initialTimeout: nil )) diff --git a/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftAuctionBidScreen.swift b/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftAuctionBidScreen.swift index b92dc37999..0d542eb9f3 100644 --- a/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftAuctionBidScreen.swift +++ b/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftAuctionBidScreen.swift @@ -1793,14 +1793,6 @@ private final class GiftAuctionBidScreenComponent: Component { self.giftAuctionState = state var peerIds: [EnginePeer.Id] = [] - if case let .ongoing(_, _, _, _, _, topBidders, _, _, _, _) = state?.auctionState { - for bidder in topBidders { - if self.peersMap[bidder] == nil { - peerIds.append(bidder) - } - } - } - var transition = ComponentTransition.spring(duration: 0.4) if isFirstTime { @@ -2357,17 +2349,15 @@ private final class GiftAuctionBidScreenComponent: Component { } var i: Int32 = 1 - for bidder in topBidders { - if let peer = self.peersMap[bidder] { - var bid: Int64 = 0 - for level in bidLevels { - if level.position == i { - bid = level.amount - break - } + for peer in topBidders { + var bid: Int64 = 0 + for level in bidLevels { + if level.position == i { + bid = level.amount + break } - topBidsComponents.append((bidder, AnyComponent(PeerComponent(context: component.context, theme: environment.theme, groupingSeparator: environment.dateTimeFormat.groupingSeparator, peer: peer, place: i, amount: bid, isLast: i == topBidders.count, action: peer.id != component.context.account.peerId ? { [weak self] in self?.openPeer(peer, dismiss: false) } : nil)))) } + topBidsComponents.append((peer.id, AnyComponent(PeerComponent(context: component.context, theme: environment.theme, groupingSeparator: environment.dateTimeFormat.groupingSeparator, peer: peer, place: i, amount: bid, isLast: i == topBidders.count, action: peer.id != component.context.account.peerId ? { [weak self] in self?.openPeer(peer, dismiss: false) } : nil)))) i += 1 } diff --git a/submodules/TelegramUI/Components/GlassBarButtonComponent/Sources/GlassBarButtonComponent.swift b/submodules/TelegramUI/Components/GlassBarButtonComponent/Sources/GlassBarButtonComponent.swift index 8f3d03612a..7d62fa5ec4 100644 --- a/submodules/TelegramUI/Components/GlassBarButtonComponent/Sources/GlassBarButtonComponent.swift +++ b/submodules/TelegramUI/Components/GlassBarButtonComponent/Sources/GlassBarButtonComponent.swift @@ -193,7 +193,7 @@ public final class GlassBarButtonComponent: Component { transition.setAlpha(view: self.genericContainerView, alpha: genericAlpha) transition.setFrame(view: self.genericContainerView, frame: bounds) - transition.setAlpha(view: self.glassContainerView, alpha: glassAlpha) + transition.setAlpha(view: self.glassBackgroundView, alpha: glassAlpha) transition.setFrame(view: self.glassContainerView, frame: bounds) transition.setFrame(view: self.genericBackgroundView, frame: bounds)