Skip to content

Commit ecb12a7

Browse files
committed
Various improvements
1 parent 0ac2602 commit ecb12a7

File tree

21 files changed

+1130
-598
lines changed

21 files changed

+1130
-598
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15506,3 +15506,5 @@ Error: %8$@";
1550615506
"Gift.Auction.Extension" = "+ %1$@ for late bids in top %2$@";
1550715507

1550815508
"ChatList.Auctions.UpcomingAuction" = "Upcoming Auction";
15509+
15510+
"Gift.AuctionBid.UpcomingBid" = "You placed an early bid";

submodules/AccountContext/Sources/AccountContext.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1426,10 +1426,11 @@ public protocol SharedAccountContext: AnyObject {
14261426
func makeGiftUpgradePreviewScreen(context: AccountContext, attributes: [StarGift.UniqueGift.Attribute], peerName: String) -> ViewController
14271427
func makeGiftAuctionInfoScreen(context: AccountContext, auctionContext: GiftAuctionContext, completion: (() -> Void)?) -> ViewController
14281428
func makeGiftAuctionBidScreen(context: AccountContext, toPeerId: EnginePeer.Id, text: String?, entities: [MessageTextEntity]?, hideName: Bool, auctionContext: GiftAuctionContext, acquiredGifts: Signal<[GiftAuctionAcquiredGift], NoError>?) -> ViewController
1429-
func makeGiftAuctionViewScreen(context: AccountContext, auctionContext: GiftAuctionContext, completion: @escaping (Signal<[GiftAuctionAcquiredGift], NoError>) -> Void) -> ViewController
1429+
func makeGiftAuctionViewScreen(context: AccountContext, auctionContext: GiftAuctionContext, completion: @escaping (Signal<[GiftAuctionAcquiredGift], NoError>, [StarGift.UniqueGift.Attribute]?) -> Void) -> ViewController
14301430
func makeGiftAuctionActiveBidsScreen(context: AccountContext) -> ViewController
14311431
func makeGiftOfferScreen(context: AccountContext, gift: StarGift.UniqueGift, peer: EnginePeer, amount: CurrencyAmount, commit: @escaping () -> Void) -> ViewController
14321432
func makeGiftUpgradeVariantsPreviewScreen(context: AccountContext, gift: StarGift, attributes: [StarGift.UniqueGift.Attribute]) -> ViewController
1433+
func makeGiftAuctionWearPreviewScreen(context: AccountContext, auctionContext: GiftAuctionContext, acquiredGifts: Signal<[GiftAuctionAcquiredGift], NoError>?, attributes: [StarGift.UniqueGift.Attribute], completion: @escaping () -> Void) -> ViewController
14331434

14341435
func makeStorySharingScreen(context: AccountContext, subject: StorySharingSubject, parentController: ViewController) -> ViewController
14351436

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,15 @@ public final class GiftAuctionContext {
133133
}
134134
}
135135

136+
public var isUpcoming: Bool {
137+
let currentTime = Int32(CFAbsoluteTimeGetCurrent() + kCFAbsoluteTimeIntervalSince1970)
138+
if case let .ongoing(_, startTime, _, _, _, _, _, _, _, _, _, _) = self.auctionState {
139+
return currentTime < startTime
140+
} else {
141+
return false
142+
}
143+
}
144+
136145
public convenience init(account: Account, gift: StarGift) {
137146
self.init(account: account, gift: gift, initialAuctionState: nil, initialMyState: nil, initialTimeout: nil)
138147
}

submodules/TelegramUI/Components/Chat/ChatMessageBubbleItemNode/Sources/ChatMessageBubbleItemNode.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2835,13 +2835,13 @@ public class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePreviewI
28352835
let buttonApprove = MemoryBuffer(data: Data(bytes: &buttonApproveValue, count: 1))
28362836

28372837
let customInfos: [MemoryBuffer: ChatMessageActionButtonsNode.CustomInfo] = [
2838-
buttonDecline: ChatMessageActionButtonsNode.CustomInfo(
2839-
isEnabled: true,
2840-
icon: .suggestedPostReject
2841-
),
28422838
buttonApprove: ChatMessageActionButtonsNode.CustomInfo(
28432839
isEnabled: true,
28442840
icon: .suggestedPostApprove
2841+
),
2842+
buttonDecline: ChatMessageActionButtonsNode.CustomInfo(
2843+
isEnabled: true,
2844+
icon: .suggestedPostReject
28452845
)
28462846
]
28472847
//TODO:localize

