File: inline_bot_send_data.h

package info (click to toggle)
telegram-desktop 4.6.5%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 53,300 kB
  • sloc: cpp: 605,857; python: 3,978; ansic: 1,636; sh: 965; makefile: 841; objc: 652; javascript: 187; xml: 165
file content (373 lines) | stat: -rw-r--r-- 7,942 bytes parent folder | download
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
/*
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_location_manager.h"

struct HistoryMessageMarkupData;

namespace Main {
class Session;
} // namespace Main

class History;

namespace InlineBots {

class Result;

namespace internal {

// Abstract class describing the message that will be
// sent if the user chooses this inline bot result.
// For each type of message that can be sent there will be a subclass.
class SendData {
public:
	explicit SendData(not_null<Main::Session*> session) : _session(session) {
	}
	SendData(const SendData &other) = delete;
	SendData &operator=(const SendData &other) = delete;
	virtual ~SendData() = default;

	[[nodiscard]] Main::Session &session() const {
		return *_session;
	}

	virtual bool isValid() const = 0;

	virtual void addToHistory(
		const Result *owner,
		not_null<History*> history,
		MessageFlags flags,
		MsgId msgId,
		PeerId fromId,
		TimeId date,
		UserId viaBotId,
		MsgId replyToId,
		const QString &postAuthor,
		HistoryMessageMarkupData &&markup) const = 0;
	virtual QString getErrorOnSend(
		const Result *owner,
		not_null<History*> history) const = 0;

	virtual bool hasLocationCoords() const {
		return false;
	}
	virtual std::optional<Data::LocationPoint> getLocationPoint() const {
		return std::nullopt;
	}
	virtual QString getLayoutTitle(const Result *owner) const;
	virtual QString getLayoutDescription(const Result *owner) const;

private:
	not_null<Main::Session*> _session;

};

// This class implements addHistory() for most of the types hiding
// the differences in getSentMessageFields() method.
// Only SendFile and SendPhoto work by their own.
class SendDataCommon : public SendData {
public:
	using SendData::SendData;

	struct SentMessageFields {
		TextWithEntities text;
		MTPMessageMedia media = MTP_messageMediaEmpty();
	};
	virtual SentMessageFields getSentMessageFields() const = 0;

	void addToHistory(
		const Result *owner,
		not_null<History*> history,
		MessageFlags flags,
		MsgId msgId,
		PeerId fromId,
		TimeId date,
		UserId viaBotId,
		MsgId replyToId,
		const QString &postAuthor,
		HistoryMessageMarkupData &&markup) const override;

	QString getErrorOnSend(
		const Result *owner,
		not_null<History*> history) const override;

};

// Plain text message.
class SendText : public SendDataCommon {
public:
	SendText(
		not_null<Main::Session*> session,
		const QString &message,
		const EntitiesInText &entities,
		bool/* noWebPage*/)
	: SendDataCommon(session)
	, _message(message)
	, _entities(entities) {
	}

	bool isValid() const override {
		return !_message.isEmpty();
	}

	SentMessageFields getSentMessageFields() const override;

private:
	QString _message;
	EntitiesInText _entities;

};

// Message with geo location point media.
class SendGeo : public SendDataCommon {
public:
	SendGeo(
		not_null<Main::Session*> session,
		const MTPDgeoPoint &point)
	: SendDataCommon(session)
	, _location(point) {
	}
	SendGeo(
		not_null<Main::Session*> session,
		const MTPDgeoPoint &point,
		int period,
		std::optional<int> heading,
		std::optional<int> proximityNotificationRadius)
	: SendDataCommon(session)
	, _location(point)
	, _period(period)
	, _heading(heading)
	, _proximityNotificationRadius(proximityNotificationRadius){
	}

	bool isValid() const override {
		return true;
	}

	SentMessageFields getSentMessageFields() const override;

	bool hasLocationCoords() const override {
		return true;
	}
	std::optional<Data::LocationPoint> getLocationPoint() const override {
		return _location;
	}

private:
	Data::LocationPoint _location;
	std::optional<int> _period;
	std::optional<int> _heading;
	std::optional<int> _proximityNotificationRadius;

};

