2016-09-27 14:20:49 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-09-27 14:20:49 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-09-27 14:20:49 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "base/runtime_composer.h"
|
2017-08-31 16:28:58 +00:00
|
|
|
#include "base/flags.h"
|
2017-12-13 18:10:48 +00:00
|
|
|
#include "base/value_ordering.h"
|
2016-09-29 11:37:16 +00:00
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
enum class UnreadMentionType;
|
2017-12-18 15:44:50 +00:00
|
|
|
struct HistoryMessageReplyMarkup;
|
|
|
|
class ReplyKeyboard;
|
|
|
|
class HistoryMessage;
|
|
|
|
class HistoryMedia;
|
|
|
|
|
2017-09-04 11:40:02 +00:00
|
|
|
namespace base {
|
|
|
|
template <typename Enum>
|
|
|
|
class enum_mask;
|
|
|
|
} // namespace base
|
|
|
|
|
|
|
|
namespace Storage {
|
2018-03-09 20:48:47 +00:00
|
|
|
enum class SharedMediaType : signed char;
|
2017-09-04 11:40:02 +00:00
|
|
|
using SharedMediaTypesMask = base::enum_mask<SharedMediaType>;
|
|
|
|
} // namespace Storage
|
|
|
|
|
2016-11-16 16:04:25 +00:00
|
|
|
namespace Ui {
|
|
|
|
class RippleAnimation;
|
|
|
|
} // namespace Ui
|
|
|
|
|
2016-11-16 10:44:06 +00:00
|
|
|
namespace style {
|
|
|
|
struct BotKeyboardButton;
|
2016-11-16 16:04:25 +00:00
|
|
|
struct RippleAnimation;
|
2016-11-16 10:44:06 +00:00
|
|
|
} // namespace style
|
|
|
|
|
2018-01-09 17:08:31 +00:00
|
|
|
namespace Data {
|
|
|
|
struct MessagePosition;
|
2018-01-14 16:02:25 +00:00
|
|
|
class Media;
|
2018-01-09 17:08:31 +00:00
|
|
|
} // namespace Data
|
|
|
|
|
2018-01-11 19:33:26 +00:00
|
|
|
namespace Window {
|
|
|
|
class Controller;
|
|
|
|
} // namespace Window
|
|
|
|
|
|
|
|
namespace HistoryView {
|
2018-01-27 13:59:24 +00:00
|
|
|
struct TextState;
|
|
|
|
struct StateRequest;
|
|
|
|
enum class CursorState : char;
|
|
|
|
enum class PointState : char;
|
2018-01-11 19:33:26 +00:00
|
|
|
enum class Context : char;
|
2018-01-17 16:21:01 +00:00
|
|
|
class ElementDelegate;
|
2018-01-11 19:33:26 +00:00
|
|
|
} // namespace HistoryView
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
class HistoryItem : public RuntimeComposer<HistoryItem> {
|
2016-09-27 14:20:49 +00:00
|
|
|
public:
|
2018-01-14 16:02:25 +00:00
|
|
|
static not_null<HistoryItem*> Create(
|
|
|
|
not_null<History*> history,
|
|
|
|
const MTPMessage &message);
|
|
|
|
|
2018-02-05 20:19:51 +00:00
|
|
|
struct Destroyer {
|
|
|
|
void operator()(HistoryItem *value);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-09-27 14:20:49 +00:00
|
|
|
virtual void dependencyItemRemoved(HistoryItem *dependency) {
|
|
|
|
}
|
|
|
|
virtual bool updateDependencyItem() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
virtual MsgId dependencyMsgId() const {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
virtual bool notificationReady() const {
|
|
|
|
return true;
|
|
|
|
}
|
2017-12-01 18:38:44 +00:00
|
|
|
virtual void applyGroupAdminChanges(
|
|
|
|
const base::flat_map<UserId, bool> &changes) {
|
|
|
|
}
|
2016-09-27 14:20:49 +00:00
|
|
|
|
2017-12-18 15:44:50 +00:00
|
|
|
UserData *viaBot() const;
|
2018-01-13 12:45:11 +00:00
|
|
|
UserData *getMessageBot() const;
|
2016-09-27 14:20:49 +00:00
|
|
|
|
2017-06-18 13:08:49 +00:00
|
|
|
bool isLogEntry() const {
|
|
|
|
return (id > ServerMaxMsgId);
|
|
|
|
}
|
2017-12-18 15:44:50 +00:00
|
|
|
void addLogEntryOriginal(
|
|
|
|
WebPageId localId,
|
|
|
|
const QString &label,
|
|
|
|
const TextWithEntities &content);
|
2017-06-18 13:08:49 +00:00
|
|
|
|
2017-08-25 15:17:46 +00:00
|
|
|
not_null<History*> history() const {
|
2016-09-27 14:20:49 +00:00
|
|
|
return _history;
|
|
|
|
}
|
2018-01-13 12:45:11 +00:00
|
|
|
not_null<PeerData*> from() const {
|
2016-09-27 14:20:49 +00:00
|
|
|
return _from;
|
|
|
|
}
|
2018-01-11 19:33:26 +00:00
|
|
|
HistoryView::Element *mainView() const {
|
2018-01-10 13:13:33 +00:00
|
|
|
return _mainView;
|
|
|
|
}
|
2018-03-10 12:47:19 +00:00
|
|
|
void setMainView(not_null<HistoryView::Element*> view) {
|
2018-01-11 13:07:29 +00:00
|
|
|
_mainView = view;
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
2018-01-18 13:59:22 +00:00
|
|
|
void refreshMainView();
|
2018-01-11 13:07:29 +00:00
|
|
|
void clearMainView();
|
|
|
|
void removeMainView();
|
2017-05-12 14:05:06 +00:00
|
|
|
|
2018-01-11 13:07:29 +00:00
|
|
|
void destroy();
|
2016-09-27 14:20:49 +00:00
|
|
|
bool out() const {
|
|
|
|
return _flags & MTPDmessage::Flag::f_out;
|
|
|
|
}
|
|
|
|
bool unread() const;
|
|
|
|
bool mentionsMe() const {
|
|
|
|
return _flags & MTPDmessage::Flag::f_mentioned;
|
|
|
|
}
|
2018-12-26 10:28:24 +00:00
|
|
|
bool isUnreadMention() const;
|
|
|
|
bool isUnreadMedia() const;
|
|
|
|
bool hasUnreadMediaFlag() const;
|
2017-08-25 12:48:10 +00:00
|
|
|
void markMediaRead();
|
2017-07-17 20:09:55 +00:00
|
|
|
|
|
|
|
// Zero result means this message is not self-destructing right now.
|
2019-02-19 06:57:53 +00:00
|
|
|
virtual crl::time getSelfDestructIn(crl::time now) {
|
2017-07-17 20:09:55 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-12-18 15:44:50 +00:00
|
|
|
bool definesReplyKeyboard() const;
|
|
|
|
MTPDreplyKeyboardMarkup::Flags replyKeyboardFlags() const;
|
2016-09-27 14:20:49 +00:00
|
|
|
|
|
|
|
bool hasSwitchInlineButton() const {
|
|
|
|
return _flags & MTPDmessage_ClientFlag::f_has_switch_inline_button;
|
|
|
|
}
|
|
|
|
bool hasTextLinks() const {
|
|
|
|
return _flags & MTPDmessage_ClientFlag::f_has_text_links;
|
|
|
|
}
|
2019-01-15 11:57:45 +00:00
|
|
|
bool isGroupEssential() const {
|
|
|
|
return _flags & MTPDmessage_ClientFlag::f_is_group_essential;
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
2019-01-22 07:50:21 +00:00
|
|
|
bool isGroupMigrate() const {
|
|
|
|
return isGroupEssential() && isEmpty();
|
|
|
|
}
|
2016-09-27 14:20:49 +00:00
|
|
|
bool hasViews() const {
|
|
|
|
return _flags & MTPDmessage::Flag::f_views;
|
|
|
|
}
|
|
|
|
bool isPost() const {
|
|
|
|
return _flags & MTPDmessage::Flag::f_post;
|
|
|
|
}
|
|
|
|
bool isSilent() const {
|
|
|
|
return _flags & MTPDmessage::Flag::f_silent;
|
|
|
|
}
|
2018-01-14 16:02:25 +00:00
|
|
|
virtual int viewsCount() const {
|
2016-09-27 14:20:49 +00:00
|
|
|
return hasViews() ? 1 : -1;
|
|
|
|
}
|
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
virtual bool needCheck() const;
|
2016-09-27 14:20:49 +00:00
|
|
|
|
|
|
|
virtual bool serviceMsg() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
virtual void applyEdition(const MTPDmessage &message) {
|
|
|
|
}
|
|
|
|
virtual void applyEdition(const MTPDmessageService &message) {
|
|
|
|
}
|
2018-01-17 16:21:01 +00:00
|
|
|
virtual void updateSentMedia(const MTPMessageMedia *media) {
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
2016-10-20 15:26:55 +00:00
|
|
|
virtual void updateReplyMarkup(const MTPReplyMarkup *markup) {
|
|
|
|
}
|
2017-09-04 11:40:02 +00:00
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
virtual void addToUnreadMentions(UnreadMentionType type);
|
2017-12-08 18:27:28 +00:00
|
|
|
virtual void eraseFromUnreadMentions() {
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
2018-01-14 16:02:25 +00:00
|
|
|
virtual Storage::SharedMediaTypesMask sharedMediaTypes() const = 0;
|
2016-11-18 16:27:47 +00:00
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
void indexAsNewItem();
|
2016-09-27 14:20:49 +00:00
|
|
|
|
|
|
|
virtual QString notificationHeader() const {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
virtual QString notificationText() const;
|
|
|
|
|
2017-09-05 17:21:56 +00:00
|
|
|
enum class DrawInDialog {
|
|
|
|
Normal,
|
|
|
|
WithoutSender,
|
|
|
|
};
|
|
|
|
|
2016-09-27 14:20:49 +00:00
|
|
|
// Returns text with link-start and link-end commands for service-color highlighting.
|
|
|
|
// Example: "[link1-start]You:[link1-end] [link1-start]Photo,[link1-end] caption text"
|
2017-09-05 17:21:56 +00:00
|
|
|
virtual QString inDialogsText(DrawInDialog way) const;
|
2016-09-27 14:20:49 +00:00
|
|
|
virtual QString inReplyText() const {
|
2018-05-31 11:13:11 +00:00
|
|
|
return inDialogsText(DrawInDialog::WithoutSender);
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
virtual TextWithEntities originalText() const {
|
|
|
|
return { QString(), EntitiesInText() };
|
|
|
|
}
|
2018-01-26 15:40:11 +00:00
|
|
|
virtual TextWithEntities clipboardText() const {
|
|
|
|
return { QString(), EntitiesInText() };
|
|
|
|
}
|
2016-09-27 14:20:49 +00:00
|
|
|
|
|
|
|
virtual void setViewsCount(int32 count) {
|
|
|
|
}
|
2018-01-13 12:45:11 +00:00
|
|
|
virtual void setRealId(MsgId newId);
|
2017-09-05 17:21:56 +00:00
|
|
|
|
|
|
|
void drawInDialog(
|
|
|
|
Painter &p,
|
|
|
|
const QRect &r,
|
|
|
|
bool active,
|
|
|
|
bool selected,
|
|
|
|
DrawInDialog way,
|
|
|
|
const HistoryItem *&cacheFor,
|
|
|
|
Text &cache) const;
|
2016-09-27 14:20:49 +00:00
|
|
|
|
|
|
|
bool emptyText() const {
|
|
|
|
return _text.isEmpty();
|
|
|
|
}
|
|
|
|
|
2017-11-21 13:23:56 +00:00
|
|
|
bool isPinned() const;
|
2017-04-30 13:58:45 +00:00
|
|
|
bool canPin() const;
|
2018-12-19 11:20:04 +00:00
|
|
|
bool canStopPoll() const;
|
2018-01-14 16:02:25 +00:00
|
|
|
virtual bool allowsForward() const;
|
2018-02-03 19:52:35 +00:00
|
|
|
virtual bool allowsEdit(TimeId now) const;
|
2017-04-30 13:58:45 +00:00
|
|
|
bool canDelete() const;
|
2018-02-03 19:52:35 +00:00
|
|
|
bool canDeleteForEveryone(TimeId now) const;
|
2018-05-10 14:15:16 +00:00
|
|
|
bool suggestReport() const;
|
2017-06-04 11:09:29 +00:00
|
|
|
bool suggestBanReport() const;
|
|
|
|
bool suggestDeleteAllReport() const;
|
2016-09-27 14:20:49 +00:00
|
|
|
|
2017-07-11 17:21:24 +00:00
|
|
|
bool hasDirectLink() const;
|
2017-03-10 17:25:43 +00:00
|
|
|
QString directLink() const;
|
2016-09-27 14:20:49 +00:00
|
|
|
|
|
|
|
MsgId id;
|
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
ChannelId channelId() const;
|
2016-09-27 14:20:49 +00:00
|
|
|
FullMsgId fullId() const {
|
|
|
|
return FullMsgId(channelId(), id);
|
|
|
|
}
|
2018-01-09 17:08:31 +00:00
|
|
|
Data::MessagePosition position() const;
|
2018-02-03 19:52:35 +00:00
|
|
|
TimeId date() const;
|
2016-09-27 14:20:49 +00:00
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
Data::Media *media() const {
|
2017-03-05 13:39:10 +00:00
|
|
|
return _media.get();
|
2016-09-27 14:20:49 +00:00
|
|
|
}
|
|
|
|
virtual void setText(const TextWithEntities &textWithEntities) {
|
|
|
|
}
|
|
|
|
virtual bool textHasLinks() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual HistoryMessage *toHistoryMessage() { // dynamic_cast optimize
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
virtual const HistoryMessage *toHistoryMessage() const { // dynamic_cast optimize
|
|
|
|
return nullptr;
|
|
|
|
}
|
2017-12-18 15:44:50 +00:00
|
|
|
MsgId replyToId() const;
|
2016-09-27 14:20:49 +00:00
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
not_null<PeerData*> author() const;
|
2016-09-27 14:20:49 +00:00
|
|
|
|
2018-02-03 19:52:35 +00:00
|
|
|
TimeId dateOriginal() const;
|
2018-01-13 12:45:11 +00:00
|
|
|
not_null<PeerData*> senderOriginal() const;
|
|
|
|
not_null<PeerData*> fromOriginal() const;
|
2017-12-18 15:44:50 +00:00
|
|
|
QString authorOriginal() const;
|
|
|
|
MsgId idOriginal() const;
|
2016-09-27 14:20:49 +00:00
|
|
|
|
2017-12-18 15:44:50 +00:00
|
|
|
bool isEmpty() const;
|
2017-12-13 18:10:48 +00:00
|
|
|
|
2017-12-18 15:44:50 +00:00
|
|
|
MessageGroupId groupId() const;
|
2016-09-27 14:20:49 +00:00
|
|
|
|
2018-01-11 19:33:26 +00:00
|
|
|
virtual std::unique_ptr<HistoryView::Element> createView(
|
2018-01-17 16:21:01 +00:00
|
|
|
not_null<HistoryView::ElementDelegate*> delegate) = 0;
|
2018-01-11 19:33:26 +00:00
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
virtual ~HistoryItem();
|
2016-09-27 14:20:49 +00:00
|
|
|
|
|
|
|
protected:
|
2017-08-25 15:17:46 +00:00
|
|
|
HistoryItem(
|
|
|
|
not_null<History*> history,
|
|
|
|
MsgId id,
|
|
|
|
MTPDmessage::Flags flags,
|
2018-02-03 19:52:35 +00:00
|
|
|
TimeId date,
|
2017-08-25 15:17:46 +00:00
|
|
|
UserId from);
|
2016-09-27 14:20:49 +00:00
|
|
|
|
2017-07-17 20:09:55 +00:00
|
|
|
virtual void markMediaAsReadHook() {
|
|
|
|
}
|
|
|
|
|
2016-09-27 14:20:49 +00:00
|
|
|
void finishEdition(int oldKeyboardTop);
|
|
|
|
void finishEditionToEmpty();
|
|
|
|
|
2017-08-25 15:17:46 +00:00
|
|
|
const not_null<History*> _history;
|
2017-08-17 08:31:24 +00:00
|
|
|
not_null<PeerData*> _from;
|
2017-06-21 08:53:14 +00:00
|
|
|
MTPDmessage::Flags _flags = 0;
|
2016-09-27 14:20:49 +00:00
|
|
|
|
|
|
|
const HistoryMessageReplyMarkup *inlineReplyMarkup() const {
|
2016-10-07 07:58:34 +00:00
|
|
|
return const_cast<HistoryItem*>(this)->inlineReplyMarkup();
|
|
|
|
}
|
|
|
|
const ReplyKeyboard *inlineReplyKeyboard() const {
|
|
|
|
return const_cast<HistoryItem*>(this)->inlineReplyKeyboard();
|
|
|
|
}
|
2017-12-18 15:44:50 +00:00
|
|
|
HistoryMessageReplyMarkup *inlineReplyMarkup();
|
|
|
|
ReplyKeyboard *inlineReplyKeyboard();
|
2019-01-15 11:57:45 +00:00
|
|
|
void invalidateChatListEntry();
|
2016-09-27 14:20:49 +00:00
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
void setGroupId(MessageGroupId groupId);
|
2016-09-27 14:20:49 +00:00
|
|
|
|
2019-01-18 08:11:15 +00:00
|
|
|
Text _text = { st::msgMinWidth };
|
2016-09-27 14:20:49 +00:00
|
|
|
int _textWidth = -1;
|
|
|
|
int _textHeight = 0;
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
std::unique_ptr<Data::Media> _media;
|
2016-09-27 14:20:49 +00:00
|
|
|
|
2017-05-12 13:53:08 +00:00
|
|
|
private:
|
2018-02-03 19:52:35 +00:00
|
|
|
TimeId _date = 0;
|
|
|
|
|
2018-01-11 19:33:26 +00:00
|
|
|
HistoryView::Element *_mainView = nullptr;
|
2018-01-13 12:45:11 +00:00
|
|
|
friend class HistoryView::Element;
|
2017-05-12 13:53:08 +00:00
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
MessageGroupId _groupId = MessageGroupId::None;
|
|
|
|
|
2016-09-27 14:20:49 +00:00
|
|
|
};
|
|
|
|
|
2018-02-03 19:52:35 +00:00
|
|
|
QDateTime ItemDateTime(not_null<const HistoryItem*> item);
|
|
|
|
|
2018-01-13 12:45:11 +00:00
|
|
|
ClickHandlerPtr goToMessageClickHandler(
|
|
|
|
not_null<PeerData*> peer,
|
2018-01-26 15:40:11 +00:00
|
|
|
MsgId msgId,
|
|
|
|
FullMsgId returnToId = FullMsgId());
|
|
|
|
ClickHandlerPtr goToMessageClickHandler(
|
|
|
|
not_null<HistoryItem*> item,
|
|
|
|
FullMsgId returnToId = FullMsgId());
|