mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Improved style of box for all of user's own groups and channels.
This commit is contained in:
parent
47bf099b88
commit
129b07c2c0
1 changed files with 93 additions and 12 deletions
|
@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#include "window/window_main_menu.h"
|
#include "window/window_main_menu.h"
|
||||||
|
|
||||||
|
#include "apiwrap.h"
|
||||||
#include "window/themes/window_theme.h"
|
#include "window/themes/window_theme.h"
|
||||||
#include "window/window_peer_menu.h"
|
#include "window/window_peer_menu.h"
|
||||||
#include "window/window_session_controller.h"
|
#include "window/window_session_controller.h"
|
||||||
|
@ -24,6 +25,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/text/text_options.h"
|
#include "ui/text/text_options.h"
|
||||||
#include "ui/new_badges.h"
|
#include "ui/new_badges.h"
|
||||||
#include "ui/painter.h"
|
#include "ui/painter.h"
|
||||||
|
#include "ui/rect.h"
|
||||||
#include "ui/vertical_list.h"
|
#include "ui/vertical_list.h"
|
||||||
#include "ui/unread_badge_paint.h"
|
#include "ui/unread_badge_paint.h"
|
||||||
#include "inline_bots/bot_attach_web_view.h"
|
#include "inline_bots/bot_attach_web_view.h"
|
||||||
|
@ -45,6 +47,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "boxes/premium_preview_box.h"
|
#include "boxes/premium_preview_box.h"
|
||||||
#include "calls/calls_box_controller.h"
|
#include "calls/calls_box_controller.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
|
#include "lottie/lottie_icon.h"
|
||||||
#include "core/click_handler_types.h"
|
#include "core/click_handler_types.h"
|
||||||
#include "core/application.h"
|
#include "core/application.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
|
@ -56,6 +59,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#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"
|
||||||
|
#include "data/data_document.h"
|
||||||
|
#include "data/data_file_origin.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_channel.h"
|
||||||
|
@ -116,10 +121,76 @@ not_null<Ui::SettingsButton*> AddMyChannelsBox(
|
||||||
bool chats) {
|
bool chats) {
|
||||||
button->setAcceptBoth(true);
|
button->setAcceptBoth(true);
|
||||||
|
|
||||||
|
const auto requestIcon = [=, session = &controller->session()](
|
||||||
|
not_null<Ui::GenericBox*> box,
|
||||||
|
Fn<void(not_null<DocumentData*>)> done) {
|
||||||
|
const auto api = box->lifetime().make_state<MTP::Sender>(
|
||||||
|
&session->mtp());
|
||||||
|
api->request(MTPmessages_GetStickerSet(
|
||||||
|
Data::InputStickerSet({
|
||||||
|
.shortName = u"tg_placeholders_android"_q,
|
||||||
|
}),
|
||||||
|
MTP_int(0)
|
||||||
|
)).done([=](const MTPmessages_StickerSet &result) {
|
||||||
|
result.match([&](const MTPDmessages_stickerSet &data) {
|
||||||
|
const auto &v = data.vdocuments().v;
|
||||||
|
if (v.size() > 1) {
|
||||||
|
done(session->data().processDocument(v[1]));
|
||||||
|
}
|
||||||
|
}, [](const MTPDmessages_stickerSetNotModified &) {
|
||||||
|
});
|
||||||
|
}).send();
|
||||||
|
};
|
||||||
|
const auto addIcon = [=](not_null<Ui::GenericBox*> box) {
|
||||||
|
const auto widget = box->addRow(object_ptr<Ui::RpWidget>(box));
|
||||||
|
widget->paintRequest(
|
||||||
|
) | rpl::start_with_next([=] {
|
||||||
|
auto p = QPainter(widget);
|
||||||
|
p.setFont(st::boxTextFont);
|
||||||
|
p.setPen(st::windowSubTextFg);
|
||||||
|
p.drawText(
|
||||||
|
widget->rect(),
|
||||||
|
tr::lng_contacts_loading(tr::now),
|
||||||
|
style::al_center);
|
||||||
|
}, widget->lifetime());
|
||||||
|
widget->resize(Size(st::maxStickerSize));
|
||||||
|
widget->show();
|
||||||
|
box->verticalLayout()->resizeToWidth(box->width());
|
||||||
|
requestIcon(box, [=](not_null<DocumentData*> document) {
|
||||||
|
const auto view = document->createMediaView();
|
||||||
|
const auto origin = document->stickerSetOrigin();
|
||||||
|
controller->session().downloaderTaskFinished(
|
||||||
|
) | rpl::take_while([=] {
|
||||||
|
if (view->bytes().isEmpty()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
auto owned = Lottie::MakeIcon({
|
||||||
|
.json = Images::UnpackGzip(view->bytes()),
|
||||||
|
.sizeOverride = Size(st::maxStickerSize),
|
||||||
|
});
|
||||||
|
const auto icon = owned.get();
|
||||||
|
widget->lifetime().add([kept = std::move(owned)]{});
|
||||||
|
widget->paintRequest(
|
||||||
|
) | rpl::start_with_next([=] {
|
||||||
|
auto p = QPainter(widget);
|
||||||
|
icon->paint(p, (widget->width() - icon->width()) / 2, 0);
|
||||||
|
}, widget->lifetime());
|
||||||
|
icon->animate(
|
||||||
|
[=] { widget->update(); },
|
||||||
|
0,
|
||||||
|
icon->framesCount());
|
||||||
|
return false;
|
||||||
|
}) | rpl::start(widget->lifetime());
|
||||||
|
view->automaticLoad(origin, nullptr);
|
||||||
|
view->videoThumbnailWanted(origin);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const auto myChannelsBox = [=](not_null<Ui::GenericBox*> box) {
|
const auto myChannelsBox = [=](not_null<Ui::GenericBox*> box) {
|
||||||
box->setTitle(chats
|
box->setTitle(chats
|
||||||
? tr::lng_notification_groups()
|
? tr::lng_notification_groups()
|
||||||
: tr::lng_notification_channels());
|
: tr::lng_notification_channels());
|
||||||
|
box->addButton(tr::lng_close(), [=] { box->closeBox(); });
|
||||||
|
|
||||||
const auto st = box->lifetime().make_state<style::UserpicButton>(
|
const auto st = box->lifetime().make_state<style::UserpicButton>(
|
||||||
st::defaultUserpicButton);
|
st::defaultUserpicButton);
|
||||||
|
@ -133,17 +204,22 @@ not_null<Ui::SettingsButton*> AddMyChannelsBox(
|
||||||
void setPeer(not_null<PeerData*> p) {
|
void setPeer(not_null<PeerData*> p) {
|
||||||
const auto c = p->asChannel();
|
const auto c = p->asChannel();
|
||||||
const auto g = p->asChat();
|
const auto g = p->asChat();
|
||||||
_text.setText(st::defaultPeerListItem.nameStyle, p->name());
|
_text.setText(
|
||||||
|
st::defaultPeerListItem.nameStyle,
|
||||||
|
((c && c->isMegagroup()) ? u"[s] "_q : QString())
|
||||||
|
+ p->name());
|
||||||
const auto count = c ? c->membersCount() : g->count;
|
const auto count = c ? c->membersCount() : g->count;
|
||||||
_status.setText(
|
_status.setText(
|
||||||
st::defaultTextStyle,
|
st::defaultTextStyle,
|
||||||
!p->username().isEmpty()
|
!p->username().isEmpty()
|
||||||
? ('@' + p->username())
|
? ('@' + p->username())
|
||||||
: count
|
: (count > 0)
|
||||||
? tr::lng_chat_status_subscribers(
|
? ((c && !c->isMegagroup())
|
||||||
tr::now,
|
? tr::lng_chat_status_subscribers
|
||||||
lt_count,
|
: tr::lng_chat_status_members)(
|
||||||
count)
|
tr::now,
|
||||||
|
lt_count,
|
||||||
|
count)
|
||||||
: QString());
|
: QString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,15 +268,15 @@ not_null<Ui::SettingsButton*> AddMyChannelsBox(
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto &data = controller->session().data();
|
const auto &data = controller->session().data();
|
||||||
|
auto ids = std::vector<PeerId>();
|
||||||
if (chats) {
|
if (chats) {
|
||||||
auto ids = std::vector<PeerId>();
|
|
||||||
data.enumerateGroups([&](not_null<PeerData*> peer) {
|
data.enumerateGroups([&](not_null<PeerData*> peer) {
|
||||||
peer = peer->migrateToOrMe();
|
peer = peer->migrateToOrMe();
|
||||||
const auto c = peer->asChannel();
|
|
||||||
const auto g = peer->asChat();
|
|
||||||
if (ranges::contains(ids, peer->id)) {
|
if (ranges::contains(ids, peer->id)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const auto c = peer->asChannel();
|
||||||
|
const auto g = peer->asChat();
|
||||||
if ((c && c->amCreator()) || (g && g->amCreator())) {
|
if ((c && c->amCreator()) || (g && g->amCreator())) {
|
||||||
ids.push_back(peer->id);
|
ids.push_back(peer->id);
|
||||||
add(peer);
|
add(peer);
|
||||||
|
@ -208,11 +284,16 @@ not_null<Ui::SettingsButton*> AddMyChannelsBox(
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
data.enumerateBroadcasts([&](not_null<ChannelData*> channel) {
|
data.enumerateBroadcasts([&](not_null<ChannelData*> channel) {
|
||||||
if (channel->amCreator()) {
|
if (channel->amCreator()
|
||||||
|
&& !ranges::contains(ids, channel->id)) {
|
||||||
|
ids.push_back(channel->id);
|
||||||
add(channel);
|
add(channel);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (ids.empty()) {
|
||||||
|
addIcon(box);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
using Menu = base::unique_qptr<Ui::PopupMenu>;
|
using Menu = base::unique_qptr<Ui::PopupMenu>;
|
||||||
|
@ -224,12 +305,12 @@ not_null<Ui::SettingsButton*> AddMyChannelsBox(
|
||||||
|
|
||||||
(*menu) = base::make_unique_q<Ui::PopupMenu>(
|
(*menu) = base::make_unique_q<Ui::PopupMenu>(
|
||||||
button,
|
button,
|
||||||
st::defaultPopupMenu);
|
st::popupMenuWithIcons);
|
||||||
(*menu)->addAction(
|
(*menu)->addAction(
|
||||||
(chats ? tr::lng_menu_my_groups : tr::lng_menu_my_channels)(
|
(chats ? tr::lng_menu_my_groups : tr::lng_menu_my_channels)(
|
||||||
tr::now),
|
tr::now),
|
||||||
[=] { controller->uiShow()->showBox(Box(myChannelsBox)); },
|
[=] { controller->uiShow()->showBox(Box(myChannelsBox)); },
|
||||||
nullptr);
|
chats ? &st::menuIconGroups : &st::menuIconChannel);
|
||||||
(*menu)->popup(QCursor::pos());
|
(*menu)->popup(QCursor::pos());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue