Add a gift button to channel bottom.

This commit is contained in:
John Preston 2025-01-29 10:26:42 +04:00
parent 958db945f3
commit d60ce41fa9
3 changed files with 31 additions and 0 deletions

View file

@ -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;

View file

@ -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<Ui::IconButton>(
_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<HistoryItem*> 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;

View file

@ -523,6 +523,7 @@ private:
}
void setupShortcuts();
void setupGiftToChannelButton();
void handlePeerMigration();
@ -785,6 +786,7 @@ private:
object_ptr<Ui::FlatButton> _botStart;
object_ptr<Ui::FlatButton> _joinChannel;
object_ptr<Ui::FlatButton> _muteUnmute;
QPointer<Ui::IconButton> _giftToChannel;
object_ptr<Ui::FlatButton> _reportMessages;
struct {
object_ptr<Ui::RoundButton> button = { nullptr };