data_peer_values.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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/data_peer.h"
  9. #include "data/data_chat_participant_status.h"
  10. enum class ImageRoundRadius;
  11. namespace Main {
  12. class Session;
  13. } // namespace Main
  14. namespace Data {
  15. struct Reaction;
  16. class ForumTopic;
  17. class LastseenStatus;
  18. template <typename ChangeType, typename Error, typename Generator>
  19. inline auto FlagsValueWithMask(
  20. rpl::producer<ChangeType, Error, Generator> &&value,
  21. typename ChangeType::Type mask) {
  22. return std::move(
  23. value
  24. ) | rpl::filter([mask](const ChangeType &change) {
  25. return change.diff & mask;
  26. }) | rpl::map([mask](const ChangeType &change) {
  27. return change.value & mask;
  28. });
  29. }
  30. template <typename ChangeType, typename Error, typename Generator>
  31. inline auto SingleFlagValue(
  32. rpl::producer<ChangeType, Error, Generator> &&value,
  33. typename ChangeType::Enum flag) {
  34. return FlagsValueWithMask(
  35. std::move(value),
  36. flag
  37. ) | rpl::map([](typename ChangeType::Type value) {
  38. return !!value;
  39. });
  40. }
  41. template <
  42. typename PeerType,
  43. typename ChangeType = typename PeerType::Flags::Change>
  44. inline auto PeerFlagsValue(PeerType *peer) {
  45. Expects(peer != nullptr);
  46. return peer->flagsValue();
  47. }
  48. template <
  49. typename PeerType,
  50. typename ChangeType = typename PeerType::Flags::Change>
  51. inline auto PeerFlagsValue(
  52. PeerType *peer,
  53. typename PeerType::Flags::Type mask) {
  54. return FlagsValueWithMask(PeerFlagsValue(peer), mask);
  55. }
  56. template <
  57. typename PeerType,
  58. typename ChangeType = typename PeerType::Flags::Change>
  59. inline auto PeerFlagValue(
  60. PeerType *peer,
  61. typename PeerType::Flags::Enum flag) {
  62. return SingleFlagValue(PeerFlagsValue(peer), flag);
  63. }
  64. template <
  65. typename PeerType,
  66. typename = typename PeerType::FullFlags::Change>
  67. inline auto PeerFullFlagsValue(PeerType *peer) {
  68. Expects(peer != nullptr);
  69. return peer->fullFlagsValue();
  70. }
  71. template <
  72. typename PeerType,
  73. typename = typename PeerType::FullFlags::Change>
  74. inline auto PeerFullFlagsValue(
  75. PeerType *peer,
  76. typename PeerType::FullFlags::Type mask) {
  77. return FlagsValueWithMask(PeerFullFlagsValue(peer), mask);
  78. }
  79. template <
  80. typename PeerType,
  81. typename = typename PeerType::FullFlags::Change>
  82. inline auto PeerFullFlagValue(
  83. PeerType *peer,
  84. typename PeerType::FullFlags::Enum flag) {
  85. return SingleFlagValue(PeerFullFlagsValue(peer), flag);
  86. }
  87. [[nodiscard]] rpl::producer<bool> CanSendAnyOfValue(
  88. not_null<Data::Thread*> thread,
  89. ChatRestrictions rights,
  90. bool forbidInForums = true);
  91. [[nodiscard]] rpl::producer<bool> CanSendAnyOfValue(
  92. not_null<PeerData*> peer,
  93. ChatRestrictions rights,
  94. bool forbidInForums = true);
  95. [[nodiscard]] inline rpl::producer<bool> CanSendValue(
  96. not_null<Thread*> thread,
  97. ChatRestriction right,
  98. bool forbidInForums = true) {
  99. return CanSendAnyOfValue(thread, right, forbidInForums);
  100. }
  101. [[nodiscard]] inline rpl::producer<bool> CanSendValue(
  102. not_null<PeerData*> peer,
  103. ChatRestriction right,
  104. bool forbidInForums = true) {
  105. return CanSendAnyOfValue(peer, right, forbidInForums);
  106. }
  107. [[nodiscard]] inline rpl::producer<bool> CanSendTextsValue(
  108. not_null<Thread*> thread,
  109. bool forbidInForums = true) {
  110. return CanSendValue(thread, ChatRestriction::SendOther, forbidInForums);
  111. }
  112. [[nodiscard]] inline rpl::producer<bool> CanSendTextsValue(
  113. not_null<PeerData*> peer,
  114. bool forbidInForums = true) {
  115. return CanSendValue(peer, ChatRestriction::SendOther, forbidInForums);
  116. }
  117. [[nodiscard]] inline rpl::producer<bool> CanSendAnythingValue(
  118. not_null<Thread*> thread,
  119. bool forbidInForums = true) {
  120. return CanSendAnyOfValue(thread, AllSendRestrictions(), forbidInForums);
  121. }
  122. [[nodiscard]] inline rpl::producer<bool> CanSendAnythingValue(
  123. not_null<PeerData*> peer,
  124. bool forbidInForums = true) {
  125. return CanSendAnyOfValue(peer, AllSendRestrictions(), forbidInForums);
  126. }
  127. [[nodiscard]] rpl::producer<bool> CanPinMessagesValue(
  128. not_null<PeerData*> peer);
  129. [[nodiscard]] rpl::producer<bool> CanManageGroupCallValue(
  130. not_null<PeerData*> peer);
  131. [[nodiscard]] rpl::producer<bool> PeerPremiumValue(not_null<PeerData*> peer);
  132. [[nodiscard]] rpl::producer<bool> AmPremiumValue(
  133. not_null<Main::Session*> session);
  134. [[nodiscard]] TimeId SortByOnlineValue(not_null<UserData*> user, TimeId now);
  135. [[nodiscard]] crl::time OnlineChangeTimeout(
  136. LastseenStatus status,
  137. TimeId now);
  138. [[nodiscard]] crl::time OnlineChangeTimeout(
  139. not_null<UserData*> user,
  140. TimeId now);
  141. [[nodiscard]] QString OnlineText(LastseenStatus status, TimeId now);
  142. [[nodiscard]] QString OnlineText(not_null<UserData*> user, TimeId now);
  143. [[nodiscard]] QString OnlineTextFull(not_null<UserData*> user, TimeId now);
  144. [[nodiscard]] bool OnlineTextActive(not_null<UserData*> user, TimeId now);
  145. [[nodiscard]] bool IsUserOnline(not_null<UserData*> user, TimeId now = 0);
  146. [[nodiscard]] bool ChannelHasActiveCall(not_null<ChannelData*> channel);
  147. [[nodiscard]] bool ChannelHasSubscriptionUntilDate(ChannelData *channel);
  148. [[nodiscard]] rpl::producer<QImage> PeerUserpicImageValue(
  149. not_null<PeerData*> peer,
  150. int size,
  151. std::optional<int> radius = {});
  152. [[nodiscard]] const AllowedReactions &PeerAllowedReactions(
  153. not_null<PeerData*> peer);
  154. [[nodiscard]] rpl::producer<AllowedReactions> PeerAllowedReactionsValue(
  155. not_null<PeerData*> peer);
  156. [[nodiscard]] int UniqueReactionsLimit(not_null<PeerData*> peer);
  157. [[nodiscard]] rpl::producer<int> UniqueReactionsLimitValue(
  158. not_null<PeerData*> peer);
  159. } // namespace Data