Skip to content

Commit 74e1d22

Browse files
author
Isaac
committed
Merge commit 'd574fb7a113fda8611a819d705fa1935967e2c34'
2 parents 0995e5e + d574fb7 commit 74e1d22

File tree

13 files changed

+304
-177
lines changed

13 files changed

+304
-177
lines changed

Telegram/Telegram-iOS/en.lproj/Localizable.strings

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15367,3 +15367,8 @@ Error: %8$@";
1536715367
"Stars.Transaction.LiveStreamPaidMessage_1" = "Fee for %@ Live Stream Message";
1536815368
"Stars.Transaction.LiveStreamPaidMessage_any" = "Fee for %@ Live Stream Messages";
1536915369
"Stars.Transaction.LiveStreamPaidMessage.Text" = "You receive **%@%** of the price that you charge for each incoming message.";
15370+
15371+
"Notification.StarGift.Subtitle.NoConvert" = "We'll notify you once it becomes eligible for unique upgrades.";
15372+
"Notification.StarGift.Subtitle.OtherNoConvert" = "We'll notify %1$@ once it becomes eligible for unique upgrades.";
15373+
"Gift.View.NoConvertDescription" = "We'll notify you once it becomes eligible for unique upgrades.";
15374+
"Gift.View.OtherNoConvertDescription" = "We'll notify %1$@ once it becomes eligible for unique upgrades.";

submodules/PremiumUI/Sources/PremiumGiftCodeScreen.swift

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import ViewControllerComponent
1212
import SheetComponent
1313
import MultilineTextComponent
1414
import BundleIconComponent
15-
import SolidRoundedButtonComponent
1615
import Markdown
1716
import BalancedTextComponent
1817
import ConfettiEffect
@@ -22,6 +21,8 @@ import TelegramStringFormatting
2221
import UndoUI
2322
import InvisibleInkDustNode
2423
import PremiumStarComponent
24+
import GlassBarButtonComponent
25+
import ButtonComponent
2526

