Skip to content

Commit 73ebba7

Browse files
committed
bug fixes
1 parent f283484 commit 73ebba7

File tree

5 files changed

+75
-23
lines changed

5 files changed

+75
-23
lines changed

Telegram-Mac/ChatInterfaceInteraction.swift

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -889,10 +889,11 @@ final class ChatInteraction : InterfaceObserver {
889889
}
890890
}
891891
})
892-
} else if let attribute = keyboardMessage.suggestPostAttribute, !isLogInteraction, let amount = attribute.amount {
892+
} else if let attribute = keyboardMessage.suggestPostAttribute, !isLogInteraction {
893893

894894
let context = self.context
895895
let peer = presentation.peer
896+
let amount = attribute.amount
896897

897898
return ReplyMarkupInteractions(context: context, proccess: { [weak self] button, progress in
898899

@@ -909,15 +910,20 @@ final class ChatInteraction : InterfaceObserver {
909910
} else {
910911
let comission = context.appConfiguration.getGeneralValue("ton_suggested_post_commission_permille", orElse: 850)
911912

912-
let totalAmount = "\(Double(formatCurrencyAmount(amount.amount.value, currency: TON))! * Double(comission.decemial / 100.0))".prettyCurrencyNumberUsd
913-
914913
let formatted: String
915-
switch amount.currency {
916-
case .ton:
917-
formatted = "\(totalAmount) \(TON)"
918-
case .stars:
919-
formatted = strings().starListItemCountCountable(Int(amount.amount.totalValue))
914+
if let amount {
915+
let totalAmount = "\(Double(formatCurrencyAmount(amount.amount.value, currency: TON))! * Double(comission.decemial / 100.0))".prettyCurrencyNumberUsd
916+
917+
switch amount.currency {
918+
case .ton:
919+
formatted = "\(totalAmount) \(TON)"
920+
case .stars:
921+
formatted = strings().starListItemCountCountable(Int(amount.amount.totalValue))
922+
}
923+
} else {
924+
formatted = strings().chatServiceSuggestPostHeaderPriceFree
920925
}
926+
921927

922928
if attribute.timestamp == nil {
923929
let infoText = TextViewLayout(

Telegram-Mac/ChatServiceItem.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ class ChatServiceItem: ChatRowItem {
184184

185185
attributes = .init(
186186
header: .init(
187-
.initialize(string: isIncoming ? strings().chatServiceSuggestPostHeaderTitle(peer.displayTitle) : strings().chatServiceSuggestPostHeaderTitleYou, color: color, font: .medium(.text)),
187+
.initialize(string: isIncoming ? strings().chatServiceSuggestPostHeaderTitle(peer.displayTitle) : strings().chatServiceSuggestPostHeaderTitleYou, color: color, font: .medium(.text)).detectBold(with: .medium(.text)),
188188
alignment: .center
189189
),
190190
attributes: [
@@ -221,7 +221,7 @@ class ChatServiceItem: ChatRowItem {
221221
switch status {
222222
case .approved(let timestamp, let amount):
223223
self.titleLayout = .init(
224-
.initialize(string: strings().chatServiceSuggestPostStatusTitle, color: theme.chatServiceItemTextColor, font: .medium(.text)),
224+
.initialize(string: strings().chatServiceSuggestPostStatusTitle, color: theme.chatServiceItemTextColor, font: .medium(.text)).detectBold(with: .medium(.text)),
225225
alignment: .center
226226
)
227227

@@ -308,7 +308,11 @@ class ChatServiceItem: ChatRowItem {
308308
}
309309

310310
var height: CGFloat {
311-
return 10 + titleLayout.layoutSize.height + 10 + layout.layoutSize.height + 10
311+
var height: CGFloat = 10 + titleLayout.layoutSize.height + 10
312+
if !layout.string.isEmpty {
313+
height += layout.layoutSize.height + 10
314+
}
315+
return height
312316
}
313317
}
314318

Telegram-Mac/EditPostSuggestionController.swift

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ private final class InputView : GeneralRowView {
339339
transition.updateFrame(view: inputView, frame: CGRect(origin: CGPoint(x: starView.frame.maxX + 10, y: 7), size: textSize))
340340
inputView.updateLayout(size: textSize, textHeight: textHeight, transition: transition)
341341

342-
transition.updateFrame(view: usdView, frame: usdView.centerFrameY(x: size.width - usdView.frame.width - 10))
342+
ContainedViewLayoutTransition.immediate.updateFrame(view: usdView, frame: usdView.centerFrameY(x: size.width - usdView.frame.width - 10))
343343
}
344344

345345
private func set(_ state: Updated_ChatTextInputState) {
@@ -415,7 +415,8 @@ private final class Arguments {
415415
}
416416

417417
private struct State : Equatable {
418-
var amount: Int64 = 0
418+
var starAmount: Int64 = 0
419+
var tonAmount: Int64 = 0
419420
var currency: CurrencyAmount.Currency
420421
var inputState: Updated_ChatTextInputState = .init()
421422
var date: Int32?
@@ -433,13 +434,31 @@ private struct State : Equatable {
433434
}
434435
}
435436

437+
var amount: Int64 {
438+
get {
439+
switch currency {
440+
case .stars:
441+
return starAmount
442+
case .ton:
443+
return tonAmount
444+
}
445+
}
446+
set {
447+
switch currency {
448+
case .stars:
449+
starAmount = newValue
450+
case .ton:
451+
tonAmount = newValue
452+
}
453+
}
454+
}
436455

437456
var starsAmount: StarsAmount {
438457
switch currency {
439458
case .stars:
440-
return .init(value: amount, nanos: 0)
459+
return .init(value: starAmount, nanos: 0)
441460
case .ton:
442-
return .init(value: amount * 1_000_000_000, nanos: 0)
461+
return .init(value: tonAmount * 1_000_000_000, nanos: 0)
443462
}
444463
}
445464

@@ -456,9 +475,7 @@ private struct State : Equatable {
456475
case .edit, .suggest:
457476
return strings().editPostSuggestionActionUpdate
458477
case .new:
459-
return amount == 0 ?
460-
strings().editPostSuggestionActionFree :
461-
strings().editPostSuggestionActionOffer(currencyAmount.fullyFormatted)
478+
return strings().editPostSuggestionActionOffer(currencyAmount.fullyFormatted)
462479
}
463480
}
464481
}
@@ -553,12 +570,29 @@ func EditPostSuggestionController(chatInteraction: ChatInteraction, data: ChatIn
553570
let actionsDisposable = DisposableSet()
554571

555572
let min_stars = context.appConfiguration.getGeneralValue64("stars_suggested_post_amount_min", orElse: 5)
556-
let min_ton = context.appConfiguration.getGeneralValue64("ton_suggested_post_amount_min", orElse: 1_000_000_000) / 1_000_000_000
573+
let min_ton = max(1, context.appConfiguration.getGeneralValue64("ton_suggested_post_amount_min", orElse: 1_000_000_000) / 1_000_000_000)
557574

558575

559576
let amount = data.amount ?? .init(amount: .init(value: min_stars, nanos: 0), currency: .stars)
560577

561-
let initialState = State(amount: Int64(amount.formatted) ?? 0, currency: amount.currency, inputState: .init(inputText: .initialize(string: "\(amount.formatted)")), date: data.date, mode: data.mode)
578+
let starAmount: Int64
579+
let tonAmount: Int64
580+
581+
if let currency = data.amount {
582+
switch currency.currency {
583+
case .stars:
584+
starAmount = Int64(currency.formatted) ?? 0
585+
tonAmount = min_ton
586+
case .ton:
587+
tonAmount = Int64(currency.formatted) ?? 0
588+
starAmount = min_stars
589+
}
590+
} else {
591+
starAmount = min_stars
592+
tonAmount = min_ton
593+
}
594+
595+
let initialState = State(starAmount: starAmount, tonAmount: tonAmount, currency: amount.currency, inputState: .init(inputText: .initialize(string: "\(amount.formatted)")), date: data.date, mode: data.mode)
562596

563597
let statePromise = ValuePromise(initialState, ignoreRepeated: true)
564598
let stateValue = Atomic(value: initialState)
@@ -659,12 +693,20 @@ func EditPostSuggestionController(chatInteraction: ChatInteraction, data: ChatIn
659693
return current
660694
}
661695
}), for: context.window)
662-
}, currency: { value in
696+
}, currency: { [weak interactions] value in
663697
updateState { current in
664698
var current = current
665699
current.currency = value
666700
return current
667701
}
702+
let amount = stateValue.with { $0.amount }
703+
let value = Updated_ChatTextInputState(inputText: .initialize(string: "\(amount)"))
704+
705+
DispatchQueue.main.async {
706+
interactions?.update { _ in
707+
return value
708+
}
709+
}
668710
})
669711

670712
let signal = statePromise.get() |> deliverOnPrepareQueue |> map { state in

Telegram-Mac/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
</dict>
3434
</array>
3535
<key>CFBundleVersion</key>
36-
<string>273687</string>
36+
<string>273691</string>
3737
<key>ITSAppUsesNonExemptEncryption</key>
3838
<false/>
3939
<key>LSApplicationCategoryType</key>

TelegramShare/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<key>CFBundleShortVersionString</key>
2222
<string>$(MARKETING_VERSION)</string>
2323
<key>CFBundleVersion</key>
24-
<string>273687</string>
24+
<string>273691</string>
2525
<key>ITSAppUsesNonExemptEncryption</key>
2626
<false/>
2727
<key>LSMinimumSystemVersion</key>

0 commit comments

Comments
 (0)