From fa02e521f96aec5027263b51fd2bd9b0932020e8 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sun, 24 Mar 2024 06:56:50 +0300 Subject: [PATCH] Added ability to view all of user's own channels. --- .../SourceFiles/window/window_main_menu.cpp | 112 +++++++++++++++++- 1 file changed, 109 insertions(+), 3 deletions(-) diff --git a/Telegram/SourceFiles/window/window_main_menu.cpp b/Telegram/SourceFiles/window/window_main_menu.cpp index e4f941d9e..f15aeb484 100644 --- a/Telegram/SourceFiles/window/window_main_menu.cpp +++ b/Telegram/SourceFiles/window/window_main_menu.cpp @@ -57,6 +57,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_session.h" #include "data/data_user.h" #include "data/data_changes.h" +#include "data/data_channel.h" #include "data/data_stories.h" #include "mainwidget.h" #include "styles/style_chat.h" // popupMenuExpandedSeparator @@ -108,6 +109,109 @@ public: }; +not_null AddMyChannelsBox( + not_null button, + not_null controller) { + button->setAcceptBoth(true); + + const auto myChannelsBox = [=](not_null box) { + box->setTitle(tr::lng_notification_channels()); + + const auto st = box->lifetime().make_state( + st::defaultUserpicButton); + st->photoSize = st::defaultPeerListItem.photoSize; + st->size = QSize(st->photoSize, st->photoSize); + + class Button final : public Ui::SettingsButton { + public: + using Ui::SettingsButton::SettingsButton; + + void setPeer(not_null c) { + _text.setText(st::defaultPeerListItem.nameStyle, c->name()); + _status.setText( + st::defaultTextStyle, + !c->username().isEmpty() + ? ('@' + c->username()) + : tr::lng_chat_status_subscribers( + tr::now, + lt_count, + c->membersCount())); + } + + int resizeGetHeight(int) override { + return st::defaultPeerListItem.height; + } + + void paintEvent(QPaintEvent *e) override { + Ui::SettingsButton::paintEvent(e); + auto p = Painter(this); + const auto &st = st::defaultPeerListItem; + const auto availableWidth = width() + - st::boxRowPadding.right() + - st.namePosition.x(); + p.setPen(st.nameFg); + auto context = Ui::Text::PaintContext{ + .position = st.namePosition, + .outerWidth = availableWidth, + .availableWidth = availableWidth, + .elisionLines = 1, + }; + _text.draw(p, context); + p.setPen(st.statusFg); + context.position = st.statusPosition; + _status.draw(p, context); + } + + private: + Ui::Text::String _text; + Ui::Text::String _status; + + }; + + controller->session().data().enumerateBroadcasts([&]( + not_null channel) { + if (!channel->amCreator()) { + return; + } + + const auto row = box->addRow( + object_ptr