From 35b129287b332d5810e0a5df835917119d1de189 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 8 Jul 2025 11:33:04 +0400 Subject: [PATCH] Support RemoveFee/ChargeFee in monoforums. --- Telegram/Resources/icons/menu/cancel_fee.png | Bin 0 -> 865 bytes .../Resources/icons/menu/cancel_fee@2x.png | Bin 0 -> 1810 bytes .../Resources/icons/menu/cancel_fee@3x.png | Bin 0 -> 2662 bytes Telegram/Resources/langs/lang.strings | 5 + .../SourceFiles/data/data_saved_sublist.cpp | 18 +++ .../SourceFiles/data/data_saved_sublist.h | 3 + .../view/history_view_contact_status.cpp | 66 +------- .../view/history_view_contact_status.h | 2 +- .../view/history_view_top_bar_widget.cpp | 5 + Telegram/SourceFiles/ui/menu_icons.style | 1 + Telegram/SourceFiles/window/window.style | 8 + .../SourceFiles/window/window_peer_menu.cpp | 146 ++++++++++++++++++ .../SourceFiles/window/window_peer_menu.h | 7 + Telegram/lib_ui | 2 +- 14 files changed, 202 insertions(+), 61 deletions(-) create mode 100644 Telegram/Resources/icons/menu/cancel_fee.png create mode 100644 Telegram/Resources/icons/menu/cancel_fee@2x.png create mode 100644 Telegram/Resources/icons/menu/cancel_fee@3x.png diff --git a/Telegram/Resources/icons/menu/cancel_fee.png b/Telegram/Resources/icons/menu/cancel_fee.png new file mode 100644 index 0000000000000000000000000000000000000000..467c369cec28a1ec2c2f9947fc199d6f56eec69a GIT binary patch literal 865 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1SIoCSFHz9jKx9jP7LeL$-D$|Tv8)E(|mmy zw18|52FCVG1{RPKAeI7R1_tH@j10^`nh_+nfC(-uv49!D1}S`GTDq2jf$6lTi(`m| z;MovIk41q3Vd5q&TZ~SMp6Pm}ps6v5EACTPxB1c#s~II4h94DHuynR7Xk6gh#hn@3 z)fdaseIi;U#obZNgtN=bd+p!4wfEbzuVmib`R9I(@#lMI_RO4r@W=fp$ES0amX;dM zJd?Hc*V1(9_H*a_)?cr#sfp2>e*aaFj#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Q1%9o-zw3bCjXe6}K>z>%07*qoM6N<$f@R@V AdH?_b literal 0 HcmV?d00001 diff --git a/Telegram/Resources/icons/menu/cancel_fee@3x.png b/Telegram/Resources/icons/menu/cancel_fee@3x.png new file mode 100644 index 0000000000000000000000000000000000000000..73fee9f98a6b702e08f9debc2576aa2d33f06340 GIT binary patch literal 2662 zcmV-s3YqnZP)Px#L}ge>W=%~1DgXcg2mk?xX#fNO00031000^Q000001E2u_0{{R30RRC20H6W@ z1ONa40RR91NT34%1ONa40RR91NB{r;0FW_8?*IS^&`Cr=RA>e5nsw+@TM)<&~6P*Lp07R6Rj#BRmz?s)I>-tjkkxPAAx#)G|o?9M%B z<~wtGX3h-+B2T0TB0Ui4fk+QTdf@-t15rQK^jNWCWzCv3b?VeflO|1=FyV&}AKtuq z^YrP{J9qAU|Ni}_st$j{vSrIwv0}w?<;oQ=UOY#R9P#7FH#gwZr%%_fUq5l;#DN0` z_U_$FJIy?QN(p1qty{MvM~?jM^I_-?A3of*Yu6-6lKd%+QFbIqkf3+(-cO!9@!29H z`{T!td-m)JT3DJFqp27-Zrt|m+YcQ&G-Jk$W^1loxpLvcg$EBFJbd_&-{;Str%ILT zujnUVzI?fI1qTB zy?XW9w{PE~Ho7u4!=E=vKprt-gs!edixxps!bsss;4X-!pWB7ecIy-5 z%9M$&3DZAb1!s}8YU$FYVFGr6Vcb@%SRs1v-Mg1Kabg!4U)5vBjurI%`}fC- z7tfbC%)58*#<8eexw2nDT+M?A4~q7YBS-p0u;s@+mlNjIt5@mLrL$$VsbHg1mMvet z+=j)e7+-~$Kq0()_bzkh%ud|i>-5Rczkh%4f{HVC?AT43G*M>l+O^Bl*>}a{G?PIK z&q63tq==lwH*VbUWmeOsO?T|r!61uG5DY%k5@**J6tUdx+qV@C_Amup`@)3*mqN^H z+_RUOpzo_zttx`f1XEffBVzCnHn1Q*o0!;v7Zq;O|N3W5pD!~?2+{rcm^ zjXQPflwOOii4rAp#0yp~T)0qVD^#cutnf=sm@q+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zDpYi11!lMcv^*qNHVPL?QE1Q&CtBvO*o z(-n(TQLa9~6n?xM0hfffek-l-UI;2?pwuzzDRC{zbb?@!^k|nZT?P&uC?DjomyitR zffEPk;>C-6MWr6Tv>{zVM9hP)fH%W(zjf;t-%M@WwoPqi-Me?EQ= zy7-5K1`Xm>d=zK|6$4OV`v{A`1m|4>9O-6Pf{jO6BN;JlBK55b=>;0lpg{xms{fLw zAU!VbKOzV!bwKHyVW9c44P|`X<=P%$&|_zMT9xy`oUernGa^bBkTA5w4uabgzN%ca zW)0KK5SvMp2!Tn4>la9Tx5WBX3^*Aw8g^P#Ic(xOA|Bq4pPW>a6-F6XDm7}; diff --git a/Telegram/SourceFiles/history/view/history_view_contact_status.cpp b/Telegram/SourceFiles/history/view/history_view_contact_status.cpp index f5710124bb..99c135f6f3 100644 --- a/Telegram/SourceFiles/history/view/history_view_contact_status.cpp +++ b/Telegram/SourceFiles/history/view/history_view_contact_status.cpp @@ -1194,6 +1194,7 @@ PaysStatus::PaysStatus( not_null user) : _controller(window) , _user(user) +, _paidAlready(std::make_shared>()) , _inner(Ui::CreateChild(parent.get(), user)) , _bar(parent, object_ptr::fromRaw(_inner)) { setupState(); @@ -1220,65 +1221,12 @@ void PaysStatus::setupState() { void PaysStatus::setupHandlers() { _inner->removeClicks( ) | rpl::start_with_next([=] { - const auto user = _user; - const auto exception = [=](bool refund) { - using Flag = MTPaccount_ToggleNoPaidMessagesException::Flag; - const auto api = &user->session().api(); - const auto require = false; - api->request(MTPaccount_ToggleNoPaidMessagesException( - MTP_flags((refund ? Flag::f_refund_charged : Flag()) - | (require ? Flag::f_require_payment : Flag())), - MTPInputPeer(), // parent_peer // #TODO monoforum - user->inputUser - )).done([=] { - user->clearPaysPerMessage(); - }).send(); - }; - _controller->show(Box([=](not_null box) { - const auto refund = std::make_shared>(); - Ui::ConfirmBox(box, { - .text = tr::lng_payment_refund_text( - tr::now, - lt_name, - Ui::Text::Bold(user->shortName()), - Ui::Text::WithEntities), - .confirmed = [=](Fn close) { - exception(*refund && (*refund)->checked()); - close(); - }, - .confirmText = tr::lng_payment_refund_confirm(tr::now), - .title = tr::lng_payment_refund_title(tr::now), - }); - const auto paid = box->lifetime().make_state< - rpl::variable - >(); - *paid = _paidAlready.value(); - paid->value() | rpl::start_with_next([=](int already) { - if (!already) { - delete base::take(*refund); - } else if (!*refund) { - const auto skip = st::defaultCheckbox.margin.top(); - *refund = box->addRow( - object_ptr( - box, - tr::lng_payment_refund_also( - lt_count, - paid->value() | tr::to_count()), - false, - st::defaultCheckbox), - st::boxRowPadding + QMargins(0, skip, 0, skip)); - } - }, box->lifetime()); - - user->session().api().request(MTPaccount_GetPaidMessagesRevenue( - MTP_flags(0), - MTPInputPeer(), // parent_peer // #TODO monoforum - user->inputUser - )).done(crl::guard(_inner, [=]( - const MTPaccount_PaidMessagesRevenue &result) { - _paidAlready = result.data().vstars_amount().v; - })).send(); - })); + Window::PeerMenuConfirmToggleFee( + _controller, + _paidAlready, + _user->session().user(), + _user, + true); }, _bar.lifetime()); } diff --git a/Telegram/SourceFiles/history/view/history_view_contact_status.h b/Telegram/SourceFiles/history/view/history_view_contact_status.h index 0c540a36c4..47aa1232ce 100644 --- a/Telegram/SourceFiles/history/view/history_view_contact_status.h +++ b/Telegram/SourceFiles/history/view/history_view_contact_status.h @@ -208,7 +208,7 @@ private: const not_null _controller; const not_null _user; - rpl::variable _paidAlready; + std::shared_ptr> _paidAlready; State _state; QPointer _inner; SlidingBar _bar; diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp index 2ecbe5ce3a..97edfbdc52 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp @@ -1171,6 +1171,11 @@ void TopBarWidget::updateControlsVisibility() { ? (hasPollsMenu || hasTodoListsMenu || hasTopicMenu) : (section == Section::ChatsList) ? (_activeChat.key.peer() && _activeChat.key.peer()->isForum()) + : (section == Section::SavedSublist) + ? (_activeChat.key.peer() + && _activeChat.key.peer()->isChannel() + && _activeChat.key.peer()->owner().commonStarsPerMessage( + _activeChat.key.peer()->asChannel())) : false); const auto hasInfo = !_activeChat.key.folder() && (section == Section::History diff --git a/Telegram/SourceFiles/ui/menu_icons.style b/Telegram/SourceFiles/ui/menu_icons.style index 9c3233f0e2..fcd6d2bbb8 100644 --- a/Telegram/SourceFiles/ui/menu_icons.style +++ b/Telegram/SourceFiles/ui/menu_icons.style @@ -56,6 +56,7 @@ menuIconDiscussion: icon {{ "menu/discussion", menuIconColor }}; menuIconStats: icon {{ "menu/stats", menuIconColor }}; menuIconBoosts: icon {{ "menu/boosts", menuIconColor }}; menuIconEarn: icon {{ "menu/earn", menuIconColor }}; +menuIconCancelFee: icon {{ "menu/cancel_fee", menuIconColor }}; menuIconCreatePoll: icon {{ "menu/create_poll", menuIconColor }}; menuIconCreateTodoList: icon {{ "menu/select", menuIconColor }}; menuIconQrCode: icon {{ "menu/qr_code", menuIconColor }}; diff --git a/Telegram/SourceFiles/window/window.style b/Telegram/SourceFiles/window/window.style index acdda31299..26e77ab1f1 100644 --- a/Telegram/SourceFiles/window/window.style +++ b/Telegram/SourceFiles/window/window.style @@ -316,6 +316,14 @@ windowArchiveToast: Toast(defaultToast) { maxWidth: boxWideWidth; } +windowFeeItem: Menu(defaultMenu) { + itemPadding: margins(17px, 3px, 17px, 4px); + itemRightSkip: 0px; + itemStyle: whenReadStyle; + itemFgOver: windowFg; + itemFgDisabled: windowFg; +} + ivWidthMin: 380px; ivHeightMin: 480px; ivWidthDefault: 600px; diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index 114f0ec207..8519ddf620 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -23,6 +23,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/random.h" #include "base/options.h" #include "base/unixtime.h" +#include "base/unique_qptr.h" #include "base/qt/qt_key_modifiers.h" #include "boxes/delete_messages_box.h" #include "boxes/max_invite_box.h" @@ -83,6 +84,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/stories/info_stories_widget.h" #include "data/components/scheduled_messages.h" #include "data/notify/data_notify_settings.h" +#include "data/stickers/data_custom_emoji.h" #include "data/data_changes.h" #include "data/data_session.h" #include "data/data_folder.h" @@ -98,10 +100,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_chat_filters.h" #include "dialogs/dialogs_key.h" #include "core/application.h" +#include "core/ui_integration.h" #include "export/export_manager.h" #include "boxes/peers/edit_peer_info_box.h" #include "boxes/premium_preview_box.h" #include "styles/style_chat.h" +#include "styles/style_credits.h" #include "styles/style_layers.h" #include "styles/style_boxes.h" #include "styles/style_window.h" // st::windowMinWidth @@ -277,6 +281,7 @@ private: void fillArchiveActions(); void fillSavedSublistActions(); void fillContextMenuActions(); + void fillMonoforumPeerActions(); void addHidePromotion(); void addTogglePin(); @@ -321,6 +326,7 @@ private: void addVideoChat(); void addViewStatistics(); void addBoostChat(); + void addToggleFee(); [[nodiscard]] bool skipCreateActions() const; @@ -1360,6 +1366,7 @@ void Filler::fill() { case Section::Scheduled: fillScheduledActions(); break; case Section::ContextMenu: case Section::SubsectionTabsMenu: fillContextMenuActions(); break; + case Section::SavedSublist: fillMonoforumPeerActions(); break; default: Unexpected("_request.section in Filler::fill."); } } @@ -1647,6 +1654,68 @@ void Filler::fillSavedSublistActions() { addTogglePin(); } +void Filler::fillMonoforumPeerActions() { + Expects(_sublist != nullptr); + + addToggleFee(); +} + +void Filler::addToggleFee() { + const auto feeRemoved = _sublist->isFeeRemoved(); + const auto text = feeRemoved + ? tr::lng_context_charge_fee(tr::now) + : tr::lng_context_remove_fee(tr::now); + const auto navigation = _controller; + const auto parent = _sublist->parentChat(); + const auto user = _sublist->sublistPeer()->asUser(); + if (!parent || !user) { + return; + } + const auto paidAmount = std::make_shared>(); + _addAction(text, [=] { + const auto removeFee = !feeRemoved; + PeerMenuConfirmToggleFee( + navigation, + paidAmount, + parent, + user, + removeFee); + }, feeRemoved ? &st::menuIconEarn : &st::menuIconCancelFee); + _addAction({ .isSeparator = true }); + _addAction({ .make = [=](not_null actionParent) { + const auto text = feeRemoved + ? tr::lng_context_fee_free( + tr::now, + lt_name, + TextWithEntities{ user->shortName() }, + Ui::Text::WithEntities) + : tr::lng_context_fee_now( + tr::now, + lt_name, + TextWithEntities{ user->shortName() }, + lt_amount, + user->owner().customEmojiManager().ministarEmoji( + { 0, st::giftBoxByStarsStarTop, 0, 0 } + ).append(Lang::FormatCountDecimal( + user->owner().commonStarsPerMessage(parent) + )), + Ui::Text::WithEntities); + const auto action = new QAction(actionParent); + action->setDisabled(true); + auto result = base::make_unique_q( + actionParent, + st::windowFeeItem, + action, + nullptr, + nullptr); + result->setMarkedText( + text, + QString(), + Core::TextContext({ .session = &user->session() })); + return result; + } }); +} + } // namespace void PeerMenuExportChat( @@ -3726,4 +3795,81 @@ bool CanArchive(History *history, PeerData *peer) { return true; } +void PeerMenuConfirmToggleFee( + not_null navigation, + std::shared_ptr> paidAmount, + not_null peer, + not_null user, + bool removeFee) { + const auto parent = peer->isChannel() ? peer->asChannel() : nullptr; + const auto exception = [=](bool refund) { + using Flag = MTPaccount_ToggleNoPaidMessagesException::Flag; + const auto api = &user->session().api(); + api->request(MTPaccount_ToggleNoPaidMessagesException( + MTP_flags((refund ? Flag::f_refund_charged : Flag()) + | (removeFee ? Flag() : Flag::f_require_payment) + | (parent ? Flag::f_parent_peer : Flag())), + parent->input, + user->inputUser + )).done([=] { + if (!parent) { + user->clearPaysPerMessage(); + } else if (const auto monoforum = peer->monoforum()) { + if (const auto sublist = monoforum->sublistLoaded(user)) { + sublist->toggleFeeRemoved(removeFee); + } + } + }).send(); + }; + if (!removeFee) { + exception(false); + return; + } + navigation->uiShow()->show(Box([=](not_null box) { + const auto refund = std::make_shared>(); + Ui::ConfirmBox(box, { + .text = tr::lng_payment_refund_text( + tr::now, + lt_name, + Ui::Text::Bold(user->shortName()), + Ui::Text::WithEntities), + .confirmed = [=](Fn close) { + exception(*refund && (*refund)->checked()); + close(); + }, + .confirmText = tr::lng_payment_refund_confirm(tr::now), + .title = tr::lng_payment_refund_title(tr::now), + }); + const auto paid = box->lifetime().make_state< + rpl::variable + >(); + *paid = paidAmount->value(); + paid->value() | rpl::start_with_next([=](int already) { + if (!already) { + delete base::take(*refund); + } else if (!*refund) { + const auto skip = st::defaultCheckbox.margin.top(); + *refund = box->addRow( + object_ptr( + box, + tr::lng_payment_refund_also( + lt_count, + paid->value() | tr::to_count()), + false, + st::defaultCheckbox), + st::boxRowPadding + QMargins(0, skip, 0, skip)); + } + }, box->lifetime()); + + using Flag = MTPaccount_GetPaidMessagesRevenue::Flag; + user->session().api().request(MTPaccount_GetPaidMessagesRevenue( + MTP_flags(parent ? Flag::f_parent_peer : Flag()), + parent ? parent->input : MTPInputPeer(), + user->inputUser + )).done([=](const MTPaccount_PaidMessagesRevenue &result) { + *paidAmount = result.data().vstars_amount().v; + }).send(); + })); +} + } // namespace Window diff --git a/Telegram/SourceFiles/window/window_peer_menu.h b/Telegram/SourceFiles/window/window_peer_menu.h index f01801423f..56c4a6baec 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.h +++ b/Telegram/SourceFiles/window/window_peer_menu.h @@ -253,4 +253,11 @@ void AddSeparatorAndShiftUp(const PeerMenuCallback &addAction); [[nodiscard]] bool IsArchived(not_null history); [[nodiscard]] bool CanArchive(History *history, PeerData *peer); +void PeerMenuConfirmToggleFee( + not_null navigation, + std::shared_ptr> paidAmount, + not_null peer, + not_null user, + bool removeFee); + } // namespace Window diff --git a/Telegram/lib_ui b/Telegram/lib_ui index 0b7933ad11..d905dad9c9 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit 0b7933ad1189076233b69fac0a5a475d2a5deb8b +Subproject commit d905dad9c9b0e7e2b6755bb13957f37862888464