history_item.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  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/runtime_composer.h"
  9. #include "data/data_media_types.h"
  10. #include "history/history_item_edition.h"
  11. #include <any>
  12. class HiddenSenderInfo;
  13. class History;
  14. struct HistoryMessageReply;
  15. struct HistoryMessageViews;
  16. struct HistoryMessageMarkupData;
  17. struct HistoryMessageReplyMarkup;
  18. struct HistoryMessageTranslation;
  19. struct HistoryMessageForwarded;
  20. struct HistoryMessageSavedMediaData;
  21. struct HistoryMessageFactcheck;
  22. struct HistoryServiceDependentData;
  23. enum class HistorySelfDestructType;
  24. struct PreparedServiceText;
  25. struct MessageFactcheck;
  26. class ReplyKeyboard;
  27. struct LanguageId;
  28. namespace Api {
  29. struct SendOptions;
  30. } // namespace Api
  31. namespace base {
  32. template <typename Enum>
  33. class enum_mask;
  34. } // namespace base
  35. namespace Storage {
  36. enum class SharedMediaType : signed char;
  37. using SharedMediaTypesMask = base::enum_mask<SharedMediaType>;
  38. } // namespace Storage
  39. namespace Ui {
  40. class RippleAnimation;
  41. } // namespace Ui
  42. namespace style {
  43. struct BotKeyboardButton;
  44. struct RippleAnimation;
  45. } // namespace style
  46. namespace Data {
  47. struct MessagePosition;
  48. struct RecentReaction;
  49. struct MessageReactionsTopPaid;
  50. struct ReactionId;
  51. class Media;
  52. struct MessageReaction;
  53. class MessageReactions;
  54. class ForumTopic;
  55. class Thread;
  56. struct SponsoredFrom;
  57. class Story;
  58. class SavedSublist;
  59. struct PaidReactionSend;
  60. struct SendError;
  61. } // namespace Data
  62. namespace Main {
  63. class Session;
  64. } // namespace Main
  65. namespace Window {
  66. class SessionController;
  67. } // namespace Window
  68. namespace HistoryUnreadThings {
  69. enum class AddType;
  70. } // namespace HistoryUnreadThings
  71. namespace HistoryView {
  72. struct TextState;
  73. struct StateRequest;
  74. enum class CursorState : char;
  75. enum class PointState : char;
  76. enum class Context : char;
  77. class ElementDelegate;
  78. class Element;
  79. class Message;
  80. class Service;
  81. class ServiceMessagePainter;
  82. } // namespace HistoryView
  83. struct HistoryItemCommonFields {
  84. MsgId id = 0;
  85. MessageFlags flags = 0;
  86. PeerId from = 0;
  87. FullReplyTo replyTo;
  88. TimeId date = 0;
  89. BusinessShortcutId shortcutId = 0;
  90. int starsPaid = 0;
  91. UserId viaBotId = 0;
  92. QString postAuthor;
  93. uint64 groupedId = 0;
  94. EffectId effectId = 0;
  95. HistoryMessageMarkupData markup;
  96. bool ignoreForwardFrom = false;
  97. bool ignoreForwardCaptions = false;
  98. };
  99. enum class HistoryReactionSource : char {
  100. Selector,
  101. Quick,
  102. Existing,
  103. };
  104. class HistoryItem final : public RuntimeComposer<HistoryItem> {
  105. public:
  106. [[nodiscard]] static std::unique_ptr<Data::Media> CreateMedia(
  107. not_null<HistoryItem*> item,
  108. const MTPMessageMedia &media);
  109. HistoryItem(
  110. not_null<History*> history,
  111. MsgId id,
  112. const MTPDmessage &data,
  113. MessageFlags localFlags);
  114. HistoryItem(
  115. not_null<History*> history,
  116. MsgId id,
  117. const MTPDmessageService &data,
  118. MessageFlags localFlags);
  119. HistoryItem(
  120. not_null<History*> history,
  121. MsgId id,
  122. const MTPDmessageEmpty &data,
  123. MessageFlags localFlags);
  124. HistoryItem( // Sponsored message.
  125. not_null<History*> history,
  126. MsgId id,
  127. Data::SponsoredFrom from,
  128. const TextWithEntities &textWithEntities,
  129. HistoryItem *injectedAfter);
  130. HistoryItem( // Story wrap.
  131. not_null<History*> history,
  132. MsgId id,
  133. not_null<Data::Story*> story);
  134. HistoryItem( // Local message.
  135. not_null<History*> history,
  136. HistoryItemCommonFields &&fields,
  137. const TextWithEntities &textWithEntities,
  138. const MTPMessageMedia &media);
  139. HistoryItem( // Local service message.
  140. not_null<History*> history,
  141. HistoryItemCommonFields &&fields,
  142. PreparedServiceText &&message,
  143. PhotoData *photo = nullptr);
  144. HistoryItem( // Local forwarded.
  145. not_null<History*> history,
  146. HistoryItemCommonFields &&fields,
  147. not_null<HistoryItem*> original);
  148. HistoryItem( // Local photo.
  149. not_null<History*> history,
  150. HistoryItemCommonFields &&fields,
  151. not_null<PhotoData*> photo,
  152. const TextWithEntities &caption);
  153. HistoryItem( // Local document.
  154. not_null<History*> history,
  155. HistoryItemCommonFields &&fields,
  156. not_null<DocumentData*> document,
  157. const TextWithEntities &caption);
  158. HistoryItem( // Local game.
  159. not_null<History*> history,
  160. HistoryItemCommonFields &&fields,
  161. not_null<GameData*> game);
  162. ~HistoryItem();
  163. struct Destroyer {
  164. void operator()(HistoryItem *value);
  165. };
  166. void dependencyItemRemoved(not_null<HistoryItem*> dependency);
  167. void dependencyStoryRemoved(not_null<Data::Story*> dependency);
  168. void updateDependencyItem();
  169. [[nodiscard]] MsgId dependencyMsgId() const;
  170. [[nodiscard]] bool notificationReady() const;
  171. [[nodiscard]] PeerData *specialNotificationPeer() const;
  172. void checkStoryForwardInfo();
  173. void checkBuyButton();
  174. void resolveDependent();
  175. void updateServiceText(PreparedServiceText &&text);
  176. void updateStoryMentionText();
  177. [[nodiscard]] UserData *viaBot() const;
  178. [[nodiscard]] UserData *getMessageBot() const;
  179. [[nodiscard]] bool isHistoryEntry() const;
  180. [[nodiscard]] bool isAdminLogEntry() const;
  181. [[nodiscard]] bool isFromScheduled() const;
  182. [[nodiscard]] bool isScheduled() const;
  183. [[nodiscard]] bool isSponsored() const;
  184. [[nodiscard]] bool skipNotification() const;
  185. [[nodiscard]] bool isUserpicSuggestion() const;
  186. [[nodiscard]] BusinessShortcutId shortcutId() const;
  187. [[nodiscard]] bool isBusinessShortcut() const;
  188. void setRealShortcutId(BusinessShortcutId id);
  189. void setCustomServiceLink(ClickHandlerPtr link);
  190. void addLogEntryOriginal(
  191. WebPageId localId,
  192. const QString &label,
  193. const TextWithEntities &content);
  194. void setFactcheck(MessageFactcheck info);
  195. [[nodiscard]] bool hasUnrequestedFactcheck() const;
  196. [[nodiscard]] TextWithEntities factcheckText() const;
  197. [[nodiscard]] not_null<Data::Thread*> notificationThread() const;
  198. [[nodiscard]] not_null<History*> history() const {
  199. return _history;
  200. }
  201. [[nodiscard]] Data::ForumTopic *topic() const;
  202. [[nodiscard]] not_null<PeerData*> from() const {
  203. return _from;
  204. }
  205. [[nodiscard]] HistoryView::Element *mainView() const {
  206. return _mainView;
  207. }
  208. void setMainView(not_null<HistoryView::Element*> view) {
  209. _mainView = view;
  210. }
  211. void refreshMainView();
  212. void clearMainView();
  213. void removeMainView();
  214. void invalidateChatListEntry();
  215. void destroy();
  216. [[nodiscard]] bool out() const {
  217. return _flags & MessageFlag::Outgoing;
  218. }
  219. [[nodiscard]] bool isPinned() const {
  220. return _flags & MessageFlag::Pinned;
  221. }
  222. [[nodiscard]] bool invertMedia() const {
  223. return _flags & MessageFlag::InvertMedia;
  224. }
  225. [[nodiscard]] bool unread(not_null<Data::Thread*> thread) const;
  226. [[nodiscard]] bool showNotification() const;
  227. void markClientSideAsRead();
  228. [[nodiscard]] bool mentionsMe() const;
  229. [[nodiscard]] bool isUnreadMention() const;
  230. [[nodiscard]] bool hasUnreadReaction() const;
  231. [[nodiscard]] bool hasUnwatchedEffect() const;
  232. bool markEffectWatched();
  233. [[nodiscard]] bool isUnreadMedia() const;
  234. [[nodiscard]] bool isIncomingUnreadMedia() const;
  235. [[nodiscard]] bool hasUnreadMediaFlag() const;
  236. void markReactionsRead();
  237. void markMediaAndMentionRead();
  238. bool markContentsRead(bool fromThisClient = false);
  239. void setIsPinned(bool isPinned);
  240. // For edit media in history_message.
  241. void returnSavedMedia();
  242. void savePreviousMedia();
  243. [[nodiscard]] bool isEditingMedia() const;
  244. void clearSavedMedia();
  245. // Zero result means this message is not self-destructing right now.
  246. [[nodiscard]] crl::time getSelfDestructIn(crl::time now);
  247. [[nodiscard]] bool definesReplyKeyboard() const;
  248. [[nodiscard]] ReplyMarkupFlags replyKeyboardFlags() const;
  249. void cacheOnlyEmojiAndSpaces(bool only);
  250. [[nodiscard]] bool isOnlyEmojiAndSpaces() const;
  251. [[nodiscard]] bool hasSwitchInlineButton() const {
  252. return _flags & MessageFlag::HasSwitchInlineButton;
  253. }
  254. [[nodiscard]] bool hasTextLinks() const {
  255. return _flags & MessageFlag::HasTextLinks;
  256. }
  257. [[nodiscard]] bool isGroupEssential() const {
  258. return _flags & MessageFlag::IsGroupEssential;
  259. }
  260. [[nodiscard]] bool isLocalUpdateMedia() const {
  261. return _flags & MessageFlag::IsLocalUpdateMedia;
  262. }
  263. void setIsLocalUpdateMedia(bool flag) {
  264. if (flag) {
  265. _flags |= MessageFlag::IsLocalUpdateMedia;
  266. } else {
  267. _flags &= ~MessageFlag::IsLocalUpdateMedia;
  268. }
  269. }
  270. [[nodiscard]] bool isGroupMigrate() const {
  271. return isGroupEssential() && isEmpty();
  272. }
  273. [[nodiscard]] bool hasViews() const {
  274. return _flags & MessageFlag::HasViews;
  275. }
  276. [[nodiscard]] bool isPost() const {
  277. return _flags & MessageFlag::Post;
  278. }
  279. [[nodiscard]] bool isSilent() const {
  280. return _flags & MessageFlag::Silent;
  281. }
  282. [[nodiscard]] bool isSending() const {
  283. return _flags & MessageFlag::BeingSent;
  284. }
  285. [[nodiscard]] bool hasFailed() const {
  286. return _flags & MessageFlag::SendingFailed;
  287. }
  288. [[nodiscard]] bool hideEditedBadge() const {
  289. return (_flags & MessageFlag::HideEdited);
  290. }
  291. [[nodiscard]] bool hideDisplayDate() const {
  292. return (_flags & MessageFlag::HideDisplayDate);
  293. }
  294. [[nodiscard]] bool isLocal() const {
  295. return _flags & MessageFlag::Local;
  296. }
  297. [[nodiscard]] bool isFakeAboutView() const {
  298. return _flags & MessageFlag::FakeAboutView;
  299. }
  300. [[nodiscard]] bool showSimilarChannels() const {
  301. return _flags & MessageFlag::ShowSimilarChannels;
  302. }
  303. [[nodiscard]] bool hasRealFromId() const;
  304. [[nodiscard]] bool isPostHidingAuthor() const;
  305. [[nodiscard]] bool isPostShowingAuthor() const;
  306. [[nodiscard]] bool isRegular() const;
  307. [[nodiscard]] bool isUploading() const;
  308. void sendFailed();
  309. [[nodiscard]] int viewsCount() const;
  310. [[nodiscard]] int repliesCount() const;
  311. [[nodiscard]] bool repliesAreComments() const;
  312. [[nodiscard]] bool externalReply() const;
  313. [[nodiscard]] bool hasUnpaidContent() const;
  314. [[nodiscard]] bool inHighlightProcess() const;
  315. void highlightProcessDone();
  316. void setCommentsInboxReadTill(MsgId readTillId);
  317. void setCommentsMaxId(MsgId maxId);
  318. void setCommentsPossibleMaxId(MsgId possibleMaxId);
  319. [[nodiscard]] bool areCommentsUnread() const;
  320. [[nodiscard]] FullMsgId commentsItemId() const;
  321. void setCommentsItemId(FullMsgId id);
  322. [[nodiscard]] bool needCheck() const;
  323. [[nodiscard]] bool isService() const;
  324. void applyEdition(HistoryMessageEdition &&edition);
  325. void applyChanges(not_null<Data::Story*> story);
  326. void applyEdition(const MTPDmessageService &message);
  327. void applyEdition(const QVector<MTPMessageExtendedMedia> &media);
  328. void updateForwardedInfo(const MTPMessageFwdHeader *fwd);
  329. void updateSentContent(
  330. const TextWithEntities &textWithEntities,
  331. const MTPMessageMedia *media);
  332. void applySentMessage(const MTPDmessage &data);
  333. void applySentMessage(
  334. const QString &text,
  335. const MTPDupdateShortSentMessage &data,
  336. bool wasAlready);
  337. void updateReactions(const MTPMessageReactions *reactions);
  338. void overrideMedia(std::unique_ptr<Data::Media> media);
  339. void applyEditionToHistoryCleared();
  340. void updateReplyMarkup(HistoryMessageMarkupData &&markup);
  341. void contributeToSlowmode(TimeId realDate = 0);
  342. void addToUnreadThings(HistoryUnreadThings::AddType type);
  343. void destroyHistoryEntry();
  344. [[nodiscard]] Storage::SharedMediaTypesMask sharedMediaTypes() const;
  345. void indexAsNewItem();
  346. void addToSharedMediaIndex();
  347. void addToMessagesIndex();
  348. void removeFromSharedMediaIndex();
  349. struct NotificationTextOptions {
  350. bool spoilerLoginCode = false;
  351. };
  352. [[nodiscard]] QString notificationHeader() const;
  353. [[nodiscard]] TextWithEntities notificationText(
  354. NotificationTextOptions options) const;
  355. [[nodiscard]] TextWithEntities notificationText() const {
  356. return notificationText({});
  357. }
  358. using ToPreviewOptions = HistoryView::ToPreviewOptions;
  359. using ItemPreview = HistoryView::ItemPreview;
  360. // Returns text with link-start and link-end commands for service-color highlighting.
  361. // Example: "[link1-start]You:[link1-end] [link1-start]Photo,[link1-end] caption text"
  362. [[nodiscard]] ItemPreview toPreview(ToPreviewOptions options) const;
  363. [[nodiscard]] TextWithEntities inReplyText() const;
  364. [[nodiscard]] const TextWithEntities &originalText() const;
  365. [[nodiscard]] const TextWithEntities &translatedText() const;
  366. [[nodiscard]] TextWithEntities translatedTextWithLocalEntities() const;
  367. [[nodiscard]] const std::vector<ClickHandlerPtr> &customTextLinks() const;
  368. [[nodiscard]] TextForMimeData clipboardText() const;
  369. bool changeViewsCount(int count);
  370. void setForwardsCount(int count);
  371. void setReplies(HistoryMessageRepliesData &&data);
  372. void clearReplies();
  373. void changeRepliesCount(int delta, PeerId replier);
  374. void setReplyFields(
  375. MsgId replyTo,
  376. MsgId replyToTop,
  377. bool isForumPost);
  378. void setPostAuthor(const QString &author);
  379. void setRealId(MsgId newId);
  380. void incrementReplyToTopCounter();
  381. void applyEffectWatchedOnUnreadKnown();
  382. [[nodiscard]] bool emptyText() const {
  383. return _text.empty();
  384. }
  385. [[nodiscard]] bool canPin() const;
  386. [[nodiscard]] bool canBeEdited() const;
  387. [[nodiscard]] bool canStopPoll() const;
  388. [[nodiscard]] bool forbidsForward() const;
  389. [[nodiscard]] bool forbidsSaving() const;
  390. [[nodiscard]] bool allowsSendNow() const;
  391. [[nodiscard]] bool allowsReschedule() const;
  392. [[nodiscard]] bool allowsForward() const;
  393. [[nodiscard]] bool allowsEdit(TimeId now) const;
  394. [[nodiscard]] bool allowsEditMedia() const;
  395. [[nodiscard]] bool canDelete() const;
  396. [[nodiscard]] bool canDeleteForEveryone(TimeId now) const;
  397. [[nodiscard]] bool suggestReport() const;
  398. [[nodiscard]] bool suggestBanReport() const;
  399. [[nodiscard]] bool suggestDeleteAllReport() const;
  400. [[nodiscard]] ChatRestriction requiredSendRight() const;
  401. [[nodiscard]] bool requiresSendInlineRight() const;
  402. [[nodiscard]] Data::SendError errorTextForForward(
  403. not_null<Data::Thread*> to) const;
  404. [[nodiscard]] const HistoryMessageTranslation *translation() const;
  405. [[nodiscard]] bool translationShowRequiresCheck(LanguageId to) const;
  406. bool translationShowRequiresRequest(LanguageId to);
  407. void translationDone(LanguageId to, TextWithEntities result);
  408. [[nodiscard]] bool canReact() const;
  409. void toggleReaction(
  410. const Data::ReactionId &reaction,
  411. HistoryReactionSource source);
  412. void addPaidReaction(int count, std::optional<PeerId> shownPeer = {});
  413. void cancelScheduledPaidReaction();
  414. [[nodiscard]] Data::PaidReactionSend startPaidReactionSending();
  415. void finishPaidReactionSending(
  416. Data::PaidReactionSend send,
  417. bool success);
  418. void updateReactionsUnknown();
  419. [[nodiscard]] auto reactions() const
  420. -> const std::vector<Data::MessageReaction> &;
  421. [[nodiscard]] auto reactionsWithLocal() const
  422. -> std::vector<Data::MessageReaction>;
  423. [[nodiscard]] auto recentReactions() const
  424. -> const base::flat_map<
  425. Data::ReactionId,
  426. std::vector<Data::RecentReaction>> &;
  427. [[nodiscard]] auto topPaidReactionsWithLocal() const
  428. -> std::vector<Data::MessageReactionsTopPaid>;
  429. [[nodiscard]] int reactionsPaidScheduled() const;
  430. [[nodiscard]] PeerId reactionsLocalShownPeer() const;
  431. [[nodiscard]] bool canViewReactions() const;
  432. [[nodiscard]] std::vector<Data::ReactionId> chosenReactions() const;
  433. [[nodiscard]] Data::ReactionId lookupUnreadReaction(
  434. not_null<UserData*> from) const;
  435. [[nodiscard]] crl::time lastReactionsRefreshTime() const;
  436. [[nodiscard]] bool reactionsAreTags() const;
  437. [[nodiscard]] bool hasDirectLink() const;
  438. [[nodiscard]] bool changesWallPaper() const;
  439. [[nodiscard]] FullMsgId fullId() const;
  440. [[nodiscard]] GlobalMsgId globalId() const;
  441. [[nodiscard]] Data::MessagePosition position() const;
  442. [[nodiscard]] TimeId date() const;
  443. [[nodiscard]] bool awaitingVideoProcessing() const;
  444. [[nodiscard]] Data::Media *media() const {
  445. return _media.get();
  446. }
  447. [[nodiscard]] bool computeDropForwardedInfo() const;
  448. void setText(const TextWithEntities &textWithEntities);
  449. [[nodiscard]] MsgId replyToId() const;
  450. [[nodiscard]] FullMsgId replyToFullId() const;
  451. [[nodiscard]] MsgId replyToTop() const;
  452. [[nodiscard]] MsgId topicRootId() const;
  453. [[nodiscard]] FullStoryId replyToStory() const;
  454. [[nodiscard]] FullReplyTo replyTo() const;
  455. [[nodiscard]] bool inThread(MsgId rootId) const;
  456. [[nodiscard]] not_null<PeerData*> author() const;
  457. [[nodiscard]] TimeId originalDate() const;
  458. [[nodiscard]] PeerData *originalSender() const;
  459. [[nodiscard]] const HiddenSenderInfo *originalHiddenSenderInfo() const;
  460. [[nodiscard]] not_null<PeerData*> fromOriginal() const;
  461. [[nodiscard]] QString originalPostAuthor() const;
  462. [[nodiscard]] MsgId originalId() const;
  463. [[nodiscard]] Data::SavedSublist *savedSublist() const;
  464. [[nodiscard]] PeerData *savedSublistPeer() const;
  465. [[nodiscard]] PeerData *savedFromSender() const;
  466. [[nodiscard]] const HiddenSenderInfo *savedFromHiddenSenderInfo() const;
  467. [[nodiscard]] const HiddenSenderInfo *displayHiddenSenderInfo() const;
  468. [[nodiscard]] bool showForwardsFromSender(
  469. not_null<const HistoryMessageForwarded*> forwarded) const;
  470. [[nodiscard]] bool isEmpty() const;
  471. [[nodiscard]] MessageGroupId groupId() const;
  472. [[nodiscard]] EffectId effectId() const;
  473. [[nodiscard]] bool hasPossibleRestrictions() const;
  474. [[nodiscard]] QString computeUnavailableReason() const;
  475. [[nodiscard]] bool isMediaSensitive() const;
  476. [[nodiscard]] const HistoryMessageReplyMarkup *inlineReplyMarkup() const {
  477. return const_cast<HistoryItem*>(this)->inlineReplyMarkup();
  478. }
  479. [[nodiscard]] const ReplyKeyboard *inlineReplyKeyboard() const {
  480. return const_cast<HistoryItem*>(this)->inlineReplyKeyboard();
  481. }
  482. [[nodiscard]] HistoryMessageReplyMarkup *inlineReplyMarkup();
  483. [[nodiscard]] ReplyKeyboard *inlineReplyKeyboard();
  484. [[nodiscard]] ChannelData *discussionPostOriginalSender() const;
  485. [[nodiscard]] bool isDiscussionPost() const;
  486. [[nodiscard]] HistoryItem *lookupDiscussionPostOriginal() const;
  487. [[nodiscard]] PeerData *displayFrom() const;
  488. [[nodiscard]] uint8 colorIndex() const;
  489. // In forwards we show name in sender's color, but the message
  490. // content uses the color of the original sender.
  491. [[nodiscard]] PeerData *contentColorsFrom() const;
  492. [[nodiscard]] uint8 contentColorIndex() const;
  493. [[nodiscard]] int starsPaid() const;
  494. [[nodiscard]] std::unique_ptr<HistoryView::Element> createView(
  495. not_null<HistoryView::ElementDelegate*> delegate,
  496. HistoryView::Element *replacing = nullptr);
  497. void updateDate(TimeId newDate);
  498. [[nodiscard]] bool canUpdateDate() const;
  499. void customEmojiRepaint();
  500. [[nodiscard]] bool needsUpdateForVideoQualities(const MTPMessage &data);
  501. [[nodiscard]] TimeId ttlDestroyAt() const {
  502. return _ttlDestroyAt;
  503. }
  504. [[nodiscard]] int boostsApplied() const {
  505. return _boostsApplied;
  506. }
  507. MsgId id;
  508. private:
  509. struct CreateConfig;
  510. HistoryItem(
  511. not_null<History*> history,
  512. const HistoryItemCommonFields &fields);
  513. void createComponentsHelper(HistoryItemCommonFields &&fields);
  514. void createComponents(CreateConfig &&config);
  515. void setupForwardedComponent(const CreateConfig &config);
  516. void applyInitialEffectWatched();
  517. [[nodiscard]] bool generateLocalEntitiesByReply() const;
  518. [[nodiscard]] TextWithEntities withLocalEntities(
  519. const TextWithEntities &textWithEntities) const;
  520. void setTextValue(TextWithEntities text, bool force = false);
  521. [[nodiscard]] bool isTooOldForEdit(TimeId now) const;
  522. [[nodiscard]] bool isLegacyMessage() const {
  523. return _flags & MessageFlag::Legacy;
  524. }
  525. [[nodiscard]] bool checkCommentsLinkedChat(ChannelId id) const;
  526. void setReplyMarkup(HistoryMessageMarkupData &&markup);
  527. void changeReplyToTopCounter(
  528. not_null<HistoryMessageReply*> reply,
  529. int delta);
  530. void refreshRepliesText(
  531. not_null<HistoryMessageViews*> views,
  532. bool forceResize = false);
  533. [[nodiscard]] bool checkRepliesPts(
  534. const HistoryMessageRepliesData &data) const;
  535. [[nodiscard]] HistoryServiceDependentData *GetServiceDependentData();
  536. [[nodiscard]] auto GetServiceDependentData() const
  537. -> const HistoryServiceDependentData *;
  538. void updateDependentServiceText();
  539. void updateServiceDependent(bool force = false);
  540. void setServiceText(PreparedServiceText &&prepared);
  541. void setStoryFields(not_null<Data::Story*> story);
  542. void finishEdition(int oldKeyboardTop);
  543. void finishEditionToEmpty();
  544. void clearDependencyMessage();
  545. void setupChatThemeChange();
  546. void setupTTLChange();
  547. void translationToggle(
  548. not_null<HistoryMessageTranslation*> translation,
  549. bool used);
  550. void setSelfDestruct(HistorySelfDestructType type, MTPint mtpTTLvalue);
  551. void resolveDependent(not_null<HistoryServiceDependentData*> dependent);
  552. void resolveDependent(not_null<HistoryMessageReply*> reply);
  553. [[nodiscard]] TextWithEntities fromLinkText() const;
  554. [[nodiscard]] ClickHandlerPtr fromLink() const;
  555. void setGroupId(MessageGroupId groupId);
  556. static void FillForwardedInfo(
  557. CreateConfig &config,
  558. const MTPDmessageFwdHeader &data);
  559. void createComponents(const MTPDmessage &data);
  560. void setMedia(const MTPMessageMedia &media);
  561. void applyServiceDateEdition(const MTPDmessageService &data);
  562. void setReactions(const MTPMessageReactions *reactions);
  563. [[nodiscard]] bool changeReactions(const MTPMessageReactions *reactions);
  564. void setServiceMessageByAction(const MTPmessageAction &action);
  565. void applyAction(const MTPMessageAction &action);
  566. void refreshMedia(const MTPMessageMedia *media);
  567. void refreshSentMedia(const MTPMessageMedia *media);
  568. void createServiceFromMtp(const MTPDmessage &message);
  569. void createServiceFromMtp(const MTPDmessageService &message);
  570. void applyTTL(const MTPDmessage &data);
  571. void applyTTL(const MTPDmessageService &data);
  572. void applyTTL(TimeId destroyAt);
  573. // For an invoice button we replace the button text with a "Receipt" key.
  574. // It should show the receipt for the payed invoice. Still let mobile apps do that.
  575. void replaceBuyWithReceiptInMarkup();
  576. [[nodiscard]] PreparedServiceText preparePinnedText();
  577. [[nodiscard]] PreparedServiceText prepareGameScoreText();
  578. [[nodiscard]] PreparedServiceText preparePaymentSentText();
  579. [[nodiscard]] PreparedServiceText prepareStoryMentionText();
  580. [[nodiscard]] PreparedServiceText prepareInvitedToCallText(
  581. const std::vector<not_null<UserData*>> &users,
  582. CallId linkCallId);
  583. [[nodiscard]] PreparedServiceText prepareCallScheduledText(
  584. TimeId scheduleDate);
  585. void flagSensitiveContent();
  586. [[nodiscard]] PeerData *computeDisplayFrom() const;
  587. const not_null<History*> _history;
  588. const not_null<PeerData*> _from;
  589. mutable PeerData *_displayFrom = nullptr;
  590. mutable MessageFlags _flags = 0;
  591. TextWithEntities _text;
  592. std::unique_ptr<Data::Media> _media;
  593. std::unique_ptr<Data::MessageReactions> _reactions;
  594. crl::time _reactionsLastRefreshed = 0;
  595. TimeId _date = 0;
  596. TimeId _ttlDestroyAt = 0;
  597. int _boostsApplied = 0;
  598. int _starsPaid = 0;
  599. BusinessShortcutId _shortcutId = 0;
  600. MessageGroupId _groupId = MessageGroupId();
  601. EffectId _effectId = 0;
  602. HistoryView::Element *_mainView = nullptr;
  603. friend class HistoryView::Element;
  604. friend class HistoryView::Message;
  605. friend class HistoryView::Service;
  606. friend class HistoryView::ServiceMessagePainter;
  607. };
  608. constexpr auto kSize = int(sizeof(HistoryItem));