data_business_chatbots.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. #include "data/business/data_business_common.h"
  9. class UserData;
  10. namespace Data {
  11. class Session;
  12. struct ChatbotsSettings {
  13. UserData *bot = nullptr;
  14. BusinessRecipients recipients;
  15. bool repliesAllowed = false;
  16. friend inline bool operator==(
  17. const ChatbotsSettings &,
  18. const ChatbotsSettings &) = default;
  19. };
  20. class Chatbots final {
  21. public:
  22. explicit Chatbots(not_null<Session*> owner);
  23. ~Chatbots();
  24. void preload();
  25. [[nodiscard]] bool loaded() const;
  26. [[nodiscard]] const ChatbotsSettings &current() const;
  27. [[nodiscard]] rpl::producer<ChatbotsSettings> changes() const;
  28. [[nodiscard]] rpl::producer<ChatbotsSettings> value() const;
  29. void save(
  30. ChatbotsSettings settings,
  31. Fn<void()> done,
  32. Fn<void(QString)> fail);
  33. void togglePaused(not_null<PeerData*> peer, bool paused);
  34. void removeFrom(not_null<PeerData*> peer);
  35. private:
  36. enum class SentRequestType {
  37. Pause,
  38. Unpause,
  39. Remove,
  40. };
  41. struct SentRequest {
  42. SentRequestType type = SentRequestType::Pause;
  43. mtpRequestId requestId = 0;
  44. };
  45. void reload();
  46. const not_null<Session*> _owner;
  47. rpl::variable<ChatbotsSettings> _settings;
  48. mtpRequestId _requestId = 0;
  49. bool _loaded = false;
  50. base::flat_map<not_null<PeerData*>, SentRequest> _sentRequests;
  51. };
  52. } // namespace Data