tdesktop/Telegram/SourceFiles/history/history_message.h

280 lines
8.3 KiB
C
Raw Normal View History

/*
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"
namespace Api {
struct SendAction;
struct SendOptions;
} // namespace Api
namespace HistoryView {
class Message;
} // namespace HistoryView
struct HistoryMessageEdited;
struct HistoryMessageReply;
2020-09-03 07:19:02 +00:00
struct HistoryMessageViews;
2021-10-02 11:28:21 +00:00
struct HistoryMessageMarkupData;
[[nodiscard]] Fn<void(ChannelData*, MsgId)> HistoryDependentItemCallback(
2020-06-08 09:06:50 +00:00
not_null<HistoryItem*> item);
2021-07-28 11:55:02 +00:00
[[nodiscard]] MessageFlags NewMessageFlags(not_null<PeerData*> peer);
[[nodiscard]] bool ShouldSendSilent(
not_null<PeerData*> peer,
const Api::SendOptions &options);
[[nodiscard]] MsgId LookupReplyToTop(
not_null<History*> history,
MsgId replyToId);
[[nodiscard]] MTPMessageReplyHeader NewMessageReplyHeader(
const Api::SendAction &action);
[[nodiscard]] QString GetErrorTextForSending(
not_null<PeerData*> peer,
const HistoryItemsList &items,
bool ignoreSlowmodeCountdown = false);
[[nodiscard]] QString GetErrorTextForSending(
not_null<PeerData*> peer,
const HistoryItemsList &items,
const TextWithTags &comment,
bool ignoreSlowmodeCountdown = false);
void FastShareMessage(not_null<HistoryItem*> item);
class HistoryMessage final : public HistoryItem {
public:
2017-12-13 18:10:48 +00:00
HistoryMessage(
not_null<History*> history,
MsgId id,
const MTPDmessage &data,
2021-07-28 11:55:02 +00:00
MessageFlags localFlags);
2017-12-13 18:10:48 +00:00
HistoryMessage(
not_null<History*> history,
MsgId id,
const MTPDmessageService &data,
2021-07-28 11:55:02 +00:00
MessageFlags localFlags);
2017-12-13 18:10:48 +00:00
HistoryMessage(
not_null<History*> history,
MsgId id,
2021-07-28 11:55:02 +00:00
MessageFlags flags,
TimeId date,
PeerId from,
2017-12-13 18:10:48 +00:00
const QString &postAuthor,
not_null<HistoryMessage*> original); // local forwarded
2017-12-13 18:10:48 +00:00
HistoryMessage(
not_null<History*> history,
MsgId id,
2021-07-28 11:55:02 +00:00
MessageFlags flags,
2017-12-13 18:10:48 +00:00
MsgId replyTo,
UserId viaBotId,
TimeId date,
PeerId from,
2017-12-13 18:10:48 +00:00
const QString &postAuthor,
2021-07-28 11:55:02 +00:00
const TextWithEntities &textWithEntities,
const MTPMessageMedia &media,
2021-10-02 11:28:21 +00:00
HistoryMessageMarkupData &&markup,
2021-07-28 11:55:02 +00:00
uint64 groupedId); // local message
2017-12-13 18:10:48 +00:00
HistoryMessage(
not_null<History*> history,
MsgId id,
2021-07-28 11:55:02 +00:00
MessageFlags flags,
2017-12-13 18:10:48 +00:00
MsgId replyTo,
UserId viaBotId,
TimeId date,
PeerId from,
2017-12-13 18:10:48 +00:00
const QString &postAuthor,
not_null<DocumentData*> document,
2018-01-18 13:59:22 +00:00
const TextWithEntities &caption,
2021-10-02 11:28:21 +00:00
HistoryMessageMarkupData &&markup); // local document
2017-12-13 18:10:48 +00:00
HistoryMessage(
not_null<History*> history,
MsgId id,
2021-07-28 11:55:02 +00:00
MessageFlags flags,
2017-12-13 18:10:48 +00:00
MsgId replyTo,
UserId viaBotId,
TimeId date,
PeerId from,
2017-12-13 18:10:48 +00:00
const QString &postAuthor,
not_null<PhotoData*> photo,
2018-01-18 13:59:22 +00:00
const TextWithEntities &caption,
2021-10-02 11:28:21 +00:00
HistoryMessageMarkupData &&markup); // local photo
2017-12-13 18:10:48 +00:00
HistoryMessage(
not_null<History*> history,
MsgId id,
2021-07-28 11:55:02 +00:00
MessageFlags flags,
2017-12-13 18:10:48 +00:00
MsgId replyTo,
UserId viaBotId,
TimeId date,
PeerId from,
2017-12-13 18:10:48 +00:00
const QString &postAuthor,
not_null<GameData*> game,
2021-10-02 11:28:21 +00:00
HistoryMessageMarkupData &&markup); // local game
2018-01-18 20:02:50 +00:00
void refreshMedia(const MTPMessageMedia *media);
void refreshSentMedia(const MTPMessageMedia *media);
void returnSavedMedia() override;
2018-01-18 20:02:50 +00:00
void setMedia(const MTPMessageMedia &media);
void checkBuyButton() override;
[[nodiscard]] static std::unique_ptr<Data::Media> CreateMedia(
2018-01-18 20:02:50 +00:00
not_null<HistoryMessage*> item,
const MTPMessageMedia &media);
[[nodiscard]] bool allowsForward() const override;
[[nodiscard]] bool allowsSendNow() const override;
[[nodiscard]] bool allowsEdit(TimeId now) const override;
[[nodiscard]] bool uploading() const;
void setViewsCount(int count) override;
void setForwardsCount(int count) override;
2021-10-07 18:52:27 +00:00
void setReplies(HistoryMessageRepliesData &&data) override;
void clearReplies() override;
void changeRepliesCount(
int delta,
PeerId replier,
std::optional<bool> unread) override;
void setReplyToTop(MsgId replyToTop) override;
void setPostAuthor(const QString &author) override;
2018-01-18 20:02:50 +00:00
void setRealId(MsgId newId) override;
void incrementReplyToTopCounter() override;
2018-01-18 20:02:50 +00:00
void dependencyItemRemoved(HistoryItem *dependency) override;
[[nodiscard]] QString notificationHeader() const override;
2018-01-18 20:02:50 +00:00
2021-07-28 11:55:02 +00:00
// Looks on:
// f_edit_hide
// f_edit_date
// f_entities
// f_reply_markup
// f_media
// f_views
// f_forwards
// f_replies
// f_ttl_period
void applyEdition(HistoryMessageEdition &&edition) override;
2021-07-28 11:55:02 +00:00
2018-01-18 20:02:50 +00:00
void applyEdition(const MTPDmessageService &message) override;
void updateSentContent(
const TextWithEntities &textWithEntities,
const MTPMessageMedia *media) override;
2021-10-02 11:28:21 +00:00
void updateReplyMarkup(HistoryMessageMarkupData &&markup) override;
void updateForwardedInfo(const MTPMessageFwdHeader *fwd) override;
2019-08-20 09:42:13 +00:00
void contributeToSlowmode(TimeId realDate = 0) override;
2018-01-18 20:02:50 +00:00
void addToUnreadMentions(UnreadMentionType type) override;
void destroyHistoryEntry() override;
[[nodiscard]] Storage::SharedMediaTypesMask sharedMediaTypes() const override;
2018-01-18 20:02:50 +00:00
void setText(const TextWithEntities &textWithEntities) override;
2019-08-02 18:19:14 +00:00
[[nodiscard]] Ui::Text::IsolatedEmoji isolatedEmoji() const override;
[[nodiscard]] TextWithEntities originalText() const override;
[[nodiscard]] TextForMimeData clipboardText() const override;
[[nodiscard]] bool textHasLinks() const override;
2018-01-18 20:02:50 +00:00
[[nodiscard]] int viewsCount() const override;
[[nodiscard]] int repliesCount() const override;
2020-09-03 07:19:02 +00:00
[[nodiscard]] bool repliesAreComments() const override;
[[nodiscard]] bool externalReply() const override;
[[nodiscard]] MsgId repliesInboxReadTill() const override;
void setRepliesInboxReadTill(
MsgId readTillId,
std::optional<int> unreadCount) override;
[[nodiscard]] MsgId computeRepliesInboxReadTillFull() const override;
[[nodiscard]] MsgId repliesOutboxReadTill() const override;
void setRepliesOutboxReadTill(MsgId readTillId) override;
[[nodiscard]] MsgId computeRepliesOutboxReadTillFull() const override;
void setRepliesMaxId(MsgId maxId) override;
void setRepliesPossibleMaxId(MsgId possibleMaxId) override;
[[nodiscard]] bool areRepliesUnread() const override;
2020-09-03 08:21:31 +00:00
[[nodiscard]] FullMsgId commentsItemId() const override;
void setCommentsItemId(FullMsgId id) override;
2018-01-18 20:02:50 +00:00
bool updateDependencyItem() override;
[[nodiscard]] MsgId dependencyMsgId() const override {
2018-01-18 20:02:50 +00:00
return replyToId();
}
2021-02-02 16:38:30 +00:00
void applySentMessage(const MTPDmessage &data) override;
void applySentMessage(
const QString &text,
const MTPDupdateShortSentMessage &data,
bool wasAlready) override;
// dynamic_cast optimization.
[[nodiscard]] HistoryMessage *toHistoryMessage() override {
2018-01-18 20:02:50 +00:00
return this;
}
[[nodiscard]] const HistoryMessage *toHistoryMessage() const override {
2018-01-18 20:02:50 +00:00
return this;
}
[[nodiscard]] std::unique_ptr<HistoryView::Element> createView(
not_null<HistoryView::ElementDelegate*> delegate,
HistoryView::Element *replacing = nullptr) override;
2018-01-18 20:02:50 +00:00
~HistoryMessage();
private:
void setEmptyText();
[[nodiscard]] bool isTooOldForEdit(TimeId now) const;
[[nodiscard]] bool isLegacyMessage() const {
2021-07-28 11:55:02 +00:00
return _flags & MessageFlag::Legacy;
}
[[nodiscard]] bool checkCommentsLinkedChat(ChannelId id) const;
2019-08-02 18:19:14 +00:00
void clearIsolatedEmoji();
void checkIsolatedEmoji();
2019-08-01 21:14:19 +00:00
// For an invoice button we replace the button text with a "Receipt" key.
// It should show the receipt for the payed invoice. Still let mobile apps do that.
void replaceBuyWithReceiptInMarkup();
2021-10-02 11:28:21 +00:00
void setReplyMarkup(HistoryMessageMarkupData &&markup);
struct CreateConfig;
2021-07-28 11:55:02 +00:00
void createComponentsHelper(
MessageFlags flags,
MsgId replyTo,
UserId viaBotId,
const QString &postAuthor,
2021-10-02 11:28:21 +00:00
HistoryMessageMarkupData &&markup);
void createComponents(CreateConfig &&config);
void setupForwardedComponent(const CreateConfig &config);
2020-09-03 08:42:25 +00:00
void changeReplyToTopCounter(
not_null<HistoryMessageReply*> reply,
int delta);
2020-09-03 07:19:02 +00:00
void refreshRepliesText(
not_null<HistoryMessageViews*> views,
bool forceResize = false);
void setUnreadRepliesCount(
not_null<HistoryMessageViews*> views,
int count);
static void FillForwardedInfo(
CreateConfig &config,
const MTPDmessageFwdHeader &data);
[[nodiscard]] bool generateLocalEntitiesByReply() const;
[[nodiscard]] TextWithEntities withLocalEntities(
const TextWithEntities &textWithEntities) const;
void reapplyText();
2019-07-19 15:05:48 +00:00
[[nodiscard]] bool checkRepliesPts(
const HistoryMessageRepliesData &data) const;
2017-12-30 08:15:42 +00:00
QString _timeText;
int _timeWidth = 0;
mutable int32 _fromNameVersion = 0;
friend class HistoryView::Element;
friend class HistoryView::Message;
};