Skip to content

Commit 037890c

Browse files
committed
Merge branch 'gift-resale' of gitlab.com:peter-iakovlev/telegram-ios into gift-resale
# Conflicts: # submodules/TelegramCore/Sources/TelegramEngine/Payments/StarGifts.swift
2 parents c3c4e17 + 746239c commit 037890c

File tree

25 files changed

+1729
-666
lines changed

25 files changed

+1729
-666
lines changed

submodules/AccountContext/Sources/AccountContext.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,7 @@ public protocol SharedAccountContext: AnyObject {
11781178
func makeStarsAmountScreen(context: AccountContext, initialValue: Int64?, completion: @escaping (Int64) -> Void) -> ViewController
11791179
func makeStarsWithdrawalScreen(context: AccountContext, stats: StarsRevenueStats, completion: @escaping (Int64) -> Void) -> ViewController
11801180
func makeStarsWithdrawalScreen(context: AccountContext, completion: @escaping (Int64) -> Void) -> ViewController
1181-
func makeStarGiftResellScreen(context: AccountContext, completion: @escaping (Int64) -> Void) -> ViewController
1181+
func makeStarGiftResellScreen(context: AccountContext, update: Bool, completion: @escaping (Int64) -> Void) -> ViewController
11821182
func makeStarsGiftScreen(context: AccountContext, message: EngineMessage) -> ViewController
11831183
func makeStarsGiveawayBoostScreen(context: AccountContext, peerId: EnginePeer.Id, boost: ChannelBoostersContext.State.Boost) -> ViewController
11841184
func makeStarsIntroScreen(context: AccountContext) -> ViewController

submodules/AccountContext/Sources/AttachmentMainButtonState.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public struct AttachmentMainButtonState {
4141
public let progress: Progress
4242
public let isEnabled: Bool
4343
public let hasShimmer: Bool
44+
public let iconName: String?
4445
public let position: Position?
4546

4647
public init(
@@ -53,6 +54,7 @@ public struct AttachmentMainButtonState {
5354
progress: Progress,
5455
isEnabled: Bool,
5556
hasShimmer: Bool,
57+
iconName: String? = nil,
5658
position: Position? = nil
5759
) {
5860
self.text = text
@@ -64,6 +66,7 @@ public struct AttachmentMainButtonState {
6466
self.progress = progress
6567
self.isEnabled = isEnabled
6668
self.hasShimmer = hasShimmer
69+
self.iconName = iconName
6770
self.position = position
6871
}
6972

submodules/AttachmentUI/Sources/AttachmentPanel.swift

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ private final class MainButtonNode: HighlightTrackingButtonNode {
476476
private var size: CGSize?
477477

478478
private let backgroundAnimationNode: ASImageNode
479+
private var iconNode: ASImageNode?
479480
fileprivate let textNode: ImmediateTextNode
480481
private var badgeNode: BadgeNode?
481482
private let statusNode: SemanticStatusNode
@@ -781,6 +782,25 @@ private final class MainButtonNode: HighlightTrackingButtonNode {
781782
badgeNode.removeFromSupernode()
782783
}
783784

785+
if let iconName = state.iconName {
786+
let iconNode: ASImageNode
787+
if let current = self.iconNode {
788+
iconNode = current
789+
} else {
790+
iconNode = ASImageNode()
791+
iconNode.displaysAsynchronously = false
792+
iconNode.image = generateTintedImage(image: UIImage(bundleImageName: iconName), color: state.textColor)
793+
self.addSubnode(iconNode)
794+
}
795+
if let iconSize = iconNode.image?.size {
796+
textFrame.origin.x += (iconSize.width + 6.0) / 2.0
797+
iconNode.frame = CGRect(origin: CGPoint(x: textFrame.minX - iconSize.width - 6.0, y: textFrame.minY + floorToScreenPixels((textFrame.height - iconSize.height) * 0.5)), size: iconSize)
798+
}
799+
} else if let iconNode = self.iconNode {
800+
self.iconNode = nil
801+
iconNode.removeFromSupernode()
802+
}
803+
784804
if self.textNode.frame.width.isZero {
785805
self.textNode.frame = textFrame
786806
} else {
@@ -795,7 +815,7 @@ private final class MainButtonNode: HighlightTrackingButtonNode {
795815
self.transitionFromProgress()
796816
}
797817
}
798-
818+
799819
if let shimmerView = self.shimmerView, let borderView = self.borderView, let borderMaskView = self.borderMaskView, let borderShimmerView = self.borderShimmerView {
800820
let buttonFrame = CGRect(origin: .zero, size: size)
801821
let buttonWidth = size.width

submodules/ContextUI/Sources/ContextController.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2145,6 +2145,8 @@ public protocol ContextReferenceContentSource: AnyObject {
21452145

21462146
var shouldBeDismissed: Signal<Bool, NoError> { get }
21472147

2148+
var forceDisplayBelowKeyboard: Bool { get }
2149+
21482150
func transitionInfo() -> ContextControllerReferenceViewInfo?
21492151
}
21502152

@@ -2153,6 +2155,10 @@ public extension ContextReferenceContentSource {
21532155
return false
21542156
}
21552157

2158+
var forceDisplayBelowKeyboard: Bool {
2159+
return false
2160+
}
2161+
21562162
var shouldBeDismissed: Signal<Bool, NoError> {
21572163
return .single(false)
21582164
}
@@ -2744,7 +2750,9 @@ public final class ContextController: ViewController, StandalonePresentableContr
27442750
}
27452751

27462752
public func dismiss(result: ContextMenuActionResult, completion: (() -> Void)?) {
2747-
if viewTreeContainsFirstResponder(view: self.view) {
2753+
if let mainSource = self.configuration.sources.first(where: { $0.id == self.configuration.initialId }), case let .reference(source) = mainSource.source, source.forceDisplayBelowKeyboard {
2754+
2755+
} else if viewTreeContainsFirstResponder(view: self.view) {
27482756
self.dismissOnInputClose = (result, completion)
27492757
self.view.endEditing(true)
27502758
return

submodules/ContextUI/Sources/ContextControllerActionsStackNode.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ public final class ContextControllerActionsListActionItemNode: HighlightTracking
273273
return super.hitTest(point, with: event)
274274
}
275275

276-
func setItem(item: ContextMenuActionItem) {
276+
public func setItem(item: ContextMenuActionItem) {
277277
self.item = item
278278
self.accessibilityLabel = item.text
279279
}
@@ -363,6 +363,8 @@ public final class ContextControllerActionsListActionItemNode: HighlightTracking
363363
return ChatTextInputStateTextAttribute(type: .customEmoji(stickerPack: nil, fileId: fileId, enableAnimation: true), range: entity.range)
364364
} else if case .Bold = entity.type {
365365
return ChatTextInputStateTextAttribute(type: .bold, range: entity.range)
366+
} else if case .Italic = entity.type {
367+
return ChatTextInputStateTextAttribute(type: .italic, range: entity.range)
366368
}
367369
return nil
368370
})
@@ -373,6 +375,8 @@ public final class ContextControllerActionsListActionItemNode: HighlightTracking
373375
], range: NSRange(location: 0, length: result.length))
374376
for attribute in inputStateText.attributes {
375377
if case .bold = attribute.type {
378+
result.addAttribute(NSAttributedString.Key.font, value: Font.semibold(presentationData.listsFontSize.baseDisplaySize), range: NSRange(location: attribute.range.lowerBound, length: attribute.range.count))
379+
} else if case .italic = attribute.type {
376380
result.addAttribute(NSAttributedString.Key.font, value: Font.semibold(15.0), range: NSRange(location: attribute.range.lowerBound, length: attribute.range.count))
377381
}
378382
}

submodules/ContextUI/Sources/ContextControllerExtractedPresentationNode.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,8 @@ final class ContextControllerExtractedPresentationNode: ASDisplayNode, ContextCo
500500
func wantsDisplayBelowKeyboard() -> Bool {
501501
if let reactionContextNode = self.reactionContextNode {
502502
return reactionContextNode.wantsDisplayBelowKeyboard()
503+
} else if case let .reference(source) = self.source {
504+
return source.forceDisplayBelowKeyboard
503505
} else {
504506
return false
505507
}

submodules/MediaPickerUI/Sources/MediaPickerScreen.swift

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,6 +1823,7 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
18231823
private var isDismissing = false
18241824

18251825
fileprivate let mainButtonStatePromise = Promise<AttachmentMainButtonState?>(nil)
1826+
fileprivate let secondaryButtonStatePromise = Promise<AttachmentMainButtonState?>(nil)
18261827

18271828
private let mainButtonAction: (() -> Void)?
18281829

@@ -2380,9 +2381,23 @@ public final class MediaPickerScreenImpl: ViewController, MediaPickerScreen, Att
23802381
transition.updateAlpha(node: self.moreButtonNode.iconNode, alpha: moreIsVisible ? 1.0 : 0.0)
23812382
transition.updateTransformScale(node: self.moreButtonNode.iconNode, scale: moreIsVisible ? 1.0 : 0.1)
23822383

2383-
//if self. {
2384-
//self.mainButtonStatePromise.set(.single(AttachmentMainButtonState(text: "Add", badge: "\(count)", font: .bold, background: .color(self.presentationData.theme.actionSheet.controlAccentColor), textColor: self.presentationData.theme.list.itemCheckColors.foregroundColor, isVisible: count > 0, progress: .none, isEnabled: true, hasShimmer: false)))
2385-
//}
2384+
if self.selectionCount > 0 {
2385+
//TODO:localize
2386+
var text = "Create 1 Story"
2387+
if self.selectionCount > 1 {
2388+
text = "Create \(self.selectionCount) Stories"
2389+
}
2390+
self.mainButtonStatePromise.set(.single(AttachmentMainButtonState(text: text, badge: nil, font: .bold, background: .color(self.presentationData.theme.actionSheet.controlAccentColor), textColor: self.presentationData.theme.list.itemCheckColors.foregroundColor, isVisible: true, progress: .none, isEnabled: true, hasShimmer: false, position: .top)))
2391+
2392+
if self.selectionCount > 1 && self.selectionCount <= 6 {
2393+
self.secondaryButtonStatePromise.set(.single(AttachmentMainButtonState(text: "Combine into Collage", badge: nil, font: .regular, background: .color(.clear), textColor: self.presentationData.theme.actionSheet.controlAccentColor, isVisible: true, progress: .none, isEnabled: true, hasShimmer: false, iconName: "Media Editor/Collage", position: .bottom)))
2394+
} else {
2395+
self.secondaryButtonStatePromise.set(.single(nil))
2396+
}
2397+
} else {
2398+
self.mainButtonStatePromise.set(.single(nil))
2399+
self.secondaryButtonStatePromise.set(.single(nil))
2400+
}
23862401
}
23872402

23882403
private func updateThemeAndStrings() {
@@ -2933,6 +2948,10 @@ final class MediaPickerContext: AttachmentMediaPickerContext {
29332948
return self.controller?.mainButtonStatePromise.get() ?? .single(nil)
29342949
}
29352950

2951+
public var secondaryButtonState: Signal<AttachmentMainButtonState?, NoError> {
2952+
return self.controller?.secondaryButtonStatePromise.get() ?? .single(nil)
2953+
}
2954+
29362955
init(controller: MediaPickerScreenImpl) {
29372956
self.controller = controller
29382957
}
@@ -2952,6 +2971,10 @@ final class MediaPickerContext: AttachmentMediaPickerContext {
29522971
func mainButtonAction() {
29532972
self.controller?.mainButtonPressed()
29542973
}
2974+
2975+
func secondaryButtonAction() {
2976+
self.controller?.mainButtonPressed()
2977+
}
29552978
}
29562979

29572980
private final class MediaPickerContextReferenceContentSource: ContextReferenceContentSource {

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

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,23 +1459,26 @@ private final class ProfileGiftsContextImpl {
14591459
return _internal_transferStarGift(account: self.account, prepaid: prepaid, reference: reference, peerId: peerId)
14601460
}
14611461

1462-
func buyStarGift(gift inputGift: TelegramCore.StarGift, peerId: EnginePeer.Id) -> Signal<Never, BuyStarGiftError> {
1463-
var gift = self.gifts.first(where: { $0.gift == inputGift })
1464-
if gift == nil {
1465-
gift = self.filteredGifts.first(where: { $0.gift == inputGift })
1466-
}
1467-
guard case let .unique(uniqueGift) = gift?.gift else {
1468-
return .complete()
1469-
}
1470-
1462+
func buyStarGift(slug: String, peerId: EnginePeer.Id) -> Signal<Never, BuyStarGiftError> {
14711463
if let count = self.count {
14721464
self.count = max(0, count - 1)
14731465
}
1474-
self.gifts.removeAll(where: { $0.gift == inputGift })
1475-
self.filteredGifts.removeAll(where: { $0.gift == inputGift })
1466+
self.gifts.removeAll(where: { gift in
1467+
if case let .unique(uniqueGift) = gift.gift, uniqueGift.slug == slug {
1468+
return true
1469+
}
1470+
return false
1471+
})
1472+
self.filteredGifts.removeAll(where: { gift in
1473+
if case let .unique(uniqueGift) = gift.gift, uniqueGift.slug == slug {
1474+
return true
1475+
}
1476+
return false
1477+
})
1478+
14761479
self.pushState()
14771480

1478-
return _internal_buyStarGift(account: self.account, slug: uniqueGift.slug, peerId: peerId)
1481+
return _internal_buyStarGift(account: self.account, slug: slug, peerId: peerId)
14791482
}
14801483

14811484
func removeStarGift(gift: TelegramCore.StarGift) {
@@ -1899,11 +1902,11 @@ public final class ProfileGiftsContext {
18991902
}
19001903
}
19011904

1902-
public func buyStarGift(gift: TelegramCore.StarGift, peerId: EnginePeer.Id) -> Signal<Never, BuyStarGiftError> {
1905+
public func buyStarGift(slug: String, peerId: EnginePeer.Id) -> Signal<Never, BuyStarGiftError> {
19031906
return Signal { subscriber in
19041907
let disposable = MetaDisposable()
19051908
self.impl.with { impl in
1906-
disposable.set(impl.buyStarGift(gift: gift, peerId: peerId).start(error: { error in
1909+
disposable.set(impl.buyStarGift(slug: slug, peerId: peerId).start(error: { error in
19071910
subscriber.putError(error)
19081911
}, completed: {
19091912
subscriber.putCompletion()
@@ -2308,7 +2311,7 @@ private final class ResaleGiftsContextImpl {
23082311

23092312
private let disposable = MetaDisposable()
23102313

2311-
private var sorting: ResaleGiftsContext.Sorting = .date
2314+
private var sorting: ResaleGiftsContext.Sorting = .value
23122315
private var filterAttributes: [ResaleGiftsContext.Attribute] = []
23132316

23142317
private var gifts: [StarGift] = []
@@ -2431,7 +2434,15 @@ private final class ResaleGiftsContextImpl {
24312434

24322435
let parsedPeers = AccumulatedPeers(transaction: transaction, chats: chats, users: users)
24332436
updatePeers(transaction: transaction, accountPeerId: accountPeerId, peers: parsedPeers)
2434-
return (gifts.compactMap { StarGift(apiStarGift: $0) }, resultAttributes, attributeCount, count, nextOffset)
2437+
2438+
var mappedGifts: [StarGift] = []
2439+
for gift in gifts {
2440+
if let mappedGift = StarGift(apiStarGift: gift), case let .unique(uniqueGift) = mappedGift, let resellStars = uniqueGift.resellStars, resellStars > 0 {
2441+
mappedGifts.append(mappedGift)
2442+
}
2443+
}
2444+
2445+
return (mappedGifts, resultAttributes, attributeCount, count, nextOffset)
24352446
}
24362447
}
24372448
}
@@ -2444,9 +2455,7 @@ private final class ResaleGiftsContextImpl {
24442455
if initialNextOffset == nil || reload {
24452456
self.gifts = gifts
24462457
} else {
2447-
for gift in gifts {
2448-
self.gifts.append(gift)
2449-
}
2458+
self.gifts.append(contentsOf: gifts)
24502459
}
24512460

24522461
let updatedCount = max(Int32(self.gifts.count), count)
@@ -2473,6 +2482,11 @@ private final class ResaleGiftsContextImpl {
24732482
self.loadMore()
24742483
}
24752484

2485+
func removeStarGift(gift: TelegramCore.StarGift) {
2486+
self.gifts.removeAll(where: { $0 == gift })
2487+
self.pushState()
2488+
}
2489+
24762490
func updateSorting(_ sorting: ResaleGiftsContext.Sorting) {
24772491
guard self.sorting != sorting else {
24782492
return
@@ -2571,6 +2585,12 @@ public final class ResaleGiftsContext {
25712585
impl.updateFilterAttributes(attributes)
25722586
}
25732587
}
2588+
2589+
public func removeStarGift(gift: TelegramCore.StarGift) {
2590+
self.impl.with { impl in
2591+
impl.removeStarGift(gift: gift)
2592+
}
2593+
}
25742594

25752595
public var currentState: ResaleGiftsContext.State? {
25762596
var state: ResaleGiftsContext.State?

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public extension TelegramEngine {
125125
return _internal_transferStarGift(account: self.account, prepaid: prepaid, reference: reference, peerId: peerId)
126126
}
127127

128-
public func buyStarGift(prepaid: Bool, slug: String, peerId: EnginePeer.Id) -> Signal<Never, BuyStarGiftError> {
128+
public func buyStarGift(slug: String, peerId: EnginePeer.Id) -> Signal<Never, BuyStarGiftError> {
129129
return _internal_buyStarGift(account: self.account, slug: slug, peerId: peerId)
130130
}
131131

submodules/TelegramUI/Components/CameraScreen/Sources/CameraScreen.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2726,9 +2726,13 @@ public class CameraScreenImpl: ViewController, CameraScreen {
27262726
self.additionalPreviewView.isEnabled = false
27272727
self.collageView?.isEnabled = false
27282728

2729+
#if targetEnvironment(simulator)
2730+
2731+
#else
27292732
Queue.mainQueue().after(0.3) {
27302733
self.previewBlurPromise.set(true)
27312734
}
2735+
#endif
27322736
self.camera?.stopCapture()
27332737

27342738
self.cameraIsActive = false
@@ -3627,12 +3631,17 @@ public class CameraScreenImpl: ViewController, CameraScreen {
36273631
if self.cameraState.isCollageEnabled, let collage = self.node.collage {
36283632
selectionLimit = collage.grid.count - collage.results.count
36293633
} else {
3630-
selectionLimit = 6
3634+
if self.cameraState.isCollageEnabled {
3635+
selectionLimit = 6
3636+
} else {
3637+
selectionLimit = 10
3638+
}
36313639
}
3640+
//TODO:unmock
36323641
controller = self.context.sharedContext.makeStoryMediaPickerScreen(
36333642
context: self.context,
36343643
isDark: true,
3635-
forCollage: self.cameraState.isCollageEnabled,
3644+
forCollage: self.cameraState.isCollageEnabled || "".isEmpty,
36363645
selectionLimit: selectionLimit,
36373646
getSourceRect: { [weak self] in
36383647
if let self {

0 commit comments

Comments
 (0)