tdesktop/Telegram/SourceFiles/history/history_message.h

195 lines
5.5 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 HistoryView {
class Message;
} // namespace HistoryView
struct HistoryMessageEdited;
Fn<void(ChannelData*, MsgId)> HistoryDependentItemCallback(
const FullMsgId &msgId);
MTPDmessage::Flags NewMessageFlags(not_null<PeerData*> peer);
QString GetErrorTextForForward(
not_null<PeerData*> peer,
const HistoryItemsList &items,
bool ignoreSlowmodeCountdown = false);
QString GetErrorTextForForward(
not_null<PeerData*> peer,
const HistoryItemsList &items,
const TextWithTags &comment,
bool ignoreSlowmodeCountdown = false);
void FastShareMessage(not_null<HistoryItem*> item);
class HistoryMessage
2018-01-18 20:02:50 +00:00
: public HistoryItem {
public:
2017-12-13 18:10:48 +00:00
HistoryMessage(
not_null<History*> history,
const MTPDmessage &data);
2017-12-13 18:10:48 +00:00
HistoryMessage(
not_null<History*> history,
const MTPDmessageService &data);
2017-12-13 18:10:48 +00:00
HistoryMessage(
not_null<History*> history,
MsgId id,
2017-12-13 18:10:48 +00:00
MTPDmessage::Flags flags,
TimeId date,
2017-12-13 18:10:48 +00:00
UserId from,
const QString &postAuthor,
not_null<HistoryMessage*> original); // local forwarded
2017-12-13 18:10:48 +00:00
HistoryMessage(
not_null<History*> history,
MsgId id,
2017-12-13 18:10:48 +00:00
MTPDmessage::Flags flags,
MsgId replyTo,
UserId viaBotId,
TimeId date,
2017-12-13 18:10:48 +00:00
UserId from,
const QString &postAuthor,
const TextWithEntities &textWithEntities); // local message
HistoryMessage(
not_null<History*> history,
MsgId id,
2017-12-13 18:10:48 +00:00
MTPDmessage::Flags flags,
MsgId replyTo,
UserId viaBotId,
TimeId date,
2017-12-13 18:10:48 +00:00
UserId from,
const QString &postAuthor,
not_null<DocumentData*> document,
2018-01-18 13:59:22 +00:00
const TextWithEntities &caption,
2017-12-13 18:10:48 +00:00
const MTPReplyMarkup &markup); // local document
HistoryMessage(
not_null<History*> history,
MsgId id,
2017-12-13 18:10:48 +00:00
MTPDmessage::Flags flags,
MsgId replyTo,
UserId viaBotId,
TimeId date,
2017-12-13 18:10:48 +00:00
UserId from,
const QString &postAuthor,
not_null<PhotoData*> photo,
2018-01-18 13:59:22 +00:00
const TextWithEntities &caption,
2017-12-13 18:10:48 +00:00
const MTPReplyMarkup &markup); // local photo
HistoryMessage(
not_null<History*> history,
MsgId id,
2017-12-13 18:10:48 +00:00
MTPDmessage::Flags flags,
MsgId replyTo,
UserId viaBotId,
TimeId date,
2017-12-13 18:10:48 +00:00
UserId from,
const QString &postAuthor,
not_null<GameData*> game,
const MTPReplyMarkup &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);
[[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 allowsEdit(TimeId now) const override;
[[nodiscard]] bool uploading() const;
2019-07-19 15:05:48 +00:00
[[nodiscard]] const Ui::Text::String &messageBadge() const {
return _messageBadge;
}
2019-07-19 15:05:48 +00:00
[[nodiscard]] bool hasMessageBadge() const {
return !_messageBadge.isEmpty();
}
2018-01-18 20:02:50 +00:00
void applyGroupAdminChanges(
const base::flat_set<UserId> &changes) override;
2018-01-18 20:02:50 +00:00
void setViewsCount(int32 count) override;
void setRealId(MsgId newId) override;
void dependencyItemRemoved(HistoryItem *dependency) override;
[[nodiscard]] QString notificationHeader() const override;
2018-01-18 20:02:50 +00:00
void applyEdition(const MTPDmessage &message) override;
void applyEdition(const MTPDmessageService &message) override;
void updateSentMedia(const MTPMessageMedia *media) override;
void updateReplyMarkup(const MTPReplyMarkup *markup) override {
setReplyMarkup(markup);
}
void updateForwardedInfo(const MTPMessageFwdHeader *fwd) override;
2018-01-18 20:02:50 +00:00
void addToUnreadMentions(UnreadMentionType type) override;
void eraseFromUnreadMentions() override;
[[nodiscard]] Storage::SharedMediaTypesMask sharedMediaTypes() const override;
2018-01-18 20:02:50 +00:00
void setText(const TextWithEntities &textWithEntities) 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;
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();
}
// 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(
2018-01-18 20:02:50 +00:00
not_null<HistoryView::ElementDelegate*> delegate) override;
~HistoryMessage();
private:
void setEmptyText();
[[nodiscard]] bool isTooOldForEdit(TimeId now) const;
[[nodiscard]] bool isLegacyMessage() const {
2019-05-20 14:57:25 +00:00
return _flags & MTPDmessage::Flag::f_legacy;
}
// 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();
void setReplyMarkup(const MTPReplyMarkup *markup);
struct CreateConfig;
2017-07-12 19:14:20 +00:00
void createComponentsHelper(MTPDmessage::Flags flags, MsgId replyTo, UserId viaBotId, const QString &postAuthor, const MTPReplyMarkup &markup);
void createComponents(const CreateConfig &config);
void setupForwardedComponent(const CreateConfig &config);
static void FillForwardedInfo(
CreateConfig &config,
const MTPDmessageFwdHeader &data);
2019-07-19 15:05:48 +00:00
void refreshMessageBadge();
Ui::Text::String _messageBadge;
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;
};