2627
private final class PremiumGiftCodeSheetContent: CombinedComponent {
2728
typealias EnvironmentType = ViewControllerComponentContainer.Environment
@@ -74,9 +75,7 @@ private final class PremiumGiftCodeSheetContent: CombinedComponent {
7475
var initialized = false
7576

7677
var peerMap: [EnginePeer.Id: EnginePeer] = [:]
77-
78-
var cachedCloseImage: (UIImage, PresentationTheme)?
79-
78+
8079
var inProgress = false
8180

8281
init(context: AccountContext, subject: PremiumGiftCodeScreen.Subject) {
@@ -132,14 +131,14 @@ private final class PremiumGiftCodeSheetContent: CombinedComponent {
132131
}
133132

134133
static var body: Body {
135-
let closeButton = Child(Button.self)
134+
let closeButton = Child(GlassBarButtonComponent.self)
136135
let title = Child(MultilineTextComponent.self)
137136
let star = Child(PremiumStarComponent.self)
138137
let description = Child(BalancedTextComponent.self)
139138
let linkButton = Child(Button.self)
140139
let table = Child(TableComponent.self)
141140
let additional = Child(BalancedTextComponent.self)
142-
let button = Child(SolidRoundedButtonComponent.self)
141+
let button = Child(ButtonComponent.self)
143142

144143
return { context in
145144
let environment = context.environment[ViewControllerComponentContainer.Environment.self].value
@@ -155,22 +154,23 @@ private final class PremiumGiftCodeSheetContent: CombinedComponent {
155154
let sideInset: CGFloat = 16.0 + environment.safeInsets.left
156155
let textSideInset: CGFloat = 32.0 + environment.safeInsets.left
157156

158-
let closeImage: UIImage
159-
if let (image, theme) = state.cachedCloseImage, theme === environment.theme {
160-
closeImage = image
161-
} else {
162-
closeImage = generateCloseButtonImage(backgroundColor: UIColor(rgb: 0x808084, alpha: 0.1), foregroundColor: theme.actionSheet.inputClearButtonColor)!
163-
state.cachedCloseImage = (closeImage, theme)
164-
}
165-
166157
let closeButton = closeButton.update(
167-
component: Button(
168-
content: AnyComponent(Image(image: closeImage)),
169-
action: { [weak component] in
170-
component?.cancel(true)
158+
component: GlassBarButtonComponent(
159+
size: CGSize(width: 40.0, height: 40.0),
160+
backgroundColor: theme.rootController.navigationBar.glassBarButtonBackgroundColor,
161+
isDark: theme.overallDarkAppearance,
162+
state: .generic,
163+
component: AnyComponentWithIdentity(id: "close", component: AnyComponent(
164+
BundleIconComponent(
165+
name: "Navigation/Close",
166+
tintColor: theme.rootController.navigationBar.glassBarButtonForegroundColor
167+
)
168+
)),
169+
action: { _ in
170+
component.cancel(true)
171171
}
172172
),
173-
availableSize: CGSize(width: 30.0, height: 30.0),
173+
availableSize: CGSize(width: 40.0, height: 40.0),
174174
transition: .immediate
175175
)
176176

@@ -312,7 +312,7 @@ private final class PremiumGiftCodeSheetContent: CombinedComponent {
312312
}
313313
}
314314
),
315-
availableSize: CGSize(width: context.availableSize.width - sideInset * 2.0, height: 50.0),
315+
availableSize: CGSize(width: context.availableSize.width - sideInset * 2.0, height: 52.0),
316316
transition: .immediate
317317
)
318318

@@ -462,20 +462,21 @@ private final class PremiumGiftCodeSheetContent: CombinedComponent {
462462
availableSize: CGSize(width: context.availableSize.width - textSideInset * 2.0, height: context.availableSize.height),
463463
transition: .immediate
464464
)
465-
465+
466+
let buttonInsets = ContainerViewLayout.concentricInsets(bottomInset: environment.safeInsets.bottom, innerDiameter: 52.0, sideInset: 30.0)
466467
let button = button.update(
467-
component: SolidRoundedButtonComponent(
468-
title: buttonText,
469-
theme: SolidRoundedButtonComponent.Theme(theme: theme),
470-
font: .bold,
471-
fontSize: 17.0,
472-
height: 50.0,
473-
cornerRadius: 10.0,
474-
gloss: gloss,
475-
iconName: nil,
476-
animationName: nil,
477-
iconPosition: .left,
478-
isLoading: state.inProgress,
468+
component: ButtonComponent(
469+
background: ButtonComponent.Background(
470+
style: .glass,
471+
color: theme.list.itemCheckColors.fillColor,
472+
foreground: theme.list.itemCheckColors.foregroundColor,
473+
pressedColor: theme.list.itemCheckColors.fillColor.withMultipliedAlpha(0.9),
474+
cornerRadius: 10.0,
475+
),
476+
content: AnyComponentWithIdentity(
477+
id: AnyHashable(0),
478+
component: AnyComponent(MultilineTextComponent(text: .plain(NSMutableAttributedString(string: buttonText, font: Font.semibold(17.0), textColor: theme.list.itemCheckColors.foregroundColor, paragraphAlignment: .center))))
479+
),
479480
action: { [weak state] in
480481
if gloss {
481482
component.action()
@@ -488,20 +489,20 @@ private final class PremiumGiftCodeSheetContent: CombinedComponent {
488489
}
489490
}
490491
),
491-
availableSize: CGSize(width: context.availableSize.width - sideInset * 2.0, height: 50.0),
492-
transition: context.transition
492+
availableSize: CGSize(width: context.availableSize.width - buttonInsets.left - buttonInsets.right, height: 52.0),
493+
transition: .immediate
493494
)
494495

495496
context.add(title
496-
.position(CGPoint(x: context.availableSize.width / 2.0, y: 28.0))
497+
.position(CGPoint(x: context.availableSize.width / 2.0, y: 36.0))
497498
)
498499

499500
context.add(star
500501
.position(CGPoint(x: context.availableSize.width / 2.0, y: star.size.height / 2.0))
501502
)
502503

503504
var originY: CGFloat = 0.0
504-
originY += star.size.height - 32.0
505+
originY += star.size.height - 24.0
505506

506507
context.add(description
507508
.position(CGPoint(x: context.availableSize.width / 2.0, y: originY + description.size.height / 2.0))
@@ -523,16 +524,17 @@ private final class PremiumGiftCodeSheetContent: CombinedComponent {
523524
)
524525
originY += additional.size.height + 23.0
525526

526-
let buttonFrame = CGRect(origin: CGPoint(x: sideInset, y: originY), size: button.size)
527527
context.add(button
528-
.position(CGPoint(x: buttonFrame.midX, y: buttonFrame.midY))
528+
.position(CGPoint(x: context.availableSize.width / 2.0, y: originY + button.size.height / 2.0))
529529
)
530+
originY += button.size.height
531+
originY += buttonInsets.bottom
530532

531533
context.add(closeButton
532-
.position(CGPoint(x: context.availableSize.width - environment.safeInsets.left - closeButton.size.width, y: 28.0))
534+
.position(CGPoint(x: 16.0 + closeButton.size.width / 2.0, y: 16.0 + closeButton.size.height / 2.0))
533535
)
534536

535-
let contentSize = CGSize(width: context.availableSize.width, height: buttonFrame.maxY + 5.0 + environment.safeInsets.bottom)
537+
let contentSize = CGSize(width: context.availableSize.width, height: originY)
536538

537539
return contentSize
538540
}
@@ -612,6 +614,7 @@ private final class PremiumGiftCodeSheetComponent: CombinedComponent {
612614
shareLink: context.component.shareLink,
613615
displayHiddenTooltip: context.component.displayHiddenTooltip
614616
)),
617+
style: .glass,
615618
backgroundColor: .color(environment.theme.actionSheet.opaqueItemBackgroundColor),
616619
followContentSizeChanges: true,
617620
clipsContent: true,
@@ -799,10 +802,10 @@ final class GiftLinkButtonContentComponent: CombinedComponent {
799802
return { context in
800803
let component = context.component
801804

802-
let sideInset: CGFloat = 38.0
805+
let sideInset: CGFloat = 42.0
803806

804807
let background = background.update(
805-
component: RoundedRectangle(color: component.isSeparateSection ? component.theme.list.itemBlocksBackgroundColor : component.theme.list.itemInputField.backgroundColor, cornerRadius: 10.0),
808+
component: RoundedRectangle(color: component.isSeparateSection ? component.theme.list.itemBlocksBackgroundColor : component.theme.list.itemInputField.backgroundColor, cornerRadius: 26.0),
806809
availableSize: context.availableSize,
807810
transition: context.transition
808811
)
@@ -989,8 +992,8 @@ private final class TableComponent: CombinedComponent {
989992
if let (currentImage, theme) = context.state.cachedBorderImage, theme === context.component.theme {
990993
borderImage = currentImage
991994
} else {
992-
let borderRadius: CGFloat = 5.0
993-
borderImage = generateImage(CGSize(width: 16.0, height: 16.0), rotatedContext: { size, context in
995+
let borderRadius: CGFloat = 14.0
996+
borderImage = generateImage(CGSize(width: borderRadius * 2.0 + 6.0, height: borderRadius * 2.0 + 6.0), rotatedContext: { size, context in
994997
let bounds = CGRect(origin: .zero, size: size)
995998
context.setFillColor(backgroundColor.cgColor)
996999
context.fill(bounds)
@@ -1005,7 +1008,7 @@ private final class TableComponent: CombinedComponent {
10051008
context.setLineWidth(borderWidth)
10061009
context.addPath(path)
10071010
context.strokePath()
1008-
})!.stretchableImage(withLeftCapWidth: 5, topCapHeight: 5)
1011+
})!.stretchableImage(withLeftCapWidth: Int(borderRadius), topCapHeight: Int(borderRadius))
10091012
context.state.cachedBorderImage = (borderImage, context.component.theme)
10101013
}
10111014

submodules/TelegramBaseController/Sources/TelegramBaseController.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,13 @@ open class TelegramBaseController: ViewController, KeyShortcutResponder {
368368
guard let self else {
369369
return
370370
}
371-
self.giftAuctionStates = states
372-
371+
self.giftAuctionStates = states.filter { state in
372+
if case .ongoing = state.auctionState {
373+
return true
374+
} else {
375+
return false
376+
}
377+
}
373378
})
374379
}
375380

submodules/TelegramCore/Sources/State/AccountStateManagementUtils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1901,7 +1901,7 @@ private func finalStateWithUpdatesAndServerTime(accountPeerId: PeerId, postbox:
19011901
case let .updateMonoForumNoPaidException(flags, channelId, savedPeerId):
19021902
updatedState.updateMonoForumNoPaidException(peerId: PeerId(namespace: Namespaces.Peer.CloudChannel, id: PeerId.Id._internalFromInt64Value(channelId)), threadId: savedPeerId.peerId.toInt64(), isFree: (flags & (1 << 0)) != 0)
19031903
case let .updateStarGiftAuctionState(giftId, state):
1904-
if let state = GiftAuctionContext.State.AuctionState(apiAuctionState: state) {
1904+
if let state = GiftAuctionContext.State.AuctionState(apiAuctionState: state, peers: updatedState.peers) {
19051905
updatedState.updateStarGiftAuctionState(giftId: giftId, state: state)
19061906
}
19071907
case let .updateStarGiftAuctionUserState(giftId, userState):

submodules/TelegramCore/Sources/TelegramEngine/Payments/StarGiftsAuctions.swift

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ private func _internal_getStarGiftAuctionState(postbox: Postbox, network: Networ
3737
}
3838
return (
3939
gift: gift,
40-
state: GiftAuctionContext.State.AuctionState(apiAuctionState: state),
40+
state: GiftAuctionContext.State.AuctionState(apiAuctionState: state, transaction: transaction),
4141
myState: GiftAuctionContext.State.MyState(apiAuctionUserState: userState),
4242
timeout: timeout
4343
)
@@ -55,7 +55,7 @@ public final class GiftAuctionContext {
5555
}
5656

5757
public enum AuctionState: Equatable {
58-
case ongoing(version: Int32, startDate: Int32, endDate: Int32, minBidAmount: Int64, bidLevels: [BidLevel], topBidders: [EnginePeer.Id], nextRoundDate: Int32, giftsLeft: Int32, currentRound: Int32, totalRounds: Int32)
58+
case ongoing(version: Int32, startDate: Int32, endDate: Int32, minBidAmount: Int64, bidLevels: [BidLevel], topBidders: [EnginePeer], nextRoundDate: Int32, giftsLeft: Int32, currentRound: Int32, totalRounds: Int32)
5959
case finished(startDate: Int32, endDate: Int32, averagePrice: Int64)
6060
}
6161

@@ -208,10 +208,33 @@ extension GiftAuctionContext.State.BidLevel {
208208
}
209209

210210
extension GiftAuctionContext.State.AuctionState {
211-
init?(apiAuctionState: Api.StarGiftAuctionState) {
211+
init?(apiAuctionState: Api.StarGiftAuctionState, peers: [PeerId: Peer]) {
212212
switch apiAuctionState {
213-
case let .starGiftAuctionState(version, startDate, endDate, minBidAmount, bidLevels, topBidders, nextRoundAt, giftsLeft, currentRound, totalRounds):
214-
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)
213+
case let .starGiftAuctionState(version, startDate, endDate, minBidAmount, bidLevels, topBiddersPeerIds, nextRoundAt, giftsLeft, currentRound, totalRounds):
214+
var topBidders: [EnginePeer] = []
215+
for peerId in topBiddersPeerIds {
216+
if let peer = peers[PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(peerId))] {
217+
topBidders.append(EnginePeer(peer))
218+
}
219+
}
220+
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)
221+
case let .starGiftAuctionStateFinished(startDate, endDate, averagePrice):
222+
self = .finished(startDate: startDate, endDate: endDate, averagePrice: averagePrice)
223+
case .starGiftAuctionStateNotModified:
224+
return nil
225+
}
226+
}
227+
228+
init?(apiAuctionState: Api.StarGiftAuctionState, transaction: Transaction) {
229+
switch apiAuctionState {
230+
case let .starGiftAuctionState(version, startDate, endDate, minBidAmount, bidLevels, topBiddersPeerIds, nextRoundAt, giftsLeft, currentRound, totalRounds):
231+
var topBidders: [EnginePeer] = []
232+
for peerId in topBiddersPeerIds {
233+
if let peer = transaction.getPeer(PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt64Value(peerId))) {
234+
topBidders.append(EnginePeer(peer))
235+
}
236+
}
237+
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)
215238
case let .starGiftAuctionStateFinished(startDate, endDate, averagePrice):
216239
self = .finished(startDate: startDate, endDate: endDate, averagePrice: averagePrice)
217240
case .starGiftAuctionStateNotModified:
@@ -314,7 +337,7 @@ func _internal_getActiveGiftAuctions(account: Account, hash: Int64) -> Signal<[G
314337
auctionContexts.append(GiftAuctionContext(
315338
account: account,
316339
gift: gift,
317-
initialAuctionState: GiftAuctionContext.State.AuctionState(apiAuctionState: auctionState),
340+
initialAuctionState: GiftAuctionContext.State.AuctionState(apiAuctionState: auctionState, transaction: transaction),
318341
initialMyState: GiftAuctionContext.State.MyState(apiAuctionUserState: userState),
319342
initialTimeout: nil
320343
))
@@ -436,18 +459,20 @@ public class GiftAuctionsManager {
436459
}
437460

438461
private func updateState() {
439-
var signals: [Signal<GiftAuctionContext.State, NoError>] = []
462+
var signals: [Signal<GiftAuctionContext.State?, NoError>] = []
440463
for auction in self.auctionContexts.values.sorted(by: { $0.gift.giftId < $1.gift.giftId }) {
441-
signals.append(auction.state
442-
|> mapToSignal { state in
443-
if let state, state.myState.bidAmount != nil, case .ongoing = state.auctionState {
444-
return .single(state)
445-
} else {
446-
return .complete()
447-
}
448-
})
464+
signals.append(auction.state)
449465
}
450-
self.statePromise.set(combineLatest(signals))
466+
self.statePromise.set(combineLatest(signals)
467+
|> map { states -> [GiftAuctionContext.State] in
468+
var filteredStates: [GiftAuctionContext.State] = []
469+
for state in states {
470+
if let state, case .ongoing = state.auctionState, state.myState.bidAmount != nil {
471+
filteredStates.append(state)
472+
}
473+
}
474+
return filteredStates
475+
})
451476
}
452477
}
453478

0 commit comments

Comments
 (0)