history_view_message.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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 "history/view/history_view_element.h"
  9. #include "history/view/history_view_bottom_info.h"
  10. #include "ui/effects/animations.h"
  11. class HistoryItem;
  12. struct HistoryMessageEdited;
  13. struct HistoryMessageForwarded;
  14. struct HistoryMessageReplyMarkup;
  15. namespace Data {
  16. struct ReactionId;
  17. } // namespace Data
  18. namespace Ui {
  19. struct BubbleRounding;
  20. class RoundCheckbox;
  21. } // namespace Ui
  22. namespace HistoryView {
  23. class ViewButton;
  24. class WebPage;
  25. namespace Reactions {
  26. class InlineList;
  27. } // namespace Reactions
  28. // Special type of Component for the channel actions log.
  29. struct LogEntryOriginal
  30. : public RuntimeComponent<LogEntryOriginal, Element> {
  31. LogEntryOriginal();
  32. LogEntryOriginal(LogEntryOriginal &&other);
  33. LogEntryOriginal &operator=(LogEntryOriginal &&other);
  34. ~LogEntryOriginal();
  35. std::unique_ptr<WebPage> page;
  36. };
  37. struct Factcheck
  38. : public RuntimeComponent<Factcheck, Element> {
  39. std::unique_ptr<WebPage> page;
  40. bool expanded = false;
  41. };
  42. struct PsaTooltipState : public RuntimeComponent<PsaTooltipState, Element> {
  43. QString type;
  44. mutable ClickHandlerPtr link;
  45. mutable Ui::Animations::Simple buttonVisibleAnimation;
  46. mutable bool buttonVisible = true;
  47. };
  48. struct BottomRippleMask {
  49. QImage image;
  50. int shift = 0;
  51. };
  52. class Message final : public Element {
  53. public:
  54. Message(
  55. not_null<ElementDelegate*> delegate,
  56. not_null<HistoryItem*> data,
  57. Element *replacing);
  58. ~Message();
  59. void clickHandlerPressedChanged(
  60. const ClickHandlerPtr &handler,
  61. bool pressed) override;
  62. [[nodiscard]] const HistoryMessageEdited *displayedEditBadge() const;
  63. [[nodiscard]] HistoryMessageEdited *displayedEditBadge();
  64. bool embedReactionsInBubble() const override;
  65. int marginTop() const override;
  66. int marginBottom() const override;
  67. void draw(Painter &p, const PaintContext &context) const override;
  68. PointState pointState(QPoint point) const override;
  69. TextState textState(
  70. QPoint point,
  71. StateRequest request) const override;
  72. void updatePressed(QPoint point) override;
  73. void drawInfo(
  74. Painter &p,
  75. const PaintContext &context,
  76. int right,
  77. int bottom,
  78. int width,
  79. InfoDisplayType type) const override;
  80. TextState bottomInfoTextState(
  81. int right,
  82. int bottom,
  83. QPoint point,
  84. InfoDisplayType type) const override;
  85. TextForMimeData selectedText(TextSelection selection) const override;
  86. SelectedQuote selectedQuote(TextSelection selection) const override;
  87. TextSelection selectionFromQuote(
  88. const SelectedQuote &quote) const override;
  89. TextSelection adjustSelection(
  90. TextSelection selection,
  91. TextSelectType type) const override;
  92. Reactions::ButtonParameters reactionButtonParameters(
  93. QPoint position,
  94. const TextState &reactionState) const override;
  95. int reactionsOptimalWidth() const override;
  96. bool hasHeavyPart() const override;
  97. void unloadHeavyPart() override;
  98. // hasFromPhoto() returns true even if we don't display the photo
  99. // but we need to skip a place at the left side for this photo
  100. bool hasFromPhoto() const override;
  101. bool displayFromPhoto() const override;
  102. bool hasFromName() const override;
  103. bool displayFromName() const override;
  104. bool displayForwardedFrom() const override;
  105. bool hasOutLayout() const override;
  106. bool drawBubble() const override;
  107. bool hasBubble() const override;
  108. TopicButton *displayedTopicButton() const override;
  109. bool unwrapped() const override;
  110. int minWidthForMedia() const override;
  111. bool displayRightActionComments() const;
  112. std::optional<QSize> rightActionSize() const override;
  113. void drawRightAction(
  114. Painter &p,
  115. const PaintContext &context,
  116. int left,
  117. int top,
  118. int outerWidth) const override;
  119. [[nodiscard]] ClickHandlerPtr rightActionLink(
  120. std::optional<QPoint> pressPoint) const override;
  121. [[nodiscard]] TimeId displayedEditDate() const override;
  122. [[nodiscard]] bool toggleSelectionByHandlerClick(
  123. const ClickHandlerPtr &handler) const override;
  124. [[nodiscard]] bool allowTextSelectionByHandler(
  125. const ClickHandlerPtr &handler) const override;
  126. [[nodiscard]] int infoWidth() const override;
  127. [[nodiscard]] int bottomInfoFirstLineWidth() const override;
  128. [[nodiscard]] bool bottomInfoIsWide() const override;
  129. [[nodiscard]] bool isSignedAuthorElided() const override;
  130. void itemDataChanged() override;
  131. VerticalRepaintRange verticalRepaintRange() const override;
  132. void applyGroupAdminChanges(
  133. const base::flat_set<UserId> &changes) override;
  134. void animateReaction(Ui::ReactionFlyAnimationArgs &&args) override;
  135. void animateEffect(Ui::ReactionFlyAnimationArgs &&args) override;
  136. auto takeEffectAnimation()
  137. -> std::unique_ptr<Ui::ReactionFlyAnimation> override;
  138. QRect effectIconGeometry() const override;
  139. QRect innerGeometry() const override;
  140. [[nodiscard]] BottomRippleMask bottomRippleMask(int buttonHeight) const;
  141. protected:
  142. void refreshDataIdHook() override;
  143. private:
  144. struct CommentsButton;
  145. struct FromNameStatus;
  146. struct RightAction;
  147. bool updateBottomInfo();
  148. void initPaidInformation();
  149. void initLogEntryOriginal();
  150. void initPsa();
  151. void fromNameUpdated(int width) const;
  152. [[nodiscard]] TextSelection skipTextSelection(
  153. TextSelection selection) const;
  154. [[nodiscard]] TextSelection unskipTextSelection(
  155. TextSelection selection) const;
  156. void toggleCommentsButtonRipple(bool pressed);
  157. void createCommentsButtonRipple();
  158. void toggleTopicButtonRipple(bool pressed);
  159. void createTopicButtonRipple();
  160. void toggleRightActionRipple(bool pressed);
  161. void toggleReplyRipple(bool pressed);
  162. void paintCommentsButton(
  163. Painter &p,
  164. QRect &g,
  165. const PaintContext &context) const;
  166. void paintFromName(
  167. Painter &p,
  168. QRect &trect,
  169. const PaintContext &context) const;
  170. void paintTopicButton(
  171. Painter &p,
  172. QRect &trect,
  173. const PaintContext &context) const;
  174. void paintForwardedInfo(
  175. Painter &p,
  176. QRect &trect,
  177. const PaintContext &context) const;
  178. void paintReplyInfo(
  179. Painter &p,
  180. QRect &trect,
  181. const PaintContext &context) const;
  182. // This method draws "via @bot" if it is not painted
  183. // in forwarded info or in from name.
  184. void paintViaBotIdInfo(
  185. Painter &p,
  186. QRect &trect,
  187. const PaintContext &context) const;
  188. void paintText(
  189. Painter &p,
  190. QRect &trect,
  191. const PaintContext &context) const;
  192. bool getStateCommentsButton(
  193. QPoint point,
  194. QRect &g,
  195. not_null<TextState*> outResult) const;
  196. bool getStateFromName(
  197. QPoint point,
  198. QRect &trect,
  199. not_null<TextState*> outResult) const;
  200. bool getStateTopicButton(
  201. QPoint point,
  202. QRect &trect,
  203. not_null<TextState*> outResult) const;
  204. bool getStateForwardedInfo(
  205. QPoint point,
  206. QRect &trect,
  207. not_null<TextState*> outResult,
  208. StateRequest request) const;
  209. bool getStateReplyInfo(
  210. QPoint point,
  211. QRect &trect,
  212. not_null<TextState*> outResult) const;
  213. bool getStateViaBotIdInfo(
  214. QPoint point,
  215. QRect &trect,
  216. not_null<TextState*> outResult) const;
  217. bool getStateText(
  218. QPoint point,
  219. QRect &trect,
  220. not_null<TextState*> outResult,
  221. StateRequest request) const;
  222. void updateMediaInBubbleState();
  223. QRect countGeometry() const;
  224. [[nodiscard]] Ui::BubbleRounding countMessageRounding() const;
  225. [[nodiscard]] Ui::BubbleRounding countBubbleRounding(
  226. Ui::BubbleRounding messageRounding) const;
  227. [[nodiscard]] Ui::BubbleRounding countBubbleRounding() const;
  228. int resizeContentGetHeight(int newWidth);
  229. QSize performCountOptimalSize() override;
  230. QSize performCountCurrentSize(int newWidth) override;
  231. bool hasVisibleText() const override;
  232. [[nodiscard]] int visibleTextLength() const;
  233. [[nodiscard]] int visibleMediaTextLength() const;
  234. [[nodiscard]] bool needInfoDisplay() const;
  235. [[nodiscard]] bool invertMedia() const;
  236. [[nodiscard]] bool hasFastReply() const;
  237. [[nodiscard]] bool hasFastForward() const;
  238. [[nodiscard]] bool displayFastReply() const;
  239. [[nodiscard]] bool displayFastForward() const;
  240. [[nodiscard]] bool isPinnedContext() const;
  241. [[nodiscard]] bool displayFastShare() const;
  242. [[nodiscard]] bool displayGoToOriginal() const;
  243. [[nodiscard]] ClickHandlerPtr fastReplyLink() const;
  244. [[nodiscard]] ClickHandlerPtr prepareRightActionLink() const;
  245. void ensureRightAction() const;
  246. void refreshTopicButton();
  247. void refreshInfoSkipBlock(HistoryItem *textItem);
  248. [[nodiscard]] int monospaceMaxWidth() const;
  249. void validateInlineKeyboard(HistoryMessageReplyMarkup *markup);
  250. void updateViewButtonExistence();
  251. [[nodiscard]] int viewButtonHeight() const;
  252. [[nodiscard]] WebPage *logEntryOriginal() const;
  253. [[nodiscard]] WebPage *factcheckBlock() const;
  254. [[nodiscard]] ClickHandlerPtr createGoToCommentsLink() const;
  255. [[nodiscard]] ClickHandlerPtr psaTooltipLink() const;
  256. void psaTooltipToggled(bool shown) const;
  257. void refreshRightBadge();
  258. void validateFromNameText(PeerData *from) const;
  259. void ensureFromNameStatusLink(not_null<PeerData*> peer) const;
  260. mutable std::unique_ptr<RightAction> _rightAction;
  261. mutable ClickHandlerPtr _fastReplyLink;
  262. mutable std::unique_ptr<ViewButton> _viewButton;
  263. std::unique_ptr<TopicButton> _topicButton;
  264. mutable std::unique_ptr<CommentsButton> _comments;
  265. mutable Ui::Text::String _fromName;
  266. mutable std::unique_ptr<FromNameStatus> _fromNameStatus;
  267. mutable std::unique_ptr<Ui::RoundCheckbox> _selectionRoundCheckbox;
  268. Ui::Text::String _rightBadge;
  269. mutable int _fromNameVersion = 0;
  270. uint32 _bubbleWidthLimit : 28 = 0;
  271. uint32 _invertMedia : 1 = 0;
  272. uint32 _hideReply : 1 = 0;
  273. uint32 _rightBadgeHasBoosts : 1 = 0;
  274. uint32 _postShowingAuthor : 1 = 0;
  275. BottomInfo _bottomInfo;
  276. };
  277. } // namespace HistoryView