Skip to content

Commit 22330db

Browse files
committed
- bugfixes
1 parent 14825a2 commit 22330db

26 files changed

+187
-83
lines changed

‎Telegram-Mac/AccountContext.swift

+5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ let clown: String = "🤡"
2525
let focusIntentEmoji = "⛔️"
2626

2727

28+
29+
func bestWindow(_ accountContext: AccountContext, _ controller: ViewController?) -> Window {
30+
return controller?.window ?? accountContext.window
31+
}
32+
2833
public struct PremiumConfiguration {
2934
public static var defaultValue: PremiumConfiguration {
3035
return PremiumConfiguration(

‎Telegram-Mac/ApplicationContext.swift

-10
Original file line numberDiff line numberDiff line change
@@ -547,16 +547,6 @@ final class AuthorizedApplicationContext: NSObject, SplitViewDelegate {
547547
return .invoked
548548
}, with: self, for: .T, priority: .supreme, modifierFlags: [.command])
549549

550-
self.context.window.set(handler: { _ -> KeyHandlerResult in
551-
showModal(with: Star_ListScreen(context: context, source: .buy), for: context.window)
552-
return .invoked
553-
}, with: self, for: .Y, priority: .supreme, modifierFlags: [.command])
554-
555-
self.context.window.set(handler: { _ -> KeyHandlerResult in
556-
showModal(with: Star_ListScreen(context: context, source: .account), for: context.window)
557-
return .invoked
558-
}, with: self, for: .R, priority: .supreme, modifierFlags: [.command])
559-
560550
#endif
561551

562552

‎Telegram-Mac/ChannelInfoEntries.swift

+11-11
Original file line numberDiff line numberDiff line change
@@ -586,11 +586,11 @@ class ChannelInfoArguments : PeerInfoArguments {
586586

587587
}
588588

589-
func stats(_ datacenterId: Int32, monetization: Bool) {
589+
func stats(_ datacenterId: Int32, monetization: Bool, stars: Bool) {
590590
if datacenterId == 0 {
591591
self.pushViewController(ChannelBoostStatsController(context: context, peerId: peerId))
592592
} else {
593-
self.pushViewController(ChannelStatsSegmentController(context, peerId: peerId, isChannel: true, monetization: monetization))
593+
self.pushViewController(ChannelStatsSegmentController(context, peerId: peerId, isChannel: true, monetization: monetization, stars: stars))
594594
}
595595
}
596596
func share() {
@@ -691,7 +691,7 @@ enum ChannelInfoEntry: PeerInfoEntry {
691691
case requests(section: ChannelInfoSection, count: Int32, viewType: GeneralViewType)
692692
case reactions(section: ChannelInfoSection, text: String, allowedReactions: PeerAllowedReactions?, availableReactions: AvailableReactions?, reactionsCount: Int32?, viewType: GeneralViewType)
693693
case color(section: ChannelInfoSection, peer: PeerEquatable, viewType: GeneralViewType)
694-
case stats(section: ChannelInfoSection, datacenterId: Int32, monetization: Bool, viewType: GeneralViewType)
694+
case stats(section: ChannelInfoSection, datacenterId: Int32, monetization: Bool, stars: Bool, viewType: GeneralViewType)
695695
case discussion(sectionId: ChannelInfoSection, group: Peer?, participantsCount: Int32?, viewType: GeneralViewType)
696696
case discussionDesc(sectionId: ChannelInfoSection, viewType: GeneralViewType)
697697
case aboutInput(sectionId: ChannelInfoSection, description:String, viewType: GeneralViewType)
@@ -722,7 +722,7 @@ enum ChannelInfoEntry: PeerInfoEntry {
722722
case let .discussion(sectionId, group, participantsCount, _): return .discussion(sectionId: sectionId, group: group, participantsCount: participantsCount, viewType: viewType)
723723
case let .reactions(section, text, allowedReactions, availableReactions, reactionsCount, _): return .reactions(section: section, text: text, allowedReactions: allowedReactions, availableReactions: availableReactions, reactionsCount: reactionsCount, viewType: viewType)
724724
case let .color(section, peer, _): return .color(section: section, peer: peer, viewType: viewType)
725-
case let .stats(section, datacenterId, monetization, _): return .stats(section: section, datacenterId: datacenterId, monetization: monetization, viewType: viewType)
725+
case let .stats(section, datacenterId, monetization, stars, _): return .stats(section: section, datacenterId: datacenterId, monetization: monetization, stars: stars, viewType: viewType)
726726
case let .discussionDesc(sectionId, _): return .discussionDesc(sectionId: sectionId, viewType: viewType)
727727
case let .aboutInput(sectionId, description, _): return .aboutInput(sectionId: sectionId, description: description, viewType: viewType)
728728
case let .aboutDesc(sectionId, _): return .aboutDesc(sectionId: sectionId, viewType: viewType)
@@ -888,8 +888,8 @@ enum ChannelInfoEntry: PeerInfoEntry {
888888
} else {
889889
return false
890890
}
891-
case let .stats(sectionId, datacenterId, monetization, viewType):
892-
if case .stats(sectionId, datacenterId, monetization, viewType) = entry {
891+
case let .stats(sectionId, datacenterId, monetization, stars, viewType):
892+
if case .stats(sectionId, datacenterId, monetization, stars, viewType) = entry {
893893
return true
894894
} else {
895895
return false
@@ -1039,7 +1039,7 @@ enum ChannelInfoEntry: PeerInfoEntry {
10391039
return sectionId.rawValue
10401040
case let .color(sectionId, _, _):
10411041
return sectionId.rawValue
1042-
case let .stats(sectionId, _, _, _):
1042+
case let .stats(sectionId, _, _, _, _):
10431043
return sectionId.rawValue
10441044
case let .discussionDesc(sectionId, _):
10451045
return sectionId.rawValue
@@ -1096,7 +1096,7 @@ enum ChannelInfoEntry: PeerInfoEntry {
10961096
return (sectionId.rawValue * 1000) + stableIndex
10971097
case let .color(sectionId, _, _):
10981098
return (sectionId.rawValue * 1000) + stableIndex
1099-
case let .stats(sectionId, _, _, _):
1099+
case let .stats(sectionId, _, _, _, _):
11001100
return (sectionId.rawValue * 1000) + stableIndex
11011101
case let .discussionDesc(sectionId, _):
11021102
return (sectionId.rawValue * 1000) + stableIndex
@@ -1214,9 +1214,9 @@ enum ChannelInfoEntry: PeerInfoEntry {
12141214
return GeneralInteractedRowItem(initialSize, stableId: stableId.hashValue, name: strings().peerInfoChannelAppearance, icon: theme.icons.profile_channel_color, type: .imageContext(generateSettingsMenuPeerColorsLabelIcon(peer: peer.peer, context: arguments.context), ""), viewType: viewType, action: {
12151215
arguments.openNameColor(peer: peer.peer)
12161216
}, afterNameImage: level == 0 ? generateDisclosureActionBoostLevelBadgeImage(text: strings().boostBadgeLevelPLus(1)) : nil)
1217-
case let .stats(_, datacenterId, monetization, viewType):
1217+
case let .stats(_, datacenterId, monetization, stars, viewType):
12181218
return GeneralInteractedRowItem(initialSize, stableId: stableId.hashValue, name: strings().peerInfoStatAndBoosts, icon: theme.icons.profile_channel_stats, type: .next, viewType: viewType, action: {
1219-
arguments.stats(datacenterId, monetization: monetization)
1219+
arguments.stats(datacenterId, monetization: monetization, stars: stars)
12201220
})
12211221
case let .setTitle(_, text, viewType):
12221222
return InputDataRowItem(initialSize, stableId: stableId.hashValue, mode: .plain, error: nil, viewType: viewType, currentText: text, placeholder: nil, inputPlaceholder: strings().peerInfoChannelTitlePleceholder, filter: { $0 }, updated: arguments.updateEditingName, limit: 255)
@@ -1405,7 +1405,7 @@ func channelInfoEntries(view: PeerView, arguments:PeerInfoArguments, mediaTabsDa
14051405
entries.append(.members(sectionId: .manage, count: membersCount, viewType: .innerItem))
14061406

14071407
if let cachedData = view.cachedData as? CachedChannelData, cachedData.flags.contains(.canViewStats) {
1408-
entries.append(.stats(section: .manage, datacenterId: cachedData.statsDatacenterId, monetization: cachedData.flags.contains(.canViewRevenue), viewType: .innerItem))
1408+
entries.append(.stats(section: .manage, datacenterId: cachedData.statsDatacenterId, monetization: cachedData.flags.contains(.canViewRevenue), stars: cachedData.flags.contains(.canViewStarsRevenue), viewType: .innerItem))
14091409
}
14101410

14111411
entries.append(.blocked(sectionId: .manage, count: blockedCount, viewType: .innerItem))

‎Telegram-Mac/ChannelStatsSegmentController.swift

+10-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import TGUIKit
1515
private final class CenterView : TitledBarView {
1616
let segment: CatalinaStyledSegmentController
1717
var select:((Int)->Void)? = nil
18-
init(controller: ViewController, monetization: Bool) {
18+
init(controller: ViewController, monetization: Bool, stars: Bool) {
1919
self.segment = CatalinaStyledSegmentController(frame: NSMakeRect(0, 0, 240, 30))
2020
super.init(controller: controller)
2121

@@ -30,13 +30,14 @@ private final class CenterView : TitledBarView {
3030
segment.add(segment: .init(title: strings().statsMonetization, handler: { [weak self] in
3131
self?.select?(2)
3232
}))
33-
//
33+
}
34+
35+
if stars {
3436
segment.add(segment: .init(title: strings().statsStars, handler: { [weak self] in
3537
self?.select?(3)
3638
}))
3739
}
3840

39-
4041
self.addSubview(segment.view)
4142

4243
updateLocalizationAndTheme(theme: theme)
@@ -70,16 +71,19 @@ final class ChannelStatsSegmentController : SectionViewController {
7071
private let stars: ViewController?
7172
private let context: AccountContext
7273
private let peerId: PeerId
73-
init(_ context: AccountContext, peerId: PeerId, isChannel: Bool, monetization: Bool = false) {
74+
init(_ context: AccountContext, peerId: PeerId, isChannel: Bool, monetization: Bool = false, stars: Bool = false) {
7475
self.context = context
7576
self.peerId = peerId
7677
if isChannel {
7778
self.stats = ChannelStatsViewController(context, peerId: peerId)
7879
if monetization {
7980
self.monetization = FragmentMonetizationController(context: context, peerId: peerId)
80-
self.stars = FragmentStarMonetizationController(context: context, peerId: peerId, revenueContext: nil)
8181
} else {
8282
self.monetization = nil
83+
}
84+
if stars {
85+
self.stars = FragmentStarMonetizationController(context: context, peerId: peerId, revenueContext: nil)
86+
} else {
8387
self.stars = nil
8488
}
8589
} else {
@@ -104,7 +108,7 @@ final class ChannelStatsSegmentController : SectionViewController {
104108
}
105109

106110
override func getCenterBarViewOnce() -> TitledBarView {
107-
return CenterView(controller: self, monetization: self.monetization != nil)
111+
return CenterView(controller: self, monetization: self.monetization != nil, stars: self.stars != nil)
108112
}
109113

110114
override func getRightBarViewOnce() -> BarView {

‎Telegram-Mac/ContextMediaRowItem.swift

+2
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ class ContextMediaRowView: TableRowView, ModalPreviewRowViewProtocol {
255255
effectiveFile = FileMediaReference.savedSticker(media: media)
256256
case .recentSticker(media: let media):
257257
effectiveFile = FileMediaReference.recentSticker(media: media)
258+
case let .starsTransaction(transaction, media):
259+
effectiveFile = FileMediaReference.starsTransaction(transaction: transaction, media: media)
258260
}
259261

260262
}

‎Telegram-Mac/ImageCompression.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public func extractImageExtraScans(_ data: Data) -> [Int] {
5151
}
5252

5353
public func compressImageToJPEG(_ cgImage: CGImage, quality: Float) -> Data? {
54-
if let result = compressJPEGData(cgImage) {
54+
if let result = compressJPEGData(cgImage, Int32(quality * 100.0)) {
5555
return result
5656
}
5757

‎Telegram-Mac/Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
</dict>
3636
</array>
3737
<key>CFBundleVersion</key>
38-
<string>265332</string>
38+
<string>265350</string>
3939
<key>ITSAppUsesNonExemptEncryption</key>
4040
<false/>
4141
<key>LSApplicationCategoryType</key>

‎Telegram-Mac/PasscodeLockController.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -410,15 +410,15 @@ class PasscodeLockController: ModalViewController {
410410
override func windowDidBecomeKey() {
411411
super.windowDidBecomeKey()
412412

413-
if NSApp.isActive {
413+
if NSApp.isActive, useTouchId {
414414
callTouchId()
415415
}
416416
}
417417

418418
override func windowDidResignKey() {
419419
super.windowDidResignKey()
420-
if !NSApp.isActive {
421-
// invalidateTouchId()
420+
if !NSApp.isActive, useTouchId {
421+
invalidateTouchId()
422422
}
423423
}
424424

‎Telegram-Mac/PaymentsCheckoutController.swift

+25-14
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,13 @@ func PaymentsCheckoutController(context: AccountContext, source: BotPaymentInvoi
440440
completion = nil
441441
}
442442

443+
var getController:(()->ViewController?)? = nil
444+
445+
446+
let window:()->Window = {
447+
return bestWindow(context, getController?())
448+
}
449+
443450
var close:(()->Void)? = nil
444451
let actionsDisposable = DisposableSet()
445452

@@ -456,7 +463,7 @@ func PaymentsCheckoutController(context: AccountContext, source: BotPaymentInvoi
456463

457464
let canSave = paymentForm.canSaveCredentials && !paymentForm.passwordMissing
458465
if canSave {
459-
verifyAlert_button(for: context.window, information: strings().checkoutInfoSaveInfoHelp, ok: strings().modalYes, cancel: strings().modalNotNow, successHandler: { _ in
466+
verifyAlert_button(for: window(), information: strings().checkoutInfoSaveInfoHelp, ok: strings().modalYes, cancel: strings().modalNotNow, successHandler: { _ in
460467
updateState { current in
461468
var current = current
462469
current.paymentMethod = .webToken(.init(title: token.title, data: token.data, saveOnServer: true))
@@ -477,7 +484,7 @@ func PaymentsCheckoutController(context: AccountContext, source: BotPaymentInvoi
477484
}
478485
}
479486

480-
})), for: context.window)
487+
})), for: window())
481488
}
482489

483490
let arguments = Arguments(context: context, openForm: { focus in
@@ -490,7 +497,7 @@ func PaymentsCheckoutController(context: AccountContext, source: BotPaymentInvoi
490497
current.validatedInfo = validatedInfo
491498
return current
492499
}
493-
}), for: context.window)
500+
}), for: window())
494501
}
495502
}, openShippingMethod: {
496503
let state = stateValue.with({ $0 })
@@ -501,7 +508,7 @@ func PaymentsCheckoutController(context: AccountContext, source: BotPaymentInvoi
501508
current.shippingOptionId = id
502509
return current
503510
}
504-
}), for: context.window)
511+
}), for: window())
505512
}
506513
}, openPaymentMethod: {
507514
if let form = stateValue.with({ $0.form }), let value = parseRequestedPaymentMethod(paymentForm: form) {
@@ -513,7 +520,7 @@ func PaymentsCheckoutController(context: AccountContext, source: BotPaymentInvoi
513520
current.paymentMethod = method
514521
return current
515522
}
516-
}), for: context.window)
523+
}), for: window())
517524
}
518525

519526
let methods = availablePaymentMethods(form: form, current: nil)
@@ -523,7 +530,7 @@ func PaymentsCheckoutController(context: AccountContext, source: BotPaymentInvoi
523530
current.paymentMethod = .savedCredentials(selected)
524531
return current
525532
}
526-
}, addNew: openNewCard, addPaymentMethod: addPaymentMethod), for: context.window)
533+
}, addNew: openNewCard, addPaymentMethod: addPaymentMethod), for: window())
527534

