menu_mute.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. #pragma once
  8. namespace Data {
  9. class Thread;
  10. struct NotifySound;
  11. enum class DefaultNotify;
  12. } // namespace Data
  13. namespace Main {
  14. class Session;
  15. } // namespace Main
  16. namespace Ui {
  17. class PopupMenu;
  18. class RpWidget;
  19. class Show;
  20. } // namespace Ui
  21. namespace MuteMenu {
  22. struct Descriptor {
  23. not_null<Main::Session*> session;
  24. Fn<rpl::producer<bool>()> isMutedValue;
  25. Fn<std::optional<Data::NotifySound>()> currentSound;
  26. Fn<void(Data::NotifySound)> updateSound;
  27. Fn<void(TimeId)> updateMutePeriod;
  28. };
  29. [[nodiscard]] Descriptor ThreadDescriptor(not_null<Data::Thread*> thread);
  30. [[nodiscard]] Descriptor DefaultDescriptor(
  31. not_null<Main::Session*> session,
  32. Data::DefaultNotify type);
  33. void FillMuteMenu(
  34. not_null<Ui::PopupMenu*> menu,
  35. Descriptor descriptor,
  36. std::shared_ptr<Ui::Show> show);
  37. void SetupMuteMenu(
  38. not_null<Ui::RpWidget*> parent,
  39. rpl::producer<> triggers,
  40. Fn<std::optional<Descriptor>()> makeDescriptor,
  41. std::shared_ptr<Ui::Show> show);
  42. inline void FillMuteMenu(
  43. not_null<Ui::PopupMenu*> menu,
  44. not_null<Data::Thread*> thread,
  45. std::shared_ptr<Ui::Show> show) {
  46. FillMuteMenu(menu, ThreadDescriptor(thread), std::move(show));
  47. }
  48. inline void SetupMuteMenu(
  49. not_null<Ui::RpWidget*> parent,
  50. rpl::producer<> triggers,
  51. Fn<Data::Thread*()> makeThread,
  52. std::shared_ptr<Ui::Show> show) {
  53. SetupMuteMenu(parent, std::move(triggers), [=] {
  54. const auto thread = makeThread();
  55. return thread
  56. ? ThreadDescriptor(thread)
  57. : std::optional<Descriptor>();
  58. }, std::move(show));
  59. }
  60. } // namespace MuteMenu