edit_members_visible.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #include "boxes/peers/edit_members_visible.h"
  8. #include "boxes/peers/edit_peer_info_box.h"
  9. #include "data/data_channel.h"
  10. #include "ui/rp_widget.h"
  11. #include "ui/wrap/vertical_layout.h"
  12. #include "ui/wrap/slide_wrap.h"
  13. #include "ui/widgets/buttons.h"
  14. #include "ui/vertical_list.h"
  15. #include "settings/settings_common.h" // IconDescriptor.
  16. #include "main/main_app_config.h"
  17. #include "main/main_session.h"
  18. #include "apiwrap.h"
  19. #include "lang/lang_keys.h"
  20. #include "styles/style_info.h"
  21. #include "styles/style_menu_icons.h"
  22. namespace {
  23. [[nodiscard]] int EnableHideMembersMin(not_null<ChannelData*> channel) {
  24. return channel->session().appConfig().get<int>(
  25. u"hidden_members_group_size_min"_q,
  26. 100);
  27. }
  28. } // namespace
  29. [[nodiscard]] object_ptr<Ui::RpWidget> CreateMembersVisibleButton(
  30. not_null<ChannelData*> megagroup) {
  31. auto result = object_ptr<Ui::VerticalLayout>((QWidget*)nullptr);
  32. const auto container = result.data();
  33. const auto min = EnableHideMembersMin(megagroup);
  34. if (!megagroup->canBanMembers() || megagroup->membersCount() < min) {
  35. return { nullptr };
  36. }
  37. struct State {
  38. rpl::event_stream<bool> toggled;
  39. };
  40. Ui::AddSkip(container);
  41. const auto state = container->lifetime().make_state<State>();
  42. const auto button = container->add(
  43. EditPeerInfoBox::CreateButton(
  44. container,
  45. tr::lng_profile_hide_participants(),
  46. rpl::single(QString()),
  47. [] {},
  48. st::manageGroupNoIconButton,
  49. {}
  50. ))->toggleOn(rpl::single(
  51. (megagroup->flags() & ChannelDataFlag::ParticipantsHidden) != 0
  52. ) | rpl::then(state->toggled.events()));
  53. Ui::AddSkip(container);
  54. Ui::AddDividerText(container, tr::lng_profile_hide_participants_about());
  55. button->toggledValue(
  56. ) | rpl::start_with_next([=](bool toggled) {
  57. megagroup->session().api().request(
  58. MTPchannels_ToggleParticipantsHidden(
  59. megagroup->inputChannel,
  60. MTP_bool(toggled)
  61. )
  62. ).done([=](const MTPUpdates &result) {
  63. megagroup->session().api().applyUpdates(result);
  64. }).send();
  65. }, button->lifetime());
  66. return result;
  67. }