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-04-06 17:38:10 +03:00
|
|
|
#include "base/runtime_composer.h"
|
2017-08-31 19:28:58 +03:00
|
|
|
#include "base/flags.h"
|
2017-12-13 22:10:48 +04:00
|
|
|
#include "base/value_ordering.h"
|
2016-09-29 14:37:16 +03:00
|
|
|
|
2018-01-13 15:45:11 +03:00
|
|
|
enum class UnreadMentionType;
|
2017-12-18 19:44:50 +04:00
|
|
|
struct HistoryMessageReplyMarkup;
|
|
|
|
class ReplyKeyboard;
|
|
|
|
class HistoryMessage;
|
|
|
|
class HistoryMedia;
|
|
|
|
|
2017-09-04 14:40:02 +03:00
|
|
|
namespace base {
|
|
|
|
template <typename Enum>
|
|
|
|
class enum_mask;
|
|
|
|
} // namespace base
|
|
|
|
|
|
|
|
namespace Storage {
|
2018-03-09 21:48:47 +01:00
|
|
|
enum class SharedMediaType : signed char;
|
2017-09-04 14:40:02 +03:00
|
|
|
using SharedMediaTypesMask = base::enum_mask<SharedMediaType>;
|
|
|
|
} // namespace Storage
|
|
|
|
|
2016-11-16 19:04:25 +03:00
|
|
|
namespace Ui {
|
|
|
|
class RippleAnimation;
|
|
|
|
} // namespace Ui
|
|
|
|
|
2016-11-16 13:44:06 +03:00
|
|
|
namespace style {
|
|
|
|
struct BotKeyboardButton;
|
2016-11-16 19:04:25 +03:00
|
|
|
struct RippleAnimation;
|
2016-11-16 13:44:06 +03:00
|
|
|
} // namespace style
|
|
|
|
|
2018-01-09 20:08:31 +03:00
|
|
|
namespace Data {
|
|
|
|
struct MessagePosition;
|
2018-01-14 19:02:25 +03:00
|
|
|
class Media;
|
2018-01-09 20:08:31 +03:00
|
|
|
} // namespace Data
|
|
|
|
|
2018-01-11 22:33:26 +03:00
|
|
|
namespace Window {
|
|
|
|
class Controller;
|
|
|
|
} // namespace Window
|
|
|
|
|
|
|
|
namespace HistoryView {
|
2018-01-27 16:59:24 +03:00
|
|
|
struct TextState;
|
|
|
|
struct StateRequest;
|
|
|
|
enum class CursorState : char;
|
|
|
|
enum class PointState : char;
|
2018-01-11 22:33:26 +03:00
|
|
|
enum class Context : char;
|
2018-01-17 19:21:01 +03:00
|
|
|
class ElementDelegate;
|
2018-01-11 22:33:26 +03:00
|
|
|
} // namespace HistoryView
|
|
|
|
|
2018-01-14 19:02:25 +03:00
|
|
|
class HistoryItem : public RuntimeComposer<HistoryItem> {
|
2016-09-27 17:20:49 +03:00
|
|
|
public:
|
2018-01-14 19:02:25 +03:00
|
|
|
static not_null<HistoryItem*> Create(
|
|
|
|
not_null<History*> history,
|
|
|
|
const MTPMessage &message);
|
|
|
|
|
2018-02-05 23:19:51 +03:00
|
|
|
struct Destroyer {
|
|
|
|
void operator()(HistoryItem *value);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-09-27 17:20:49 +03: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 22:38:44 +04:00
|
|
|
virtual void applyGroupAdminChanges(
|
|
|
|
const base::flat_map<UserId, bool> &changes) {
|
|
|
|
}
|
2016-09-27 17:20:49 +03:00
|
|
|
|
2017-12-18 19:44:50 +04:00
|
|
|
UserData *viaBot() const;
|
2018-01-13 15:45:11 +03:00
|
|
|
UserData *getMessageBot() const;
|
2016-09-27 17:20:49 +03:00
|
|
|
|
2017-06-18 16:08:49 +03:00
|
|
|
bool isLogEntry() const {
|
|
|
|
return (id > ServerMaxMsgId);
|
|
|
|
}
|
2017-12-18 19:44:50 +04:00
|
|
|
void addLogEntryOriginal(
|
|
|
|
WebPageId localId,
|
|
|
|
const QString &label,
|
|
|
|
const TextWithEntities &content);
|
2017-06-18 16:08:49 +03:00
|
|
|
|
2017-08-25 18:17:46 +03:00
|
|
|
not_null<History*> history() const {
|
2016-09-27 17:20:49 +03:00
|
|
|
return _history;
|
|
|
|
}
|
2018-01-13 15:45:11 +03:00
|
|
|
not_null<PeerData*> from() const {
|
2016-09-27 17:20:49 +03:00
|
|
|
return _from;
|
|
|
|
}
|
2018-01-11 22:33:26 +03:00
|
|
|
HistoryView::Element *mainView() const {
|
2018-01-10 16:13:33 +03:00
|
|
|
return _mainView;
|
|
|
|
}
|
2018-03-10 15:47:19 +03:00
|
|
|
void setMainView(not_null<HistoryView::Element*> view) {
|
2018-01-11 16:07:29 +03:00
|
|
|
_mainView = view;
|
2016-09-27 17:20:49 +03:00
|
|
|
}
|
2018-01-18 16:59:22 +03:00
|
|
|
void refreshMainView();
|
2018-01-11 16:07:29 +03:00
|
|
|
void clearMainView();
|
|
|
|
void removeMainView();
|
2017-05-12 17:05:06 +03:00
|
|
|
|
2018-01-11 16:07:29 +03:00
|
|
|
void destroy();
|
2016-09-27 17:20:49 +03: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 14:28:24 +04:00
|
|
|
bool isUnreadMention() const;
|
|
|
|
bool isUnreadMedia() const;
|
|
|
|
bool hasUnreadMediaFlag() const;
|
2017-08-25 15:48:10 +03:00
|
|
|
void markMediaRead();
|
2017-07-17 23:09:55 +03:00
|
|
|
|
|
|
|
// Zero result means this message is not self-destructing right now.
|
|
|
|
virtual TimeMs getSelfDestructIn(TimeMs now) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-12-18 19:44:50 +04:00
|
|
|
bool definesReplyKeyboard() const;
|
|
|
|
MTPDreplyKeyboardMarkup::Flags replyKeyboardFlags() const;
|
2016-09-27 17:20:49 +03: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 15:57:45 +04:00
|
|
|
bool isGroupEssential() const {
|
|
|
|
return _flags & MTPDmessage_ClientFlag::f_is_group_essential;
|
2016-09-27 17:20:49 +03: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 19:02:25 +03:00
|
|
|
virtual int viewsCount() const {
|
2016-09-27 17:20:49 +03:00
|
|
|
return hasViews() ? 1 : -1;
|
|
|
|
}
|
|
|
|
|
2018-01-13 15:45:11 +03:00
|
|
|
virtual bool needCheck() const;
|
2016-09-27 17:20:49 +03:00
|
|
|
|
|
|
|
virtual bool serviceMsg() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
virtual void applyEdition(const MTPDmessage &message) {
|
|
|
|
}
|
|
|
|
virtual void applyEdition(const MTPDmessageService &message) {
|
|
|
|
}
|
2018-01-17 19:21:01 +03:00
|
|
|
virtual void updateSentMedia(const MTPMessageMedia *media) {
|
2016-09-27 17:20:49 +03:00
|
|
|
}
|
2016-10-20 18:26:55 +03:00
|
|
|
virtual void updateReplyMarkup(const MTPReplyMarkup *markup) {
|
|
|
|
}
|
2017-09-04 14:40:02 +03:00
|
|
|
|
2018-01-13 15:45:11 +03:00
|
|
|
virtual void addToUnreadMentions(UnreadMentionType type);
|
2017-12-08 22:27:28 +04:00
|
|
|
virtual void eraseFromUnreadMentions() {
|
2016-09-27 17:20:49 +03:00
|
|
|
}
|
2018-01-14 19:02:25 +03:00
|
|
|
virtual Storage::SharedMediaTypesMask sharedMediaTypes() const = 0;
|
2016-11-18 19:27:47 +03:00
|
|
|
|
2018-01-14 19:02:25 +03:00
|
|
|
void indexAsNewItem();
|
2016-09-27 17:20:49 +03:00
|
|
|
|
|
|
|
virtual QString notificationHeader() const {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
virtual QString notificationText() const;
|
|
|
|
|
2017-09-05 20:21:56 +03:00
|
|
|
enum class DrawInDialog {
|
|
|
|
Normal,
|
|
|
|
WithoutSender,
|
|
|
|
};
|
|
|
|
|
2016-09-27 17:20:49 +03: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 20:21:56 +03:00
|
|
|
virtual QString inDialogsText(DrawInDialog way) const;
|
2016-09-27 17:20:49 +03:00
|
|
|
virtual QString inReplyText() const {
|
2018-05-31 14:13:11 +03:00
|
|
|
return inDialogsText(DrawInDialog::WithoutSender);
|
2016-09-27 17:20:49 +03:00
|
|
|
}
|
|
|
|
virtual TextWithEntities originalText() const {
|
|
|
|
return { QString(), EntitiesInText() };
|
|
|
|
}
|
2018-01-26 18:40:11 +03:00
|
|
|
virtual TextWithEntities clipboardText() const {
|
|
|
|
return { QString(), EntitiesInText() };
|
|
|
|
}
|
2016-09-27 17:20:49 +03:00
|
|
|
|
|
|
|
virtual void setViewsCount(int32 count) {
|
|
|
|
}
|
2018-01-13 15:45:11 +03:00
|
|
|
virtual void setRealId(MsgId newId);
|
2017-09-05 20:21:56 +03:00
|
|
|
|
|
|
|
void drawInDialog(
|
|
|
|
Painter &p,
|
|
|
|
const QRect &r,
|
|
|
|
bool active,
|
|
|
|
bool selected,
|
|
|
|
DrawInDialog way,
|
|
|
|
const HistoryItem *&cacheFor,
|
|
|
|
Text &cache) const;
|
2016-09-27 17:20:49 +03:00
|
|
|
|
|
|
|
bool emptyText() const {
|
|
|
|
return _text.isEmpty();
|
|
|
|
}
|
|
|
|
|
2017-11-21 17:23:56 +04:00
|
|
|
bool isPinned() const;
|
2017-04-30 16:58:45 +03:00
|
|
|
bool canPin() const;
|
2018-12-19 15:20:04 +04:00
|
|
|
bool canStopPoll() const;
|
2018-01-14 19:02:25 +03:00
|
|
|
virtual bool allowsForward() const;
|
2018-02-03 22:52:35 +03:00
|
|
|
virtual bool allowsEdit(TimeId now) const;
|
2017-04-30 16:58:45 +03:00
|
|
|
bool canDelete() const;
|
2018-02-03 22:52:35 +03:00
|
|
|
bool canDeleteForEveryone(TimeId now) const;
|
2018-05-10 17:15:16 +03:00
|
|
|
bool suggestReport() const;
|
2017-06-04 14:09:29 +03:00
|
|
|
bool suggestBanReport() const;
|
|
|
|
bool suggestDeleteAllReport() const;
|
2016-09-27 17:20:49 +03:00
|
|
|
|
2017-07-11 20:21:24 +03:00
|
|
|
bool hasDirectLink() const;
|
2017-03-10 20:25:43 +03:00
|
|
|
QString directLink() const;
|
2016-09-27 17:20:49 +03:00
|
|
|
|
|
|
|
MsgId id;
|
|
|
|
|
2018-01-13 15:45:11 +03:00
|
|
|
ChannelId channelId() const;
|
2016-09-27 17:20:49 +03:00
|
|
|
FullMsgId fullId() const {
|
|
|
|
return FullMsgId(channelId(), id);
|
|
|
|
}
|
2018-01-09 20:08:31 +03:00
|
|
|
Data::MessagePosition position() const;
|
2018-02-03 22:52:35 +03:00
|
|
|
TimeId date() const;
|
2016-09-27 17:20:49 +03:00
|
|
|
|
2018-01-14 19:02:25 +03:00
|
|
|
Data::Media *media() const {
|
2017-03-05 16:39:10 +03:00
|
|
|
return _media.get();
|
2016-09-27 17:20:49 +03: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 19:44:50 +04:00
|
|
|
MsgId replyToId() const;
|
2016-09-27 17:20:49 +03:00
|
|
|
|
2018-01-13 15:45:11 +03:00
|
|
|
not_null<PeerData*> author() const;
|
2016-09-27 17:20:49 +03:00
|
|
|
|
2018-02-03 22:52:35 +03:00
|
|
|
TimeId dateOriginal() const;
|
2018-01-13 15:45:11 +03:00
|
|
|
not_null<PeerData*> senderOriginal() const;
|
|
|
|
not_null<PeerData*> fromOriginal() const;
|
2017-12-18 19:44:50 +04:00
|
|
|
QString authorOriginal() const;
|
|
|
|
MsgId idOriginal() const;
|
2016-09-27 17:20:49 +03:00
|
|
|
|
2017-12-18 19:44:50 +04:00
|
|
|
bool isEmpty() const;
|
2017-12-13 22:10:48 +04:00
|
|
|
|
2017-12-18 19:44:50 +04:00
|
|
|
MessageGroupId groupId() const;
|
2016-09-27 17:20:49 +03:00
|
|
|
|
2018-01-11 22:33:26 +03:00
|
|
|
virtual std::unique_ptr<HistoryView::Element> createView(
|
2018-01-17 19:21:01 +03:00
|
|
|
not_null<HistoryView::ElementDelegate*> delegate) = 0;
|
2018-01-11 22:33:26 +03:00
|
|
|
|
2018-01-13 15:45:11 +03:00
|
|
|
virtual ~HistoryItem();
|
2016-09-27 17:20:49 +03:00
|
|
|
|
|
|
|
protected:
|
2017-08-25 18:17:46 +03:00
|
|
|
HistoryItem(
|
|
|
|
not_null<History*> history,
|
|
|
|
MsgId id,
|
|
|
|
MTPDmessage::Flags flags,
|
2018-02-03 22:52:35 +03:00
|
|
|
TimeId date,
|
2017-08-25 18:17:46 +03:00
|
|
|
UserId from);
|
2016-09-27 17:20:49 +03:00
|
|
|
|
2017-07-17 23:09:55 +03:00
|
|
|
virtual void markMediaAsReadHook() {
|
|
|
|
}
|
|
|
|
|
2016-09-27 17:20:49 +03:00
|
|
|
void finishEdition(int oldKeyboardTop);
|
|
|
|
void finishEditionToEmpty();
|
|
|
|
|
2017-08-25 18:17:46 +03:00
|
|
|
const not_null<History*> _history;
|
2017-08-17 11:31:24 +03:00
|
|
|
not_null<PeerData*> _from;
|
2017-06-21 11:53:14 +03:00
|
|
|
MTPDmessage::Flags _flags = 0;
|
2016-09-27 17:20:49 +03:00
|
|
|
|
|
|
|
const HistoryMessageReplyMarkup *inlineReplyMarkup() const {
|
2016-10-07 10:58:34 +03:00
|
|
|
return const_cast<HistoryItem*>(this)->inlineReplyMarkup();
|
|
|
|
}
|
|
|
|
const ReplyKeyboard *inlineReplyKeyboard() const {
|
|
|
|
return const_cast<HistoryItem*>(this)->inlineReplyKeyboard();
|
|
|
|
}
|
2017-12-18 19:44:50 +04:00
|
|
|
HistoryMessageReplyMarkup *inlineReplyMarkup();
|
|
|
|
ReplyKeyboard *inlineReplyKeyboard();
|
2019-01-15 15:57:45 +04:00
|
|
|
void invalidateChatListEntry();
|
2016-09-27 17:20:49 +03:00
|
|
|
|
2018-01-14 19:02:25 +03:00
|
|
|
void setGroupId(MessageGroupId groupId);
|
2016-09-27 17:20:49 +03:00
|
|
|
|
2019-01-18 12:11:15 +04:00
|
|
|
Text _text = { st::msgMinWidth };
|
2016-09-27 17:20:49 +03:00
|
|
|
int _textWidth = -1;
|
|
|
|
int _textHeight = 0;
|
|
|
|
|
2018-01-14 19:02:25 +03:00
|
|
|
std::unique_ptr<Data::Media> _media;
|
2016-09-27 17:20:49 +03:00
|
|
|
|
2017-05-12 16:53:08 +03:00
|
|
|
private:
|
2018-02-03 22:52:35 +03:00
|
|
|
TimeId _date = 0;
|
|
|
|
|
2018-01-11 22:33:26 +03:00
|
|
|
HistoryView::Element *_mainView = nullptr;
|
2018-01-13 15:45:11 +03:00
|
|
|
friend class HistoryView::Element;
|
2017-05-12 16:53:08 +03:00
|
|
|
|
2018-01-14 19:02:25 +03:00
|
|
|
MessageGroupId _groupId = MessageGroupId::None;
|
|
|
|
|
2016-09-27 17:20:49 +03:00
|
|
|
};
|
|
|
|
|
2018-02-03 22:52:35 +03:00
|
|
|
QDateTime ItemDateTime(not_null<const HistoryItem*> item);
|
|
|
|
|
2018-01-13 15:45:11 +03:00
|
|
|
ClickHandlerPtr goToMessageClickHandler(
|
|
|
|
not_null<PeerData*> peer,
|
2018-01-26 18:40:11 +03:00
|
|
|
MsgId msgId,
|
|
|
|
FullMsgId returnToId = FullMsgId());
|
|
|
|
ClickHandlerPtr goToMessageClickHandler(
|
|
|
|
not_null<HistoryItem*> item,
|
|
|
|
FullMsgId returnToId = FullMsgId());
|