submodules/TelegramUI/Components/Gifts/GiftAnimationComponent/Sources/GiftCompositionComponent.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,12 +718,12 @@ public final class GiftCompositionComponent: Component {
718718
animationFile = file
719719
component.externalState?.previewModel = self.previewModels[Int(self.previewModelIndex)]
720720
}
721-
if case let .pattern(_, file, _) = self.previewPatterns[Int(self.previewPatternIndex)] {
721+
if !self.previewPatterns.isEmpty, case let .pattern(_, file, _) = self.previewPatterns[Int(self.previewPatternIndex)] {
722722
patternFile = file
723723
files[file.fileId.id] = file
724724
component.externalState?.previewSymbol = self.previewPatterns[Int(self.previewPatternIndex)]
725725
}
726-
if case let .backdrop(_, _, innerColorValue, outerColorValue, patternColorValue, _, _) = self.previewBackdrops[Int(self.previewBackdropIndex)] {
726+
if !self.previewBackdrops.isEmpty, case let .backdrop(_, _, innerColorValue, outerColorValue, patternColorValue, _, _) = self.previewBackdrops[Int(self.previewBackdropIndex)] {
727727
backgroundColor = UIColor(rgb: UInt32(bitPattern: outerColorValue))
728728
secondBackgroundColor = UIColor(rgb: UInt32(bitPattern: innerColorValue))
729729
patternColor = UIColor(rgb: UInt32(bitPattern: patternColorValue))

submodules/TelegramUI/Components/Gifts/GiftItemComponent/Sources/GiftItemComponent.swift

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ public final class GiftItemComponent: Component {
167167
let isPinned: Bool
168168
let isEditing: Bool
169169
let isDateLocked: Bool
170+
let isPlaceholder: Bool
170171
let mode: Mode
171172
let action: (() -> Void)?
172173
let contextAction: ((UIView, ContextGesture) -> Void)?
@@ -191,6 +192,7 @@ public final class GiftItemComponent: Component {
191192
isPinned: Bool = false,
192193
isEditing: Bool = false,
193194
isDateLocked: Bool = false,
195+
isPlaceholder: Bool = false,
194196
mode: Mode = .generic,
195197
action: (() -> Void)? = nil,
196198
contextAction: ((UIView, ContextGesture) -> Void)? = nil
@@ -214,6 +216,7 @@ public final class GiftItemComponent: Component {
214216
self.isPinned = isPinned
215217
self.isEditing = isEditing
216218
self.isDateLocked = isDateLocked
219+
self.isPlaceholder = isPlaceholder
217220
self.mode = mode
218221
self.action = action
219222
self.contextAction = contextAction
@@ -277,6 +280,9 @@ public final class GiftItemComponent: Component {
277280
if lhs.isDateLocked != rhs.isDateLocked {
278281
return false
279282
}
283+
if lhs.isPlaceholder != rhs.isPlaceholder {
284+
return false
285+
}
280286
if lhs.mode != rhs.mode {
281287
return false
282288
}
@@ -917,7 +923,7 @@ public final class GiftItemComponent: Component {
917923
let buttonSize = self.button.update(
918924
transition: transition,
919925
component: AnyComponent(
920-
ButtonContentComponent(
926+
StarsButtonContentComponent(
921927
context: component.context,
922928
text: price,
923929
color: buttonColor,
@@ -1468,28 +1474,34 @@ public final class GiftItemComponent: Component {
14681474
}
14691475
}
14701476

1471-
private final class ButtonContentComponent: Component {
1477+
public final class StarsButtonContentComponent: Component {
14721478
let context: AccountContext
14731479
let text: String
14741480
let color: UIColor
14751481
let tinted: Bool
14761482
let starsColor: UIColor?
1483+
let font: UIFont
1484+
let height: CGFloat
14771485

14781486
public init(
14791487
context: AccountContext,
14801488
text: String,
14811489
color: UIColor,
14821490
tinted: Bool = false,
1483-
starsColor: UIColor? = nil
1491+
starsColor: UIColor? = nil,
1492+
font: UIFont = Font.semibold(11.0),
1493+
height: CGFloat = 30.0
14841494
) {
14851495
self.context = context
14861496
self.text = text
14871497
self.color = color
14881498
self.tinted = tinted
14891499
self.starsColor = starsColor
1500+
self.font = font
1501+
self.height = height
14901502
}
14911503

1492-
public static func ==(lhs: ButtonContentComponent, rhs: ButtonContentComponent) -> Bool {
1504+
public static func ==(lhs: StarsButtonContentComponent, rhs: StarsButtonContentComponent) -> Bool {
14931505
if lhs.context !== rhs.context {
14941506
return false
14951507
}
@@ -1505,11 +1517,17 @@ private final class ButtonContentComponent: Component {
15051517
if lhs.starsColor != rhs.starsColor {
15061518
return false
15071519
}
1520+
if lhs.font != rhs.font {
1521+
return false
1522+
}
1523+
if lhs.height != rhs.height {
1524+
return false
1525+
}
15081526
return true
15091527
}
15101528

15111529
public final class View: UIView {
1512-
private var component: ButtonContentComponent?
1530+
private var component: StarsButtonContentComponent?
15131531
private weak var componentState: EmptyComponentState?
15141532

15151533
private let backgroundLayer = SimpleLayer()
@@ -1528,7 +1546,7 @@ private final class ButtonContentComponent: Component {
15281546
fatalError("init(coder:) has not been implemented")
15291547
}
15301548

1531-
func update(component: ButtonContentComponent, availableSize: CGSize, state: EmptyComponentState, environment: Environment<Empty>, transition: ComponentTransition) -> CGSize {
1549+
func update(component: StarsButtonContentComponent, availableSize: CGSize, state: EmptyComponentState, environment: Environment<Empty>, transition: ComponentTransition) -> CGSize {
15321550
self.component = component
15331551
self.componentState = state
15341552

@@ -1537,7 +1555,7 @@ private final class ButtonContentComponent: Component {
15371555
textColor = .white
15381556
}
15391557

1540-
let attributedText = NSMutableAttributedString(string: component.text, font: Font.semibold(11.0), textColor: textColor)
1558+
let attributedText = NSMutableAttributedString(string: component.text, font: component.font, textColor: textColor)
15411559
let range = (attributedText.string as NSString).range(of: "#")
15421560
if range.location != NSNotFound {
15431561
attributedText.addAttribute(ChatTextInputAttributes.customEmoji, value: ChatTextInputTextCustomEmojiAttribute(interactivelySelectedFromPackId: nil, fileId: 0, file: nil, custom: .stars(tinted: component.tinted)), range: range)
@@ -1563,7 +1581,7 @@ private final class ButtonContentComponent: Component {
15631581
)
15641582

15651583
let padding: CGFloat = 9.0
1566-
let size = CGSize(width: titleSize.width + padding * 2.0, height: 30.0)
1584+
let size = CGSize(width: titleSize.width + padding * 2.0, height: component.height)
15671585

15681586
if let starsColor = component.starsColor {
15691587
let starsLayer: StarsButtonEffectLayer
@@ -1574,8 +1592,10 @@ private final class ButtonContentComponent: Component {
15741592
self.layer.addSublayer(starsLayer)
15751593
self.starsLayer = starsLayer
15761594
}
1595+
starsLayer.masksToBounds = true
15771596
starsLayer.frame = CGRect(origin: .zero, size: size)
15781597
starsLayer.update(color: starsColor, size: size)
1598+
starsLayer.cornerRadius = size.height * 0.5
15791599
} else {
15801600
self.starsLayer?.removeFromSuperlayer()
15811601
self.starsLayer = nil

submodules/TelegramUI/Components/Gifts/GiftOptionsScreen/Sources/GiftOptionsScreen.swift

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -416,15 +416,31 @@ final class GiftOptionsScreenComponent: Component {
416416
let giftController = component.context.sharedContext.makeGiftAuctionViewScreen(
417417
context: component.context,
418418
auctionContext: auctionContext,
419-
completion: { [weak mainController] acquiredGifts in
420-
let controller = GiftSetupScreen(
421-
context: context,
422-
peerId: component.peerId,
423-
subject: .starGift(gift, nil),
424-
auctionAcquiredGifts: acquiredGifts,
425-
completion: nil
426-
)
427-
mainController?.push(controller)
419+
completion: { [weak mainController] acquiredGifts, upgradeAttributes in
420+
if component.peerId == context.account.peerId, let upgradeAttributes, let navigationController = mainController?.navigationController as? NavigationController {
421+
let controller = context.sharedContext.makeGiftAuctionWearPreviewScreen(context: context, auctionContext: auctionContext, acquiredGifts: acquiredGifts, attributes: upgradeAttributes, completion: {
422+
let controller = context.sharedContext.makeGiftAuctionBidScreen(
423+
context: context,
424+
toPeerId: context.account.peerId,
425+
text: "",
426+
entities: [],
427+
hideName: true,
428+
auctionContext: auctionContext,
429+
acquiredGifts: acquiredGifts
430+
)
431+
navigationController.pushViewController(controller)
432+
})
433+
mainController?.push(controller)
434+
} else {
435+
let controller = GiftSetupScreen(
436+
context: context,
437+
peerId: component.peerId,
438+
subject: .starGift(gift, nil),
439+
auctionAcquiredGifts: acquiredGifts,
440+
completion: nil
441+
)
442+
mainController?.push(controller)
443+
}
428444
}
429445
)
430446
mainController?.push(giftController)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
2+
3+
swift_library(
4+
name = "GiftRemainingCountComponent",
5+
module_name = "GiftRemainingCountComponent",
6+
srcs = glob([
7+
"Sources/**/*.swift",
8+
]),
9+
copts = [
10+
"-warnings-as-errors",
11+
],
12+
deps = [
13+
"//submodules/AsyncDisplayKit",
14+
"//submodules/Display",
15+
"//submodules/Postbox",
16+
"//submodules/TelegramCore",
17+
"//submodules/SSignalKit/SwiftSignalKit",
18+
"//submodules/ComponentFlow",
19+
"//submodules/Components/ComponentDisplayAdapters",
20+
"//submodules/TelegramPresentationData",
21+
"//submodules/AccountContext",
22+
"//submodules/AppBundle",
23+
"//submodules/TelegramUI/Components/GlassBackgroundComponent",
24+
"//submodules/Components/MultilineTextComponent",
25+
],
26+
visibility = [
27+
"//visibility:public",
28+
],
29+
)

submodules/TelegramUI/Components/Gifts/GiftSetupScreen/Sources/RemainingCountComponent.swift renamed to submodules/TelegramUI/Components/Gifts/GiftRemainingCountComponent/Sources/GiftRemainingCountComponent.swift

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,11 @@ import TelegramCore
66
import SwiftSignalKit
77
import AccountContext
88
import TelegramPresentationData
9-
import PresentationDataUtils
109
import ComponentFlow
1110
import MultilineTextComponent
12-
import Markdown
13-
import TextFormat
14-
import RoundedRectWithTailPath
1511
import GlassBackgroundComponent
1612

17-
public class RemainingCountComponent: Component {
13+
public class GiftRemainingCountComponent: Component {
1814
private let inactiveColor: UIColor
1915
private let activeColors: [UIColor]
2016
private let inactiveTitle: String
@@ -62,7 +58,7 @@ public class RemainingCountComponent: Component {
6258
self.groupingSeparator = groupingSeparator
6359
}
6460

65-
public static func ==(lhs: RemainingCountComponent, rhs: RemainingCountComponent) -> Bool {
61+
public static func ==(lhs: GiftRemainingCountComponent, rhs: GiftRemainingCountComponent) -> Bool {
6662
if lhs.inactiveColor != rhs.inactiveColor {
6763
return false
6864
}
@@ -109,7 +105,7 @@ public class RemainingCountComponent: Component {
109105
}
110106

111107
public final class View: UIView {
112-
private var component: RemainingCountComponent?
108+
private var component: GiftRemainingCountComponent?
113109

114110
private let container: UIView
115111
private let inactiveBackground: SimpleLayer
@@ -162,7 +158,7 @@ public class RemainingCountComponent: Component {
162158
}
163159

164160
var previousAvailableSize: CGSize?
165-
func update(component: RemainingCountComponent, availableSize: CGSize, transition: ComponentTransition) -> CGSize {
161+
func update(component: GiftRemainingCountComponent, availableSize: CGSize, transition: ComponentTransition) -> CGSize {
166162
self.component = component
167163
self.inactiveBackground.backgroundColor = component.inactiveColor.cgColor
168164
self.activeBackground.backgroundColor = component.activeColors.last?.cgColor

submodules/TelegramUI/Components/Gifts/GiftSetupScreen/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ swift_library(
5151
"//submodules/TelegramUI/Components/AnimatedTextComponent",
5252
"//submodules/TelegramUI/Components/GlassBackgroundComponent",
5353
"//submodules/TelegramUI/Components/MessageInputPanelComponent",
54+
"//submodules/TelegramUI/Components/Gifts/GiftRemainingCountComponent",
5455
],
5556
visibility = [
5657
"//visibility:public",

0 commit comments

Comments
 (0)