@@ -14,7 +14,7 @@ import TGUIKit
1414import SwiftSignalKit
1515import MapKit
1616import InputView
17-
17+ import CurrencyFormat
1818
1919final class ReplyMarkupInteractions {
2020 let context : AccountContext
@@ -892,6 +892,7 @@ final class ChatInteraction : InterfaceObserver {
892892 } else if let attribute = keyboardMessage. suggestPostAttribute, !isLogInteraction, let amount = attribute. amount {
893893
894894 let context = self . context
895+ let peer = presentation. peer
895896
896897 return ReplyMarkupInteractions ( context: context, proccess: { [ weak self] button, progress in
897898
@@ -900,75 +901,80 @@ final class ChatInteraction : InterfaceObserver {
900901 switch url {
901902 case SuggestedPostMessageAttribute . commandApprove:
902903
903- let comission = context. appConfiguration. getGeneralValue ( " ton_suggested_post_commission_permille " , orElse: 850 )
904-
905- let totalAmount = amount. amount. totalValue * Double( comission. decemial / 100.0 )
904+ if let peer, !peer. groupAccess. canPostMessages {
905+ _ = context. engine. messages. monoforumPerformSuggestedPostAction (
906+ id: keyboardMessage. id,
907+ action: . approve( timestamp: nil )
908+ ) . start ( )
909+ } else {
910+ let comission = context. appConfiguration. getGeneralValue ( " ton_suggested_post_commission_permille " , orElse: 850 )
911+
912+ let totalAmount = " \( Double ( formatCurrencyAmount ( amount. amount. value, currency: TON) ) ! * Double( comission. decemial / 100.0 ) ) " . prettyCurrencyNumberUsd
906913
907- let formatted : String
908- switch amount. currency {
909- case . ton:
910- formatted = " \( totalAmount) \( TON) "
911- case . stars:
912- formatted = strings ( ) . starListItemCountCountable ( Int ( totalAmount ) )
913- }
914+ 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 ) )
920+ }
914921
915- if attribute. timestamp == nil {
916- let infoText = TextViewLayout (
917- . initialize(
918- string: strings ( ) . chatSuggestPostPublishInfo ( formatted, " \( comission. decemial. string) % " ) ,
919- color: theme. colors. text,
920- font: . normal( . text)
921- ) ,
922- alignment: . center
923- )
924- infoText. measure ( width: 260 )
922+ if attribute. timestamp == nil {
923+ let infoText = TextViewLayout (
924+ . initialize(
925+ string: strings ( ) . chatSuggestPostPublishInfo ( formatted, " \( comission. decemial. string) % " ) ,
926+ color: theme. colors. text,
927+ font: . normal( . text)
928+ ) ,
929+ alignment: . center
930+ )
931+ infoText. measure ( width: 260 )
925932
926- showModal (
927- with: DateSelectorModalController (
928- context: context,
929- mode: . dateAction(
930- title: strings ( ) . chatSuggestPostPublishAcceptTitle,
931- done: { date in
932- strings ( ) . chatSuggestPostPublishDateConfirm ( stringForDate ( timestamp: Int32 ( date. timeIntervalSince1970) ) )
933+ showModal (
934+ with: DateSelectorModalController (
935+ context: context,
936+ mode: . dateAction(
937+ title: strings ( ) . chatSuggestPostPublishAcceptTitle,
938+ done: { date in
939+ strings ( ) . chatSuggestPostPublishDateConfirm ( stringForDate ( timestamp: Int32 ( date. timeIntervalSince1970) ) )
940+ } ,
941+ action: . init(
942+ string: strings ( ) . chatSuggestPostPublishActionNow,
943+ callback: {
944+ _ = context. engine. messages. monoforumPerformSuggestedPostAction (
945+ id: keyboardMessage. id,
946+ action: . approve( timestamp: nil )
947+ ) . start ( )
948+ }
949+ )
950+ ) ,
951+ selectedAt: { date in
952+ _ = context. engine. messages. monoforumPerformSuggestedPostAction (
953+ id: keyboardMessage. id,
954+ action: . approve( timestamp: Int32 ( date. timeIntervalSince1970) )
955+ ) . start ( )
933956 } ,
934- action: . init(
935- string: strings ( ) . chatSuggestPostPublishActionNow,
936- callback: {
937- _ = context. engine. messages. monoforumPerformSuggestedPostAction (
938- id: keyboardMessage. id,
939- action: . approve( timestamp: nil )
940- ) . start ( )
941- }
942- )
957+ infoText: infoText
943958 ) ,
944- selectedAt: { date in
959+ for: context. window
960+ )
961+ } else {
962+ let author = keyboardMessage. author? . displayTitle ?? " "
963+ let info = strings ( ) . chatSuggestPostPublishConfirmInfo ( author, formatted, comission. decemial. string)
964+ verifyAlert (
965+ for: context. window,
966+ header: strings ( ) . chatSuggestPostPublishConfirmHeader,
967+ information: info,
968+ ok: strings ( ) . chatSuggestPostPublishConfirmButton,
969+ successHandler: { _ in
945970 _ = context. engine. messages. monoforumPerformSuggestedPostAction (
946971 id: keyboardMessage. id,
947- action: . approve( timestamp: Int32 ( date . timeIntervalSince1970 ) )
972+ action: . approve( timestamp: nil )
948973 ) . start ( )
949- } ,
950- infoText: infoText
951- ) ,
952- for: context. window
953- )
954- } else {
955- let author = keyboardMessage. author? . displayTitle ?? " "
956- let info = strings ( ) . chatSuggestPostPublishConfirmInfo ( author, formatted, comission. decemial. string)
957- verifyAlert (
958- for: context. window,
959- header: strings ( ) . chatSuggestPostPublishConfirmHeader,
960- information: info,
961- ok: strings ( ) . chatSuggestPostPublishConfirmButton,
962- successHandler: { _ in
963- _ = context. engine. messages. monoforumPerformSuggestedPostAction (
964- id: keyboardMessage. id,
965- action: . approve( timestamp: nil )
966- ) . start ( )
967- }
968- )
974+ }
975+ )
976+ }
969977 }
970-
971-
972978
973979 case SuggestedPostMessageAttribute . commandDecline:
974980 showModal ( with: DeclineSuggestPostModalController ( context: context, callback: { comment in
0 commit comments