api_user_privacy.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 "mtproto/sender.h"
  9. class ApiWrap;
  10. namespace Main {
  11. class Session;
  12. } // namespace Main
  13. namespace Api {
  14. class UserPrivacy final {
  15. public:
  16. enum class Key {
  17. PhoneNumber,
  18. AddedByPhone,
  19. LastSeen,
  20. Calls,
  21. Invites,
  22. CallsPeer2Peer,
  23. Forwards,
  24. ProfilePhoto,
  25. Voices,
  26. About,
  27. Birthday,
  28. GiftsAutoSave,
  29. NoPaidMessages,
  30. };
  31. enum class Option {
  32. Everyone,
  33. Contacts,
  34. CloseFriends,
  35. Nobody,
  36. };
  37. struct Exceptions {
  38. std::vector<not_null<PeerData*>> peers;
  39. bool premiums = false;
  40. bool miniapps = false;
  41. };
  42. struct Rule {
  43. Option option = Option::Everyone;
  44. Exceptions always;
  45. Exceptions never;
  46. bool ignoreAlways = false;
  47. bool ignoreNever = false;
  48. };
  49. explicit UserPrivacy(not_null<ApiWrap*> api);
  50. void save(
  51. Key key,
  52. const UserPrivacy::Rule &rule);
  53. void apply(
  54. mtpTypeId type,
  55. const MTPVector<MTPPrivacyRule> &rules,
  56. bool allLoaded);
  57. void reload(Key key);
  58. rpl::producer<Rule> value(Key key);
  59. private:
  60. const not_null<Main::Session*> _session;
  61. void pushPrivacy(Key key, const MTPVector<MTPPrivacyRule> &rules);
  62. base::flat_map<mtpTypeId, mtpRequestId> _privacySaveRequests;
  63. base::flat_map<Key, mtpRequestId> _privacyRequestIds;
  64. base::flat_map<Key, Rule> _privacyValues;
  65. std::map<Key, rpl::event_stream<Rule>> _privacyChanges;
  66. MTP::Sender _api;
  67. };
  68. } // namespace Api