From ffed4a5e3266e722cbda923e03e4eb8c1233a768 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Thu, 17 Apr 2025 14:50:00 +0400 Subject: [PATCH] Fix --- .../TelegramEngine/Payments/StarGifts.swift | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Payments/StarGifts.swift b/submodules/TelegramCore/Sources/TelegramEngine/Payments/StarGifts.swift index c59ed9f0a4..8a9c186184 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Payments/StarGifts.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Payments/StarGifts.swift @@ -1459,23 +1459,25 @@ private final class ProfileGiftsContextImpl { return _internal_transferStarGift(account: self.account, prepaid: prepaid, reference: reference, peerId: peerId) } - func buyStarGift(reference: StarGiftReference, peerId: EnginePeer.Id) -> Signal { - var gift = self.gifts.first(where: { $0.reference == reference }) - if gift == nil { - gift = self.filteredGifts.first(where: { $0.reference == reference }) - } - guard case let .unique(uniqueGift) = gift?.gift else { - return .complete() - } - + func buyStarGift(slug: String, peerId: EnginePeer.Id) -> Signal { if let count = self.count { self.count = max(0, count - 1) } - self.gifts.removeAll(where: { $0.reference == reference }) - self.filteredGifts.removeAll(where: { $0.reference == reference }) + self.gifts.removeAll(where: { gift in + if case let .unique(uniqueGift) = gift.gift, uniqueGift.slug == slug { + return true + } + return false + }) + self.filteredGifts.removeAll(where: { gift in + if case let .unique(uniqueGift) = gift.gift, uniqueGift.slug == slug { + return true + } + return false + }) self.pushState() - return _internal_buyStarGift(account: self.account, slug: uniqueGift.slug, peerId: peerId) + return _internal_buyStarGift(account: self.account, slug: slug, peerId: peerId) } func upgradeStarGift(formId: Int64?, reference: StarGiftReference, keepOriginalInfo: Bool) -> Signal { @@ -1893,11 +1895,11 @@ public final class ProfileGiftsContext { } } - public func buyStarGift(reference: StarGiftReference, peerId: EnginePeer.Id) -> Signal { + public func buyStarGift(slug: String, peerId: EnginePeer.Id) -> Signal { return Signal { subscriber in let disposable = MetaDisposable() self.impl.with { impl in - disposable.set(impl.buyStarGift(reference: reference, peerId: peerId).start(error: { error in + disposable.set(impl.buyStarGift(slug: slug, peerId: peerId).start(error: { error in subscriber.putError(error) }, completed: { subscriber.putCompletion()