Skip to content

Commit f1b1a31

Browse files
committed
Share referral page info rows and top bar setup
Task: 2026/10/29/share-referral-page-rows-top-bars-and-slider-lookup
1 parent 354d298 commit f1b1a31

4 files changed

Lines changed: 135 additions & 165 deletions

File tree

‎Telegram/SourceFiles/info/bot/starref/info_bot_starref_common.cpp‎

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ For license and copyright information please follow this link:
1111
#include "boxes/peers/replace_boost_box.h" // CreateUserpicsTransfer.
1212
#include "boxes/send_credits_box.h" // Ui::CreditsEmoji.
1313
#include "chat_helpers/stickers_lottie.h"
14+
#include "core/click_handler_types.h"
1415
#include "core/ui_integration.h"
1516
#include "data/stickers/data_custom_emoji.h"
1617
#include "data/data_channel.h"
@@ -19,12 +20,16 @@ For license and copyright information please follow this link:
1920
#include "data/data_session.h"
2021
#include "history/view/media/history_view_sticker.h"
2122
#include "history/view/media/history_view_sticker_player.h"
23+
#include "info/profile/info_profile_icon.h"
24+
#include "info/info_controller.h"
25+
#include "info/info_wrap_widget.h"
2226
#include "lang/lang_keys.h"
2327
#include "main/main_session.h"
2428
#include "settings/settings_common.h"
2529
#include "ui/boxes/confirm_box.h"
2630
#include "ui/controls/userpic_button.h"
2731
#include "ui/controls/who_reacted_context_action.h"
32+
#include "ui/effects/premium_top_bar.h"
2833
#include "ui/dynamic_image.h"
2934
#include "ui/dynamic_thumbnails.h"
3035
#include "ui/layers/generic_box.h"
@@ -1040,4 +1045,84 @@ object_ptr<Ui::RpWidget> CreateLinkHeaderIcon(
10401045
return CreateLinkIcon(parent, session, usersCount);
10411046
}
10421047

1048+
object_ptr<Ui::RpWidget> MakeInfoRow(
1049+
not_null<QWidget*> parent,
1050+
rpl::producer<QString> title,
1051+
rpl::producer<QString> text,
1052+
not_null<const style::icon*> icon) {
1053+
auto result = object_ptr<Ui::VerticalLayout>(parent);
1054+
const auto raw = result.data();
1055+
1056+
raw->add(
1057+
object_ptr<Ui::FlatLabel>(
1058+
raw,
1059+
std::move(title) | rpl::map(tr::bold),
1060+
st::defaultFlatLabel),
1061+
st::settingsPremiumRowTitlePadding);
1062+
raw->add(
1063+
object_ptr<Ui::FlatLabel>(
1064+
raw,
1065+
std::move(text),
1066+
st::boxDividerLabel),
1067+
st::settingsPremiumRowAboutPadding);
1068+
object_ptr<Info::Profile::FloatingIcon>(
1069+
raw,
1070+
*icon,
1071+
st::starrefInfoIconPosition);
1072+
1073+
return result;
1074+
}
1075+
1076+
std::unique_ptr<Ui::Premium::TopBar> MakeTopBar(
1077+
not_null<QWidget*> parent,
1078+
not_null<Controller*> controller,
1079+
rpl::producer<QString> title,
1080+
rpl::producer<TextWithEntities> about,
1081+
Fn<void(int)> updateTopSkip) {
1082+
const auto weak = base::make_weak(controller->parentController());
1083+
const auto clickContextOther = [=] {
1084+
return QVariant::fromValue(ClickHandlerContext{
1085+
.sessionWindow = weak,
1086+
.botStartAutoSubmit = true,
1087+
});
1088+
};
1089+
auto result = std::make_unique<Ui::Premium::TopBar>(
1090+
parent,
1091+
st::starrefCover,
1092+
Ui::Premium::TopBarDescriptor{
1093+
.clickContextOther = clickContextOther,
1094+
.logo = u"affiliate"_q,
1095+
.title = std::move(title),
1096+
.about = std::move(about),
1097+
.light = true,
1098+
});
1099+
const auto raw = result.get();
1100+
1101+
controller->wrapValue(
1102+
) | rpl::on_next([=](Info::Wrap wrap) {
1103+
raw->setRoundEdges(wrap == Info::Wrap::Layer);
1104+
}, raw->lifetime());
1105+
1106+
const auto baseHeight = st::starrefCoverHeight;
1107+
raw->resize(parent->width(), baseHeight);
1108+
const auto setTopHeight = [=](int height) {
1109+
if (height > raw->maximumHeight()) {
1110+
raw->setMaximumHeight(height);
1111+
raw->setMinimumHeight(height);
1112+
} else {
1113+
raw->setMinimumHeight(height);
1114+
raw->setMaximumHeight(height);
1115+
}
1116+
raw->resize(raw->width(), height);
1117+
updateTopSkip(raw->height());
1118+
};
1119+
1120+
raw->additionalHeight(
1121+
) | rpl::on_next([=](int additionalHeight) {
1122+
setTopHeight(baseHeight + additionalHeight);
1123+
}, raw->lifetime());
1124+
1125+
return result;
1126+
}
1127+
10431128
} // namespace Info::BotStarRef

