From d60ce41fa9b1cb448439b587dd3e0255e3984f31 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 29 Jan 2025 10:26:42 +0400 Subject: [PATCH] Add a gift button to channel bottom. --- .../chat_helpers/chat_helpers.style | 7 ++++++ .../SourceFiles/history/history_widget.cpp | 22 +++++++++++++++++++ Telegram/SourceFiles/history/history_widget.h | 2 ++ 3 files changed, 31 insertions(+) diff --git a/Telegram/SourceFiles/chat_helpers/chat_helpers.style b/Telegram/SourceFiles/chat_helpers/chat_helpers.style index 2ad236013..3c1518b37 100644 --- a/Telegram/SourceFiles/chat_helpers/chat_helpers.style +++ b/Telegram/SourceFiles/chat_helpers/chat_helpers.style @@ -855,6 +855,13 @@ historyComposeButton: FlatButton { color: historyComposeButtonBgRipple; } } +historyGiftToChannel: IconButton(defaultIconButton) { + width: 46px; + height: 46px; + + icon: icon{{ "menu/gift_premium", windowActiveTextFg }}; + iconOver: icon{{ "menu/gift_premium", windowActiveTextFg }}; +} historyUnblock: FlatButton(historyComposeButton) { color: attentionButtonFg; overColor: attentionButtonFgOver; diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 6c337f9c0..74f354e8a 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -22,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/moderate_messages_box.h" #include "boxes/premium_limits_box.h" #include "boxes/premium_preview_box.h" +#include "boxes/star_gift_box.h" #include "boxes/peers/edit_peer_permissions_box.h" // ShowAboutGigagroup. #include "boxes/peers/edit_peer_requests_box.h" #include "core/file_utilities.h" @@ -377,6 +378,7 @@ HistoryWidget::HistoryWidget( _botStart->addClickHandler([=] { sendBotStartCommand(); }); _joinChannel->addClickHandler([=] { joinChannel(); }); _muteUnmute->addClickHandler([=] { toggleMuteUnmute(); }); + setupGiftToChannelButton(); _reportMessages->addClickHandler([=] { reportSelectedMessages(); }); _field->submits( ) | rpl::start_with_next([=](Qt::KeyboardModifiers modifiers) { @@ -2033,6 +2035,20 @@ void HistoryWidget::setupShortcuts() { }, lifetime()); } +void HistoryWidget::setupGiftToChannelButton() { + _giftToChannel = Ui::CreateChild( + _muteUnmute.data(), + st::historyGiftToChannel); + _muteUnmute->widthValue() | rpl::start_with_next([=](int width) { + _giftToChannel->moveToRight(0, 0); + }, _giftToChannel->lifetime()); + _giftToChannel->setClickedCallback([=] { + if (_peer) { + Ui::ShowStarGiftBox(controller(), _peer); + } + }); +} + void HistoryWidget::pushReplyReturn(not_null item) { if (item->history() != _history && item->history() != _migrated) { return; @@ -2415,6 +2431,8 @@ void HistoryWidget::showHistory( ) | rpl::start_with_next([=] { updateControlsGeometry(); }, _businessBotStatus->bar().lifetime()); + } else if (const auto channel = _peer->asChannel()) { + _giftToChannel->setVisible(channel->stargiftsAvailable()); } orderWidgets(); controller()->tabbedSelector()->setCurrentPeer(_peer); @@ -8358,6 +8376,10 @@ void HistoryWidget::fullInfoUpdated() { if (clearMaybeSendStart() && !_history->isDisplayedEmpty()) { sendBotStartCommand(); } + + if (const auto channel = _peer->asChannel()) { + _giftToChannel->setVisible(channel->stargiftsAvailable()); + } } if (updateCmdStartShown()) { refresh = true; diff --git a/Telegram/SourceFiles/history/history_widget.h b/Telegram/SourceFiles/history/history_widget.h index 7fa51470f..9bdced55b 100644 --- a/Telegram/SourceFiles/history/history_widget.h +++ b/Telegram/SourceFiles/history/history_widget.h @@ -523,6 +523,7 @@ private: } void setupShortcuts(); + void setupGiftToChannelButton(); void handlePeerMigration(); @@ -785,6 +786,7 @@ private: object_ptr _botStart; object_ptr _joinChannel; object_ptr _muteUnmute; + QPointer _giftToChannel; object_ptr _reportMessages; struct { object_ptr button = { nullptr };