mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 14:38:15 +00:00
Allow hiding members list in groups.
This commit is contained in:
61
Telegram/SourceFiles/boxes/peers/edit_members_visible.cpp
Normal file
61
Telegram/SourceFiles/boxes/peers/edit_members_visible.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
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 "boxes/peers/edit_members_visible.h"
|
||||
|
||||
#include "boxes/peers/edit_peer_info_box.h"
|
||||
#include "data/data_channel.h"
|
||||
#include "ui/rp_widget.h"
|
||||
#include "ui/wrap/vertical_layout.h"
|
||||
#include "ui/wrap/slide_wrap.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "settings/settings_common.h"
|
||||
#include "main/main_session.h"
|
||||
#include "apiwrap.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "styles/style_info.h"
|
||||
|
||||
[[nodiscard]] object_ptr<Ui::RpWidget> CreateMembersVisibleButton(
|
||||
not_null<ChannelData*> megagroup) {
|
||||
auto result = object_ptr<Ui::VerticalLayout>((QWidget*)nullptr);
|
||||
const auto container = result.data();
|
||||
|
||||
struct State {
|
||||
rpl::event_stream<bool> toggled;
|
||||
};
|
||||
Settings::AddSkip(container);
|
||||
const auto state = container->lifetime().make_state<State>();
|
||||
const auto button = container->add(
|
||||
EditPeerInfoBox::CreateButton(
|
||||
container,
|
||||
tr::lng_profile_hide_participants(),
|
||||
rpl::single(QString()),
|
||||
[] {},
|
||||
st::manageGroupTopicsButton,
|
||||
{ &st::infoRoundedIconAntiSpam, Settings::kIconPurple }
|
||||
))->toggleOn(rpl::single(
|
||||
(megagroup->flags() & ChannelDataFlag::ParticipantsHidden) != 0
|
||||
) | rpl::then(state->toggled.events()));
|
||||
Settings::AddSkip(container);
|
||||
Settings::AddDividerText(
|
||||
container,
|
||||
tr::lng_profile_hide_participants_about());
|
||||
|
||||
button->toggledValue(
|
||||
) | rpl::start_with_next([=](bool toggled) {
|
||||
megagroup->session().api().request(
|
||||
MTPchannels_ToggleParticipantsHidden(
|
||||
megagroup->inputChannel,
|
||||
MTP_bool(toggled)
|
||||
)
|
||||
).done([=](const MTPUpdates &result) {
|
||||
megagroup->session().api().applyUpdates(result);
|
||||
}).send();
|
||||
}, button->lifetime());
|
||||
|
||||
return result;
|
||||
}
|
19
Telegram/SourceFiles/boxes/peers/edit_members_visible.h
Normal file
19
Telegram/SourceFiles/boxes/peers/edit_members_visible.h
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
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
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "base/object_ptr.h"
|
||||
|
||||
class ChannelData;
|
||||
|
||||
namespace Ui {
|
||||
class RpWidget;
|
||||
} // namespace Ui
|
||||
|
||||
[[nodiscard]] object_ptr<Ui::RpWidget> CreateMembersVisibleButton(
|
||||
not_null<ChannelData*> megagroup);
|
@@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "boxes/peers/edit_participant_box.h"
|
||||
#include "boxes/peers/add_participants_box.h"
|
||||
#include "boxes/peers/prepare_short_info_box.h" // PrepareShortInfoBox
|
||||
#include "boxes/peers/edit_members_visible.h"
|
||||
#include "ui/boxes/confirm_box.h"
|
||||
#include "boxes/max_invite_box.h"
|
||||
#include "boxes/add_contact_box.h"
|
||||
@@ -1188,11 +1189,14 @@ void ParticipantsBoxController::prepare() {
|
||||
Unexpected("Role in ParticipantsBoxController::prepare()");
|
||||
}();
|
||||
if (const auto megagroup = _peer->asMegagroup()) {
|
||||
if ((_role == Role::Admins)
|
||||
if ((_role == Role::Members) && megagroup->canBanMembers()) {
|
||||
delegate()->peerListSetAboveWidget(CreateMembersVisibleButton(
|
||||
megagroup));
|
||||
} else if ((_role == Role::Admins)
|
||||
&& (megagroup->amCreator() || megagroup->hasAdminRights())) {
|
||||
const auto validator = AntiSpamMenu::AntiSpamValidator(
|
||||
_navigation->parentController(),
|
||||
_peer->asChannel());
|
||||
megagroup);
|
||||
delegate()->peerListSetAboveWidget(validator.createButton());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user