‎Telegram/SourceFiles/info/bot/starref/info_bot_starref_common.h‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ class RpWidget;
1919
class Show;
2020
} // namespace Ui
2121

22+
namespace Ui::Premium {
23+
class TopBar;
24+
} // namespace Ui::Premium
25+
2226
namespace style {
2327
struct RoundButton;
2428
struct InputField;
@@ -28,6 +32,10 @@ namespace Main {
2832
class Session;
2933
} // namespace Main
3034

35+
namespace Info {
36+
class Controller;
37+
} // namespace Info
38+
3139
namespace Info::BotStarRef {
3240

3341
struct ConnectedBotState {
@@ -109,4 +117,16 @@ void FinishProgram(
109117
not_null<Main::Session*> session,
110118
int usersCount = 0);
111119

120+
[[nodiscard]] object_ptr<Ui::RpWidget> MakeInfoRow(
121+
not_null<QWidget*> parent,
122+
rpl::producer<QString> title,
123+
rpl::producer<QString> text,
124+
not_null<const style::icon*> icon);
125+
[[nodiscard]] std::unique_ptr<Ui::Premium::TopBar> MakeTopBar(
126+
not_null<QWidget*> parent,
127+
not_null<Controller*> controller,
128+
rpl::producer<QString> title,
129+
rpl::producer<TextWithEntities> about,
130+
Fn<void(int)> updateTopSkip);
131+
112132
} // namespace Info::BotStarRef

‎Telegram/SourceFiles/info/bot/starref/info_bot_starref_join_widget.cpp‎

Lines changed: 15 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ For license and copyright information please follow this link:
1212
#include "base/unixtime.h"
1313
#include "base/weak_ptr.h"
1414
#include "boxes/peer_list_box.h"
15-
#include "core/click_handler_types.h"
1615
#include "data/data_channel.h"
1716
#include "data/data_session.h"
1817
#include "data/data_user.h"
@@ -688,11 +687,6 @@ class InnerWidget final : public Ui::RpWidget {
688687
not_null<ListController*> setupSuggested();
689688
void setupSort(not_null<Ui::RpWidget*> label);
690689

691-
[[nodiscard]] object_ptr<Ui::RpWidget> infoRow(
692-
rpl::producer<QString> title,
693-
rpl::producer<QString> text,
694-
not_null<const style::icon*> icon);
695-
696690
const not_null<Controller*> _controller;
697691
const not_null<Ui::VerticalLayout*> _container;
698692
rpl::variable<SuggestedSort> _sort = SuggestedSort::Profitability;
@@ -721,17 +715,20 @@ void InnerWidget::prepare() {
721715
void InnerWidget::setupInfo() {
722716
AddSkip(_container, st::defaultVerticalListSkip * 2);
723717

724-
_container->add(infoRow(
718+
_container->add(MakeInfoRow(
719+
_container,
725720
tr::lng_star_ref_reliable_title(),
726721
tr::lng_star_ref_reliable_about(),
727722
&st::menuIconAntispam));
728723

729-
_container->add(infoRow(
724+
_container->add(MakeInfoRow(
725+
_container,
730726
tr::lng_star_ref_transparent_title(),
731727
tr::lng_star_ref_transparent_about(),
732728
&st::menuIconTransparent));
733729

734-
_container->add(infoRow(
730+
_container->add(MakeInfoRow(
731+
_container,
735732
tr::lng_star_ref_simple_title(),
736733
tr::lng_star_ref_simple_about(),
737734
&st::menuIconLike));
@@ -861,33 +858,6 @@ not_null<ListController*> InnerWidget::setupSuggested() {
861858
return controller;
862859
}
863860

864-
object_ptr<Ui::RpWidget> InnerWidget::infoRow(
865-
rpl::producer<QString> title,
866-
rpl::producer<QString> text,
867-
not_null<const style::icon*> icon) {
868-
auto result = object_ptr<Ui::VerticalLayout>(_container);
869-
const auto raw = result.data();
870-
871-
raw->add(
872-
object_ptr<Ui::FlatLabel>(
873-
raw,
874-
std::move(title) | rpl::map(tr::bold),
875-
st::defaultFlatLabel),
876-
st::settingsPremiumRowTitlePadding);
877-
raw->add(
878-
object_ptr<Ui::FlatLabel>(
879-
raw,
880-
std::move(text),
881-
st::boxDividerLabel),
882-
st::settingsPremiumRowAboutPadding);
883-
object_ptr<Info::Profile::FloatingIcon>(
884-
raw,
885-
*icon,
886-
st::starrefInfoIconPosition);
887-
888-
return result;
889-
}
890-
891861
not_null<PeerData*> InnerWidget::peer() const {
892862
return _controller->key().starrefPeer();
893863
}
@@ -993,56 +963,19 @@ void Widget::restoreState(not_null<Memento*> memento) {
993963

994964
std::unique_ptr<Ui::Premium::TopBarAbstract> Widget::setupTop() {
995965
auto title = tr::lng_star_ref_list_title();
996-
auto about = tr::lng_star_ref_list_about_channel(tr::marked);
997966

998967
const auto controller = this->controller();
999-
const auto weak = base::make_weak(controller->parentController());
1000-
const auto clickContextOther = [=] {
1001-
return QVariant::fromValue(ClickHandlerContext{
1002-
.sessionWindow = weak,
1003-
.botStartAutoSubmit = true,
1004-
});
1005-
};
1006-
auto result = std::make_unique<Ui::Premium::TopBar>(
1007-
this,
1008-
st::starrefCover,
1009-
Ui::Premium::TopBarDescriptor{
1010-
.clickContextOther = clickContextOther,
1011-
.logo = u"affiliate"_q,
1012-
.title = std::move(title),
1013-
.about = std::move(about),
1014-
.light = true,
1015-
});
1016-
const auto raw = result.get();
1017-
1018-
controller->wrapValue(
1019-
) | rpl::on_next([=](Info::Wrap wrap) {
1020-
raw->setRoundEdges(wrap == Info::Wrap::Layer);
1021-
}, raw->lifetime());
1022-
1023-
const auto baseHeight = st::starrefCoverHeight;
1024-
raw->resize(width(), baseHeight);
1025-
const auto updateTopSkip = [=] {
1026-
const auto height = raw->height();
968+
const auto updateTopSkip = [=](int height) {
1027969
setPaintPadding({ 0, height, 0, 0 });
1028970
setScrollTopSkip(height);
1029971
};
1030-
const auto setTopHeight = [=](int height) {
1031-
if (height > raw->maximumHeight()) {
1032-
raw->setMaximumHeight(height);
1033-
raw->setMinimumHeight(height);
1034-
} else {
1035-
raw->setMinimumHeight(height);
1036-
raw->setMaximumHeight(height);
1037-
}
1038-
raw->resize(raw->width(), height);
1039-
updateTopSkip();
1040-
};
1041-
1042-
raw->additionalHeight(
1043-
) | rpl::on_next([=](int additionalHeight) {
1044-
setTopHeight(baseHeight + additionalHeight);
1045-
}, raw->lifetime());
972+
auto result = MakeTopBar(
973+
this,
974+
controller,
975+
std::move(title),
976+
tr::lng_star_ref_list_about_channel(tr::marked),
977+
updateTopSkip);
978+
const auto raw = result.get();
1046979

1047980
controller->wrapValue(
1048981
) | rpl::on_next([=](Info::Wrap wrap) {
@@ -1094,7 +1027,7 @@ std::unique_ptr<Ui::Premium::TopBarAbstract> Widget::setupTop() {
10941027
raw->move(0, 0);
10951028
widthValue() | rpl::on_next([=](int width) {
10961029
raw->resizeToWidth(width);
1097-
updateTopSkip();
1030+
updateTopSkip(raw->height());
10981031
}, raw->lifetime());
10991032

11001033
return result;

0 commit comments

Comments
 (0)