2022-05-01 18:08:16 +00:00
|
|
|
/*
|
|
|
|
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 "settings/settings_blocked_peers.h"
|
|
|
|
|
|
|
|
#include "api/api_blocked_peers.h"
|
|
|
|
#include "apiwrap.h"
|
|
|
|
#include "data/data_changes.h"
|
|
|
|
#include "data/data_peer.h"
|
|
|
|
#include "lang/lang_keys.h"
|
|
|
|
#include "lottie/lottie_icon.h"
|
|
|
|
#include "main/main_session.h"
|
|
|
|
#include "settings/settings_privacy_controllers.h"
|
|
|
|
#include "ui/widgets/buttons.h"
|
|
|
|
#include "ui/wrap/padding_wrap.h"
|
|
|
|
#include "ui/wrap/slide_wrap.h"
|
|
|
|
#include "ui/wrap/vertical_layout.h"
|
|
|
|
#include "window/window_session_controller.h"
|
|
|
|
#include "styles/style_settings.h"
|
|
|
|
#include "styles/style_boxes.h"
|
2022-05-03 16:38:34 +00:00
|
|
|
#include "styles/style_menu_icons.h"
|
2022-05-01 18:08:16 +00:00
|
|
|
|
|
|
|
namespace Settings {
|
|
|
|
|
|
|
|
Blocked::Blocked(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<Window::SessionController*> controller)
|
|
|
|
: Section(parent)
|
2022-08-02 09:38:28 +00:00
|
|
|
, _controller(controller)
|
|
|
|
, _container(Ui::CreateChild<Ui::VerticalLayout>(this)) {
|
2022-05-01 18:08:16 +00:00
|
|
|
|
|
|
|
setupContent();
|
|
|
|
|
|
|
|
{
|
|
|
|
auto padding = st::changePhoneIconPadding;
|
|
|
|
padding.setBottom(padding.top());
|
|
|
|
_loading = base::make_unique_q<Ui::CenterWrap<>>(
|
|
|
|
this,
|
|
|
|
object_ptr<Ui::PaddingWrap<>>(
|
|
|
|
this,
|
|
|
|
object_ptr<Ui::FlatLabel>(
|
|
|
|
this,
|
|
|
|
tr::lng_contacts_loading(),
|
|
|
|
st::changePhoneDescription),
|
|
|
|
std::move(padding)));
|
|
|
|
Ui::ResizeFitChild(this, _loading.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
_controller->session().api().blockedPeers().slice(
|
|
|
|
) | rpl::start_with_next([=](const Api::BlockedPeers::Slice &slice) {
|
|
|
|
checkTotal(slice.total);
|
|
|
|
}, lifetime());
|
|
|
|
|
|
|
|
_controller->session().changes().peerUpdates(
|
|
|
|
Data::PeerUpdate::Flag::IsBlocked
|
|
|
|
) | rpl::start_with_next([=](const Data::PeerUpdate &update) {
|
|
|
|
if (update.peer->isBlocked()) {
|
|
|
|
checkTotal(1);
|
|
|
|
}
|
|
|
|
}, lifetime());
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<QString> Blocked::title() {
|
|
|
|
return tr::lng_settings_blocked_users();
|
|
|
|
}
|
|
|
|
|
|
|
|
QPointer<Ui::RpWidget> Blocked::createPinnedToTop(not_null<QWidget*> parent) {
|
|
|
|
const auto content = Ui::CreateChild<Ui::VerticalLayout>(parent.get());
|
|
|
|
|
|
|
|
AddSkip(content);
|
|
|
|
|
|
|
|
AddButton(
|
|
|
|
content,
|
|
|
|
tr::lng_blocked_list_add(),
|
2022-05-03 16:38:34 +00:00
|
|
|
st::settingsButtonActive,
|
|
|
|
{ &st::menuIconBlockSettings, 0, IconType::Round, &st::transparent }
|
2022-05-01 18:08:16 +00:00
|
|
|
)->addClickHandler([=] {
|
|
|
|
BlockedBoxController::BlockNewPeer(_controller);
|
|
|
|
});
|
|
|
|
|
|
|
|
AddSkip(content);
|
|
|
|
AddDividerText(content, tr::lng_blocked_list_about());
|
|
|
|
|
|
|
|
{
|
|
|
|
const auto subtitle = content->add(
|
|
|
|
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
|
|
|
content,
|
|
|
|
object_ptr<Ui::VerticalLayout>(content)))->setDuration(0);
|
|
|
|
AddSkip(subtitle->entity());
|
|
|
|
auto subtitleText = _countBlocked.value(
|
|
|
|
) | rpl::map([=](int count) {
|
|
|
|
return tr::lng_blocked_list_subtitle(tr::now, lt_count, count);
|
|
|
|
});
|
|
|
|
AddSubsectionTitle(
|
|
|
|
subtitle->entity(),
|
|
|
|
rpl::duplicate(subtitleText),
|
|
|
|
st::blockedUsersListSubtitleAddPadding);
|
|
|
|
subtitle->toggleOn(
|
|
|
|
rpl::merge(
|
|
|
|
_emptinessChanges.events() | rpl::map(!rpl::mappers::_1),
|
|
|
|
_countBlocked.value() | rpl::map(rpl::mappers::_1 > 0)
|
|
|
|
) | rpl::distinct_until_changed());
|
|
|
|
|
|
|
|
// Workaround.
|
|
|
|
std::move(
|
|
|
|
subtitleText
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
subtitle->entity()->resizeToWidth(content->width());
|
|
|
|
}, subtitle->lifetime());
|
|
|
|
}
|
|
|
|
|
|
|
|
return Ui::MakeWeak(not_null<Ui::RpWidget*>{ content });
|
|
|
|
}
|
|
|
|
|
|
|
|
void Blocked::setupContent() {
|
|
|
|
using namespace rpl::mappers;
|
|
|
|
|
2022-08-02 09:38:28 +00:00
|
|
|
const auto listWrap = _container->add(
|
2022-05-01 18:08:16 +00:00
|
|
|
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
2022-08-02 09:38:28 +00:00
|
|
|
_container,
|
|
|
|
object_ptr<Ui::VerticalLayout>(_container)));
|
2022-05-01 18:08:16 +00:00
|
|
|
listWrap->toggleOn(
|
|
|
|
_emptinessChanges.events_starting_with(true) | rpl::map(!_1),
|
|
|
|
anim::type::instant);
|
|
|
|
|
|
|
|
{
|
|
|
|
struct State {
|
|
|
|
std::unique_ptr<BlockedBoxController> controller;
|
|
|
|
std::unique_ptr<PeerListContentDelegateSimple> delegate;
|
|
|
|
};
|
|
|
|
|
|
|
|
auto controller = std::make_unique<BlockedBoxController>(_controller);
|
|
|
|
const auto content = listWrap->entity()->add(
|
|
|
|
object_ptr<PeerListContent>(this, controller.get()));
|
|
|
|
|
|
|
|
const auto state = content->lifetime().make_state<State>();
|
|
|
|
state->controller = std::move(controller);
|
|
|
|
state->delegate = std::make_unique<PeerListContentDelegateSimple>();
|
|
|
|
|
|
|
|
state->delegate->setContent(content);
|
|
|
|
state->controller->setDelegate(state->delegate.get());
|
|
|
|
|
|
|
|
state->controller->rowsCountChanges(
|
|
|
|
) | rpl::start_with_next([=](int total) {
|
|
|
|
_countBlocked = total;
|
|
|
|
checkTotal(total);
|
|
|
|
}, content->lifetime());
|
|
|
|
_countBlocked = content->fullRowsCount();
|
|
|
|
}
|
|
|
|
|
2022-08-02 09:38:28 +00:00
|
|
|
const auto emptyWrap = _container->add(
|
2022-05-01 18:08:16 +00:00
|
|
|
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
2022-08-02 09:38:28 +00:00
|
|
|
_container,
|
|
|
|
object_ptr<Ui::VerticalLayout>(_container)));
|
2022-05-01 18:08:16 +00:00
|
|
|
emptyWrap->toggleOn(
|
|
|
|
_emptinessChanges.events_starting_with(false),
|
|
|
|
anim::type::instant);
|
|
|
|
|
|
|
|
{
|
|
|
|
const auto content = emptyWrap->entity();
|
2022-05-03 21:02:52 +00:00
|
|
|
auto icon = CreateLottieIcon(
|
|
|
|
content,
|
|
|
|
{
|
|
|
|
.name = u"blocked_peers_empty"_q,
|
|
|
|
.sizeOverride = {
|
|
|
|
st::changePhoneIconSize,
|
|
|
|
st::changePhoneIconSize,
|
|
|
|
},
|
2022-05-01 18:08:16 +00:00
|
|
|
},
|
2022-05-04 07:39:53 +00:00
|
|
|
st::blockedUsersListIconPadding);
|
2022-05-01 18:08:16 +00:00
|
|
|
content->add(std::move(icon.widget));
|
|
|
|
|
|
|
|
_showFinished.events(
|
|
|
|
) | rpl::start_with_next([animate = std::move(icon.animate)] {
|
2022-05-04 07:39:53 +00:00
|
|
|
animate(anim::repeat::once);
|
2022-05-01 18:08:16 +00:00
|
|
|
}, content->lifetime());
|
|
|
|
|
|
|
|
content->add(
|
|
|
|
object_ptr<Ui::CenterWrap<>>(
|
|
|
|
content,
|
|
|
|
object_ptr<Ui::FlatLabel>(
|
|
|
|
content,
|
|
|
|
tr::lng_blocked_list_empty_title(),
|
|
|
|
st::changePhoneTitle)),
|
|
|
|
st::changePhoneTitlePadding);
|
|
|
|
|
|
|
|
content->add(
|
|
|
|
object_ptr<Ui::CenterWrap<>>(
|
|
|
|
content,
|
|
|
|
object_ptr<Ui::FlatLabel>(
|
|
|
|
content,
|
|
|
|
tr::lng_blocked_list_empty_description(),
|
|
|
|
st::changePhoneDescription)),
|
|
|
|
st::changePhoneDescriptionPadding);
|
|
|
|
|
|
|
|
AddSkip(content, st::blockedUsersListIconPadding.top());
|
|
|
|
}
|
|
|
|
|
2022-08-02 09:38:28 +00:00
|
|
|
Ui::ResizeFitChild(this, _container);
|
2022-05-01 18:08:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Blocked::checkTotal(int total) {
|
|
|
|
_loading = nullptr;
|
|
|
|
_emptinessChanges.fire(total <= 0);
|
|
|
|
}
|
|
|
|
|
2022-08-02 09:38:28 +00:00
|
|
|
void Blocked::visibleTopBottomUpdated(int visibleTop, int visibleBottom) {
|
|
|
|
setChildVisibleTopBottom(_container, visibleTop, visibleBottom);
|
|
|
|
}
|
|
|
|
|
2022-05-01 18:08:16 +00:00
|
|
|
void Blocked::showFinished() {
|
|
|
|
_showFinished.fire({});
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Settings
|