2016-09-27 17:20:49 +03:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 13:23:14 +03:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-09-27 17:20:49 +03:00
|
|
|
|
2018-01-03 13:23:14 +03:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-09-27 17:20:49 +03:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-12-18 19:44:50 +04:00
|
|
|
#include "history/history_item.h"
|
|
|
|
|
|
|
|
struct HistoryMessageEdited;
|
|
|
|
|
|
|
|
base::lambda<void(ChannelData*, MsgId)> HistoryDependentItemCallback(
|
|
|
|
const FullMsgId &msgId);
|
2017-08-17 11:31:24 +03:00
|
|
|
MTPDmessage::Flags NewMessageFlags(not_null<PeerData*> peer);
|
2017-12-06 14:13:38 +04:00
|
|
|
QString GetErrorTextForForward(
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
const HistoryItemsList &items);
|
2017-08-17 11:31:24 +03:00
|
|
|
void FastShareMessage(not_null<HistoryItem*> item);
|
2016-09-27 17:20:49 +03:00
|
|
|
|
2017-12-18 19:44:50 +04:00
|
|
|
class HistoryMessage
|
|
|
|
: public HistoryItem
|
|
|
|
, private HistoryItemInstantiated<HistoryMessage> {
|
2016-09-27 17:20:49 +03:00
|
|
|
public:
|
2017-12-13 22:10:48 +04:00
|
|
|
static not_null<HistoryMessage*> create(
|
|
|
|
not_null<History*> history,
|
|
|
|
const MTPDmessage &msg) {
|
2016-09-27 17:20:49 +03:00
|
|
|
return _create(history, msg);
|
|
|
|
}
|
2017-12-13 22:10:48 +04:00
|
|
|
static not_null<HistoryMessage*> create(
|
|
|
|
not_null<History*> history,
|
|
|
|
const MTPDmessageService &msg) {
|
2017-04-28 00:17:00 +03:00
|
|
|
return _create(history, msg);
|
|
|
|
}
|
2017-12-13 22:10:48 +04:00
|
|
|
static not_null<HistoryMessage*> create(
|
|
|
|
not_null<History*> history,
|
|
|
|
MsgId msgId,
|
|
|
|
MTPDmessage::Flags flags,
|
|
|
|
QDateTime date,
|
|
|
|
UserId from,
|
|
|
|
const QString &postAuthor,
|
|
|
|
not_null<HistoryMessage*> fwd) {
|
2017-07-12 22:14:20 +03:00
|
|
|
return _create(history, msgId, flags, date, from, postAuthor, fwd);
|
2016-09-27 17:20:49 +03:00
|
|
|
}
|
2017-12-13 22:10:48 +04:00
|
|
|
static not_null<HistoryMessage*> create(
|
|
|
|
not_null<History*> history,
|
|
|
|
MsgId msgId,
|
|
|
|
MTPDmessage::Flags flags,
|
|
|
|
MsgId replyTo,
|
|
|
|
UserId viaBotId,
|
|
|
|
QDateTime date,
|
|
|
|
UserId from,
|
|
|
|
const QString &postAuthor,
|
|
|
|
const TextWithEntities &textWithEntities) {
|
|
|
|
return _create(
|
|
|
|
history,
|
|
|
|
msgId,
|
|
|
|
flags,
|
|
|
|
replyTo,
|
|
|
|
viaBotId,
|
|
|
|
date,
|
|
|
|
from,
|
|
|
|
postAuthor,
|
|
|
|
textWithEntities);
|
2016-09-27 17:20:49 +03:00
|
|
|
}
|
2017-12-13 22:10:48 +04:00
|
|
|
static not_null<HistoryMessage*> create(
|
|
|
|
not_null<History*> history,
|
|
|
|
MsgId msgId,
|
|
|
|
MTPDmessage::Flags flags,
|
|
|
|
MsgId replyTo,
|
|
|
|
UserId viaBotId,
|
|
|
|
QDateTime date,
|
|
|
|
UserId from,
|
|
|
|
const QString &postAuthor,
|
|
|
|
not_null<DocumentData*> document,
|
|
|
|
const QString &caption,
|
|
|
|
const MTPReplyMarkup &markup) {
|
|
|
|
return _create(
|
|
|
|
history,
|
|
|
|
msgId,
|
|
|
|
flags,
|
|
|
|
replyTo,
|
|
|
|
viaBotId,
|
|
|
|
date,
|
|
|
|
from,
|
|
|
|
postAuthor,
|
|
|
|
document,
|
|
|
|
caption,
|
|
|
|
markup);
|
2016-09-27 17:20:49 +03:00
|
|
|
}
|
2017-12-13 22:10:48 +04:00
|
|
|
static not_null<HistoryMessage*> create(
|
|
|
|
not_null<History*> history,
|
|
|
|
MsgId msgId,
|
|
|
|
MTPDmessage::Flags flags,
|
|
|
|
MsgId replyTo,
|
|
|
|
UserId viaBotId,
|
|
|
|
QDateTime date,
|
|
|
|
UserId from,
|
|
|
|
const QString &postAuthor,
|
|
|
|
not_null<PhotoData*> photo,
|
|
|
|
const QString &caption,
|
|
|
|
const MTPReplyMarkup &markup) {
|
|
|
|
return _create(
|
|
|
|
history,
|
|
|
|
msgId,
|
|
|
|
flags,
|
|
|
|
replyTo,
|
|
|
|
viaBotId,
|
|
|
|
date,
|
|
|
|
from,
|
|
|
|
postAuthor,
|
|
|
|
photo,
|
|
|
|
caption,
|
|
|
|
markup);
|
2016-09-27 17:20:49 +03:00
|
|
|
}
|
2017-12-13 22:10:48 +04:00
|
|
|
static not_null<HistoryMessage*> create(
|
|
|
|
not_null<History*> history,
|
|
|
|
MsgId msgId,
|
|
|
|
MTPDmessage::Flags flags,
|
|
|
|
MsgId replyTo,
|
|
|
|
UserId viaBotId,
|
|
|
|
QDateTime date,
|
|
|
|
UserId from,
|
|
|
|
const QString &postAuthor,
|
|
|
|
not_null<GameData*> game,
|
|
|
|
const MTPReplyMarkup &markup) {
|
|
|
|
return _create(
|
|
|
|
history,
|
|
|
|
msgId,
|
|
|
|
flags,
|
|
|
|
replyTo,
|
|
|
|
viaBotId,
|
|
|
|
date,
|
|
|
|
from,
|
|
|
|
postAuthor,
|
|
|
|
game,
|
|
|
|
markup);
|
2016-09-28 19:23:25 +03:00
|
|
|
}
|
2016-09-27 17:20:49 +03:00
|
|
|
|
|
|
|
void initTime();
|
2016-09-28 14:38:35 +03:00
|
|
|
void initMedia(const MTPMessageMedia *media);
|
2016-09-27 17:20:49 +03:00
|
|
|
void initMediaFromDocument(DocumentData *doc, const QString &caption);
|
|
|
|
void fromNameUpdated(int32 width) const;
|
|
|
|
|
|
|
|
int32 plainMaxWidth() const;
|
2017-06-21 11:53:14 +03:00
|
|
|
QRect countGeometry() const;
|
2016-09-27 17:20:49 +03:00
|
|
|
|
2017-06-20 22:48:53 +03:00
|
|
|
bool drawBubble() const;
|
2016-09-27 17:20:49 +03:00
|
|
|
bool hasBubble() const override {
|
|
|
|
return drawBubble();
|
|
|
|
}
|
2017-12-05 20:14:28 +04:00
|
|
|
bool hasFromName() const;
|
2016-09-27 17:20:49 +03:00
|
|
|
bool displayFromName() const {
|
|
|
|
if (!hasFromName()) return false;
|
|
|
|
if (isAttachedToPrevious()) return false;
|
2017-02-09 17:34:19 +03:00
|
|
|
return true;
|
2016-09-27 17:20:49 +03:00
|
|
|
}
|
2017-12-30 11:15:42 +03:00
|
|
|
bool hasFastReply() const;
|
|
|
|
bool displayFastReply() const;
|
2017-12-16 17:09:53 +04:00
|
|
|
bool displayForwardedFrom() const;
|
2017-06-22 18:11:41 +03:00
|
|
|
bool uploading() const;
|
2017-12-05 20:14:28 +04:00
|
|
|
bool displayRightAction() const override;
|
2016-09-27 17:20:49 +03:00
|
|
|
|
2017-12-01 22:38:44 +04:00
|
|
|
void applyGroupAdminChanges(
|
|
|
|
const base::flat_map<UserId, bool> &changes) override;
|
|
|
|
|
2016-09-27 17:20:49 +03:00
|
|
|
void drawInfo(Painter &p, int32 right, int32 bottom, int32 width, bool selected, InfoDisplayType type) const override;
|
2017-12-05 20:14:28 +04:00
|
|
|
void drawRightAction(Painter &p, int left, int top, int outerWidth) const override;
|
2016-09-27 17:20:49 +03:00
|
|
|
void setViewsCount(int32 count) override;
|
|
|
|
void setId(MsgId newId) override;
|
2017-06-21 11:53:14 +03:00
|
|
|
void draw(Painter &p, QRect clip, TextSelection selection, TimeMs ms) const override;
|
2017-12-05 20:14:28 +04:00
|
|
|
ClickHandlerPtr rightActionLink() const override;
|
2016-09-27 17:20:49 +03:00
|
|
|
|
|
|
|
void dependencyItemRemoved(HistoryItem *dependency) override;
|
|
|
|
|
2017-06-22 00:38:31 +03:00
|
|
|
bool hasPoint(QPoint point) const override;
|
|
|
|
bool pointInTime(int right, int bottom, QPoint point, InfoDisplayType type) const override;
|
2016-09-27 17:20:49 +03:00
|
|
|
|
2017-06-22 00:38:31 +03:00
|
|
|
HistoryTextState getState(QPoint point, HistoryStateRequest request) const override;
|
|
|
|
void updatePressed(QPoint point) override;
|
2016-09-27 17:20:49 +03:00
|
|
|
|
|
|
|
TextSelection adjustSelection(TextSelection selection, TextSelectType type) const override;
|
|
|
|
|
|
|
|
QString notificationHeader() const override;
|
|
|
|
|
|
|
|
void applyEdition(const MTPDmessage &message) override;
|
|
|
|
void applyEdition(const MTPDmessageService &message) override;
|
|
|
|
void updateMedia(const MTPMessageMedia *media) override;
|
2016-10-20 18:26:55 +03:00
|
|
|
void updateReplyMarkup(const MTPReplyMarkup *markup) override {
|
|
|
|
setReplyMarkup(markup);
|
|
|
|
}
|
2017-09-04 14:40:02 +03:00
|
|
|
|
2017-12-21 16:11:33 +04:00
|
|
|
void addToUnreadMentions(UnreadMentionType type) override;
|
2017-12-08 22:27:28 +04:00
|
|
|
void eraseFromUnreadMentions() override;
|
2017-09-04 14:40:02 +03:00
|
|
|
Storage::SharedMediaTypesMask sharedMediaTypes() const override;
|
2016-09-27 17:20:49 +03:00
|
|
|
|
|
|
|
TextWithEntities selectedText(TextSelection selection) const override;
|
|
|
|
void setText(const TextWithEntities &textWithEntities) override;
|
|
|
|
TextWithEntities originalText() const override;
|
|
|
|
bool textHasLinks() const override;
|
|
|
|
|
2017-12-16 20:32:10 +04:00
|
|
|
bool displayEditedBadge() const override;
|
|
|
|
QDateTime displayedEditDate() const override;
|
|
|
|
|
2016-09-30 15:52:03 +03:00
|
|
|
int infoWidth() const override;
|
|
|
|
int timeLeft() const override;
|
|
|
|
int timeWidth() const override {
|
2016-09-27 17:20:49 +03:00
|
|
|
return _timeWidth;
|
|
|
|
}
|
|
|
|
|
2017-12-18 19:44:50 +04:00
|
|
|
int viewsCount() const override;
|
2017-12-05 20:14:28 +04:00
|
|
|
not_null<PeerData*> displayFrom() const;
|
2017-12-18 19:44:50 +04:00
|
|
|
bool updateDependencyItem() override;
|
2016-09-27 17:20:49 +03:00
|
|
|
MsgId dependencyMsgId() const override {
|
|
|
|
return replyToId();
|
|
|
|
}
|
|
|
|
|
|
|
|
HistoryMessage *toHistoryMessage() override { // dynamic_cast optimize
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
const HistoryMessage *toHistoryMessage() const override { // dynamic_cast optimize
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// hasFromPhoto() returns true even if we don't display the photo
|
|
|
|
// but we need to skip a place at the left side for this photo
|
|
|
|
bool displayFromPhoto() const;
|
|
|
|
bool hasFromPhoto() const;
|
|
|
|
|
2018-01-11 22:33:26 +03:00
|
|
|
std::unique_ptr<HistoryView::Element> createView(
|
|
|
|
not_null<Window::Controller*> controller,
|
|
|
|
HistoryView::Context context) override;
|
|
|
|
|
2016-09-27 17:20:49 +03:00
|
|
|
~HistoryMessage();
|
|
|
|
|
2017-12-16 20:32:10 +04:00
|
|
|
protected:
|
|
|
|
void refreshEditedBadge() override;
|
|
|
|
|
2016-09-27 17:20:49 +03:00
|
|
|
private:
|
2017-12-13 22:10:48 +04:00
|
|
|
HistoryMessage(
|
|
|
|
not_null<History*> history,
|
|
|
|
const MTPDmessage &msg);
|
|
|
|
HistoryMessage(
|
|
|
|
not_null<History*> history,
|
|
|
|
const MTPDmessageService &msg);
|
|
|
|
HistoryMessage(
|
|
|
|
not_null<History*> history,
|
|
|
|
MsgId msgId,
|
|
|
|
MTPDmessage::Flags flags,
|
|
|
|
QDateTime date,
|
|
|
|
UserId from,
|
|
|
|
const QString &postAuthor,
|
|
|
|
not_null<HistoryMessage*> fwd); // local forwarded
|
|
|
|
HistoryMessage(
|
|
|
|
not_null<History*> history,
|
|
|
|
MsgId msgId,
|
|
|
|
MTPDmessage::Flags flags,
|
|
|
|
MsgId replyTo,
|
|
|
|
UserId viaBotId,
|
|
|
|
QDateTime date,
|
|
|
|
UserId from,
|
|
|
|
const QString &postAuthor,
|
|
|
|
const TextWithEntities &textWithEntities); // local message
|
|
|
|
HistoryMessage(
|
|
|
|
not_null<History*> history,
|
|
|
|
MsgId msgId,
|
|
|
|
MTPDmessage::Flags flags,
|
|
|
|
MsgId replyTo,
|
|
|
|
UserId viaBotId,
|
|
|
|
QDateTime date,
|
|
|
|
UserId from,
|
|
|
|
const QString &postAuthor,
|
|
|
|
not_null<DocumentData*> document,
|
|
|
|
const QString &caption,
|
|
|
|
const MTPReplyMarkup &markup); // local document
|
|
|
|
HistoryMessage(
|
|
|
|
not_null<History*> history,
|
|
|
|
MsgId msgId,
|
|
|
|
MTPDmessage::Flags flags,
|
|
|
|
MsgId replyTo,
|
|
|
|
UserId viaBotId,
|
|
|
|
QDateTime date,
|
|
|
|
UserId from,
|
|
|
|
const QString &postAuthor,
|
|
|
|
not_null<PhotoData*> photo,
|
|
|
|
const QString &caption,
|
|
|
|
const MTPReplyMarkup &markup); // local photo
|
|
|
|
HistoryMessage(
|
|
|
|
not_null<History*> history,
|
|
|
|
MsgId msgId,
|
|
|
|
MTPDmessage::Flags flags,
|
|
|
|
MsgId replyTo,
|
|
|
|
UserId viaBotId,
|
|
|
|
QDateTime date,
|
|
|
|
UserId from,
|
|
|
|
const QString &postAuthor,
|
|
|
|
not_null<GameData*> game,
|
|
|
|
const MTPReplyMarkup &markup); // local game
|
2016-09-27 17:20:49 +03:00
|
|
|
friend class HistoryItemInstantiated<HistoryMessage>;
|
|
|
|
|
|
|
|
void setEmptyText();
|
|
|
|
|
2017-03-06 18:00:59 +03: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();
|
|
|
|
|
2016-09-27 17:20:49 +03:00
|
|
|
void initDimensions() override;
|
2017-06-21 11:53:14 +03:00
|
|
|
int resizeContentGetHeight() override;
|
|
|
|
int performResizeGetHeight();
|
2016-09-27 17:20:49 +03:00
|
|
|
void applyEditionToEmpty();
|
2017-12-16 20:32:10 +04:00
|
|
|
QDateTime displayedEditDate(bool hasViaBotOrInlineMarkup) const;
|
|
|
|
const HistoryMessageEdited *displayedEditBadge() const;
|
|
|
|
HistoryMessageEdited *displayedEditBadge();
|
2016-09-27 17:20:49 +03:00
|
|
|
|
|
|
|
void paintFromName(Painter &p, QRect &trect, bool selected) const;
|
|
|
|
void paintForwardedInfo(Painter &p, QRect &trect, bool selected) const;
|
|
|
|
void paintReplyInfo(Painter &p, QRect &trect, bool selected) const;
|
|
|
|
// this method draws "via @bot" if it is not painted in forwarded info or in from name
|
|
|
|
void paintViaBotIdInfo(Painter &p, QRect &trect, bool selected) const;
|
|
|
|
void paintText(Painter &p, QRect &trect, TextSelection selection) const;
|
|
|
|
|
2017-12-15 19:25:47 +03:00
|
|
|
bool getStateFromName(
|
|
|
|
QPoint point,
|
|
|
|
QRect &trect,
|
|
|
|
not_null<HistoryTextState*> outResult) const;
|
|
|
|
bool getStateForwardedInfo(
|
|
|
|
QPoint point,
|
|
|
|
QRect &trect,
|
|
|
|
not_null<HistoryTextState*> outResult,
|
2018-01-11 22:33:26 +03:00
|
|
|
HistoryStateRequest request) const;
|
2017-12-15 19:25:47 +03:00
|
|
|
bool getStateReplyInfo(
|
|
|
|
QPoint point,
|
|
|
|
QRect &trect,
|
|
|
|
not_null<HistoryTextState*> outResult) const;
|
|
|
|
bool getStateViaBotIdInfo(
|
|
|
|
QPoint point,
|
|
|
|
QRect &trect,
|
|
|
|
not_null<HistoryTextState*> outResult) const;
|
|
|
|
bool getStateText(
|
|
|
|
QPoint point,
|
|
|
|
QRect &trect,
|
|
|
|
not_null<HistoryTextState*> outResult,
|
2018-01-11 22:33:26 +03:00
|
|
|
HistoryStateRequest request) const;
|
2016-09-28 13:15:03 +03:00
|
|
|
|
2016-09-27 17:20:49 +03:00
|
|
|
void setMedia(const MTPMessageMedia *media);
|
|
|
|
void setReplyMarkup(const MTPReplyMarkup *markup);
|
|
|
|
|
2017-12-05 20:14:28 +04:00
|
|
|
bool displayFastShare() const;
|
|
|
|
bool displayGoToOriginal() const;
|
|
|
|
|
2017-12-18 19:44:50 +04:00
|
|
|
struct CreateConfig;
|
2017-07-12 22:14:20 +03:00
|
|
|
void createComponentsHelper(MTPDmessage::Flags flags, MsgId replyTo, UserId viaBotId, const QString &postAuthor, const MTPReplyMarkup &markup);
|
2016-09-27 17:20:49 +03:00
|
|
|
void createComponents(const CreateConfig &config);
|
|
|
|
|
2016-09-28 13:15:03 +03:00
|
|
|
void updateMediaInBubbleState();
|
2017-12-01 22:38:44 +04:00
|
|
|
void updateAdminBadgeState();
|
2017-12-30 11:15:42 +03:00
|
|
|
ClickHandlerPtr fastReplyLink() const;
|
|
|
|
|
|
|
|
QString _timeText;
|
|
|
|
int _timeWidth = 0;
|
|
|
|
|
|
|
|
mutable ClickHandlerPtr _rightActionLink;
|
|
|
|
mutable ClickHandlerPtr _fastReplyLink;
|
|
|
|
mutable int32 _fromNameVersion = 0;
|
2016-09-28 13:15:03 +03:00
|
|
|
|
2016-09-27 17:20:49 +03:00
|
|
|
};
|