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 groups.
This commit is contained in:
parent
8492b7144f
commit
bb438880e3
1 changed files with 46 additions and 28 deletions
|
@ -52,6 +52,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "main/main_account.h"
|
#include "main/main_account.h"
|
||||||
#include "main/main_domain.h"
|
#include "main/main_domain.h"
|
||||||
#include "mtproto/mtproto_config.h"
|
#include "mtproto/mtproto_config.h"
|
||||||
|
#include "data/data_chat.h"
|
||||||
#include "data/data_document_media.h"
|
#include "data/data_document_media.h"
|
||||||
#include "data/data_folder.h"
|
#include "data/data_folder.h"
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
|
@ -111,7 +112,8 @@ public:
|
||||||
|
|
||||||
not_null<Ui::SettingsButton*> AddMyChannelsBox(
|
not_null<Ui::SettingsButton*> AddMyChannelsBox(
|
||||||
not_null<Ui::SettingsButton*> button,
|
not_null<Ui::SettingsButton*> button,
|
||||||
not_null<SessionController*> controller) {
|
not_null<SessionController*> controller,
|
||||||
|
bool chats) {
|
||||||
button->setAcceptBoth(true);
|
button->setAcceptBoth(true);
|
||||||
|
|
||||||
const auto myChannelsBox = [=](not_null<Ui::GenericBox*> box) {
|
const auto myChannelsBox = [=](not_null<Ui::GenericBox*> box) {
|
||||||
|
@ -126,16 +128,21 @@ not_null<Ui::SettingsButton*> AddMyChannelsBox(
|
||||||
public:
|
public:
|
||||||
using Ui::SettingsButton::SettingsButton;
|
using Ui::SettingsButton::SettingsButton;
|
||||||
|
|
||||||
void setPeer(not_null<ChannelData*> c) {
|
void setPeer(not_null<PeerData*> p) {
|
||||||
_text.setText(st::defaultPeerListItem.nameStyle, c->name());
|
const auto c = p->asChannel();
|
||||||
|
const auto g = p->asChat();
|
||||||
|
_text.setText(st::defaultPeerListItem.nameStyle, p->name());
|
||||||
|
const auto count = c ? c->membersCount() : g->count;
|
||||||
_status.setText(
|
_status.setText(
|
||||||
st::defaultTextStyle,
|
st::defaultTextStyle,
|
||||||
!c->username().isEmpty()
|
!p->userName().isEmpty()
|
||||||
? ('@' + c->username())
|
? ('@' + p->userName())
|
||||||
: tr::lng_chat_status_subscribers(
|
: count
|
||||||
|
? tr::lng_chat_status_subscribers(
|
||||||
tr::now,
|
tr::now,
|
||||||
lt_count,
|
lt_count,
|
||||||
c->membersCount()));
|
count)
|
||||||
|
: QString());
|
||||||
}
|
}
|
||||||
|
|
||||||
int resizeGetHeight(int) override {
|
int resizeGetHeight(int) override {
|
||||||
|
@ -168,34 +175,42 @@ not_null<Ui::SettingsButton*> AddMyChannelsBox(
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
controller->session().data().enumerateBroadcasts([&](
|
const auto add = [&](not_null<PeerData*> peer) {
|
||||||
not_null<ChannelData*> channel) {
|
|
||||||
if (!channel->amCreator()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto row = box->addRow(
|
const auto row = box->addRow(
|
||||||
object_ptr<Button>(box, rpl::single(QString())),
|
object_ptr<Button>(box, rpl::single(QString())),
|
||||||
{});
|
{});
|
||||||
row->setPeer(channel);
|
row->setPeer(peer);
|
||||||
row->setClickedCallback([=] {
|
row->setClickedCallback([=] {
|
||||||
controller->showPeerHistory(channel);
|
controller->showPeerHistory(peer);
|
||||||
});
|
});
|
||||||
const auto userpic = Ui::CreateChild<Ui::UserpicButton>(
|
using Button = Ui::UserpicButton;
|
||||||
row,
|
const auto userpic = Ui::CreateChild<Button>(row, peer, *st);
|
||||||
channel,
|
|
||||||
*st);
|
|
||||||
userpic->move(st::defaultPeerListItem.photoPosition);
|
userpic->move(st::defaultPeerListItem.photoPosition);
|
||||||
userpic->setAttribute(Qt::WA_TransparentForMouseEvents);
|
userpic->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||||
});
|
};
|
||||||
|
|
||||||
|
const auto &data = controller->session().data();
|
||||||
|
if (chats) {
|
||||||
|
data.enumerateGroups([&](not_null<PeerData*> peer) {
|
||||||
|
const auto c = peer->asChannel();
|
||||||
|
const auto g = peer->asChat();
|
||||||
|
if ((c && c->amCreator()) || (g && g->amCreator())) {
|
||||||
|
add(peer);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
data.enumerateBroadcasts([&](not_null<ChannelData*> channel) {
|
||||||
|
if (channel->amCreator()) {
|
||||||
|
add(channel);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
using Menu = base::unique_qptr<Ui::PopupMenu>;
|
using Menu = base::unique_qptr<Ui::PopupMenu>;
|
||||||
const auto menu = button->lifetime().make_state<Menu>();
|
const auto menu = button->lifetime().make_state<Menu>();
|
||||||
button->addClickHandler([=](Qt::MouseButton which) {
|
button->addClickHandler([=](Qt::MouseButton which) {
|
||||||
if ((which != Qt::RightButton)
|
if (which != Qt::RightButton) {
|
||||||
|| !((button->clickModifiers() & Qt::ShiftModifier)
|
|
||||||
&& (button->clickModifiers() & Qt::AltModifier))) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,7 +218,7 @@ not_null<Ui::SettingsButton*> AddMyChannelsBox(
|
||||||
button,
|
button,
|
||||||
st::defaultPopupMenu);
|
st::defaultPopupMenu);
|
||||||
(*menu)->addAction(
|
(*menu)->addAction(
|
||||||
u"My Channels"_q,
|
chats ? u"My Groups"_q : u"My Channels"_q,
|
||||||
[=] { controller->uiShow()->showBox(Box(myChannelsBox)); },
|
[=] { controller->uiShow()->showBox(Box(myChannelsBox)); },
|
||||||
nullptr);
|
nullptr);
|
||||||
(*menu)->popup(QCursor::pos());
|
(*menu)->popup(QCursor::pos());
|
||||||
|
@ -957,16 +972,19 @@ void MainMenu::setupMenu() {
|
||||||
std::move(descriptor));
|
std::move(descriptor));
|
||||||
};
|
};
|
||||||
if (!_controller->session().supportMode()) {
|
if (!_controller->session().supportMode()) {
|
||||||
addAction(
|
AddMyChannelsBox(addAction(
|
||||||
tr::lng_create_group_title(),
|
tr::lng_create_group_title(),
|
||||||
{ &st::menuIconGroups }
|
{ &st::menuIconGroups }
|
||||||
)->setClickedCallback([=] {
|
), controller, true)->addClickHandler([=](Qt::MouseButton which) {
|
||||||
controller->showNewGroup();
|
if (which == Qt::LeftButton) {
|
||||||
|
controller->showNewGroup();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
AddMyChannelsBox(addAction(
|
AddMyChannelsBox(addAction(
|
||||||
tr::lng_create_channel_title(),
|
tr::lng_create_channel_title(),
|
||||||
{ &st::menuIconChannel }
|
{ &st::menuIconChannel }
|
||||||
), controller)->addClickHandler([=](Qt::MouseButton which) {
|
), controller, false)->addClickHandler([=](Qt::MouseButton which) {
|
||||||
if (which == Qt::LeftButton) {
|
if (which == Qt::LeftButton) {
|
||||||
controller->showNewChannel();
|
controller->showNewChannel();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue