-
Notifications
You must be signed in to change notification settings - Fork 5.4k
/
Copy pathhistory_message.h
260 lines (224 loc) · 8.23 KB
/
history_message.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/*
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;
struct HistoryMessageViews;
[[nodiscard]] Fn<void(ChannelData*, MsgId)> HistoryDependentItemCallback(
not_null<HistoryItem*> item);
[[nodiscard]] MTPDmessage::Flags NewMessageFlags(not_null<PeerData*> peer);
[[nodiscard]] bool ShouldSendSilent(
not_null<PeerData*> peer,
const Api::SendOptions &options);
[[nodiscard]] MTPDmessage_ClientFlags NewMessageClientFlags();
[[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:
HistoryMessage(
not_null<History*> history,
const MTPDmessage &data,
MTPDmessage_ClientFlags clientFlags);
HistoryMessage(
not_null<History*> history,
const MTPDmessageService &data,
MTPDmessage_ClientFlags clientFlags);
HistoryMessage(
not_null<History*> history,
MsgId id,
MTPDmessage::Flags flags,
MTPDmessage_ClientFlags clientFlags,
TimeId date,
PeerId from,
const QString &postAuthor,
not_null<HistoryMessage*> original); // local forwarded
HistoryMessage(
not_null<History*> history,
MsgId id,
MTPDmessage::Flags flags,
MTPDmessage_ClientFlags clientFlags,
MsgId replyTo,
UserId viaBotId,
TimeId date,
PeerId from,
const QString &postAuthor,
const TextWithEntities &textWithEntities); // local message
HistoryMessage(
not_null<History*> history,
MsgId id,
MTPDmessage::Flags flags,
MTPDmessage_ClientFlags clientFlags,
MsgId replyTo,
UserId viaBotId,
TimeId date,
PeerId from,
const QString &postAuthor,
not_null<DocumentData*> document,
const TextWithEntities &caption,
const MTPReplyMarkup &markup); // local document
HistoryMessage(
not_null<History*> history,
MsgId id,
MTPDmessage::Flags flags,
MTPDmessage_ClientFlags clientFlags,
MsgId replyTo,
UserId viaBotId,
TimeId date,
PeerId from,
const QString &postAuthor,
not_null<PhotoData*> photo,
const TextWithEntities &caption,
const MTPReplyMarkup &markup); // local photo
HistoryMessage(
not_null<History*> history,
MsgId id,
MTPDmessage::Flags flags,
MTPDmessage_ClientFlags clientFlags,
MsgId replyTo,
UserId viaBotId,
TimeId date,
PeerId from,
const QString &postAuthor,
not_null<GameData*> game,
const MTPReplyMarkup &markup); // local game
void refreshMedia(const MTPMessageMedia *media);
void refreshSentMedia(const MTPMessageMedia *media);
void returnSavedMedia() override;
void setMedia(const MTPMessageMedia &media);
void checkBuyButton() override;
[[nodiscard]] static std::unique_ptr<Data::Media> CreateMedia(
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;
[[nodiscard]] bool hideEditedBadge() const {
return (_flags & MTPDmessage::Flag::f_edit_hide);
}
void setViewsCount(int count) override;
void setForwardsCount(int count) override;
void setReplies(const MTPMessageReplies &data) override;
void clearReplies() override;
void changeRepliesCount(int delta, PeerId replier) override;
void setReplyToTop(MsgId replyToTop) override;
void setPostAuthor(const QString &author) override;
void setRealId(MsgId newId) override;
void incrementReplyToTopCounter() override;
void dependencyItemRemoved(HistoryItem *dependency) override;
[[nodiscard]] QString notificationHeader() const override;
void applyEdition(const MTPDmessage &message) override;
void applyEdition(const MTPDmessageService &message) override;
void updateSentContent(
const TextWithEntities &textWithEntities,
const MTPMessageMedia *media) override;
void updateReplyMarkup(const MTPReplyMarkup *markup) override {
setReplyMarkup(markup);
}
void updateForwardedInfo(const MTPMessageFwdHeader *fwd) override;
void contributeToSlowmode(TimeId realDate = 0) override;
void addToUnreadMentions(UnreadMentionType type) override;
void destroyHistoryEntry() override;
[[nodiscard]] Storage::SharedMediaTypesMask sharedMediaTypes() const override;
void setText(const TextWithEntities &textWithEntities) override;
[[nodiscard]] Ui::Text::IsolatedEmoji isolatedEmoji() const override;
[[nodiscard]] TextWithEntities originalText() const override;
[[nodiscard]] TextForMimeData clipboardText() const override;
[[nodiscard]] bool textHasLinks() const override;
[[nodiscard]] int viewsCount() const override;
[[nodiscard]] int repliesCount() const override;
[[nodiscard]] bool repliesAreComments() const override;
[[nodiscard]] bool externalReply() const override;
[[nodiscard]] MsgId repliesInboxReadTill() const override;
void setRepliesInboxReadTill(MsgId readTillId) 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;
[[nodiscard]] FullMsgId commentsItemId() const override;
void setCommentsItemId(FullMsgId id) override;
bool updateDependencyItem() override;
[[nodiscard]] MsgId dependencyMsgId() const override {
return replyToId();
}
void applySentMessage(const MTPDmessage &data) override;
void applySentMessage(
const QString &text,
const MTPDupdateShortSentMessage &data,
bool wasAlready) override;
// dynamic_cast optimization.
[[nodiscard]] HistoryMessage *toHistoryMessage() override {
return this;
}
[[nodiscard]] const HistoryMessage *toHistoryMessage() const override {
return this;
}
[[nodiscard]] std::unique_ptr<HistoryView::Element> createView(
not_null<HistoryView::ElementDelegate*> delegate,
HistoryView::Element *replacing = nullptr) override;
~HistoryMessage();
private:
void setEmptyText();
[[nodiscard]] bool isTooOldForEdit(TimeId now) const;
[[nodiscard]] bool isLegacyMessage() const {
return _flags & MTPDmessage::Flag::f_legacy;
}
[[nodiscard]] bool checkCommentsLinkedChat(ChannelId id) const;
void clearIsolatedEmoji();
void checkIsolatedEmoji();
// 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;
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);
void changeReplyToTopCounter(
not_null<HistoryMessageReply*> reply,
int delta);
void refreshRepliesText(
not_null<HistoryMessageViews*> views,
bool forceResize = false);
static void FillForwardedInfo(
CreateConfig &config,
const MTPDmessageFwdHeader &data);
[[nodiscard]] bool generateLocalEntitiesByReply() const;
[[nodiscard]] TextWithEntities withLocalEntities(
const TextWithEntities &textWithEntities) const;
void reapplyText();
[[nodiscard]] bool checkRepliesPts(const MTPMessageReplies &data) const;
QString _timeText;
int _timeWidth = 0;
mutable int32 _fromNameVersion = 0;
friend class HistoryView::Element;
friend class HistoryView::Message;
};