/* This file is part of Telegram Desktop, the official desktop application for the Telegram messaging service. For license and copyright information please follow this link: https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once #include "history/history_item.h" #include "ui/empty_userpic.h" #include "ui/effects/animations.h" struct WebPageData; namespace Data { class Session; } // namespace Data namespace HistoryView { class Element; class Document; } // namespace HistoryView struct HistoryMessageVia : public RuntimeComponent { void create(not_null owner, UserId userId); void resize(int32 availw) const; UserData *bot = nullptr; mutable QString text; mutable int width = 0; mutable int maxWidth = 0; ClickHandlerPtr link; }; struct HistoryMessageViews : public RuntimeComponent { struct Part { QString text; int textWidth = 0; int count = -1; }; std::vector recentRepliers; Part views; Part replies; ChannelId repliesChannelId = 0; static constexpr auto kMaxRecentRepliers = 3; }; struct HistoryMessageSigned : public RuntimeComponent { void refresh(const QString &date); int maxWidth() const; bool isElided = false; QString author; Ui::Text::String signature; }; struct HistoryMessageEdited : public RuntimeComponent { void refresh(const QString &date, bool displayed); int maxWidth() const; TimeId date = 0; Ui::Text::String text; }; struct HiddenSenderInfo { explicit HiddenSenderInfo(const QString &name); QString name; QString firstName; QString lastName; PeerId colorPeerId = 0; Ui::EmptyUserpic userpic; Ui::Text::String nameText; inline bool operator==(const HiddenSenderInfo &other) const { return name == other.name; } inline bool operator!=(const HiddenSenderInfo &other) const { return !(*this == other); } }; struct HistoryMessageForwarded : public RuntimeComponent { void create(const HistoryMessageVia *via) const; TimeId originalDate = 0; PeerData *originalSender = nullptr; std::unique_ptr hiddenSenderInfo; QString originalAuthor; QString psaType; MsgId originalId = 0; mutable Ui::Text::String text = { 1 }; PeerData *savedFromPeer = nullptr; MsgId savedFromMsgId = 0; }; struct HistoryMessageReply : public RuntimeComponent { HistoryMessageReply() = default; HistoryMessageReply(const HistoryMessageReply &other) = delete; HistoryMessageReply(HistoryMessageReply &&other) = delete; HistoryMessageReply &operator=(const HistoryMessageReply &other) = delete; HistoryMessageReply &operator=(HistoryMessageReply &&other) { replyToMsgId = other.replyToMsgId; replyToMsgTop = other.replyToMsgTop; replyToDocumentId = other.replyToDocumentId; std::swap(replyToMsg, other.replyToMsg); replyToLnk = std::move(other.replyToLnk); replyToName = std::move(other.replyToName); replyToText = std::move(other.replyToText); replyToVersion = other.replyToVersion; maxReplyWidth = other.maxReplyWidth; replyToVia = std::move(other.replyToVia); return *this; } ~HistoryMessageReply() { // clearData() should be called by holder. Expects(replyToMsg == nullptr); Expects(replyToVia == nullptr); } bool updateData(not_null holder, bool force = false); // Must be called before destructor. void clearData(not_null holder); bool isNameUpdated() const; void updateName() const; void resize(int width) const; void itemRemoved(HistoryMessage *holder, HistoryItem *removed); enum class PaintFlag { InBubble = (1 << 0), Selected = (1 << 1), }; using PaintFlags = base::flags; friend inline constexpr auto is_flag_type(PaintFlag) { return true; }; void paint( Painter &p, not_null holder, int x, int y, int w, PaintFlags flags) const; [[nodiscard]] MsgId replyToId() const { return replyToMsgId; } [[nodiscard]] MsgId replyToTop() const { return replyToMsgTop; } [[nodiscard]] int replyToWidth() const { return maxReplyWidth; } [[nodiscard]] ClickHandlerPtr replyToLink() const { return replyToLnk; } void setReplyToLinkFrom( not_null holder); void refreshReplyToDocument(); MsgId replyToMsgId = 0; MsgId replyToMsgTop = 0; HistoryItem *replyToMsg = nullptr; DocumentId replyToDocumentId = 0; ClickHandlerPtr replyToLnk; mutable Ui::Text::String replyToName, replyToText; mutable int replyToVersion = 0; mutable int maxReplyWidth = 0; std::unique_ptr replyToVia; int toWidth = 0; }; struct HistoryMessageMarkupButton { enum class Type { Default, Url, Callback, CallbackWithPassword, RequestPhone, RequestLocation, RequestPoll, SwitchInline, SwitchInlineSame, Game, Buy, Auth, }; HistoryMessageMarkupButton( Type type, const QString &text, const QByteArray &data = QByteArray(), const QString &forwardText = QString(), int32 buttonId = 0); static HistoryMessageMarkupButton *Get( not_null owner, FullMsgId itemId, int row, int column); Type type; QString text, forwardText; QByteArray data; int32 buttonId = 0; mutable mtpRequestId requestId = 0; }; struct HistoryMessageReplyMarkup : public RuntimeComponent { using Button = HistoryMessageMarkupButton; HistoryMessageReplyMarkup() = default; HistoryMessageReplyMarkup(MTPDreplyKeyboardMarkup::Flags f) : flags(f) { } void create(const MTPReplyMarkup &markup); void create(const HistoryMessageReplyMarkup &markup); std::vector> rows; MTPDreplyKeyboardMarkup::Flags flags = 0; std::unique_ptr inlineKeyboard; private: void createFromButtonRows(const QVector &v); }; class ReplyMarkupClickHandler : public LeftButtonClickHandler { public: ReplyMarkupClickHandler( not_null owner, int row, int column, FullMsgId context); QString tooltip() const override { return _fullDisplayed ? QString() : buttonText(); } void setFullDisplayed(bool full) { _fullDisplayed = full; } // Copy to clipboard support. QString copyToClipboardText() const override; QString copyToClipboardContextItemText() const override; // Finds the corresponding button in the items markup struct. // If the button is not found it returns nullptr. // Note: it is possible that we will point to the different button // than the one was used when constructing the handler, but not a big deal. const HistoryMessageMarkupButton *getButton() const; // We hold only FullMsgId, not HistoryItem*, because all click handlers // are activated async and the item may be already destroyed. void setMessageId(const FullMsgId &msgId) { _itemId = msgId; } protected: void onClickImpl() const override; private: const not_null _owner; FullMsgId _itemId; int _row = 0; int _column = 0; bool _fullDisplayed = true; // Returns the full text of the corresponding button. QString buttonText() const; }; class ReplyKeyboard { private: struct Button; public: class Style { public: Style(const style::BotKeyboardButton &st) : _st(&st) { } virtual void startPaint(Painter &p) const = 0; virtual const style::TextStyle &textStyle() const = 0; int buttonSkip() const; int buttonPadding() const; int buttonHeight() const; virtual int buttonRadius() const = 0; virtual void repaint(not_null item) const = 0; virtual ~Style() { } protected: virtual void paintButtonBg( Painter &p, const QRect &rect, float64 howMuchOver) const = 0; virtual void paintButtonIcon( Painter &p, const QRect &rect, int outerWidth, HistoryMessageMarkupButton::Type type) const = 0; virtual void paintButtonLoading( Painter &p, const QRect &rect) const = 0; virtual int minButtonWidth( HistoryMessageMarkupButton::Type type) const = 0; private: const style::BotKeyboardButton *_st; void paintButton(Painter &p, int outerWidth, const ReplyKeyboard::Button &button) const; friend class ReplyKeyboard; }; ReplyKeyboard( not_null item, std::unique_ptr