@@ -852,6 +852,7 @@ public enum BuyStarGiftError {
852852
853853public enum UpdateStarGiftPriceError {
854854 case generic
855+ case starGiftResellTooEarly( Int32 )
855856}
856857
857858
@@ -1486,11 +1487,18 @@ private final class ProfileGiftsContextImpl {
14861487 }
14871488 return false
14881489 } )
1490+
14891491 self . pushState ( )
14901492
14911493 return _internal_buyStarGift ( account: self . account, slug: slug, peerId: peerId)
14921494 }
14931495
1496+ func removeStarGift( gift: TelegramCore . StarGift ) {
1497+ self . gifts. removeAll ( where: { $0. gift == gift } )
1498+ self . filteredGifts. removeAll ( where: { $0. gift == gift } )
1499+ self . pushState ( )
1500+ }
1501+
14941502 func upgradeStarGift( formId: Int64 ? , reference: StarGiftReference , keepOriginalInfo: Bool ) -> Signal < ProfileGiftsContext . State . StarGift , UpgradeStarGiftError > {
14951503 return Signal { [ weak self] subscriber in
14961504 guard let self else {
@@ -1526,7 +1534,7 @@ private final class ProfileGiftsContextImpl {
15261534 }
15271535 }
15281536
1529- func updateStarGiftResellPrice( reference: StarGiftReference , price: Int64 ? ) -> Signal < Never , UpdateStarGiftPriceError > {
1537+ func updateStarGiftResellPrice( reference: StarGiftReference , price: Int64 ? , id : Int64 ? ) -> Signal < Never , UpdateStarGiftPriceError > {
15301538 return Signal { [ weak self] subscriber in
15311539 guard let self else {
15321540 return EmptyDisposable
@@ -1545,6 +1553,16 @@ private final class ProfileGiftsContextImpl {
15451553 if gift. reference == reference {
15461554 return true
15471555 }
1556+ switch gift. gift {
1557+ case . generic( let gift) :
1558+ if gift. id == id {
1559+ return true
1560+ }
1561+ case . unique( let uniqueGift) :
1562+ if uniqueGift. id == id {
1563+ return true
1564+ }
1565+ }
15481566 return false
15491567 } ) {
15501568 if case let . unique( uniqueGift) = self . gifts [ index] . gift {
@@ -1558,6 +1576,16 @@ private final class ProfileGiftsContextImpl {
15581576 if gift. reference == reference {
15591577 return true
15601578 }
1579+ switch gift. gift {
1580+ case . generic( let gift) :
1581+ if gift. id == id {
1582+ return true
1583+ }
1584+ case . unique( let uniqueGift) :
1585+ if uniqueGift. id == id {
1586+ return true
1587+ }
1588+ }
15611589 return false
15621590 } ) {
15631591 if case let . unique( uniqueGift) = self . filteredGifts [ index] . gift {
@@ -1941,6 +1969,12 @@ public final class ProfileGiftsContext {
19411969 }
19421970 }
19431971
1972+ public func removeStarGift( gift: TelegramCore . StarGift ) {
1973+ self . impl. with { impl in
1974+ impl. removeStarGift ( gift: gift)
1975+ }
1976+ }
1977+
19441978 public func transferStarGift( prepaid: Bool , reference: StarGiftReference , peerId: EnginePeer . Id ) -> Signal < Never , TransferStarGiftError > {
19451979 return Signal { subscriber in
19461980 let disposable = MetaDisposable ( )
@@ -1971,11 +2005,11 @@ public final class ProfileGiftsContext {
19712005 }
19722006 }
19732007
1974- public func updateStarGiftResellPrice( reference: StarGiftReference , price: Int64 ? ) -> Signal < Never , UpdateStarGiftPriceError > {
2008+ public func updateStarGiftResellPrice( reference: StarGiftReference , price: Int64 ? , id : Int64 ? = nil ) -> Signal < Never , UpdateStarGiftPriceError > {
19752009 return Signal { subscriber in
19762010 let disposable = MetaDisposable ( )
19772011 self . impl. with { impl in
1978- disposable. set ( impl. updateStarGiftResellPrice ( reference: reference, price: price) . start ( error: { error in
2012+ disposable. set ( impl. updateStarGiftResellPrice ( reference: reference, price: price, id : id ) . start ( error: { error in
19792013 subscriber. putError ( error)
19802014 } , completed: {
19812015 subscriber. putCompletion ( )
@@ -2325,6 +2359,12 @@ func _internal_updateStarGiftResalePrice(account: Account, reference: StarGiftRe
23252359 }
23262360 return account. network. request ( Api . functions. payments. updateStarGiftPrice ( stargift: starGift, resellStars: price ?? 0 ) )
23272361 |> mapError { error -> UpdateStarGiftPriceError in
2362+ if error. errorDescription. hasPrefix ( " STARGIFT_RESELL_TOO_EARLY_ " ) {
2363+ let timeout = String ( error. errorDescription [ error. errorDescription. index ( error. errorDescription. startIndex, offsetBy: " STARGIFT_RESELL_TOO_EARLY_ " . count) ... ] )
2364+ if let value = Int32 ( timeout) {
2365+ return . starGiftResellTooEarly( value)
2366+ }
2367+ }
23282368 return . generic
23292369 }
23302370 |> mapToSignal { updates -> Signal < Void , UpdateStarGiftPriceError > in
@@ -2524,6 +2564,11 @@ private final class ResaleGiftsContextImpl {
25242564 self . loadMore ( )
25252565 }
25262566
2567+ func removeStarGift( gift: TelegramCore . StarGift ) {
2568+ self . gifts. removeAll ( where: { $0 == gift } )
2569+ self . pushState ( )
2570+ }
2571+
25272572 func updateSorting( _ sorting: ResaleGiftsContext . Sorting ) {
25282573 guard self . sorting != sorting else {
25292574 return
@@ -2710,6 +2755,13 @@ public final class ResaleGiftsContext {
27102755 return disposable
27112756 }
27122757 }
2758+
2759+ public func removeStarGift( gift: TelegramCore . StarGift ) {
2760+ self . impl. with { impl in
2761+ impl. removeStarGift ( gift: gift)
2762+ }
2763+ }
2764+
27132765
27142766 public var currentState : ResaleGiftsContext . State ? {
27152767 var state : ResaleGiftsContext . State ?
0 commit comments