// Message with venue media.
class SendVenue : public SendDataCommon {
public:
	SendVenue(
		not_null<Main::Session*> session,
		const MTPDgeoPoint &point,
		const QString &venueId,
		const QString &provider,
		const QString &title,
		const QString &address)
	: SendDataCommon(session)
	, _location(point)
	, _venueId(venueId)
	, _provider(provider)
	, _title(title)
	, _address(address) {
	}

	bool isValid() const override {
		return true;
	}

	SentMessageFields getSentMessageFields() const override;

	bool hasLocationCoords() const override {
		return true;
	}
	std::optional<Data::LocationPoint> getLocationPoint() const override {
		return _location;
	}

private:
	Data::LocationPoint _location;
	QString _venueId, _provider, _title, _address;

};

// Message with shared contact media.
class SendContact : public SendDataCommon {
public:
	SendContact(
		not_null<Main::Session*> session,
		const QString &firstName,
		const QString &lastName,
		const QString &phoneNumber)
	: SendDataCommon(session)
	, _firstName(firstName)
	, _lastName(lastName)
	, _phoneNumber(phoneNumber) {
	}

	bool isValid() const override {
		return (!_firstName.isEmpty() || !_lastName.isEmpty()) && !_phoneNumber.isEmpty();
	}

	SentMessageFields getSentMessageFields() const override;

	QString getLayoutDescription(const Result *owner) const override;

private:
	QString _firstName, _lastName, _phoneNumber;

};

// Message with photo.
class SendPhoto : public SendData {
public:
	SendPhoto(
		not_null<Main::Session*> session,
		PhotoData *photo,
		const QString &message,
		const EntitiesInText &entities)
	: SendData(session)
	, _photo(photo)
	, _message(message)
	, _entities(entities) {
	}

	bool isValid() const override {
		return _photo != nullptr;
	}

	void addToHistory(
		const Result *owner,
		not_null<History*> history,
		MessageFlags flags,
		MsgId msgId,
		PeerId fromId,
		TimeId date,
		UserId viaBotId,
		MsgId replyToId,
		const QString &postAuthor,
		HistoryMessageMarkupData &&markup) const override;

	QString getErrorOnSend(
		const Result *owner,
		not_null<History*> history) const override;

private:
	PhotoData *_photo;
	QString _message;
	EntitiesInText _entities;

};

// Message with file.
class SendFile : public SendData {
public:
	SendFile(
		not_null<Main::Session*> session,
		DocumentData *document,
		const QString &message,
		const EntitiesInText &entities)
	: SendData(session)
	, _document(document)
	, _message(message)
	, _entities(entities) {
	}

	bool isValid() const override {
		return _document != nullptr;
	}

	void addToHistory(
		const Result *owner,
		not_null<History*> history,
		MessageFlags flags,
		MsgId msgId,
		PeerId fromId,
		TimeId date,
		UserId viaBotId,
		MsgId replyToId,
		const QString &postAuthor,
		HistoryMessageMarkupData &&markup) const override;

	QString getErrorOnSend(
		const Result *owner,
		not_null<History*> history) const override;

private:
	DocumentData *_document;
	QString _message;
	EntitiesInText _entities;

};

// Message with game.
class SendGame : public SendData {
public:
	SendGame(not_null<Main::Session*> session, GameData *game)
	: SendData(session)
	, _game(game) {
	}

	bool isValid() const override {
		return _game != nullptr;
	}

	void addToHistory(
		const Result *owner,
		not_null<History*> history,
		MessageFlags flags,
		MsgId msgId,
		PeerId fromId,
		TimeId date,
		UserId viaBotId,
		MsgId replyToId,
		const QString &postAuthor,
		HistoryMessageMarkupData &&markup) const override;

	QString getErrorOnSend(
		const Result *owner,
		not_null<History*> history) const override;

private:
	GameData *_game;

};

class SendInvoice : public SendDataCommon {
public:
	SendInvoice(
		not_null<Main::Session*> session,
		MTPMessageMedia media)
	: SendDataCommon(session)
	, _media(media) {
	}

	bool isValid() const override {
		return true;
	}

	SentMessageFields getSentMessageFields() const override;

	QString getLayoutDescription(const Result *owner) const override;

private:
	MTPMessageMedia _media;

};

} // namespace internal
} // namespace InlineBots