data_chat_participant_status.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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 ChatHelpers {
  9. class Show;
  10. } // namespace ChatHelpers
  11. namespace Ui {
  12. struct PreparedList;
  13. struct PreparedFile;
  14. } // namespace Ui
  15. namespace Window {
  16. class SessionNavigation;
  17. } // namespace Window
  18. enum class ChatAdminRight {
  19. ChangeInfo = (1 << 0),
  20. PostMessages = (1 << 1),
  21. EditMessages = (1 << 2),
  22. DeleteMessages = (1 << 3),
  23. BanUsers = (1 << 4),
  24. InviteByLinkOrAdd = (1 << 5),
  25. PinMessages = (1 << 7),
  26. AddAdmins = (1 << 9),
  27. Anonymous = (1 << 10),
  28. ManageCall = (1 << 11),
  29. Other = (1 << 12),
  30. ManageTopics = (1 << 13),
  31. PostStories = (1 << 14),
  32. EditStories = (1 << 15),
  33. DeleteStories = (1 << 16),
  34. };
  35. inline constexpr bool is_flag_type(ChatAdminRight) { return true; }
  36. using ChatAdminRights = base::flags<ChatAdminRight>;
  37. enum class ChatRestriction {
  38. ViewMessages = (1 << 0),
  39. SendStickers = (1 << 3),
  40. SendGifs = (1 << 4),
  41. SendGames = (1 << 5),
  42. SendInline = (1 << 6),
  43. SendPolls = (1 << 8),
  44. SendPhotos = (1 << 19),
  45. SendVideos = (1 << 20),
  46. SendVideoMessages = (1 << 21),
  47. SendMusic = (1 << 22),
  48. SendVoiceMessages = (1 << 23),
  49. SendFiles = (1 << 24),
  50. SendOther = (1 << 25),
  51. EmbedLinks = (1 << 7),
  52. ChangeInfo = (1 << 10),
  53. AddParticipants = (1 << 15),
  54. PinMessages = (1 << 17),
  55. CreateTopics = (1 << 18),
  56. };
  57. inline constexpr bool is_flag_type(ChatRestriction) { return true; }
  58. using ChatRestrictions = base::flags<ChatRestriction>;
  59. struct ChatAdminRightsInfo {
  60. ChatAdminRightsInfo() = default;
  61. explicit ChatAdminRightsInfo(ChatAdminRights flags) : flags(flags) {
  62. }
  63. explicit ChatAdminRightsInfo(const MTPChatAdminRights &rights);
  64. ChatAdminRights flags;
  65. };
  66. struct ChatRestrictionsInfo {
  67. ChatRestrictionsInfo() = default;
  68. ChatRestrictionsInfo(ChatRestrictions flags, TimeId until)
  69. : flags(flags)
  70. , until(until) {
  71. }
  72. explicit ChatRestrictionsInfo(const MTPChatBannedRights &rights);
  73. ChatRestrictions flags;
  74. TimeId until = 0;
  75. };
  76. namespace Data {
  77. class Thread;
  78. struct AdminRightsSetOptions {
  79. bool isGroup : 1 = false;
  80. bool isForum : 1 = false;
  81. bool anyoneCanAddMembers : 1 = false;
  82. };
  83. struct RestrictionsSetOptions {
  84. bool isForum = false;
  85. };
  86. [[nodiscard]] std::vector<ChatRestrictions> ListOfRestrictions(
  87. RestrictionsSetOptions options);
  88. [[nodiscard]] inline constexpr auto AllSendRestrictionsList() {
  89. return std::array{
  90. ChatRestriction::SendOther,
  91. ChatRestriction::SendStickers,
  92. ChatRestriction::SendGifs,
  93. ChatRestriction::SendGames,
  94. ChatRestriction::SendInline,
  95. ChatRestriction::SendPolls,
  96. ChatRestriction::SendPhotos,
  97. ChatRestriction::SendVideos,
  98. ChatRestriction::SendVideoMessages,
  99. ChatRestriction::SendMusic,
  100. ChatRestriction::SendVoiceMessages,
  101. ChatRestriction::SendFiles,
  102. };
  103. }
  104. [[nodiscard]] inline constexpr auto FilesSendRestrictionsList() {
  105. return std::array{
  106. ChatRestriction::SendStickers,
  107. ChatRestriction::SendGifs,
  108. ChatRestriction::SendPhotos,
  109. ChatRestriction::SendVideos,
  110. ChatRestriction::SendMusic,
  111. ChatRestriction::SendFiles,
  112. };
  113. }
  114. [[nodiscard]] inline constexpr auto TabbedPanelSendRestrictionsList() {
  115. return std::array{
  116. ChatRestriction::SendStickers,
  117. ChatRestriction::SendGifs,
  118. ChatRestriction::SendOther,
  119. };
  120. }
  121. [[nodiscard]] ChatRestrictions AllSendRestrictions();
  122. [[nodiscard]] ChatRestrictions FilesSendRestrictions();
  123. [[nodiscard]] ChatRestrictions TabbedPanelSendRestrictions();
  124. [[nodiscard]] bool CanSendAnyOf(
  125. not_null<const Thread*> thread,
  126. ChatRestrictions rights,
  127. bool forbidInForums = true);
  128. [[nodiscard]] bool CanSendAnyOf(
  129. not_null<const PeerData*> peer,
  130. ChatRestrictions rights,
  131. bool forbidInForums = true);
  132. [[nodiscard]] inline bool CanSend(
  133. not_null<const Thread*> thread,
  134. ChatRestriction right,
  135. bool forbidInForums = true) {
  136. return CanSendAnyOf(thread, right, forbidInForums);
  137. }
  138. [[nodiscard]] inline bool CanSend(
  139. not_null<const PeerData*> peer,
  140. ChatRestriction right,
  141. bool forbidInForums = true) {
  142. return CanSendAnyOf(peer, right, forbidInForums);
  143. }
  144. [[nodiscard]] inline bool CanSendTexts(
  145. not_null<const Thread*> thread,
  146. bool forbidInForums = true) {
  147. return CanSend(thread, ChatRestriction::SendOther, forbidInForums);
  148. }
  149. [[nodiscard]] inline bool CanSendTexts(
  150. not_null<const PeerData*> peer,
  151. bool forbidInForums = true) {
  152. return CanSend(peer, ChatRestriction::SendOther, forbidInForums);
  153. }
  154. [[nodiscard]] inline bool CanSendAnything(
  155. not_null<const Thread*> thread,
  156. bool forbidInForums = true) {
  157. return CanSendAnyOf(thread, AllSendRestrictions(), forbidInForums);
  158. }
  159. [[nodiscard]] inline bool CanSendAnything(
  160. not_null<const PeerData*> peer,
  161. bool forbidInForums = true) {
  162. return CanSendAnyOf(peer, AllSendRestrictions(), forbidInForums);
  163. }
  164. struct SendError {
  165. SendError(QString text = QString()) : text(std::move(text)) {
  166. }
  167. struct Args {
  168. QString text;
  169. int boostsToLift = 0;
  170. bool premiumToLift = false;
  171. };
  172. SendError(Args &&args)
  173. : text(std::move(args.text))
  174. , boostsToLift(args.boostsToLift)
  175. , premiumToLift(args.premiumToLift) {
  176. }
  177. QString text;
  178. int boostsToLift = 0;
  179. bool premiumToLift = false;
  180. [[nodiscard]] SendError value_or(SendError other) const {
  181. return *this ? *this : other;
  182. }
  183. explicit operator bool() const {
  184. return !text.isEmpty();
  185. }
  186. [[nodiscard]] bool has_value() const {
  187. return !text.isEmpty();
  188. }
  189. [[nodiscard]] const QString &operator*() const {
  190. return text;
  191. }
  192. };
  193. struct SendErrorWithThread {
  194. SendError error;
  195. Thread *thread = nullptr;
  196. };
  197. [[nodiscard]] SendError RestrictionError(
  198. not_null<PeerData*> peer,
  199. ChatRestriction restriction);
  200. [[nodiscard]] SendError AnyFileRestrictionError(not_null<PeerData*> peer);
  201. [[nodiscard]] SendError FileRestrictionError(
  202. not_null<PeerData*> peer,
  203. const Ui::PreparedList &list,
  204. std::optional<bool> compress);
  205. [[nodiscard]] SendError FileRestrictionError(
  206. not_null<PeerData*> peer,
  207. const Ui::PreparedFile &file,
  208. std::optional<bool> compress);
  209. void ShowSendErrorToast(
  210. not_null<Window::SessionNavigation*> navigation,
  211. not_null<PeerData*> peer,
  212. SendError error);
  213. void ShowSendErrorToast(
  214. std::shared_ptr<ChatHelpers::Show> show,
  215. not_null<PeerData*> peer,
  216. SendError error);
  217. } // namespace Data