528535
} else if let paymentForm = stateValue.with({ $0.form }) {
529536
if let url = paymentForm.url {
@@ -546,7 +553,7 @@ func PaymentsCheckoutController(context: AccountContext, source: BotPaymentInvoi
546553

547554
let paySignal = context.engine.payments.sendBotPaymentForm(source: source, formId: form.id, validatedInfoId: state.validatedInfo?.id, shippingOptionId: state.shippingOptionId?.id, tipAmount: state.form?.invoice.tip != nil ? (state.currentTip ?? 0) : nil, credentials: credentials)
548555

549-
_ = showModalProgress(signal: paySignal, for: context.window).start(next: { result in
556+
_ = showModalProgress(signal: paySignal, for: window()).start(next: { result in
550557

551558
let success:(Bool)->Void = { value in
552559
if value {
@@ -557,14 +564,14 @@ func PaymentsCheckoutController(context: AccountContext, source: BotPaymentInvoi
557564

558565
let total = formatCurrencyAmount(totalValue, currency: form.invoice.currency)
559566

560-
showModalText(for: context.window, text: strings().paymentsPaid(total, invoice.title))
567+
showModalText(for: window(), text: strings().paymentsPaid(total, invoice.title))
561568
}
562569
}
563570
switch result {
564571
case .done:
565572
success(true)
566573
case let .externalVerificationRequired(url: url):
567-
showModal(with: PaymentWebInteractionController(context: context, url: url, intent: .externalVerification(success)), for: context.window)
574+
showModal(with: PaymentWebInteractionController(context: context, url: url, intent: .externalVerification(success)), for: window())
568575
}
569576
}, error: { error in
570577
let text: String
@@ -578,7 +585,7 @@ func PaymentsCheckoutController(context: AccountContext, source: BotPaymentInvoi
578585
case .precheckoutFailed:
579586
text = strings().checkoutErrorPrecheckoutFailed
580587
}
581-
alert(for: context.window, info: text)
588+
alert(for: window(), info: text)
582589
invokeCompletion(.failed)
583590
close?()
584591
})
@@ -596,7 +603,7 @@ func PaymentsCheckoutController(context: AccountContext, source: BotPaymentInvoi
596603
if value {
597604
pay()
598605
} else {
599-
verifyAlert_button(for: context.window, header: strings().paymentsWarninTitle, information: strings().paymentsWarningText(botPeer.compactDisplayTitle, providerPeer.compactDisplayTitle, botPeer.compactDisplayTitle, botPeer.compactDisplayTitle), successHandler: { _ in
606+
verifyAlert_button(for: window(), header: strings().paymentsWarninTitle, information: strings().paymentsWarningText(botPeer.compactDisplayTitle, providerPeer.compactDisplayTitle, botPeer.compactDisplayTitle, botPeer.compactDisplayTitle), successHandler: { _ in
600607
pay()
601608
_ = ApplicationSpecificNotice.setBotPaymentLiability(accountManager: context.sharedContext.accountManager, peerId: botPeer.id).start()
602609
})
@@ -634,15 +641,15 @@ func PaymentsCheckoutController(context: AccountContext, source: BotPaymentInvoi
634641
}
635642
})
636643
}
637-
}), for: context.window)
644+
}), for: window())
638645
}
639646
})
640647
}
641648
}
642649
case let .webToken(token):
643650
pay(.generic(data: token.data, saveOnServer: token.saveOnServer))
644651
default:
645-
alert(for: context.window, info: "Unsupported")
652+
alert(for: window(), info: "Unsupported")
646653
return
647654
}
648655
}, selectTip: { value in
@@ -733,10 +740,14 @@ func PaymentsCheckoutController(context: AccountContext, source: BotPaymentInvoi
733740
close?()
734741
switch error {
735742
case .generic:
736-
alert(for: context.window, info: strings().unknownError)
743+
alert(for: window(), info: strings().unknownError)
737744
}
738745
}))
739746

747+
getController = { [weak controller] in
748+
return controller
749+
}
750+
740751

741752
controller.onDeinit = {
742753
actionsDisposable.dispose()

0 commit comments

Comments
 (0)