mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 06:07:06 +02:00
Implement premium lock of similar channels.
This commit is contained in:
parent
2542ec5d93
commit
ae1da5baf4
18 changed files with 785 additions and 112 deletions
|
@ -899,6 +899,8 @@ PRIVATE
|
|||
info/profile/info_profile_widget.h
|
||||
info/settings/info_settings_widget.cpp
|
||||
info/settings/info_settings_widget.h
|
||||
info/similar_channels/info_similar_channels_widget.cpp
|
||||
info/similar_channels/info_similar_channels_widget.h
|
||||
info/statistics/info_statistics_common.h
|
||||
info/statistics/info_statistics_inner_widget.cpp
|
||||
info/statistics/info_statistics_inner_widget.h
|
||||
|
|
|
@ -1175,6 +1175,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
"lng_profile_bot_privacy" = "Bot Privacy Policy";
|
||||
"lng_profile_common_groups#one" = "{count} group in common";
|
||||
"lng_profile_common_groups#other" = "{count} groups in common";
|
||||
"lng_profile_similar_channels#one" = "{count} similar channel";
|
||||
"lng_profile_similar_channels#other" = "{count} similar channels";
|
||||
"lng_profile_participants_section" = "Members";
|
||||
"lng_profile_subscribers_section" = "Subscribers";
|
||||
"lng_profile_add_contact" = "Add Contact";
|
||||
|
@ -1686,6 +1688,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
"lng_similar_channels_premium_all#one" = "Subscribe to {link} to unlock up to **{count}** similar channel.";
|
||||
"lng_similar_channels_premium_all#other" = "Subscribe to {link} to unlock up to **{count}** similar channels.";
|
||||
"lng_similar_channels_premium_all_link" = "Telegram Premium";
|
||||
"lng_similar_channels_show_more" = "Show more channels";
|
||||
|
||||
"lng_premium_gift_duration_months#one" = "for {count} month";
|
||||
"lng_premium_gift_duration_months#other" = "for {count} months";
|
||||
|
|
|
@ -227,7 +227,9 @@ void ApplyBotsList(
|
|||
}
|
||||
}
|
||||
if constexpr (MTPDmessages_chatsSlice::Is<decltype(data)>()) {
|
||||
result.more = data.vcount().v - data.vchats().v.size();
|
||||
if (channel->session().premiumPossible()) {
|
||||
result.more = data.vcount().v - data.vchats().v.size();
|
||||
}
|
||||
}
|
||||
});
|
||||
return result;
|
||||
|
|
|
@ -29,6 +29,18 @@ int PremiumLimits::channelsCurrent() const {
|
|||
: channelsDefault();
|
||||
}
|
||||
|
||||
int PremiumLimits::similarChannelsDefault() const {
|
||||
return appConfigLimit("recommended_channels_limit_default", 10);
|
||||
}
|
||||
int PremiumLimits::similarChannelsPremium() const {
|
||||
return appConfigLimit("recommended_channels_limit_premium", 100);
|
||||
}
|
||||
int PremiumLimits::similarChannelsCurrent() const {
|
||||
return isPremium()
|
||||
? channelsPremium()
|
||||
: channelsDefault();
|
||||
}
|
||||
|
||||
int PremiumLimits::gifsDefault() const {
|
||||
return appConfigLimit("saved_gifs_limit_default", 200);
|
||||
}
|
||||
|
|
|
@ -21,6 +21,10 @@ public:
|
|||
[[nodiscard]] int channelsPremium() const;
|
||||
[[nodiscard]] int channelsCurrent() const;
|
||||
|
||||
[[nodiscard]] int similarChannelsDefault() const;
|
||||
[[nodiscard]] int similarChannelsPremium() const;
|
||||
[[nodiscard]] int similarChannelsCurrent() const;
|
||||
|
||||
[[nodiscard]] int gifsDefault() const;
|
||||
[[nodiscard]] int gifsPremium() const;
|
||||
[[nodiscard]] int gifsCurrent() const;
|
||||
|
|
|
@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "boxes/peer_lists_box.h"
|
||||
#include "core/click_handler_types.h"
|
||||
#include "data/data_channel.h"
|
||||
#include "data/data_premium_limits.h"
|
||||
#include "data/data_session.h"
|
||||
#include "dialogs/ui/dialogs_stories_content.h"
|
||||
#include "dialogs/ui/dialogs_stories_list.h"
|
||||
|
@ -19,9 +20,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "history/view/history_view_cursor_state.h"
|
||||
#include "history/history.h"
|
||||
#include "history/history_item.h"
|
||||
#include "info/similar_channels/info_similar_channels_widget.h"
|
||||
#include "info/info_controller.h"
|
||||
#include "info/info_memento.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "main/main_account.h"
|
||||
#include "main/main_app_config.h"
|
||||
#include "main/main_session.h"
|
||||
#include "settings/settings_premium.h"
|
||||
#include "ui/chat/chat_style.h"
|
||||
|
@ -37,73 +39,19 @@ namespace {
|
|||
|
||||
using Channels = Api::ChatParticipants::Channels;
|
||||
|
||||
class SimilarChannelsController final : public PeerListController {
|
||||
public:
|
||||
SimilarChannelsController(
|
||||
not_null<Window::SessionController*> controller,
|
||||
Channels channels);
|
||||
|
||||
void prepare() override;
|
||||
void loadMoreRows() override;
|
||||
void rowClicked(not_null<PeerListRow*> row) override;
|
||||
Main::Session &session() const override;
|
||||
|
||||
private:
|
||||
const not_null<Window::SessionController*> _controller;
|
||||
const Channels _channels;
|
||||
|
||||
};
|
||||
|
||||
SimilarChannelsController::SimilarChannelsController(
|
||||
not_null<Window::SessionController*> controller,
|
||||
Channels channels)
|
||||
: _controller(controller)
|
||||
, _channels(std::move(channels)) {
|
||||
}
|
||||
|
||||
void SimilarChannelsController::prepare() {
|
||||
for (const auto &channel : _channels.list) {
|
||||
auto row = std::make_unique<PeerListRow>(channel);
|
||||
if (const auto count = channel->membersCount(); count > 1) {
|
||||
row->setCustomStatus(tr::lng_chat_status_subscribers(
|
||||
tr::now,
|
||||
lt_count,
|
||||
count));
|
||||
}
|
||||
delegate()->peerListAppendRow(std::move(row));
|
||||
}
|
||||
delegate()->peerListRefreshRows();
|
||||
}
|
||||
|
||||
void SimilarChannelsController::loadMoreRows() {
|
||||
}
|
||||
|
||||
void SimilarChannelsController::rowClicked(not_null<PeerListRow*> row) {
|
||||
const auto other = ClickHandlerContext{
|
||||
.sessionWindow = _controller,
|
||||
.show = _controller->uiShow(),
|
||||
};
|
||||
row->peer()->openLink()->onClick({
|
||||
Qt::LeftButton,
|
||||
QVariant::fromValue(other)
|
||||
});
|
||||
}
|
||||
|
||||
Main::Session &SimilarChannelsController::session() const {
|
||||
return _channels.list.front()->session();
|
||||
}
|
||||
|
||||
[[nodiscard]] object_ptr<Ui::BoxContent> SimilarChannelsBox(
|
||||
not_null<Window::SessionController*> controller,
|
||||
const Channels &channels) {
|
||||
const auto initBox = [=](not_null<PeerListBox*> box) {
|
||||
box->setTitle(tr::lng_similar_channels_title());
|
||||
box->addButton(tr::lng_close(), [=] { box->closeBox(); });
|
||||
};
|
||||
return Box<PeerListBox>(
|
||||
std::make_unique<SimilarChannelsController>(controller, channels),
|
||||
initBox);
|
||||
}
|
||||
//void SimilarChannelsController::prepare() {
|
||||
// for (const auto &channel : _channels.list) {
|
||||
// auto row = std::make_unique<PeerListRow>(channel);
|
||||
// if (const auto count = channel->membersCount(); count > 1) {
|
||||
// row->setCustomStatus(tr::lng_chat_status_subscribers(
|
||||
// tr::now,
|
||||
// lt_count,
|
||||
// count));
|
||||
// }
|
||||
// delegate()->peerListAppendRow(std::move(row));
|
||||
// }
|
||||
// delegate()->peerListRefreshRows();
|
||||
//}
|
||||
|
||||
[[nodiscard]] ClickHandlerPtr MakeViewAllLink(
|
||||
not_null<ChannelData*> channel,
|
||||
|
@ -113,10 +61,8 @@ Main::Session &SimilarChannelsController::session() const {
|
|||
if (const auto strong = my.sessionWindow.get()) {
|
||||
Assert(channel != nullptr);
|
||||
if (promoForNonPremium && !channel->session().premium()) {
|
||||
const auto account = &channel->session().account();
|
||||
const auto upto = account->appConfig().get<int>(
|
||||
u"recommended_channels_limit_premium"_q,
|
||||
100);
|
||||
const auto upto = Data::PremiumLimits(
|
||||
&channel->session()).similarChannelsPremium();
|
||||
Settings::ShowPremiumPromoToast(
|
||||
strong->uiShow(),
|
||||
tr::lng_similar_channels_premium_all(
|
||||
|
@ -137,7 +83,10 @@ Main::Session &SimilarChannelsController::session() const {
|
|||
if (list.list.empty()) {
|
||||
return;
|
||||
}
|
||||
strong->show(SimilarChannelsBox(strong, list));
|
||||
strong->showSection(
|
||||
std::make_shared<Info::Memento>(
|
||||
channel,
|
||||
Info::Section::Type::SimilarChannels));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -217,6 +166,7 @@ void SimilarChannels::draw(Painter &p, const PaintContext &context) const {
|
|||
const auto padding = st::chatSimilarChannelPadding;
|
||||
p.setClipRect(geometry);
|
||||
_hasHeavyPart = 1;
|
||||
validateLastPremiumLock();
|
||||
const auto drawOne = [&](const Channel &channel) {
|
||||
const auto geometry = channel.geometry.translated(-_scrollLeft, 0);
|
||||
const auto right = geometry.x() + geometry.width();
|
||||
|
@ -394,12 +344,68 @@ void SimilarChannels::draw(Painter &p, const PaintContext &context) const {
|
|||
p.setClipping(false);
|
||||
}
|
||||
|
||||
void SimilarChannels::validateLastPremiumLock() const {
|
||||
if (_channels.empty()) {
|
||||
return;
|
||||
}
|
||||
if (!_moreThumbnailsValid) {
|
||||
_moreThumbnailsValid = 1;
|
||||
fillMoreThumbnails();
|
||||
}
|
||||
const auto &last = _channels.back();
|
||||
if (!last.more) {
|
||||
return;
|
||||
}
|
||||
const auto premium = history()->session().premium();
|
||||
const auto locked = !premium && history()->session().premiumPossible();
|
||||
if (last.moreLocked == locked) {
|
||||
return;
|
||||
}
|
||||
last.moreLocked = locked ? 1 : 0;
|
||||
last.counterBgValid = 0;
|
||||
}
|
||||
|
||||
void SimilarChannels::fillMoreThumbnails() const {
|
||||
const auto channel = parent()->history()->peer->asChannel();
|
||||
Assert(channel != nullptr);
|
||||
|
||||
_moreThumbnails = {};
|
||||
const auto api = &channel->session().api();
|
||||
const auto &similar = api->chatParticipants().similar(channel);
|
||||
for (auto i = 0, count = int(_moreThumbnails.size()); i != count; ++i) {
|
||||
if (similar.list.size() <= _channels.size() + i) {
|
||||
break;
|
||||
}
|
||||
_moreThumbnails[i] = Dialogs::Stories::MakeUserpicThumbnail(
|
||||
similar.list[_channels.size() + i]);
|
||||
}
|
||||
}
|
||||
|
||||
void SimilarChannels::validateCounterBg(const Channel &channel) const {
|
||||
if (channel.counterBgValid) {
|
||||
return;
|
||||
}
|
||||
channel.counterBgValid = 1;
|
||||
|
||||
const auto photo = st::chatSimilarChannelPhoto;
|
||||
const auto inner = QRect(0, 0, photo, photo);
|
||||
const auto outer = inner.marginsAdded(st::chatSimilarChannelPadding);
|
||||
const auto length = st::chatSimilarBadgeFont->width(channel.counter);
|
||||
const auto contents = length
|
||||
+ (!channel.more
|
||||
? st::chatSimilarBadgeIcon.width()
|
||||
: channel.moreLocked
|
||||
? st::chatSimilarLockedIcon.width()
|
||||
: 0);
|
||||
const auto delta = (outer.width() - contents) / 2;
|
||||
const auto badge = QRect(
|
||||
delta,
|
||||
st::chatSimilarBadgeTop,
|
||||
outer.width() - 2 * delta,
|
||||
st::chatSimilarBadgeFont->height);
|
||||
channel.counterRect = badge.marginsAdded(
|
||||
st::chatSimilarBadgePadding);
|
||||
|
||||
const auto width = channel.counterRect.width();
|
||||
const auto height = channel.counterRect.height();
|
||||
const auto ratio = style::DevicePixelRatio();
|
||||
|
@ -517,8 +523,9 @@ QSize SimilarChannels::countOptimalSize() {
|
|||
const auto api = &channel->session().api();
|
||||
api->chatParticipants().loadSimilarChannels(channel);
|
||||
const auto premium = channel->session().premium();
|
||||
const auto similar = api->chatParticipants().similar(channel);
|
||||
const auto &similar = api->chatParticipants().similar(channel);
|
||||
_empty = similar.list.empty() ? 1 : 0;
|
||||
_moreThumbnailsValid = 0;
|
||||
using Flag = ChannelDataFlag;
|
||||
_toggled = (channel->flags() & Flag::SimilarExpanded) ? 1 : 0;
|
||||
if (_empty || !_toggled) {
|
||||
|
@ -532,9 +539,8 @@ QSize SimilarChannels::countOptimalSize() {
|
|||
const auto photo = st::chatSimilarChannelPhoto;
|
||||
const auto inner = QRect(0, 0, photo, photo);
|
||||
const auto outer = inner.marginsAdded(st::chatSimilarChannelPadding);
|
||||
const auto limit = channel->session().account().appConfig().get<int>(
|
||||
u"recommended_channels_limit_default"_q,
|
||||
10);
|
||||
const auto limit = Data::PremiumLimits(
|
||||
&channel->session()).similarChannelsDefault();
|
||||
const auto take = (similar.more > 0 || similar.list.size() > 2 * limit)
|
||||
? limit
|
||||
: int(similar.list.size());
|
||||
|
@ -565,34 +571,11 @@ QSize SimilarChannels::countOptimalSize() {
|
|||
? moreCounter :
|
||||
channel->membersCount();
|
||||
if (moreCounter || counter > 1) {
|
||||
const auto text = (moreCounter ? u"+"_q : QString())
|
||||
last.counter = (moreCounter ? u"+"_q : QString())
|
||||
+ Lang::FormatCountToShort(counter).string;
|
||||
const auto length = st::chatSimilarBadgeFont->width(text);
|
||||
const auto width = length
|
||||
+ (!moreCounter
|
||||
? st::chatSimilarBadgeIcon.width()
|
||||
: !premium
|
||||
? st::chatSimilarLockedIcon.width()
|
||||
: 0);
|
||||
const auto delta = (outer.width() - width) / 2;
|
||||
const auto badge = QRect(
|
||||
delta,
|
||||
st::chatSimilarBadgeTop,
|
||||
outer.width() - 2 * delta,
|
||||
st::chatSimilarBadgeFont->height);
|
||||
last.counter = text;
|
||||
last.counterRect = badge.marginsAdded(
|
||||
st::chatSimilarBadgePadding);
|
||||
}
|
||||
x += outer.width() + skip;
|
||||
}
|
||||
for (auto i = 0, count = int(_moreThumbnails.size()); i != count; ++i) {
|
||||
if (similar.list.size() <= _channels.size() + i) {
|
||||
break;
|
||||
}
|
||||
_moreThumbnails[i] = Dialogs::Stories::MakeUserpicThumbnail(
|
||||
similar.list[_channels.size() + i]);
|
||||
}
|
||||
_title = tr::lng_similar_channels_title(tr::now);
|
||||
_titleWidth = st::chatSimilarTitle->width(_title);
|
||||
_viewAll = tr::lng_similar_channels_view_all(tr::now);
|
||||
|
@ -604,7 +587,7 @@ QSize SimilarChannels::countOptimalSize() {
|
|||
const auto bubble = full.marginsAdded(st::chatSimilarPadding);
|
||||
_fullWidth = bubble.width();
|
||||
const auto titleSkip = st::chatSimilarTitlePosition.x();
|
||||
const auto min = _titleWidth + 2 * titleSkip;
|
||||
const auto min = int(_titleWidth) + 2 * titleSkip;
|
||||
const auto limited = std::max(
|
||||
std::min(int(_fullWidth), st::chatSimilarWidthMax),
|
||||
min);
|
||||
|
|
|
@ -65,16 +65,18 @@ private:
|
|||
std::shared_ptr<Thumbnail> thumbnail;
|
||||
ClickHandlerPtr link;
|
||||
QString counter;
|
||||
QRect counterRect;
|
||||
mutable QRect counterRect;
|
||||
mutable QImage counterBg;
|
||||
mutable std::unique_ptr<Ui::RippleAnimation> ripple;
|
||||
uint32 more : 29 = 0;
|
||||
uint32 moreLocked : 1 = 0;
|
||||
mutable uint32 moreLocked : 1 = 0;
|
||||
mutable uint32 subscribed : 1 = 0;
|
||||
mutable uint32 counterBgValid : 1 = 0;
|
||||
};
|
||||
|
||||
void ensureCacheReady(QSize size) const;
|
||||
void validateLastPremiumLock() const;
|
||||
void fillMoreThumbnails() const;
|
||||
void validateCounterBg(const Channel &channel) const;
|
||||
[[nodiscard]] ClickHandlerPtr ensureToggleLink() const;
|
||||
|
||||
|
@ -85,7 +87,8 @@ private:
|
|||
mutable QImage _roundedCache;
|
||||
mutable std::array<QImage, 4> _roundedCorners;
|
||||
mutable QPoint _lastPoint;
|
||||
int _titleWidth = 0;
|
||||
uint32 _titleWidth : 15 = 0;
|
||||
mutable uint32 _moreThumbnailsValid : 1 = 0;
|
||||
uint32 _viewAllWidth : 15 = 0;
|
||||
uint32 _fullWidth : 15 = 0;
|
||||
uint32 _empty : 1 = 0;
|
||||
|
@ -96,7 +99,7 @@ private:
|
|||
mutable uint32 _hasHeavyPart : 1 = 0;
|
||||
|
||||
std::vector<Channel> _channels;
|
||||
std::array<std::shared_ptr<Thumbnail>, 2> _moreThumbnails;
|
||||
mutable std::array<std::shared_ptr<Thumbnail>, 2> _moreThumbnails;
|
||||
mutable ClickHandlerPtr _viewAllLink;
|
||||
mutable ClickHandlerPtr _toggleLink;
|
||||
|
||||
|
|
|
@ -395,6 +395,7 @@ infoIconMediaFile: icon {{ "info/info_media_file", infoIconFg }};
|
|||
infoIconMediaAudio: icon {{ "info/info_media_audio", infoIconFg }};
|
||||
infoIconMediaLink: icon {{ "info/info_media_link", infoIconFg }};
|
||||
infoIconMediaGroup: icon {{ "info/info_common_groups", infoIconFg }};
|
||||
infoIconMediaChannel: icon {{ "menu/channel", infoIconFg, point(4px, 4px) }};
|
||||
infoIconMediaVoice: icon {{ "info/info_media_voice", infoIconFg }};
|
||||
infoIconMediaStories: icon {{ "info/info_media_stories", infoIconFg }};
|
||||
infoIconMediaStoriesArchive: icon {{ "info/info_stories_archive", infoIconFg }};
|
||||
|
@ -530,7 +531,7 @@ infoMediaLeft: 3px;
|
|||
infoMediaMargin: margins(0px, 6px, 0px, 2px);
|
||||
infoMediaMinGridSize: 90px;
|
||||
|
||||
infoCommonGroupsMargin: margins(0px, 13px, 0px, 2px);
|
||||
infoCommonGroupsMargin: margins(0px, 2px, 0px, 2px);
|
||||
infoCommonGroupsListItem: PeerListItem(defaultPeerListItem) {
|
||||
height: 52px;
|
||||
photoSize: 40px;
|
||||
|
@ -952,3 +953,14 @@ shortInfoCover: ShortInfoCover {
|
|||
}
|
||||
|
||||
permissionsExpandIcon: icon{{ "info/edit/expand_arrow_small", windowBoldFg }};
|
||||
|
||||
similarChannelsLockOverlap: 58px;
|
||||
similarChannelsLockFade: 58px;
|
||||
similarChannelsLock: defaultActiveButton;
|
||||
similarChannelsLockPadding: margins(12px, 12px, 12px, 12px);
|
||||
similarChannelsLockAbout: FlatLabel(defaultFlatLabel) {
|
||||
textFg: windowSubTextFg;
|
||||
align: align(top);
|
||||
minWidth: 128px;
|
||||
}
|
||||
similarChannelsLockAboutPadding: margins(12px, 12px, 12px, 12px);
|
||||
|
|
|
@ -125,6 +125,7 @@ public:
|
|||
Profile,
|
||||
Media,
|
||||
CommonGroups,
|
||||
SimilarChannels,
|
||||
Members,
|
||||
Settings,
|
||||
Downloads,
|
||||
|
|
|
@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "info/members/info_members_widget.h"
|
||||
#include "info/common_groups/info_common_groups_widget.h"
|
||||
#include "info/settings/info_settings_widget.h"
|
||||
#include "info/similar_channels/info_similar_channels_widget.h"
|
||||
#include "info/polls/info_polls_results_widget.h"
|
||||
#include "info/info_section_widget.h"
|
||||
#include "info/info_layer_widget.h"
|
||||
|
@ -141,6 +142,9 @@ std::shared_ptr<ContentMemento> Memento::DefaultContent(
|
|||
section.mediaType());
|
||||
case Section::Type::CommonGroups:
|
||||
return std::make_shared<CommonGroups::Memento>(peer->asUser());
|
||||
case Section::Type::SimilarChannels:
|
||||
return std::make_shared<SimilarChannels::Memento>(
|
||||
peer->asChannel());
|
||||
case Section::Type::Members:
|
||||
return std::make_shared<Members::Memento>(
|
||||
peer,
|
||||
|
|
|
@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/wrap/vertical_layout.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "window/window_session_controller.h"
|
||||
#include "data/data_channel.h"
|
||||
#include "data/data_user.h"
|
||||
#include "styles/style_info.h"
|
||||
|
||||
|
@ -120,7 +121,33 @@ inline auto AddCommonGroupsButton(
|
|||
tracker)->entity();
|
||||
result->addClickHandler([=] {
|
||||
navigation->showSection(
|
||||
std::make_shared<Info::Memento>(user, Section::Type::CommonGroups));
|
||||
std::make_shared<Info::Memento>(
|
||||
user,
|
||||
Section::Type::CommonGroups));
|
||||
});
|
||||
return result;
|
||||
};
|
||||
|
||||
inline auto AddSimilarChannelsButton(
|
||||
Ui::VerticalLayout *parent,
|
||||
not_null<Window::SessionNavigation*> navigation,
|
||||
not_null<ChannelData*> channel,
|
||||
Ui::MultiSlideTracker &tracker) {
|
||||
auto result = AddCountedButton(
|
||||
parent,
|
||||
Profile::SimilarChannelsCountValue(channel),
|
||||
[](int count) {
|
||||
return tr::lng_profile_similar_channels(
|
||||
tr::now,
|
||||
lt_count,
|
||||
count);
|
||||
},
|
||||
tracker)->entity();
|
||||
result->addClickHandler([=] {
|
||||
navigation->showSection(
|
||||
std::make_shared<Info::Memento>(
|
||||
channel,
|
||||
Section::Type::SimilarChannels));
|
||||
});
|
||||
return result;
|
||||
};
|
||||
|
|
|
@ -186,6 +186,19 @@ object_ptr<Ui::RpWidget> InnerWidget::setupSharedMedia(
|
|||
icon,
|
||||
st::infoSharedMediaButtonIconPosition);
|
||||
};
|
||||
const auto addSimilarChannelsButton = [&](
|
||||
not_null<ChannelData*> channel,
|
||||
const style::icon &icon) {
|
||||
auto result = Media::AddSimilarChannelsButton(
|
||||
content,
|
||||
_controller,
|
||||
channel,
|
||||
tracker);
|
||||
object_ptr<Profile::FloatingIcon>(
|
||||
result,
|
||||
icon,
|
||||
st::infoSharedMediaButtonIconPosition);
|
||||
};
|
||||
auto addStoriesButton = [&](
|
||||
not_null<PeerData*> peer,
|
||||
const style::icon &icon) {
|
||||
|
@ -211,8 +224,10 @@ object_ptr<Ui::RpWidget> InnerWidget::setupSharedMedia(
|
|||
addMediaButton(MediaType::Link, st::infoIconMediaLink);
|
||||
addMediaButton(MediaType::RoundVoiceFile, st::infoIconMediaVoice);
|
||||
addMediaButton(MediaType::GIF, st::infoIconMediaGif);
|
||||
if (auto user = _peer->asUser()) {
|
||||
if (const auto user = _peer->asUser()) {
|
||||
addCommonGroupsButton(user, st::infoIconMediaGroup);
|
||||
} else if (const auto channel = _peer->asChannel()) {
|
||||
addSimilarChannelsButton(channel, st::infoIconMediaChannel);
|
||||
}
|
||||
|
||||
auto result = object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
||||
|
|
|
@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
*/
|
||||
#include "info/profile/info_profile_values.h"
|
||||
|
||||
#include "api/api_chat_participants.h"
|
||||
#include "apiwrap.h"
|
||||
#include "info/profile/info_profile_badge.h"
|
||||
#include "core/application.h"
|
||||
#include "core/click_handler_types.h"
|
||||
|
@ -520,6 +522,20 @@ rpl::producer<int> CommonGroupsCountValue(not_null<UserData*> user) {
|
|||
});
|
||||
}
|
||||
|
||||
rpl::producer<int> SimilarChannelsCountValue(
|
||||
not_null<ChannelData*> channel) {
|
||||
const auto participants = &channel->session().api().chatParticipants();
|
||||
participants->loadSimilarChannels(channel);
|
||||
return rpl::single(channel) | rpl::then(
|
||||
participants->similarLoaded()
|
||||
) | rpl::filter(
|
||||
rpl::mappers::_1 == channel
|
||||
) | rpl::map([=] {
|
||||
const auto &similar = participants->similar(channel);
|
||||
return int(similar.list.size()) + similar.more;
|
||||
});
|
||||
}
|
||||
|
||||
rpl::producer<bool> CanAddMemberValue(not_null<PeerData*> peer) {
|
||||
if (const auto chat = peer->asChat()) {
|
||||
return peer->session().changes().peerFlagsValue(
|
||||
|
|
|
@ -102,6 +102,8 @@ rpl::producer<not_null<PeerData*>> MigratedOrMeValue(
|
|||
Storage::SharedMediaType type);
|
||||
[[nodiscard]] rpl::producer<int> CommonGroupsCountValue(
|
||||
not_null<UserData*> user);
|
||||
[[nodiscard]] rpl::producer<int> SimilarChannelsCountValue(
|
||||
not_null<ChannelData*> channel);
|
||||
[[nodiscard]] rpl::producer<bool> CanAddMemberValue(
|
||||
not_null<PeerData*> peer);
|
||||
[[nodiscard]] rpl::producer<int> FullReactionsCountValue(
|
||||
|
|
|
@ -0,0 +1,515 @@
|
|||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "info/similar_channels/info_similar_channels_widget.h"
|
||||
|
||||
#include "api/api_chat_participants.h"
|
||||
#include "apiwrap.h"
|
||||
#include "boxes/peer_list_box.h"
|
||||
#include "data/data_channel.h"
|
||||
#include "data/data_peer_values.h"
|
||||
#include "data/data_premium_limits.h"
|
||||
#include "data/data_session.h"
|
||||
#include "info/info_controller.h"
|
||||
#include "main/main_session.h"
|
||||
#include "ui/text/text_utilities.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/widgets/scroll_area.h"
|
||||
#include "ui/widgets/tooltip.h"
|
||||
#include "ui/ui_utility.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "settings/settings_premium.h"
|
||||
#include "window/window_session_controller.h"
|
||||
#include "styles/style_info.h"
|
||||
#include "styles/style_widgets.h"
|
||||
|
||||
namespace Info::SimilarChannels {
|
||||
namespace {
|
||||
|
||||
class ListController final : public PeerListController {
|
||||
public:
|
||||
ListController(
|
||||
not_null<Controller*> controller,
|
||||
not_null<ChannelData*> channel);
|
||||
|
||||
Main::Session &session() const override;
|
||||
void prepare() override;
|
||||
void rowClicked(not_null<PeerListRow*> row) override;
|
||||
void loadMoreRows() override;
|
||||
|
||||
std::unique_ptr<PeerListRow> createRestoredRow(
|
||||
not_null<PeerData*> peer) override {
|
||||
return createRow(peer);
|
||||
}
|
||||
|
||||
std::unique_ptr<PeerListState> saveState() const override;
|
||||
void restoreState(std::unique_ptr<PeerListState> state) override;
|
||||
|
||||
void setContentWidget(not_null<Ui::RpWidget*> widget);
|
||||
[[nodiscard]] rpl::producer<int> unlockHeightValue() const;
|
||||
|
||||
private:
|
||||
std::unique_ptr<PeerListRow> createRow(not_null<PeerData*> peer);
|
||||
void setupUnlock();
|
||||
void rebuild();
|
||||
|
||||
struct SavedState : SavedStateBase {
|
||||
};
|
||||
const not_null<Controller*> _controller;
|
||||
const not_null<ChannelData*> _channel;
|
||||
Ui::RpWidget *_content = nullptr;
|
||||
Ui::RpWidget *_unlock = nullptr;
|
||||
rpl::variable<int> _unlockHeight;
|
||||
|
||||
};
|
||||
|
||||
ListController::ListController(
|
||||
not_null<Controller*> controller,
|
||||
not_null<ChannelData*> channel)
|
||||
: PeerListController()
|
||||
, _controller(controller)
|
||||
, _channel(channel) {
|
||||
}
|
||||
|
||||
Main::Session &ListController::session() const {
|
||||
return _channel->session();
|
||||
}
|
||||
|
||||
std::unique_ptr<PeerListRow> ListController::createRow(
|
||||
not_null<PeerData*> peer) {
|
||||
auto result = std::make_unique<PeerListRow>(peer);
|
||||
if (const auto channel = peer->asChannel()) {
|
||||
if (const auto count = channel->membersCount(); count > 1) {
|
||||
result->setCustomStatus(
|
||||
tr::lng_chat_status_subscribers(tr::now, lt_count, count));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void ListController::prepare() {
|
||||
delegate()->peerListSetTitle(tr::lng_similar_channels_title());
|
||||
|
||||
const auto participants = &_channel->session().api().chatParticipants();
|
||||
|
||||
Data::AmPremiumValue(
|
||||
&_channel->session()
|
||||
) | rpl::start_with_next([=] {
|
||||
participants->loadSimilarChannels(_channel);
|
||||
rebuild();
|
||||
}, lifetime());
|
||||
|
||||
participants->similarLoaded(
|
||||
) | rpl::filter(
|
||||
rpl::mappers::_1 == _channel
|
||||
) | rpl::start_with_next([=] {
|
||||
rebuild();
|
||||
}, lifetime());
|
||||
}
|
||||
|
||||
void ListController::setContentWidget(not_null<Ui::RpWidget*> widget) {
|
||||
_content = widget;
|
||||
}
|
||||
|
||||
rpl::producer<int> ListController::unlockHeightValue() const {
|
||||
return _unlockHeight.value();
|
||||
}
|
||||
|
||||
void ListController::rebuild() {
|
||||
const auto participants = &_channel->session().api().chatParticipants();
|
||||
const auto &list = participants->similar(_channel);
|
||||
for (const auto channel : list.list) {
|
||||
if (!delegate()->peerListFindRow(channel->id.value)) {
|
||||
delegate()->peerListAppendRow(createRow(channel));
|
||||
}
|
||||
}
|
||||
if (!list.more
|
||||
|| _channel->session().premium()
|
||||
|| !_channel->session().premiumPossible()) {
|
||||
delete base::take(_unlock);
|
||||
_unlockHeight = 0;
|
||||
} else if (!_unlock) {
|
||||
setupUnlock();
|
||||
}
|
||||
delegate()->peerListRefreshRows();
|
||||
}
|
||||
|
||||
void ListController::setupUnlock() {
|
||||
Expects(_content != nullptr);
|
||||
|
||||
_unlock = Ui::CreateChild<Ui::RpWidget>(_content);
|
||||
_unlock->show();
|
||||
|
||||
const auto button = Ui::CreateChild<Ui::RoundButton>(
|
||||
_unlock,
|
||||
tr::lng_similar_channels_show_more(),
|
||||
st::similarChannelsLock);
|
||||
button->setTextTransform(Ui::RoundButton::TextTransform::NoTransform);
|
||||
button->setClickedCallback([=] {
|
||||
const auto window = _controller->parentController();
|
||||
::Settings::ShowPremium(window, u"similar_channels"_q);
|
||||
});
|
||||
const auto upto = Data::PremiumLimits(
|
||||
&_channel->session()).similarChannelsPremium();
|
||||
const auto about = Ui::CreateChild<Ui::FlatLabel>(
|
||||
_unlock,
|
||||
tr::lng_similar_channels_premium_all(
|
||||
lt_count,
|
||||
rpl::single(upto * 1.),
|
||||
lt_link,
|
||||
tr::lng_similar_channels_premium_all_link(
|
||||
) | Ui::Text::ToBold() | Ui::Text::ToLink(),
|
||||
Ui::Text::RichLangValue),
|
||||
st::similarChannelsLockAbout);
|
||||
about->setClickHandlerFilter([=](const auto &...) {
|
||||
const auto window = _controller->parentController();
|
||||
::Settings::ShowPremium(window, u"similar_channels"_q);
|
||||
return false;
|
||||
});
|
||||
|
||||
rpl::combine(
|
||||
_content->sizeValue(),
|
||||
tr::lng_similar_channels_show_more()
|
||||
) | rpl::start_with_next([=](QSize size, const auto &) {
|
||||
auto top = st::similarChannelsLockFade
|
||||
+ st::similarChannelsLockPadding.top();
|
||||
button->setGeometry(
|
||||
st::similarChannelsLockPadding.left(),
|
||||
top,
|
||||
(size.width()
|
||||
- st::similarChannelsLockPadding.left()
|
||||
- st::similarChannelsLockPadding.right()),
|
||||
button->height());
|
||||
top += button->height() + st::similarChannelsLockPadding.bottom();
|
||||
|
||||
const auto minWidth = st::similarChannelsLockAbout.minWidth;
|
||||
const auto maxWidth = std::max(
|
||||
minWidth + 1,
|
||||
(size.width()
|
||||
- st::similarChannelsLockAboutPadding.left()
|
||||
- st::similarChannelsLockAboutPadding.right()));
|
||||
const auto countAboutHeight = [&](int width) {
|
||||
about->resizeToWidth(width);
|
||||
return about->height();
|
||||
};
|
||||
const auto desired = Ui::FindNiceTooltipWidth(
|
||||
minWidth,
|
||||
maxWidth,
|
||||
countAboutHeight);
|
||||
about->resizeToWidth(desired);
|
||||
about->move((size.width() - about->width()) / 2, top);
|
||||
top += about->height()
|
||||
+ st::similarChannelsLockAboutPadding.bottom();
|
||||
_unlock->setGeometry(0, size.height() - top, size.width(), top);
|
||||
}, _unlock->lifetime());
|
||||
|
||||
_unlockHeight = _unlock->heightValue();
|
||||
|
||||
_unlock->paintRequest(
|
||||
) | rpl::start_with_next([=] {
|
||||
auto p = QPainter(_unlock);
|
||||
const auto width = _unlock->width();
|
||||
const auto fade = st::similarChannelsLockFade;
|
||||
auto gradient = QLinearGradient(0, 0, 0, fade);
|
||||
gradient.setStops({
|
||||
{ 0., QColor(255, 255, 255, 0) },
|
||||
{ 1., st::windowBg->c },
|
||||
});
|
||||
p.fillRect(0, 0, width, fade, gradient);
|
||||
p.fillRect(0, fade, width, _unlock->height() - fade, st::windowBg);
|
||||
}, _unlock->lifetime());
|
||||
}
|
||||
|
||||
void ListController::loadMoreRows() {
|
||||
}
|
||||
|
||||
std::unique_ptr<PeerListState> ListController::saveState() const {
|
||||
auto result = PeerListController::saveState();
|
||||
auto my = std::make_unique<SavedState>();
|
||||
result->controllerState = std::move(my);
|
||||
return result;
|
||||
}
|
||||
|
||||
void ListController::restoreState(
|
||||
std::unique_ptr<PeerListState> state) {
|
||||
auto typeErasedState = state
|
||||
? state->controllerState.get()
|
||||
: nullptr;
|
||||
if (auto my = dynamic_cast<SavedState*>(typeErasedState)) {
|
||||
PeerListController::restoreState(std::move(state));
|
||||
}
|
||||
}
|
||||
|
||||
void ListController::rowClicked(not_null<PeerListRow*> row) {
|
||||
_controller->parentController()->showPeerHistory(
|
||||
row->peer(),
|
||||
Window::SectionShow::Way::Forward);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
class InnerWidget final
|
||||
: public Ui::RpWidget
|
||||
, private PeerListContentDelegate {
|
||||
public:
|
||||
InnerWidget(
|
||||
QWidget *parent,
|
||||
not_null<Controller*> controller,
|
||||
not_null<ChannelData*> channel);
|
||||
|
||||
[[nodiscard]] not_null<ChannelData*> channel() const {
|
||||
return _channel;
|
||||
}
|
||||
|
||||
rpl::producer<Ui::ScrollToRequest> scrollToRequests() const;
|
||||
|
||||
int desiredHeight() const;
|
||||
|
||||
void saveState(not_null<Memento*> memento);
|
||||
void restoreState(not_null<Memento*> memento);
|
||||
|
||||
protected:
|
||||
void visibleTopBottomUpdated(
|
||||
int visibleTop,
|
||||
int visibleBottom) override;
|
||||
|
||||
private:
|
||||
using ListWidget = PeerListContent;
|
||||
|
||||
// PeerListContentDelegate interface.
|
||||
void peerListSetTitle(rpl::producer<QString> title) override;
|
||||
void peerListSetAdditionalTitle(rpl::producer<QString> title) override;
|
||||
bool peerListIsRowChecked(not_null<PeerListRow*> row) override;
|
||||
int peerListSelectedRowsCount() override;
|
||||
void peerListScrollToTop() override;
|
||||
void peerListAddSelectedPeerInBunch(
|
||||
not_null<PeerData*> peer) override;
|
||||
void peerListAddSelectedRowInBunch(
|
||||
not_null<PeerListRow*> row) override;
|
||||
void peerListFinishSelectedRowsBunch() override;
|
||||
void peerListSetDescription(
|
||||
object_ptr<Ui::FlatLabel> description) override;
|
||||
std::shared_ptr<Main::SessionShow> peerListUiShow() override;
|
||||
|
||||
object_ptr<ListWidget> setupList(
|
||||
RpWidget *parent,
|
||||
not_null<ListController*> controller);
|
||||
|
||||
const std::shared_ptr<Main::SessionShow> _show;
|
||||
not_null<Controller*> _controller;
|
||||
const not_null<ChannelData*> _channel;
|
||||
std::unique_ptr<ListController> _listController;
|
||||
object_ptr<ListWidget> _list;
|
||||
|
||||
rpl::event_stream<Ui::ScrollToRequest> _scrollToRequests;
|
||||
|
||||
};
|
||||
|
||||
InnerWidget::InnerWidget(
|
||||
QWidget *parent,
|
||||
not_null<Controller*> controller,
|
||||
not_null<ChannelData*> channel)
|
||||
: RpWidget(parent)
|
||||
, _show(controller->uiShow())
|
||||
, _controller(controller)
|
||||
, _channel(channel)
|
||||
, _listController(std::make_unique<ListController>(controller, _channel))
|
||||
, _list(setupList(this, _listController.get())) {
|
||||
setContent(_list.data());
|
||||
_listController->setDelegate(static_cast<PeerListDelegate*>(this));
|
||||
}
|
||||
|
||||
void InnerWidget::visibleTopBottomUpdated(
|
||||
int visibleTop,
|
||||
int visibleBottom) {
|
||||
setChildVisibleTopBottom(_list, visibleTop, visibleBottom);
|
||||
}
|
||||
|
||||
void InnerWidget::saveState(not_null<Memento*> memento) {
|
||||
memento->setListState(_listController->saveState());
|
||||
}
|
||||
|
||||
void InnerWidget::restoreState(not_null<Memento*> memento) {
|
||||
_listController->restoreState(memento->listState());
|
||||
}
|
||||
|
||||
rpl::producer<Ui::ScrollToRequest> InnerWidget::scrollToRequests() const {
|
||||
return _scrollToRequests.events();
|
||||
}
|
||||
|
||||
int InnerWidget::desiredHeight() const {
|
||||
auto desired = 0;
|
||||
desired += _list->fullRowsCount() * st::infoMembersList.item.height;
|
||||
return qMax(height(), desired);
|
||||
}
|
||||
|
||||
object_ptr<InnerWidget::ListWidget> InnerWidget::setupList(
|
||||
RpWidget *parent,
|
||||
not_null<ListController*> controller) {
|
||||
controller->setStyleOverrides(&st::infoMembersList);
|
||||
auto result = object_ptr<ListWidget>(
|
||||
parent,
|
||||
controller);
|
||||
controller->setContentWidget(this);
|
||||
result->scrollToRequests(
|
||||
) | rpl::start_with_next([this](Ui::ScrollToRequest request) {
|
||||
auto addmin = (request.ymin < 0)
|
||||
? 0
|
||||
: st::infoCommonGroupsMargin.top();
|
||||
auto addmax = (request.ymax < 0)
|
||||
? 0
|
||||
: st::infoCommonGroupsMargin.top();
|
||||
_scrollToRequests.fire({
|
||||
request.ymin + addmin,
|
||||
request.ymax + addmax });
|
||||
}, result->lifetime());
|
||||
result->moveToLeft(0, st::infoCommonGroupsMargin.top());
|
||||
parent->widthValue(
|
||||
) | rpl::start_with_next([list = result.data()](int newWidth) {
|
||||
list->resizeToWidth(newWidth);
|
||||
}, result->lifetime());
|
||||
rpl::combine(
|
||||
result->heightValue(),
|
||||
controller->unlockHeightValue()
|
||||
) | rpl::start_with_next([=](int listHeight, int unlockHeight) {
|
||||
auto newHeight = st::infoCommonGroupsMargin.top()
|
||||
+ listHeight
|
||||
+ (unlockHeight
|
||||
? (unlockHeight - st::similarChannelsLockOverlap)
|
||||
: st::infoCommonGroupsMargin.bottom());
|
||||
parent->resize(parent->width(), std::max(newHeight, 0));
|
||||
}, result->lifetime());
|
||||
return result;
|
||||
}
|
||||
|
||||
void InnerWidget::peerListSetTitle(rpl::producer<QString> title) {
|
||||
}
|
||||
|
||||
void InnerWidget::peerListSetAdditionalTitle(rpl::producer<QString> title) {
|
||||
}
|
||||
|
||||
bool InnerWidget::peerListIsRowChecked(not_null<PeerListRow*> row) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int InnerWidget::peerListSelectedRowsCount() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void InnerWidget::peerListScrollToTop() {
|
||||
_scrollToRequests.fire({ -1, -1 });
|
||||
}
|
||||
|
||||
void InnerWidget::peerListAddSelectedPeerInBunch(not_null<PeerData*> peer) {
|
||||
Unexpected("Item selection in Info::Profile::Members.");
|
||||
}
|
||||
|
||||
void InnerWidget::peerListAddSelectedRowInBunch(not_null<PeerListRow*> row) {
|
||||
Unexpected("Item selection in Info::Profile::Members.");
|
||||
}
|
||||
|
||||
void InnerWidget::peerListFinishSelectedRowsBunch() {
|
||||
}
|
||||
|
||||
void InnerWidget::peerListSetDescription(
|
||||
object_ptr<Ui::FlatLabel> description) {
|
||||
description.destroy();
|
||||
}
|
||||
|
||||
std::shared_ptr<Main::SessionShow> InnerWidget::peerListUiShow() {
|
||||
return _show;
|
||||
}
|
||||
|
||||
Memento::Memento(not_null<ChannelData*> channel)
|
||||
: ContentMemento(channel, nullptr, PeerId()) {
|
||||
}
|
||||
|
||||
Section Memento::section() const {
|
||||
return Section(Section::Type::SimilarChannels);
|
||||
}
|
||||
|
||||
not_null<ChannelData*> Memento::channel() const {
|
||||
return peer()->asChannel();
|
||||
}
|
||||
|
||||
object_ptr<ContentWidget> Memento::createWidget(
|
||||
QWidget *parent,
|
||||
not_null<Controller*> controller,
|
||||
const QRect &geometry) {
|
||||
auto result = object_ptr<Widget>(parent, controller, channel());
|
||||
result->setInternalState(geometry, this);
|
||||
return result;
|
||||
}
|
||||
|
||||
void Memento::setListState(std::unique_ptr<PeerListState> state) {
|
||||
_listState = std::move(state);
|
||||
}
|
||||
|
||||
std::unique_ptr<PeerListState> Memento::listState() {
|
||||
return std::move(_listState);
|
||||
}
|
||||
|
||||
Memento::~Memento() = default;
|
||||
|
||||
Widget::Widget(
|
||||
QWidget *parent,
|
||||
not_null<Controller*> controller,
|
||||
not_null<ChannelData*> channel)
|
||||
: ContentWidget(parent, controller) {
|
||||
_inner = setInnerWidget(object_ptr<InnerWidget>(
|
||||
this,
|
||||
controller,
|
||||
channel));
|
||||
}
|
||||
|
||||
rpl::producer<QString> Widget::title() {
|
||||
return tr::lng_similar_channels_title();
|
||||
}
|
||||
|
||||
not_null<ChannelData*> Widget::channel() const {
|
||||
return _inner->channel();
|
||||
}
|
||||
|
||||
bool Widget::showInternal(not_null<ContentMemento*> memento) {
|
||||
if (!controller()->validateMementoPeer(memento)) {
|
||||
return false;
|
||||
}
|
||||
if (auto similarMemento = dynamic_cast<Memento*>(memento.get())) {
|
||||
if (similarMemento->channel() == channel()) {
|
||||
restoreState(similarMemento);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Widget::setInternalState(
|
||||
const QRect &geometry,
|
||||
not_null<Memento*> memento) {
|
||||
setGeometry(geometry);
|
||||
Ui::SendPendingMoveResizeEvents(this);
|
||||
restoreState(memento);
|
||||
}
|
||||
|
||||
std::shared_ptr<ContentMemento> Widget::doCreateMemento() {
|
||||
auto result = std::make_shared<Memento>(channel());
|
||||
saveState(result.get());
|
||||
return result;
|
||||
}
|
||||
|
||||
void Widget::saveState(not_null<Memento*> memento) {
|
||||
memento->setScrollTop(scrollTopSave());
|
||||
_inner->saveState(memento);
|
||||
}
|
||||
|
||||
void Widget::restoreState(not_null<Memento*> memento) {
|
||||
_inner->restoreState(memento);
|
||||
scrollTopRestore(memento->scrollTop());
|
||||
}
|
||||
|
||||
} // namespace Info::SimilarChannels
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "info/info_content_widget.h"
|
||||
|
||||
class ChannelData;
|
||||
struct PeerListState;
|
||||
|
||||
namespace Info::SimilarChannels {
|
||||
|
||||
class InnerWidget;
|
||||
|
||||
class Memento final : public ContentMemento {
|
||||
public:
|
||||
explicit Memento(not_null<ChannelData*> channel);
|
||||
|
||||
object_ptr<ContentWidget> createWidget(
|
||||
QWidget *parent,
|
||||
not_null<Controller*> controller,
|
||||
const QRect &geometry) override;
|
||||
|
||||
Section section() const override;
|
||||
|
||||
[[nodiscard]] not_null<ChannelData*> channel() const;
|
||||
|
||||
void setListState(std::unique_ptr<PeerListState> state);
|
||||
std::unique_ptr<PeerListState> listState();
|
||||
|
||||
~Memento();
|
||||
|
||||
private:
|
||||
std::unique_ptr<PeerListState> _listState;
|
||||
|
||||
};
|
||||
|
||||
class Widget final : public ContentWidget {
|
||||
public:
|
||||
Widget(
|
||||
QWidget *parent,
|
||||
not_null<Controller*> controller,
|
||||
not_null<ChannelData*> channel);
|
||||
|
||||
[[nodiscard]] not_null<ChannelData*> channel() const;
|
||||
|
||||
bool showInternal(
|
||||
not_null<ContentMemento*> memento) override;
|
||||
|
||||
void setInternalState(
|
||||
const QRect &geometry,
|
||||
not_null<Memento*> memento);
|
||||
|
||||
rpl::producer<QString> title() override;
|
||||
|
||||
private:
|
||||
void saveState(not_null<Memento*> memento);
|
||||
void restoreState(not_null<Memento*> memento);
|
||||
|
||||
std::shared_ptr<ContentMemento> doCreateMemento() override;
|
||||
|
||||
InnerWidget *_inner = nullptr;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Info::SimilarChannels
|
||||
|
|
@ -160,6 +160,7 @@ struct SectionShow {
|
|||
anim::activation activation = anim::activation::normal;
|
||||
bool thirdColumn = false;
|
||||
bool childColumn = false;
|
||||
bool forbidLayer = false;
|
||||
bool reapplyLocalDraft = false;
|
||||
Origin origin;
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 66ca90c1b2c111fe8ae45453c7bf180af2593d8d
|
||||
Subproject commit 44161f183c255dc0dac7ebe9558a1ca48f5e5258
|
Loading…
Add table
Reference in a new issue