data_peer_notify_settings.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 NotifyPeerSettingsValue;
  10. struct NotifySound {
  11. QString title;
  12. QString data;
  13. DocumentId id = 0;
  14. bool none = false;
  15. };
  16. struct MuteValue {
  17. bool unmute = false;
  18. bool forever = false;
  19. int period = 0;
  20. [[nodiscard]] explicit operator bool() const {
  21. return unmute || forever || period;
  22. }
  23. [[nodiscard]] int until() const;
  24. };
  25. inline bool operator==(const NotifySound &a, const NotifySound &b) {
  26. return (a.id == b.id)
  27. && (a.none == b.none)
  28. && (a.title == b.title)
  29. && (a.data == b.data);
  30. }
  31. class PeerNotifySettings {
  32. public:
  33. PeerNotifySettings();
  34. bool change(const MTPPeerNotifySettings &settings);
  35. bool change(
  36. MuteValue muteForSeconds,
  37. std::optional<bool> silentPosts,
  38. std::optional<NotifySound> sound,
  39. std::optional<bool> storiesMuted);
  40. bool resetToDefault();
  41. bool settingsUnknown() const;
  42. std::optional<TimeId> muteUntil() const;
  43. std::optional<bool> silentPosts() const;
  44. std::optional<NotifySound> sound() const;
  45. MTPinputPeerNotifySettings serialize() const;
  46. ~PeerNotifySettings();
  47. private:
  48. bool _known = false;
  49. std::unique_ptr<NotifyPeerSettingsValue> _value;
  50. };
  51. } // namespace Data