mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added ability to view all of user's own channels.
This commit is contained in:
parent
d03d50ef0d
commit
fa02e521f9
1 changed files with 109 additions and 3 deletions
|
@ -57,6 +57,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
#include "data/data_user.h"
|
#include "data/data_user.h"
|
||||||
#include "data/data_changes.h"
|
#include "data/data_changes.h"
|
||||||
|
#include "data/data_channel.h"
|
||||||
#include "data/data_stories.h"
|
#include "data/data_stories.h"
|
||||||
#include "mainwidget.h"
|
#include "mainwidget.h"
|
||||||
#include "styles/style_chat.h" // popupMenuExpandedSeparator
|
#include "styles/style_chat.h" // popupMenuExpandedSeparator
|
||||||
|
@ -108,6 +109,109 @@ public:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
not_null<Ui::SettingsButton*> AddMyChannelsBox(
|
||||||
|
not_null<Ui::SettingsButton*> button,
|
||||||
|
not_null<SessionController*> controller) {
|
||||||
|
button->setAcceptBoth(true);
|
||||||
|
|
||||||
|
const auto myChannelsBox = [=](not_null<Ui::GenericBox*> box) {
|
||||||
|
box->setTitle(tr::lng_notification_channels());
|
||||||
|
|
||||||
|
const auto st = box->lifetime().make_state<style::UserpicButton>(
|
||||||
|
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<ChannelData*> 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<ChannelData*> channel) {
|
||||||
|
if (!channel->amCreator()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto row = box->addRow(
|
||||||
|
object_ptr<Button>(box, rpl::single(QString())),
|
||||||
|
{});
|
||||||
|
row->setPeer(channel);
|
||||||
|
row->setClickedCallback([=] {
|
||||||
|
controller->showPeerHistory(channel);
|
||||||
|
});
|
||||||
|
const auto userpic = Ui::CreateChild<Ui::UserpicButton>(
|
||||||
|
row,
|
||||||
|
channel,
|
||||||
|
*st);
|
||||||
|
userpic->move(st::defaultPeerListItem.photoPosition);
|
||||||
|
userpic->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
using Menu = base::unique_qptr<Ui::PopupMenu>;
|
||||||
|
const auto menu = button->lifetime().make_state<Menu>();
|
||||||
|
button->addClickHandler([=](Qt::MouseButton which) {
|
||||||
|
if ((which != Qt::RightButton)
|
||||||
|
|| !((button->clickModifiers() & Qt::ShiftModifier)
|
||||||
|
&& (button->clickModifiers() & Qt::AltModifier))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
(*menu) = base::make_unique_q<Ui::PopupMenu>(
|
||||||
|
button,
|
||||||
|
st::defaultPopupMenu);
|
||||||
|
(*menu)->addAction(
|
||||||
|
u"My Channels"_q,
|
||||||
|
[=] { controller->uiShow()->showBox(Box(myChannelsBox)); },
|
||||||
|
nullptr);
|
||||||
|
(*menu)->popup(QCursor::pos());
|
||||||
|
});
|
||||||
|
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] bool CanCheckSpecialEvent() {
|
[[nodiscard]] bool CanCheckSpecialEvent() {
|
||||||
static const auto result = [] {
|
static const auto result = [] {
|
||||||
const auto now = QDate::currentDate();
|
const auto now = QDate::currentDate();
|
||||||
|
@ -859,11 +963,13 @@ void MainMenu::setupMenu() {
|
||||||
)->setClickedCallback([=] {
|
)->setClickedCallback([=] {
|
||||||
controller->showNewGroup();
|
controller->showNewGroup();
|
||||||
});
|
});
|
||||||
addAction(
|
AddMyChannelsBox(addAction(
|
||||||
tr::lng_create_channel_title(),
|
tr::lng_create_channel_title(),
|
||||||
{ &st::menuIconChannel }
|
{ &st::menuIconChannel }
|
||||||
)->setClickedCallback([=] {
|
), controller)->addClickHandler([=](Qt::MouseButton which) {
|
||||||
controller->showNewChannel();
|
if (which == Qt::LeftButton) {
|
||||||
|
controller->showNewChannel();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const auto wrap = _menu->add(
|
const auto wrap = _menu->add(
|
||||||
|
|
Loading…
Add table
Reference in a new issue