history_item_helpers.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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 "base/object_ptr.h"
  9. class History;
  10. namespace style {
  11. struct FlatLabel;
  12. struct Checkbox;
  13. } // namespace style
  14. namespace Api {
  15. struct SendOptions;
  16. struct SendAction;
  17. } // namespace Api
  18. namespace ChatHelpers {
  19. class Show;
  20. } // namespace ChatHelpers
  21. namespace Data {
  22. class Story;
  23. class Thread;
  24. struct SendError;
  25. struct SendErrorWithThread;
  26. } // namespace Data
  27. namespace Main {
  28. class Session;
  29. class SessionShow;
  30. } // namespace Main
  31. namespace Ui {
  32. class BoxContent;
  33. } // namespace Ui
  34. namespace Window {
  35. class SessionNavigation;
  36. } // namespace Window
  37. struct PreparedServiceText {
  38. TextWithEntities text;
  39. std::vector<ClickHandlerPtr> links;
  40. };
  41. [[nodiscard]] MessageFlags FlagsFromMTP(
  42. MsgId id,
  43. MTPDmessage::Flags flags,
  44. MessageFlags localFlags);
  45. [[nodiscard]] MessageFlags FlagsFromMTP(
  46. MsgId id,
  47. MTPDmessageService::Flags flags,
  48. MessageFlags localFlags);
  49. [[nodiscard]] MTPMessageReplyHeader NewMessageReplyHeader(
  50. const Api::SendAction &action);
  51. enum class MediaCheckResult {
  52. Good,
  53. Unsupported,
  54. Empty,
  55. HasExpiredMediaTimeToLive,
  56. HasUnsupportedTimeToLive,
  57. HasStoryMention,
  58. };
  59. [[nodiscard]] MediaCheckResult CheckMessageMedia(
  60. const MTPMessageMedia &media);
  61. [[nodiscard]] CallId CallIdFromInput(const MTPInputGroupCall &data);
  62. [[nodiscard]] std::vector<not_null<UserData*>> ParseInvitedToCallUsers(
  63. not_null<HistoryItem*> item,
  64. const QVector<MTPlong> &users);
  65. inline constexpr auto kMaxUnreadReactions = 5; // Now 3, but just in case.
  66. using OnStackUsers = std::array<UserData*, kMaxUnreadReactions>;
  67. [[nodiscard]] OnStackUsers LookupRecentUnreadReactedUsers(
  68. not_null<HistoryItem*> item);
  69. void CheckReactionNotificationSchedule(
  70. not_null<HistoryItem*> item,
  71. const OnStackUsers &wasUsers);
  72. [[nodiscard]] MessageFlags NewForwardedFlags(
  73. not_null<PeerData*> peer,
  74. PeerId from,
  75. not_null<HistoryItem*> fwd);
  76. [[nodiscard]] MessageFlags FinalizeMessageFlags(
  77. not_null<History*> history,
  78. MessageFlags flags);
  79. [[nodiscard]] bool CopyMarkupToForward(not_null<const HistoryItem*> item);
  80. [[nodiscard]] TextWithEntities EnsureNonEmpty(
  81. const TextWithEntities &text = TextWithEntities());
  82. [[nodiscard]] TextWithEntities UnsupportedMessageText();
  83. void RequestDependentMessageItem(
  84. not_null<HistoryItem*> item,
  85. PeerId peerId,
  86. MsgId msgId);
  87. void RequestDependentMessageStory(
  88. not_null<HistoryItem*> item,
  89. PeerId peerId,
  90. StoryId storyId);
  91. [[nodiscard]] MessageFlags NewMessageFlags(not_null<PeerData*> peer);
  92. [[nodiscard]] TimeId NewMessageDate(TimeId scheduled);
  93. [[nodiscard]] TimeId NewMessageDate(const Api::SendOptions &options);
  94. [[nodiscard]] PeerId NewMessageFromId(const Api::SendAction &action);
  95. [[nodiscard]] QString NewMessagePostAuthor(const Api::SendAction &action);
  96. [[nodiscard]] bool ShouldSendSilent(
  97. not_null<PeerData*> peer,
  98. const Api::SendOptions &options);
  99. [[nodiscard]] HistoryItem *LookupReplyTo(
  100. not_null<History*> history,
  101. FullMsgId replyToId);
  102. [[nodiscard]] MsgId LookupReplyToTop(
  103. not_null<History*> history,
  104. HistoryItem *replyTo);
  105. [[nodiscard]] MsgId LookupReplyToTop(
  106. not_null<History*> history,
  107. FullReplyTo replyTo);
  108. [[nodiscard]] bool LookupReplyIsTopicPost(HistoryItem *replyTo);
  109. struct SendingErrorRequest {
  110. MsgId topicRootId = 0;
  111. const HistoryItemsList *forward = nullptr;
  112. const Data::Story *story = nullptr;
  113. const TextWithTags *text = nullptr;
  114. int messagesCount = 0;
  115. bool ignoreSlowmodeCountdown = false;
  116. };
  117. [[nodiscard]] int ComputeSendingMessagesCount(
  118. not_null<History*> history,
  119. const SendingErrorRequest &request);
  120. [[nodiscard]] Data::SendError GetErrorForSending(
  121. not_null<PeerData*> peer,
  122. SendingErrorRequest request);
  123. [[nodiscard]] Data::SendError GetErrorForSending(
  124. not_null<Data::Thread*> thread,
  125. SendingErrorRequest request);
  126. struct SendPaymentDetails {
  127. int messages = 0;
  128. int stars = 0;
  129. };
  130. [[nodiscard]] std::optional<SendPaymentDetails> ComputePaymentDetails(
  131. not_null<PeerData*> peer,
  132. int messagesCount);
  133. struct PaidConfirmStyles {
  134. const style::FlatLabel *label = nullptr;
  135. const style::Checkbox *checkbox = nullptr;
  136. };
  137. void ShowSendPaidConfirm(
  138. not_null<Window::SessionNavigation*> navigation,
  139. not_null<PeerData*> peer,
  140. SendPaymentDetails details,
  141. Fn<void()> confirmed,
  142. PaidConfirmStyles styles = {});
  143. void ShowSendPaidConfirm(
  144. std::shared_ptr<Main::SessionShow> show,
  145. not_null<PeerData*> peer,
  146. SendPaymentDetails details,
  147. Fn<void()> confirmed,
  148. PaidConfirmStyles styles = {});
  149. void ShowSendPaidConfirm(
  150. std::shared_ptr<Main::SessionShow> show,
  151. const std::vector<not_null<PeerData*>> &peers,
  152. SendPaymentDetails details,
  153. Fn<void()> confirmed,
  154. PaidConfirmStyles styles = {});
  155. class SendPaymentHelper final {
  156. public:
  157. [[nodiscard]] bool check(
  158. not_null<Window::SessionNavigation*> navigation,
  159. not_null<PeerData*> peer,
  160. int messagesCount,
  161. int starsApproved,
  162. Fn<void(int)> resend,
  163. PaidConfirmStyles styles = {});
  164. [[nodiscard]] bool check(
  165. std::shared_ptr<Main::SessionShow> show,
  166. not_null<PeerData*> peer,
  167. int messagesCount,
  168. int starsApproved,
  169. Fn<void(int)> resend,
  170. PaidConfirmStyles styles = {});
  171. void clear();
  172. private:
  173. Fn<void()> _resend;
  174. rpl::lifetime _lifetime;
  175. };
  176. [[nodiscard]] Data::SendErrorWithThread GetErrorForSending(
  177. const std::vector<not_null<Data::Thread*>> &threads,
  178. SendingErrorRequest request);
  179. [[nodiscard]] object_ptr<Ui::BoxContent> MakeSendErrorBox(
  180. const Data::SendErrorWithThread &error,
  181. bool withTitle);
  182. [[nodiscard]] TextWithEntities DropDisallowedCustomEmoji(
  183. not_null<PeerData*> to,
  184. TextWithEntities text);
  185. [[nodiscard]] Main::Session *SessionByUniqueId(uint64 sessionUniqueId);
  186. [[nodiscard]] HistoryItem *MessageByGlobalId(GlobalMsgId globalId);
  187. [[nodiscard]] QDateTime ItemDateTime(not_null<const HistoryItem*> item);
  188. [[nodiscard]] QString ItemDateText(
  189. not_null<const HistoryItem*> item,
  190. bool isUntilOnline);
  191. [[nodiscard]] bool IsItemScheduledUntilOnline(
  192. not_null<const HistoryItem*> item);
  193. [[nodiscard]] ClickHandlerPtr JumpToMessageClickHandler(
  194. not_null<PeerData*> peer,
  195. MsgId msgId,
  196. FullMsgId returnToId = FullMsgId(),
  197. TextWithEntities highlightPart = {},
  198. int highlightPartOffsetHint = 0);
  199. [[nodiscard]] ClickHandlerPtr JumpToMessageClickHandler(
  200. not_null<HistoryItem*> item,
  201. FullMsgId returnToId = FullMsgId(),
  202. TextWithEntities highlightPart = {},
  203. int highlightPartOffsetHint = 0);
  204. [[nodiscard]] ClickHandlerPtr JumpToStoryClickHandler(
  205. not_null<Data::Story*> story);
  206. ClickHandlerPtr JumpToStoryClickHandler(
  207. not_null<PeerData*> peer,
  208. StoryId storyId);
  209. [[nodiscard]] ClickHandlerPtr HideSponsoredClickHandler();
  210. [[nodiscard]] ClickHandlerPtr ReportSponsoredClickHandler(
  211. not_null<HistoryItem*> item);
  212. [[nodiscard]] ClickHandlerPtr AboutSponsoredClickHandler();
  213. [[nodiscard]] not_null<HistoryItem*> GenerateJoinedMessage(
  214. not_null<History*> history,
  215. TimeId inviteDate,
  216. not_null<UserData*> inviter,
  217. bool viaRequest);
  218. [[nodiscard]] std::optional<bool> PeerHasThisCall(
  219. not_null<PeerData*> peer,
  220. CallId id);
  221. [[nodiscard]] rpl::producer<bool> PeerHasThisCallValue(
  222. not_null<PeerData*> peer,
  223. CallId id);
  224. [[nodiscard]] ClickHandlerPtr GroupCallClickHandler(
  225. not_null<PeerData*> peer,
  226. CallId callId);
  227. void ShowTrialTranscribesToast(int left, TimeId until);
  228. void ClearMediaAsExpired(not_null<HistoryItem*> item);
  229. [[nodiscard]] int ItemsForwardSendersCount(const HistoryItemsList &list);
  230. [[nodiscard]] int ItemsForwardCaptionsCount(const HistoryItemsList &list);