mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-08 08:31:13 +00:00
Birthday gifts
This commit is contained in:
parent
10984d7ce4
commit
30a85d1fe1
@ -35,6 +35,7 @@ final class GiftOptionsScreenComponent: Component {
|
|||||||
let starsContext: StarsContext
|
let starsContext: StarsContext
|
||||||
let peerId: EnginePeer.Id
|
let peerId: EnginePeer.Id
|
||||||
let premiumOptions: [CachedPremiumGiftOption]
|
let premiumOptions: [CachedPremiumGiftOption]
|
||||||
|
let hasBirthday: Bool
|
||||||
let completion: (() -> Void)?
|
let completion: (() -> Void)?
|
||||||
|
|
||||||
init(
|
init(
|
||||||
@ -42,12 +43,14 @@ final class GiftOptionsScreenComponent: Component {
|
|||||||
starsContext: StarsContext,
|
starsContext: StarsContext,
|
||||||
peerId: EnginePeer.Id,
|
peerId: EnginePeer.Id,
|
||||||
premiumOptions: [CachedPremiumGiftOption],
|
premiumOptions: [CachedPremiumGiftOption],
|
||||||
|
hasBirthday: Bool,
|
||||||
completion: (() -> Void)?
|
completion: (() -> Void)?
|
||||||
) {
|
) {
|
||||||
self.context = context
|
self.context = context
|
||||||
self.starsContext = starsContext
|
self.starsContext = starsContext
|
||||||
self.peerId = peerId
|
self.peerId = peerId
|
||||||
self.premiumOptions = premiumOptions
|
self.premiumOptions = premiumOptions
|
||||||
|
self.hasBirthday = hasBirthday
|
||||||
self.completion = completion
|
self.completion = completion
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,6 +64,9 @@ final class GiftOptionsScreenComponent: Component {
|
|||||||
if lhs.premiumOptions != rhs.premiumOptions {
|
if lhs.premiumOptions != rhs.premiumOptions {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
if lhs.hasBirthday != rhs.hasBirthday {
|
||||||
|
return false
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,32 +133,43 @@ final class GiftOptionsScreenComponent: Component {
|
|||||||
private var _effectiveStarGifts: ([StarGift], StarsFilter)?
|
private var _effectiveStarGifts: ([StarGift], StarsFilter)?
|
||||||
private var effectiveStarGifts: [StarGift]? {
|
private var effectiveStarGifts: [StarGift]? {
|
||||||
get {
|
get {
|
||||||
if case .all = self.starsFilter {
|
if let (currentGifts, currentFilter) = self._effectiveStarGifts, currentFilter == self.starsFilter {
|
||||||
return self.state?.starGifts
|
return currentGifts
|
||||||
} else {
|
} else if let allGifts = self.state?.starGifts {
|
||||||
if let (currentGifts, currentFilter) = self._effectiveStarGifts, currentFilter == self.starsFilter {
|
var sortedGifts = allGifts
|
||||||
return currentGifts
|
if self.component?.hasBirthday == true {
|
||||||
} else if let allGifts = self.state?.starGifts {
|
var updatedGifts: [StarGift] = []
|
||||||
let filteredGifts: [StarGift] = allGifts.filter {
|
for gift in allGifts {
|
||||||
switch self.starsFilter {
|
if gift.flags.contains(.isBirthdayGift) {
|
||||||
case .all:
|
updatedGifts.append(gift)
|
||||||
return true
|
|
||||||
case .limited:
|
|
||||||
if $0.availability != nil {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
case let .stars(stars):
|
|
||||||
if $0.price == stars {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
self._effectiveStarGifts = (filteredGifts, self.starsFilter)
|
for gift in allGifts {
|
||||||
return filteredGifts
|
if !gift.flags.contains(.isBirthdayGift) {
|
||||||
} else {
|
updatedGifts.append(gift)
|
||||||
return nil
|
}
|
||||||
|
}
|
||||||
|
sortedGifts = updatedGifts
|
||||||
}
|
}
|
||||||
|
let filteredGifts: [StarGift] = sortedGifts.filter {
|
||||||
|
switch self.starsFilter {
|
||||||
|
case .all:
|
||||||
|
return true
|
||||||
|
case .limited:
|
||||||
|
if $0.availability != nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
case let .stars(stars):
|
||||||
|
if $0.price == stars {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
self._effectiveStarGifts = (filteredGifts, self.starsFilter)
|
||||||
|
return filteredGifts
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1073,6 +1090,7 @@ open class GiftOptionsScreen: ViewControllerComponentContainer, GiftOptionsScree
|
|||||||
starsContext: StarsContext,
|
starsContext: StarsContext,
|
||||||
peerId: EnginePeer.Id,
|
peerId: EnginePeer.Id,
|
||||||
premiumOptions: [CachedPremiumGiftOption],
|
premiumOptions: [CachedPremiumGiftOption],
|
||||||
|
hasBirthday: Bool,
|
||||||
completion: (() -> Void)? = nil
|
completion: (() -> Void)? = nil
|
||||||
) {
|
) {
|
||||||
self.context = context
|
self.context = context
|
||||||
@ -1082,6 +1100,7 @@ open class GiftOptionsScreen: ViewControllerComponentContainer, GiftOptionsScree
|
|||||||
starsContext: starsContext,
|
starsContext: starsContext,
|
||||||
peerId: peerId,
|
peerId: peerId,
|
||||||
premiumOptions: premiumOptions,
|
premiumOptions: premiumOptions,
|
||||||
|
hasBirthday: hasBirthday,
|
||||||
completion: completion
|
completion: completion
|
||||||
), navigationBarAppearance: .none, theme: .default, updatedPresentationData: nil)
|
), navigationBarAppearance: .none, theme: .default, updatedPresentationData: nil)
|
||||||
|
|
||||||
|
@ -591,7 +591,7 @@ extension ChatControllerImpl {
|
|||||||
if let peer = strongSelf.presentationInterfaceState.renderedPeer?.peer, let starsContext = context.starsContext {
|
if let peer = strongSelf.presentationInterfaceState.renderedPeer?.peer, let starsContext = context.starsContext {
|
||||||
let premiumGiftOptions = strongSelf.presentationInterfaceState.premiumGiftOptions
|
let premiumGiftOptions = strongSelf.presentationInterfaceState.premiumGiftOptions
|
||||||
if !premiumGiftOptions.isEmpty {
|
if !premiumGiftOptions.isEmpty {
|
||||||
let controller = PremiumGiftAttachmentScreen(context: context, starsContext: starsContext, peerId: peer.id, premiumOptions: premiumGiftOptions, completion: { [weak self] in
|
let controller = PremiumGiftAttachmentScreen(context: context, starsContext: starsContext, peerId: peer.id, premiumOptions: premiumGiftOptions, hasBirthday: true, completion: { [weak self] in
|
||||||
guard let self else {
|
guard let self else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -2336,7 +2336,7 @@ public final class SharedAccountContextImpl: SharedAccountContext {
|
|||||||
.startStandalone(next: { [weak controller] result, options in
|
.startStandalone(next: { [weak controller] result, options in
|
||||||
if let (peers, _, _, _, _, _) = result, let contactPeer = peers.first, case let .peer(peer, _, _) = contactPeer, let starsContext = context.starsContext {
|
if let (peers, _, _, _, _, _) = result, let contactPeer = peers.first, case let .peer(peer, _, _) = contactPeer, let starsContext = context.starsContext {
|
||||||
let premiumOptions = options.filter { $0.users == 1 }.map { CachedPremiumGiftOption(months: $0.months, currency: $0.currency, amount: $0.amount, botUrl: "", storeProductId: $0.storeProductId) }
|
let premiumOptions = options.filter { $0.users == 1 }.map { CachedPremiumGiftOption(months: $0.months, currency: $0.currency, amount: $0.amount, botUrl: "", storeProductId: $0.storeProductId) }
|
||||||
let giftController = GiftOptionsScreen(context: context, starsContext: starsContext, peerId: peer.id, premiumOptions: premiumOptions)
|
let giftController = GiftOptionsScreen(context: context, starsContext: starsContext, peerId: peer.id, premiumOptions: premiumOptions, hasBirthday: true)
|
||||||
giftController.navigationPresentation = .modal
|
giftController.navigationPresentation = .modal
|
||||||
controller?.push(giftController)
|
controller?.push(giftController)
|
||||||
}
|
}
|
||||||
@ -2406,7 +2406,7 @@ public final class SharedAccountContextImpl: SharedAccountContext {
|
|||||||
guard let starsContext = context.starsContext else {
|
guard let starsContext = context.starsContext else {
|
||||||
fatalError()
|
fatalError()
|
||||||
}
|
}
|
||||||
let controller = GiftOptionsScreen(context: context, starsContext: starsContext, peerId: peerId, premiumOptions: premiumOptions)
|
let controller = GiftOptionsScreen(context: context, starsContext: starsContext, peerId: peerId, premiumOptions: premiumOptions, hasBirthday: false)
|
||||||
controller.navigationPresentation = .modal
|
controller.navigationPresentation = .modal
|
||||||
return controller
|
return controller
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user