2018-09-28 22:57:34 +02:00
|
|
|
//
|
2022-12-31 22:28:08 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
|
2018-09-28 22:57:34 +02:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
#include "td/telegram/MessageContent.h"
|
|
|
|
|
2023-09-19 20:59:14 +02:00
|
|
|
#include "td/telegram/AccessRights.h"
|
2018-09-28 22:57:34 +02:00
|
|
|
#include "td/telegram/AnimationsManager.h"
|
|
|
|
#include "td/telegram/AnimationsManager.hpp"
|
|
|
|
#include "td/telegram/AudiosManager.h"
|
|
|
|
#include "td/telegram/AudiosManager.hpp"
|
|
|
|
#include "td/telegram/AuthManager.h"
|
2023-04-10 15:32:59 +02:00
|
|
|
#include "td/telegram/BackgroundInfo.hpp"
|
2018-09-28 22:57:34 +02:00
|
|
|
#include "td/telegram/CallDiscardReason.h"
|
|
|
|
#include "td/telegram/ChannelId.h"
|
|
|
|
#include "td/telegram/ChatId.h"
|
|
|
|
#include "td/telegram/Contact.h"
|
|
|
|
#include "td/telegram/ContactsManager.h"
|
2022-10-03 00:26:32 +02:00
|
|
|
#include "td/telegram/CustomEmojiId.h"
|
2021-04-04 02:23:22 +02:00
|
|
|
#include "td/telegram/Dependencies.h"
|
2021-09-19 00:52:56 +02:00
|
|
|
#include "td/telegram/DialogAction.h"
|
2021-04-13 01:59:33 +02:00
|
|
|
#include "td/telegram/DialogParticipant.h"
|
2022-06-02 16:52:12 +02:00
|
|
|
#include "td/telegram/Dimensions.h"
|
2019-04-09 17:38:57 +02:00
|
|
|
#include "td/telegram/Document.h"
|
2018-09-28 22:57:34 +02:00
|
|
|
#include "td/telegram/DocumentsManager.h"
|
|
|
|
#include "td/telegram/DocumentsManager.hpp"
|
|
|
|
#include "td/telegram/files/FileId.h"
|
|
|
|
#include "td/telegram/files/FileId.hpp"
|
2019-01-19 22:54:29 +01:00
|
|
|
#include "td/telegram/files/FileLocation.h"
|
2018-09-28 22:57:34 +02:00
|
|
|
#include "td/telegram/files/FileManager.h"
|
2019-01-19 22:54:29 +01:00
|
|
|
#include "td/telegram/files/FileType.h"
|
2022-10-18 21:16:03 +02:00
|
|
|
#include "td/telegram/ForumTopicEditedData.h"
|
|
|
|
#include "td/telegram/ForumTopicEditedData.hpp"
|
2022-10-18 15:08:53 +02:00
|
|
|
#include "td/telegram/ForumTopicIcon.h"
|
|
|
|
#include "td/telegram/ForumTopicIcon.hpp"
|
2022-10-27 18:03:58 +02:00
|
|
|
#include "td/telegram/ForumTopicManager.h"
|
2018-09-28 22:57:34 +02:00
|
|
|
#include "td/telegram/Game.h"
|
|
|
|
#include "td/telegram/Game.hpp"
|
2023-10-12 16:05:03 +02:00
|
|
|
#include "td/telegram/GiveawayParameters.h"
|
|
|
|
#include "td/telegram/GiveawayParameters.hpp"
|
2018-09-28 22:57:34 +02:00
|
|
|
#include "td/telegram/Global.h"
|
2020-12-03 17:52:50 +01:00
|
|
|
#include "td/telegram/GroupCallManager.h"
|
2020-01-27 01:34:23 +01:00
|
|
|
#include "td/telegram/HashtagHints.h"
|
2020-11-24 12:33:16 +01:00
|
|
|
#include "td/telegram/InputGroupCallId.h"
|
2022-09-22 18:08:06 +02:00
|
|
|
#include "td/telegram/InputInvoice.h"
|
|
|
|
#include "td/telegram/InputInvoice.hpp"
|
2018-09-28 22:57:34 +02:00
|
|
|
#include "td/telegram/InputMessageText.h"
|
|
|
|
#include "td/telegram/Location.h"
|
|
|
|
#include "td/telegram/MessageEntity.h"
|
|
|
|
#include "td/telegram/MessageEntity.hpp"
|
|
|
|
#include "td/telegram/MessageId.h"
|
2020-08-22 09:27:13 +02:00
|
|
|
#include "td/telegram/MessageSearchFilter.h"
|
2021-11-14 23:18:47 +01:00
|
|
|
#include "td/telegram/MessageSender.h"
|
2023-04-13 21:41:22 +02:00
|
|
|
#include "td/telegram/MessagesManager.h"
|
2018-09-28 22:57:34 +02:00
|
|
|
#include "td/telegram/misc.h"
|
2022-08-18 16:00:18 +02:00
|
|
|
#include "td/telegram/OptionManager.h"
|
2022-09-22 18:28:39 +02:00
|
|
|
#include "td/telegram/OrderInfo.h"
|
|
|
|
#include "td/telegram/OrderInfo.hpp"
|
2018-09-28 22:57:34 +02:00
|
|
|
#include "td/telegram/Photo.h"
|
|
|
|
#include "td/telegram/Photo.hpp"
|
2022-04-09 22:21:07 +02:00
|
|
|
#include "td/telegram/PhotoFormat.h"
|
2022-04-10 00:15:49 +02:00
|
|
|
#include "td/telegram/PhotoSize.h"
|
2019-02-19 14:45:32 +01:00
|
|
|
#include "td/telegram/PollId.h"
|
|
|
|
#include "td/telegram/PollId.hpp"
|
|
|
|
#include "td/telegram/PollManager.h"
|
2018-09-28 22:57:34 +02:00
|
|
|
#include "td/telegram/secret_api.hpp"
|
|
|
|
#include "td/telegram/SecureValue.h"
|
|
|
|
#include "td/telegram/SecureValue.hpp"
|
2022-01-18 17:20:43 +01:00
|
|
|
#include "td/telegram/StickerFormat.h"
|
2018-09-28 22:57:34 +02:00
|
|
|
#include "td/telegram/StickersManager.h"
|
|
|
|
#include "td/telegram/StickersManager.hpp"
|
2022-07-18 13:51:37 +02:00
|
|
|
#include "td/telegram/StickerType.h"
|
2023-06-12 18:23:58 +02:00
|
|
|
#include "td/telegram/StoryFullId.h"
|
2023-07-01 15:22:01 +02:00
|
|
|
#include "td/telegram/StoryId.h"
|
2023-06-12 18:23:58 +02:00
|
|
|
#include "td/telegram/StoryManager.h"
|
2018-09-28 22:57:34 +02:00
|
|
|
#include "td/telegram/Td.h"
|
2023-07-01 13:53:04 +02:00
|
|
|
#include "td/telegram/telegram_api.h"
|
2020-01-27 01:25:23 +01:00
|
|
|
#include "td/telegram/TopDialogManager.h"
|
2018-09-28 22:57:34 +02:00
|
|
|
#include "td/telegram/UserId.h"
|
2019-10-13 01:39:44 +02:00
|
|
|
#include "td/telegram/Venue.h"
|
2018-09-29 03:41:15 +02:00
|
|
|
#include "td/telegram/Version.h"
|
2018-09-28 22:57:34 +02:00
|
|
|
#include "td/telegram/VideoNotesManager.h"
|
|
|
|
#include "td/telegram/VideoNotesManager.hpp"
|
2018-09-29 03:41:15 +02:00
|
|
|
#include "td/telegram/VideosManager.h"
|
|
|
|
#include "td/telegram/VideosManager.hpp"
|
2018-09-28 22:57:34 +02:00
|
|
|
#include "td/telegram/VoiceNotesManager.h"
|
|
|
|
#include "td/telegram/VoiceNotesManager.hpp"
|
2023-02-22 10:24:43 +01:00
|
|
|
#include "td/telegram/WebApp.h"
|
|
|
|
#include "td/telegram/WebApp.hpp"
|
2018-09-28 22:57:34 +02:00
|
|
|
#include "td/telegram/WebPageId.h"
|
|
|
|
#include "td/telegram/WebPagesManager.h"
|
|
|
|
|
2020-01-27 02:54:01 +01:00
|
|
|
#include "td/actor/actor.h"
|
2018-09-28 22:57:34 +02:00
|
|
|
#include "td/actor/MultiPromise.h"
|
|
|
|
|
2021-01-01 13:59:53 +01:00
|
|
|
#include "td/utils/algorithm.h"
|
2021-09-21 05:32:34 +02:00
|
|
|
#include "td/utils/emoji.h"
|
2018-09-28 22:57:34 +02:00
|
|
|
#include "td/utils/format.h"
|
|
|
|
#include "td/utils/HttpUrl.h"
|
2018-09-29 01:45:43 +02:00
|
|
|
#include "td/utils/logging.h"
|
2018-09-28 22:57:34 +02:00
|
|
|
#include "td/utils/MimeType.h"
|
|
|
|
#include "td/utils/misc.h"
|
|
|
|
#include "td/utils/PathView.h"
|
2020-01-27 02:54:01 +01:00
|
|
|
#include "td/utils/Slice.h"
|
2021-05-17 14:21:11 +02:00
|
|
|
#include "td/utils/SliceBuilder.h"
|
2018-09-28 22:57:34 +02:00
|
|
|
#include "td/utils/tl_helpers.h"
|
2019-08-14 02:13:34 +02:00
|
|
|
#include "td/utils/utf8.h"
|
2018-09-29 03:41:15 +02:00
|
|
|
|
2021-09-01 19:31:39 +02:00
|
|
|
#include <limits>
|
2018-09-29 03:41:15 +02:00
|
|
|
#include <utility>
|
2018-09-28 22:57:34 +02:00
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessageText final : public MessageContent {
|
2018-09-28 22:57:34 +02:00
|
|
|
public:
|
|
|
|
FormattedText text;
|
|
|
|
WebPageId web_page_id;
|
2023-10-16 15:47:22 +02:00
|
|
|
bool force_small_media = false;
|
|
|
|
bool force_large_media = false;
|
2023-10-19 12:03:27 +02:00
|
|
|
bool skip_web_page_confirmation = false;
|
2023-10-16 21:33:53 +02:00
|
|
|
string web_page_url;
|
2018-09-28 22:57:34 +02:00
|
|
|
|
|
|
|
MessageText() = default;
|
2023-10-16 21:33:53 +02:00
|
|
|
MessageText(FormattedText text, WebPageId web_page_id, bool force_small_media, bool force_large_media,
|
2023-10-19 12:03:27 +02:00
|
|
|
bool skip_web_page_confirmation, string web_page_url)
|
2023-10-16 15:47:22 +02:00
|
|
|
: text(std::move(text))
|
|
|
|
, web_page_id(web_page_id)
|
|
|
|
, force_small_media(force_small_media)
|
|
|
|
, force_large_media(force_large_media)
|
2023-10-19 12:03:27 +02:00
|
|
|
, skip_web_page_confirmation(skip_web_page_confirmation)
|
2023-10-16 21:33:53 +02:00
|
|
|
, web_page_url(std::move(web_page_url)) {
|
2023-10-16 23:08:50 +02:00
|
|
|
if (web_page_url.empty()) {
|
|
|
|
force_small_media = false;
|
|
|
|
force_large_media = false;
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2018-09-28 22:57:34 +02:00
|
|
|
return MessageContentType::Text;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessageAnimation final : public MessageContent {
|
2018-09-28 22:57:34 +02:00
|
|
|
public:
|
|
|
|
FileId file_id;
|
|
|
|
|
|
|
|
FormattedText caption;
|
2022-12-26 12:20:48 +01:00
|
|
|
bool has_spoiler = false;
|
2018-09-28 22:57:34 +02:00
|
|
|
|
|
|
|
MessageAnimation() = default;
|
2022-12-26 12:20:48 +01:00
|
|
|
MessageAnimation(FileId file_id, FormattedText &&caption, bool has_spoiler)
|
|
|
|
: file_id(file_id), caption(std::move(caption)), has_spoiler(has_spoiler) {
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2018-09-28 22:57:34 +02:00
|
|
|
return MessageContentType::Animation;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessageAudio final : public MessageContent {
|
2018-09-28 22:57:34 +02:00
|
|
|
public:
|
|
|
|
FileId file_id;
|
|
|
|
|
|
|
|
FormattedText caption;
|
|
|
|
|
|
|
|
MessageAudio() = default;
|
|
|
|
MessageAudio(FileId file_id, FormattedText &&caption) : file_id(file_id), caption(std::move(caption)) {
|
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2018-09-28 22:57:34 +02:00
|
|
|
return MessageContentType::Audio;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessageDocument final : public MessageContent {
|
2018-09-28 22:57:34 +02:00
|
|
|
public:
|
|
|
|
FileId file_id;
|
|
|
|
|
|
|
|
FormattedText caption;
|
|
|
|
|
|
|
|
MessageDocument() = default;
|
|
|
|
MessageDocument(FileId file_id, FormattedText &&caption) : file_id(file_id), caption(std::move(caption)) {
|
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2018-09-28 22:57:34 +02:00
|
|
|
return MessageContentType::Document;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessagePhoto final : public MessageContent {
|
2018-09-28 22:57:34 +02:00
|
|
|
public:
|
|
|
|
Photo photo;
|
|
|
|
|
|
|
|
FormattedText caption;
|
2022-12-20 16:06:21 +01:00
|
|
|
bool has_spoiler = false;
|
2018-09-28 22:57:34 +02:00
|
|
|
|
|
|
|
MessagePhoto() = default;
|
2022-12-20 16:06:21 +01:00
|
|
|
MessagePhoto(Photo &&photo, FormattedText &&caption, bool has_spoiler)
|
|
|
|
: photo(std::move(photo)), caption(std::move(caption)), has_spoiler(has_spoiler) {
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2018-09-28 22:57:34 +02:00
|
|
|
return MessageContentType::Photo;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessageSticker final : public MessageContent {
|
2018-09-28 22:57:34 +02:00
|
|
|
public:
|
|
|
|
FileId file_id;
|
2022-06-03 15:33:49 +02:00
|
|
|
bool is_premium = false;
|
2018-09-28 22:57:34 +02:00
|
|
|
|
|
|
|
MessageSticker() = default;
|
2022-06-03 15:33:49 +02:00
|
|
|
MessageSticker(FileId file_id, bool is_premium) : file_id(file_id), is_premium(is_premium) {
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2018-09-28 22:57:34 +02:00
|
|
|
return MessageContentType::Sticker;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessageVideo final : public MessageContent {
|
2018-09-28 22:57:34 +02:00
|
|
|
public:
|
|
|
|
FileId file_id;
|
|
|
|
|
|
|
|
FormattedText caption;
|
2022-12-20 16:06:21 +01:00
|
|
|
bool has_spoiler = false;
|
2018-09-28 22:57:34 +02:00
|
|
|
|
|
|
|
MessageVideo() = default;
|
2022-12-20 16:06:21 +01:00
|
|
|
MessageVideo(FileId file_id, FormattedText &&caption, bool has_spoiler)
|
|
|
|
: file_id(file_id), caption(std::move(caption)), has_spoiler(has_spoiler) {
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2018-09-28 22:57:34 +02:00
|
|
|
return MessageContentType::Video;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessageVoiceNote final : public MessageContent {
|
2018-09-28 22:57:34 +02:00
|
|
|
public:
|
|
|
|
FileId file_id;
|
|
|
|
|
|
|
|
FormattedText caption;
|
|
|
|
bool is_listened;
|
|
|
|
|
|
|
|
MessageVoiceNote() = default;
|
|
|
|
MessageVoiceNote(FileId file_id, FormattedText &&caption, bool is_listened)
|
|
|
|
: file_id(file_id), caption(std::move(caption)), is_listened(is_listened) {
|
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2018-09-28 22:57:34 +02:00
|
|
|
return MessageContentType::VoiceNote;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessageContact final : public MessageContent {
|
2018-09-28 22:57:34 +02:00
|
|
|
public:
|
|
|
|
Contact contact;
|
|
|
|
|
|
|
|
MessageContact() = default;
|
|
|
|
explicit MessageContact(Contact &&contact) : contact(std::move(contact)) {
|
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2018-09-28 22:57:34 +02:00
|
|
|
return MessageContentType::Contact;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessageLocation final : public MessageContent {
|
2018-09-28 22:57:34 +02:00
|
|
|
public:
|
|
|
|
Location location;
|
|
|
|
|
|
|
|
MessageLocation() = default;
|
|
|
|
explicit MessageLocation(Location &&location) : location(std::move(location)) {
|
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2018-09-28 22:57:34 +02:00
|
|
|
return MessageContentType::Location;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessageVenue final : public MessageContent {
|
2018-09-28 22:57:34 +02:00
|
|
|
public:
|
|
|
|
Venue venue;
|
|
|
|
|
|
|
|
MessageVenue() = default;
|
|
|
|
explicit MessageVenue(Venue &&venue) : venue(std::move(venue)) {
|
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2018-09-28 22:57:34 +02:00
|
|
|
return MessageContentType::Venue;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessageChatCreate final : public MessageContent {
|
2018-09-28 22:57:34 +02:00
|
|
|
public:
|
|
|
|
string title;
|
|
|
|
vector<UserId> participant_user_ids;
|
|
|
|
|
|
|
|
MessageChatCreate() = default;
|
|
|
|
MessageChatCreate(string &&title, vector<UserId> &&participant_user_ids)
|
|
|
|
: title(std::move(title)), participant_user_ids(std::move(participant_user_ids)) {
|
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2018-09-28 22:57:34 +02:00
|
|
|
return MessageContentType::ChatCreate;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessageChatChangeTitle final : public MessageContent {
|
2018-09-28 22:57:34 +02:00
|
|
|
public:
|
|
|
|
string title;
|
|
|
|
|
|
|
|
MessageChatChangeTitle() = default;
|
|
|
|
explicit MessageChatChangeTitle(string &&title) : title(std::move(title)) {
|
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2018-09-28 22:57:34 +02:00
|
|
|
return MessageContentType::ChatChangeTitle;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessageChatChangePhoto final : public MessageContent {
|
2018-09-28 22:57:34 +02:00
|
|
|
public:
|
|
|
|
Photo photo;
|
|
|
|
|
|
|
|
MessageChatChangePhoto() = default;
|
|
|
|
explicit MessageChatChangePhoto(Photo &&photo) : photo(std::move(photo)) {
|
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2018-09-28 22:57:34 +02:00
|
|
|
return MessageContentType::ChatChangePhoto;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessageChatDeletePhoto final : public MessageContent {
|
2018-09-28 22:57:34 +02:00
|
|
|
public:
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2018-09-28 22:57:34 +02:00
|
|
|
return MessageContentType::ChatDeletePhoto;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessageChatDeleteHistory final : public MessageContent {
|
2018-09-28 22:57:34 +02:00
|
|
|
public:
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2018-09-28 22:57:34 +02:00
|
|
|
return MessageContentType::ChatDeleteHistory;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessageChatAddUsers final : public MessageContent {
|
2018-09-28 22:57:34 +02:00
|
|
|
public:
|
|
|
|
vector<UserId> user_ids;
|
|
|
|
|
|
|
|
MessageChatAddUsers() = default;
|
|
|
|
explicit MessageChatAddUsers(vector<UserId> &&user_ids) : user_ids(std::move(user_ids)) {
|
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2018-09-28 22:57:34 +02:00
|
|
|
return MessageContentType::ChatAddUsers;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessageChatJoinedByLink final : public MessageContent {
|
2018-09-28 22:57:34 +02:00
|
|
|
public:
|
2021-10-09 14:04:17 +02:00
|
|
|
bool is_approved = false;
|
|
|
|
|
|
|
|
MessageChatJoinedByLink() = default;
|
|
|
|
explicit MessageChatJoinedByLink(bool is_approved) : is_approved(is_approved) {
|
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2018-09-28 22:57:34 +02:00
|
|
|
return MessageContentType::ChatJoinedByLink;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessageChatDeleteUser final : public MessageContent {
|
2018-09-28 22:57:34 +02:00
|
|
|
public:
|
|
|
|
UserId user_id;
|
|
|
|
|
|
|
|
MessageChatDeleteUser() = default;
|
|
|
|
explicit MessageChatDeleteUser(UserId user_id) : user_id(user_id) {
|
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2018-09-28 22:57:34 +02:00
|
|
|
return MessageContentType::ChatDeleteUser;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessageChatMigrateTo final : public MessageContent {
|
2018-09-28 22:57:34 +02:00
|
|
|
public:
|
|
|
|
ChannelId migrated_to_channel_id;
|
|
|
|
|
|
|
|
MessageChatMigrateTo() = default;
|
|
|
|
explicit MessageChatMigrateTo(ChannelId migrated_to_channel_id) : migrated_to_channel_id(migrated_to_channel_id) {
|
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2018-09-28 22:57:34 +02:00
|
|
|
return MessageContentType::ChatMigrateTo;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessageChannelCreate final : public MessageContent {
|
2018-09-28 22:57:34 +02:00
|
|
|
public:
|
|
|
|
string title;
|
|
|
|
|
|
|
|
MessageChannelCreate() = default;
|
|
|
|
explicit MessageChannelCreate(string &&title) : title(std::move(title)) {
|
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2018-09-28 22:57:34 +02:00
|
|
|
return MessageContentType::ChannelCreate;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessageChannelMigrateFrom final : public MessageContent {
|
2018-09-28 22:57:34 +02:00
|
|
|
public:
|
|
|
|
string title;
|
|
|
|
ChatId migrated_from_chat_id;
|
|
|
|
|
|
|
|
MessageChannelMigrateFrom() = default;
|
|
|
|
MessageChannelMigrateFrom(string &&title, ChatId migrated_from_chat_id)
|
|
|
|
: title(std::move(title)), migrated_from_chat_id(migrated_from_chat_id) {
|
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2018-09-28 22:57:34 +02:00
|
|
|
return MessageContentType::ChannelMigrateFrom;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessagePinMessage final : public MessageContent {
|
2018-09-28 22:57:34 +02:00
|
|
|
public:
|
|
|
|
MessageId message_id;
|
|
|
|
|
|
|
|
MessagePinMessage() = default;
|
|
|
|
explicit MessagePinMessage(MessageId message_id) : message_id(message_id) {
|
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2018-09-28 22:57:34 +02:00
|
|
|
return MessageContentType::PinMessage;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessageGame final : public MessageContent {
|
2018-09-28 22:57:34 +02:00
|
|
|
public:
|
|
|
|
Game game;
|
|
|
|
|
|
|
|
MessageGame() = default;
|
|
|
|
explicit MessageGame(Game &&game) : game(std::move(game)) {
|
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2018-09-28 22:57:34 +02:00
|
|
|
return MessageContentType::Game;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessageGameScore final : public MessageContent {
|
2018-09-28 22:57:34 +02:00
|
|
|
public:
|
|
|
|
MessageId game_message_id;
|
|
|
|
int64 game_id;
|
|
|
|
int32 score;
|
|
|
|
|
|
|
|
MessageGameScore() = default;
|
|
|
|
MessageGameScore(MessageId game_message_id, int64 game_id, int32 score)
|
|
|
|
: game_message_id(game_message_id), game_id(game_id), score(score) {
|
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2018-09-28 22:57:34 +02:00
|
|
|
return MessageContentType::GameScore;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessageScreenshotTaken final : public MessageContent {
|
2018-09-28 22:57:34 +02:00
|
|
|
public:
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2018-09-28 22:57:34 +02:00
|
|
|
return MessageContentType::ScreenshotTaken;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessageChatSetTtl final : public MessageContent {
|
2018-09-28 22:57:34 +02:00
|
|
|
public:
|
|
|
|
int32 ttl;
|
2022-11-29 12:02:05 +01:00
|
|
|
UserId from_user_id;
|
2018-09-28 22:57:34 +02:00
|
|
|
|
|
|
|
MessageChatSetTtl() = default;
|
2022-11-29 12:02:05 +01:00
|
|
|
MessageChatSetTtl(int32 ttl, UserId from_user_id) : ttl(ttl), from_user_id(from_user_id) {
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2018-09-28 22:57:34 +02:00
|
|
|
return MessageContentType::ChatSetTtl;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessageUnsupported final : public MessageContent {
|
2018-09-28 22:57:34 +02:00
|
|
|
public:
|
2023-10-16 10:31:11 +02:00
|
|
|
static constexpr int32 CURRENT_VERSION = 23;
|
2018-12-25 18:47:37 +01:00
|
|
|
int32 version = CURRENT_VERSION;
|
|
|
|
|
|
|
|
MessageUnsupported() = default;
|
|
|
|
explicit MessageUnsupported(int32 version) : version(version) {
|
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2018-09-28 22:57:34 +02:00
|
|
|
return MessageContentType::Unsupported;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessageCall final : public MessageContent {
|
2018-09-28 22:57:34 +02:00
|
|
|
public:
|
|
|
|
int64 call_id;
|
|
|
|
int32 duration;
|
|
|
|
CallDiscardReason discard_reason;
|
2019-06-08 11:26:35 +02:00
|
|
|
bool is_video;
|
2018-09-28 22:57:34 +02:00
|
|
|
|
|
|
|
MessageCall() = default;
|
2019-06-08 11:26:35 +02:00
|
|
|
MessageCall(int64 call_id, int32 duration, CallDiscardReason discard_reason, bool is_video)
|
|
|
|
: call_id(call_id), duration(duration), discard_reason(discard_reason), is_video(is_video) {
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2018-09-28 22:57:34 +02:00
|
|
|
return MessageContentType::Call;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessageInvoice final : public MessageContent {
|
2018-09-28 22:57:34 +02:00
|
|
|
public:
|
2021-03-31 00:20:40 +02:00
|
|
|
InputInvoice input_invoice;
|
2018-09-28 22:57:34 +02:00
|
|
|
|
|
|
|
MessageInvoice() = default;
|
2021-03-31 00:20:40 +02:00
|
|
|
explicit MessageInvoice(InputInvoice &&input_invoice) : input_invoice(std::move(input_invoice)) {
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2018-09-28 22:57:34 +02:00
|
|
|
return MessageContentType::Invoice;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessagePaymentSuccessful final : public MessageContent {
|
2018-09-28 22:57:34 +02:00
|
|
|
public:
|
2021-03-31 14:36:25 +02:00
|
|
|
DialogId invoice_dialog_id;
|
2018-09-28 22:57:34 +02:00
|
|
|
MessageId invoice_message_id;
|
|
|
|
string currency;
|
|
|
|
int64 total_amount = 0;
|
2022-05-11 17:52:45 +02:00
|
|
|
string invoice_payload; // or invoice_slug for users
|
2022-05-30 15:35:25 +02:00
|
|
|
bool is_recurring = false;
|
|
|
|
bool is_first_recurring = false;
|
2018-09-28 22:57:34 +02:00
|
|
|
|
|
|
|
// bots only part
|
|
|
|
string shipping_option_id;
|
|
|
|
unique_ptr<OrderInfo> order_info;
|
|
|
|
string telegram_payment_charge_id;
|
|
|
|
string provider_payment_charge_id;
|
|
|
|
|
|
|
|
MessagePaymentSuccessful() = default;
|
2021-03-31 14:36:25 +02:00
|
|
|
MessagePaymentSuccessful(DialogId invoice_dialog_id, MessageId invoice_message_id, string &¤cy,
|
2022-05-30 15:35:25 +02:00
|
|
|
int64 total_amount, string &&invoice_payload, bool is_recurring, bool is_first_recurring)
|
2021-03-31 14:36:25 +02:00
|
|
|
: invoice_dialog_id(invoice_dialog_id)
|
|
|
|
, invoice_message_id(invoice_message_id)
|
|
|
|
, currency(std::move(currency))
|
2022-05-11 17:52:45 +02:00
|
|
|
, total_amount(total_amount)
|
2022-05-30 15:35:25 +02:00
|
|
|
, invoice_payload(std::move(invoice_payload))
|
|
|
|
, is_recurring(is_recurring || is_first_recurring)
|
|
|
|
, is_first_recurring(is_first_recurring) {
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2018-09-28 22:57:34 +02:00
|
|
|
return MessageContentType::PaymentSuccessful;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessageVideoNote final : public MessageContent {
|
2018-09-28 22:57:34 +02:00
|
|
|
public:
|
|
|
|
FileId file_id;
|
|
|
|
|
|
|
|
bool is_viewed = false;
|
|
|
|
|
|
|
|
MessageVideoNote() = default;
|
|
|
|
MessageVideoNote(FileId file_id, bool is_viewed) : file_id(file_id), is_viewed(is_viewed) {
|
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2018-09-28 22:57:34 +02:00
|
|
|
return MessageContentType::VideoNote;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessageContactRegistered final : public MessageContent {
|
2018-09-28 22:57:34 +02:00
|
|
|
public:
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2018-09-28 22:57:34 +02:00
|
|
|
return MessageContentType::ContactRegistered;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessageExpiredPhoto final : public MessageContent {
|
2018-09-28 22:57:34 +02:00
|
|
|
public:
|
|
|
|
MessageExpiredPhoto() = default;
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2018-09-28 22:57:34 +02:00
|
|
|
return MessageContentType::ExpiredPhoto;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessageExpiredVideo final : public MessageContent {
|
2018-09-28 22:57:34 +02:00
|
|
|
public:
|
|
|
|
MessageExpiredVideo() = default;
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2018-09-28 22:57:34 +02:00
|
|
|
return MessageContentType::ExpiredVideo;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessageLiveLocation final : public MessageContent {
|
2018-09-28 22:57:34 +02:00
|
|
|
public:
|
|
|
|
Location location;
|
2020-10-16 22:08:28 +02:00
|
|
|
int32 period = 0;
|
|
|
|
int32 heading = 0;
|
2020-10-30 13:51:20 +01:00
|
|
|
int32 proximity_alert_radius = 0;
|
2018-09-28 22:57:34 +02:00
|
|
|
|
|
|
|
MessageLiveLocation() = default;
|
2020-10-30 13:51:20 +01:00
|
|
|
MessageLiveLocation(Location &&location, int32 period, int32 heading, int32 proximity_alert_radius)
|
2020-10-24 23:49:41 +02:00
|
|
|
: location(std::move(location))
|
|
|
|
, period(period)
|
|
|
|
, heading(heading)
|
2020-10-30 13:51:20 +01:00
|
|
|
, proximity_alert_radius(proximity_alert_radius) {
|
2020-10-24 23:49:41 +02:00
|
|
|
if (period < 0) {
|
2021-10-19 17:11:16 +02:00
|
|
|
this->period = 0;
|
2020-10-24 23:49:41 +02:00
|
|
|
}
|
2020-10-16 22:08:28 +02:00
|
|
|
if (heading < 0 || heading > 360) {
|
|
|
|
LOG(ERROR) << "Receive wrong heading " << heading;
|
2021-10-19 17:11:16 +02:00
|
|
|
this->heading = 0;
|
2020-10-16 22:08:28 +02:00
|
|
|
}
|
2020-10-30 13:51:20 +01:00
|
|
|
if (proximity_alert_radius < 0) {
|
2021-10-19 17:11:16 +02:00
|
|
|
this->proximity_alert_radius = 0;
|
2020-10-24 23:49:41 +02:00
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2018-09-28 22:57:34 +02:00
|
|
|
return MessageContentType::LiveLocation;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessageCustomServiceAction final : public MessageContent {
|
2018-09-28 22:57:34 +02:00
|
|
|
public:
|
|
|
|
string message;
|
|
|
|
|
|
|
|
MessageCustomServiceAction() = default;
|
|
|
|
explicit MessageCustomServiceAction(string &&message) : message(std::move(message)) {
|
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2018-09-28 22:57:34 +02:00
|
|
|
return MessageContentType::CustomServiceAction;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessageWebsiteConnected final : public MessageContent {
|
2018-09-28 22:57:34 +02:00
|
|
|
public:
|
|
|
|
string domain_name;
|
|
|
|
|
|
|
|
MessageWebsiteConnected() = default;
|
|
|
|
explicit MessageWebsiteConnected(string &&domain_name) : domain_name(std::move(domain_name)) {
|
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2018-09-28 22:57:34 +02:00
|
|
|
return MessageContentType::WebsiteConnected;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessagePassportDataSent final : public MessageContent {
|
2018-09-28 22:57:34 +02:00
|
|
|
public:
|
|
|
|
vector<SecureValueType> types;
|
|
|
|
|
|
|
|
MessagePassportDataSent() = default;
|
|
|
|
explicit MessagePassportDataSent(vector<SecureValueType> &&types) : types(std::move(types)) {
|
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2018-09-28 22:57:34 +02:00
|
|
|
return MessageContentType::PassportDataSent;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessagePassportDataReceived final : public MessageContent {
|
2018-09-28 22:57:34 +02:00
|
|
|
public:
|
|
|
|
vector<EncryptedSecureValue> values;
|
|
|
|
EncryptedSecureCredentials credentials;
|
|
|
|
|
|
|
|
MessagePassportDataReceived() = default;
|
|
|
|
MessagePassportDataReceived(vector<EncryptedSecureValue> &&values, EncryptedSecureCredentials &&credentials)
|
|
|
|
: values(std::move(values)), credentials(std::move(credentials)) {
|
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2018-09-28 22:57:34 +02:00
|
|
|
return MessageContentType::PassportDataReceived;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessagePoll final : public MessageContent {
|
2019-02-19 14:45:32 +01:00
|
|
|
public:
|
|
|
|
PollId poll_id;
|
|
|
|
|
|
|
|
MessagePoll() = default;
|
|
|
|
explicit MessagePoll(PollId poll_id) : poll_id(poll_id) {
|
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2019-02-19 14:45:32 +01:00
|
|
|
return MessageContentType::Poll;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessageDice final : public MessageContent {
|
2020-03-14 17:56:39 +01:00
|
|
|
public:
|
2020-04-18 07:45:41 +02:00
|
|
|
string emoji;
|
2020-03-29 23:34:37 +02:00
|
|
|
int32 dice_value = 0;
|
2020-03-14 17:56:39 +01:00
|
|
|
|
2020-04-18 07:45:41 +02:00
|
|
|
static constexpr const char *DEFAULT_EMOJI = "🎲";
|
|
|
|
|
2020-03-29 23:34:37 +02:00
|
|
|
MessageDice() = default;
|
2021-09-20 12:45:49 +02:00
|
|
|
MessageDice(const string &emoji, int32 dice_value)
|
2022-05-12 17:02:27 +02:00
|
|
|
: emoji(emoji.empty() ? string(DEFAULT_EMOJI) : remove_emoji_modifiers(emoji)), dice_value(dice_value) {
|
2020-03-14 17:56:39 +01:00
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2020-03-29 23:34:37 +02:00
|
|
|
return MessageContentType::Dice;
|
2020-03-14 17:56:39 +01:00
|
|
|
}
|
2020-04-19 08:47:37 +02:00
|
|
|
|
|
|
|
bool is_valid() const {
|
|
|
|
if (dice_value < 0) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-05-17 00:28:56 +02:00
|
|
|
if (emoji == DEFAULT_EMOJI || emoji == "🎯") {
|
2020-04-19 08:47:37 +02:00
|
|
|
return dice_value <= 6;
|
|
|
|
}
|
|
|
|
return dice_value <= 1000;
|
|
|
|
}
|
2020-03-14 17:56:39 +01:00
|
|
|
};
|
|
|
|
|
2020-11-24 12:33:16 +01:00
|
|
|
constexpr const char *MessageDice::DEFAULT_EMOJI;
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessageProximityAlertTriggered final : public MessageContent {
|
2020-10-19 19:44:09 +02:00
|
|
|
public:
|
2020-10-30 23:38:11 +01:00
|
|
|
DialogId traveler_dialog_id;
|
|
|
|
DialogId watcher_dialog_id;
|
2020-10-19 19:44:09 +02:00
|
|
|
int32 distance = 0;
|
|
|
|
|
2020-10-29 20:25:58 +01:00
|
|
|
MessageProximityAlertTriggered() = default;
|
2020-10-30 23:38:11 +01:00
|
|
|
MessageProximityAlertTriggered(DialogId traveler_dialog_id, DialogId watcher_dialog_id, int32 distance)
|
|
|
|
: traveler_dialog_id(traveler_dialog_id), watcher_dialog_id(watcher_dialog_id), distance(distance) {
|
2020-10-19 19:44:09 +02:00
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2020-10-29 20:25:58 +01:00
|
|
|
return MessageContentType::ProximityAlertTriggered;
|
2020-10-19 19:44:09 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessageGroupCall final : public MessageContent {
|
2020-11-24 12:33:16 +01:00
|
|
|
public:
|
2020-12-03 17:52:50 +01:00
|
|
|
InputGroupCallId input_group_call_id;
|
2020-11-24 12:33:16 +01:00
|
|
|
int32 duration = -1;
|
2021-04-05 23:24:05 +02:00
|
|
|
int32 schedule_date = -1;
|
2020-11-24 12:33:16 +01:00
|
|
|
|
|
|
|
MessageGroupCall() = default;
|
2021-04-05 23:24:05 +02:00
|
|
|
MessageGroupCall(InputGroupCallId input_group_call_id, int32 duration, int32 schedule_date)
|
|
|
|
: input_group_call_id(input_group_call_id), duration(duration), schedule_date(schedule_date) {
|
2020-11-24 12:33:16 +01:00
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2020-11-24 12:33:16 +01:00
|
|
|
return MessageContentType::GroupCall;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class MessageInviteToGroupCall final : public MessageContent {
|
2020-11-24 12:33:16 +01:00
|
|
|
public:
|
2020-12-03 17:52:50 +01:00
|
|
|
InputGroupCallId input_group_call_id;
|
2020-11-29 13:41:03 +01:00
|
|
|
vector<UserId> user_ids;
|
2020-11-24 12:33:16 +01:00
|
|
|
|
|
|
|
MessageInviteToGroupCall() = default;
|
2020-12-03 17:52:50 +01:00
|
|
|
MessageInviteToGroupCall(InputGroupCallId input_group_call_id, vector<UserId> &&user_ids)
|
|
|
|
: input_group_call_id(input_group_call_id), user_ids(std::move(user_ids)) {
|
2020-11-24 12:33:16 +01:00
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
MessageContentType get_type() const final {
|
2020-11-24 12:33:16 +01:00
|
|
|
return MessageContentType::InviteToGroupCall;
|
|
|
|
}
|
|
|
|
};
|
2020-04-18 07:45:41 +02:00
|
|
|
|
2021-08-18 15:03:10 +02:00
|
|
|
class MessageChatSetTheme final : public MessageContent {
|
|
|
|
public:
|
|
|
|
string emoji;
|
|
|
|
|
|
|
|
MessageChatSetTheme() = default;
|
|
|
|
explicit MessageChatSetTheme(string &&emoji) : emoji(std::move(emoji)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageContentType get_type() const final {
|
|
|
|
return MessageContentType::ChatSetTheme;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-03-28 09:01:39 +02:00
|
|
|
class MessageWebViewDataSent final : public MessageContent {
|
|
|
|
public:
|
|
|
|
string button_text;
|
|
|
|
|
|
|
|
MessageWebViewDataSent() = default;
|
|
|
|
explicit MessageWebViewDataSent(string &&button_text) : button_text(std::move(button_text)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageContentType get_type() const final {
|
|
|
|
return MessageContentType::WebViewDataSent;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class MessageWebViewDataReceived final : public MessageContent {
|
|
|
|
public:
|
|
|
|
string button_text;
|
|
|
|
string data;
|
|
|
|
|
|
|
|
MessageWebViewDataReceived() = default;
|
|
|
|
MessageWebViewDataReceived(string &&button_text, string &&data)
|
|
|
|
: button_text(std::move(button_text)), data(std::move(data)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageContentType get_type() const final {
|
|
|
|
return MessageContentType::WebViewDataReceived;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-07-01 14:28:22 +02:00
|
|
|
class MessageGiftPremium final : public MessageContent {
|
|
|
|
public:
|
|
|
|
string currency;
|
|
|
|
int64 amount = 0;
|
2023-03-21 12:54:36 +01:00
|
|
|
string crypto_currency;
|
|
|
|
int64 crypto_amount = 0;
|
2022-07-01 14:28:22 +02:00
|
|
|
int32 months = 0;
|
|
|
|
|
|
|
|
MessageGiftPremium() = default;
|
2023-03-21 12:54:36 +01:00
|
|
|
MessageGiftPremium(string &¤cy, int64 amount, string &&crypto_currency, int64 crypto_amount, int32 months)
|
|
|
|
: currency(std::move(currency))
|
|
|
|
, amount(amount)
|
|
|
|
, crypto_currency(std::move(crypto_currency))
|
|
|
|
, crypto_amount(crypto_amount)
|
|
|
|
, months(months) {
|
2022-07-01 14:28:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
MessageContentType get_type() const final {
|
|
|
|
return MessageContentType::GiftPremium;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-10-18 15:08:53 +02:00
|
|
|
class MessageTopicCreate final : public MessageContent {
|
|
|
|
public:
|
|
|
|
string title;
|
|
|
|
ForumTopicIcon icon;
|
|
|
|
|
|
|
|
MessageTopicCreate() = default;
|
2022-10-18 21:16:03 +02:00
|
|
|
MessageTopicCreate(string &&title, ForumTopicIcon &&icon) : title(std::move(title)), icon(std::move(icon)) {
|
2022-10-18 15:08:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
MessageContentType get_type() const final {
|
|
|
|
return MessageContentType::TopicCreate;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-10-18 21:16:03 +02:00
|
|
|
class MessageTopicEdit final : public MessageContent {
|
|
|
|
public:
|
|
|
|
ForumTopicEditedData edited_data;
|
|
|
|
|
|
|
|
MessageTopicEdit() = default;
|
|
|
|
explicit MessageTopicEdit(ForumTopicEditedData &&edited_data) : edited_data(std::move(edited_data)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageContentType get_type() const final {
|
|
|
|
return MessageContentType::TopicEdit;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-12-09 12:13:37 +01:00
|
|
|
class MessageSuggestProfilePhoto final : public MessageContent {
|
|
|
|
public:
|
|
|
|
Photo photo;
|
|
|
|
|
|
|
|
MessageSuggestProfilePhoto() = default;
|
|
|
|
explicit MessageSuggestProfilePhoto(Photo &&photo) : photo(std::move(photo)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageContentType get_type() const final {
|
|
|
|
return MessageContentType::SuggestProfilePhoto;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-12-14 19:13:48 +01:00
|
|
|
class MessageWriteAccessAllowed final : public MessageContent {
|
|
|
|
public:
|
|
|
|
MessageContentType get_type() const final {
|
|
|
|
return MessageContentType::WriteAccessAllowed;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-01-10 14:20:30 +01:00
|
|
|
class MessageRequestedDialog final : public MessageContent {
|
|
|
|
public:
|
|
|
|
DialogId dialog_id;
|
|
|
|
int32 button_id = 0;
|
|
|
|
|
|
|
|
MessageRequestedDialog() = default;
|
|
|
|
MessageRequestedDialog(DialogId dialog_id, int32 button_id) : dialog_id(dialog_id), button_id(button_id) {
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageContentType get_type() const final {
|
|
|
|
return MessageContentType::RequestedDialog;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-02-22 10:24:43 +01:00
|
|
|
class MessageWebViewWriteAccessAllowed final : public MessageContent {
|
|
|
|
public:
|
|
|
|
WebApp web_app;
|
|
|
|
|
|
|
|
MessageWebViewWriteAccessAllowed() = default;
|
|
|
|
explicit MessageWebViewWriteAccessAllowed(WebApp &&web_app) : web_app(std::move(web_app)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageContentType get_type() const final {
|
|
|
|
return MessageContentType::WebViewWriteAccessAllowed;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-04-10 13:12:35 +02:00
|
|
|
class MessageSetBackground final : public MessageContent {
|
|
|
|
public:
|
|
|
|
MessageId old_message_id;
|
2023-04-10 15:32:59 +02:00
|
|
|
BackgroundInfo background_info;
|
2023-04-10 13:12:35 +02:00
|
|
|
|
|
|
|
MessageSetBackground() = default;
|
2023-04-10 15:32:59 +02:00
|
|
|
MessageSetBackground(MessageId old_message_id, BackgroundInfo background_info)
|
|
|
|
: old_message_id(old_message_id), background_info(std::move(background_info)) {
|
2023-04-10 13:12:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
MessageContentType get_type() const final {
|
|
|
|
return MessageContentType::SetBackground;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-06-12 18:23:58 +02:00
|
|
|
class MessageStory final : public MessageContent {
|
|
|
|
public:
|
|
|
|
StoryFullId story_full_id;
|
|
|
|
bool via_mention = false;
|
|
|
|
|
|
|
|
MessageStory() = default;
|
|
|
|
MessageStory(StoryFullId story_full_id, bool via_mention) : story_full_id(story_full_id), via_mention(via_mention) {
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageContentType get_type() const final {
|
|
|
|
return MessageContentType::Story;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-08-25 15:53:50 +02:00
|
|
|
class MessageWriteAccessAllowedByRequest final : public MessageContent {
|
|
|
|
public:
|
|
|
|
MessageContentType get_type() const final {
|
|
|
|
return MessageContentType::WriteAccessAllowedByRequest;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-09-29 16:55:03 +02:00
|
|
|
class MessageGiftCode final : public MessageContent {
|
|
|
|
public:
|
|
|
|
DialogId creator_dialog_id;
|
|
|
|
int32 months = 0;
|
|
|
|
bool via_giveaway = false;
|
|
|
|
string code;
|
|
|
|
|
|
|
|
MessageGiftCode() = default;
|
|
|
|
MessageGiftCode(DialogId creator_dialog_id, int32 months, bool via_giveaway, string &&code)
|
|
|
|
: creator_dialog_id(creator_dialog_id), months(months), via_giveaway(via_giveaway), code(std::move(code)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageContentType get_type() const final {
|
|
|
|
return MessageContentType::GiftCode;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-09-29 23:32:39 +02:00
|
|
|
class MessageGiveaway final : public MessageContent {
|
|
|
|
public:
|
2023-10-12 16:05:03 +02:00
|
|
|
GiveawayParameters giveaway_parameters;
|
2023-09-29 23:32:39 +02:00
|
|
|
int32 quantity = 0;
|
|
|
|
int32 months = 0;
|
|
|
|
|
|
|
|
MessageGiveaway() = default;
|
2023-10-12 16:05:03 +02:00
|
|
|
MessageGiveaway(GiveawayParameters giveaway_parameters, int32 quantity, int32 months)
|
|
|
|
: giveaway_parameters(std::move(giveaway_parameters)), quantity(quantity), months(months) {
|
2023-09-29 23:32:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
MessageContentType get_type() const final {
|
|
|
|
return MessageContentType::Giveaway;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-10-16 10:31:11 +02:00
|
|
|
class MessageGiveawayLaunch final : public MessageContent {
|
|
|
|
public:
|
|
|
|
MessageGiveawayLaunch() = default;
|
|
|
|
|
|
|
|
MessageContentType get_type() const final {
|
|
|
|
return MessageContentType::GiveawayLaunch;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-09-28 22:57:34 +02:00
|
|
|
template <class StorerT>
|
|
|
|
static void store(const MessageContent *content, StorerT &storer) {
|
|
|
|
CHECK(content != nullptr);
|
|
|
|
|
|
|
|
Td *td = storer.context()->td().get_actor_unsafe();
|
|
|
|
CHECK(td != nullptr);
|
|
|
|
|
|
|
|
auto content_type = content->get_type();
|
|
|
|
store(content_type, storer);
|
|
|
|
|
|
|
|
switch (content_type) {
|
|
|
|
case MessageContentType::Animation: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageAnimation *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
td->animations_manager_->store_animation(m->file_id, storer);
|
2022-12-26 12:20:48 +01:00
|
|
|
BEGIN_STORE_FLAGS();
|
|
|
|
STORE_FLAG(m->has_spoiler);
|
|
|
|
END_STORE_FLAGS();
|
2018-09-28 22:57:34 +02:00
|
|
|
store(m->caption, storer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Audio: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageAudio *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
td->audios_manager_->store_audio(m->file_id, storer);
|
|
|
|
store(m->caption, storer);
|
|
|
|
store(true, storer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Contact: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageContact *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
store(m->contact, storer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Document: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageDocument *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
td->documents_manager_->store_document(m->file_id, storer);
|
|
|
|
store(m->caption, storer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Game: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageGame *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
store(m->game, storer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Invoice: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageInvoice *>(content);
|
2021-03-31 00:20:40 +02:00
|
|
|
store(m->input_invoice, storer);
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::LiveLocation: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageLiveLocation *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
store(m->location, storer);
|
|
|
|
store(m->period, storer);
|
2020-10-16 22:08:28 +02:00
|
|
|
store(m->heading, storer);
|
2020-10-30 13:51:20 +01:00
|
|
|
store(m->proximity_alert_radius, storer);
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Location: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageLocation *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
store(m->location, storer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Photo: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessagePhoto *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
store(m->photo, storer);
|
2022-12-20 16:06:21 +01:00
|
|
|
BEGIN_STORE_FLAGS();
|
|
|
|
STORE_FLAG(m->has_spoiler);
|
|
|
|
END_STORE_FLAGS();
|
2018-09-28 22:57:34 +02:00
|
|
|
store(m->caption, storer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Sticker: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageSticker *>(content);
|
2021-09-13 15:03:21 +02:00
|
|
|
td->stickers_manager_->store_sticker(m->file_id, false, storer, "MessageSticker");
|
2022-06-03 15:33:49 +02:00
|
|
|
BEGIN_STORE_FLAGS();
|
|
|
|
STORE_FLAG(m->is_premium);
|
|
|
|
END_STORE_FLAGS();
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Text: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageText *>(content);
|
2023-10-16 15:47:22 +02:00
|
|
|
bool has_web_page_id = m->web_page_id.is_valid();
|
2023-10-16 21:33:53 +02:00
|
|
|
bool has_web_page_url = !m->web_page_url.empty();
|
2023-10-16 15:47:22 +02:00
|
|
|
BEGIN_STORE_FLAGS();
|
|
|
|
STORE_FLAG(has_web_page_id);
|
|
|
|
STORE_FLAG(m->force_small_media);
|
|
|
|
STORE_FLAG(m->force_large_media);
|
2023-10-16 21:33:53 +02:00
|
|
|
STORE_FLAG(has_web_page_url);
|
2023-10-19 12:03:27 +02:00
|
|
|
STORE_FLAG(m->skip_web_page_confirmation);
|
2023-10-16 15:47:22 +02:00
|
|
|
END_STORE_FLAGS();
|
2018-09-28 22:57:34 +02:00
|
|
|
store(m->text, storer);
|
2023-10-16 15:47:22 +02:00
|
|
|
if (has_web_page_id) {
|
|
|
|
store(m->web_page_id, storer);
|
|
|
|
}
|
2023-10-16 21:33:53 +02:00
|
|
|
if (has_web_page_url) {
|
|
|
|
store(m->web_page_url, storer);
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
|
|
|
}
|
2018-12-25 18:47:37 +01:00
|
|
|
case MessageContentType::Unsupported: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageUnsupported *>(content);
|
2018-12-25 18:47:37 +01:00
|
|
|
store(m->version, storer);
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
2018-12-25 18:47:37 +01:00
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::Venue: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageVenue *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
store(m->venue, storer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Video: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageVideo *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
td->videos_manager_->store_video(m->file_id, storer);
|
2022-12-20 16:06:21 +01:00
|
|
|
BEGIN_STORE_FLAGS();
|
|
|
|
STORE_FLAG(m->has_spoiler);
|
|
|
|
END_STORE_FLAGS();
|
2018-09-28 22:57:34 +02:00
|
|
|
store(m->caption, storer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::VideoNote: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageVideoNote *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
td->video_notes_manager_->store_video_note(m->file_id, storer);
|
|
|
|
store(m->is_viewed, storer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::VoiceNote: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageVoiceNote *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
td->voice_notes_manager_->store_voice_note(m->file_id, storer);
|
|
|
|
store(m->caption, storer);
|
|
|
|
store(m->is_listened, storer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::ChatCreate: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageChatCreate *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
store(m->title, storer);
|
|
|
|
store(m->participant_user_ids, storer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::ChatChangeTitle: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageChatChangeTitle *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
store(m->title, storer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::ChatChangePhoto: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageChatChangePhoto *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
store(m->photo, storer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::ChatDeletePhoto:
|
2022-12-09 12:13:37 +01:00
|
|
|
break;
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::ChatDeleteHistory:
|
|
|
|
break;
|
|
|
|
case MessageContentType::ChatAddUsers: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageChatAddUsers *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
store(m->user_ids, storer);
|
|
|
|
break;
|
|
|
|
}
|
2021-10-09 14:04:17 +02:00
|
|
|
case MessageContentType::ChatJoinedByLink: {
|
|
|
|
auto m = static_cast<const MessageChatJoinedByLink *>(content);
|
|
|
|
BEGIN_STORE_FLAGS();
|
|
|
|
STORE_FLAG(m->is_approved);
|
|
|
|
END_STORE_FLAGS();
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
2021-10-09 14:04:17 +02:00
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::ChatDeleteUser: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageChatDeleteUser *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
store(m->user_id, storer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::ChatMigrateTo: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageChatMigrateTo *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
store(m->migrated_to_channel_id, storer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::ChannelCreate: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageChannelCreate *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
store(m->title, storer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::ChannelMigrateFrom: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageChannelMigrateFrom *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
store(m->title, storer);
|
|
|
|
store(m->migrated_from_chat_id, storer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::PinMessage: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessagePinMessage *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
store(m->message_id, storer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::GameScore: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageGameScore *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
store(m->game_message_id, storer);
|
|
|
|
store(m->game_id, storer);
|
|
|
|
store(m->score, storer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::ScreenshotTaken:
|
|
|
|
break;
|
|
|
|
case MessageContentType::ChatSetTtl: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageChatSetTtl *>(content);
|
2022-11-29 12:02:05 +01:00
|
|
|
bool has_from_user_id = m->from_user_id.is_valid();
|
|
|
|
BEGIN_STORE_FLAGS();
|
|
|
|
STORE_FLAG(has_from_user_id);
|
|
|
|
END_STORE_FLAGS();
|
2018-09-28 22:57:34 +02:00
|
|
|
store(m->ttl, storer);
|
2022-11-29 12:02:05 +01:00
|
|
|
if (has_from_user_id) {
|
|
|
|
store(m->from_user_id, storer);
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Call: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageCall *>(content);
|
2019-06-08 11:26:35 +02:00
|
|
|
BEGIN_STORE_FLAGS();
|
|
|
|
STORE_FLAG(m->is_video);
|
|
|
|
END_STORE_FLAGS();
|
2018-09-28 22:57:34 +02:00
|
|
|
store(m->call_id, storer);
|
|
|
|
store(m->duration, storer);
|
|
|
|
store(m->discard_reason, storer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::PaymentSuccessful: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessagePaymentSuccessful *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
bool has_payload = !m->invoice_payload.empty();
|
|
|
|
bool has_shipping_option_id = !m->shipping_option_id.empty();
|
|
|
|
bool has_order_info = m->order_info != nullptr;
|
|
|
|
bool has_telegram_payment_charge_id = !m->telegram_payment_charge_id.empty();
|
|
|
|
bool has_provider_payment_charge_id = !m->provider_payment_charge_id.empty();
|
|
|
|
bool has_invoice_message_id = m->invoice_message_id.is_valid();
|
2021-04-02 16:04:51 +02:00
|
|
|
bool is_correctly_stored = true;
|
2021-03-31 14:36:25 +02:00
|
|
|
bool has_invoice_dialog_id = m->invoice_dialog_id.is_valid();
|
2018-09-28 22:57:34 +02:00
|
|
|
BEGIN_STORE_FLAGS();
|
|
|
|
STORE_FLAG(has_payload);
|
|
|
|
STORE_FLAG(has_shipping_option_id);
|
|
|
|
STORE_FLAG(has_order_info);
|
|
|
|
STORE_FLAG(has_telegram_payment_charge_id);
|
|
|
|
STORE_FLAG(has_provider_payment_charge_id);
|
|
|
|
STORE_FLAG(has_invoice_message_id);
|
2021-04-02 16:04:51 +02:00
|
|
|
STORE_FLAG(is_correctly_stored);
|
2021-03-31 14:36:25 +02:00
|
|
|
STORE_FLAG(has_invoice_dialog_id);
|
2022-05-30 15:35:25 +02:00
|
|
|
STORE_FLAG(m->is_recurring);
|
|
|
|
STORE_FLAG(m->is_first_recurring);
|
2018-09-28 22:57:34 +02:00
|
|
|
END_STORE_FLAGS();
|
|
|
|
store(m->currency, storer);
|
|
|
|
store(m->total_amount, storer);
|
|
|
|
if (has_payload) {
|
2021-04-02 16:04:51 +02:00
|
|
|
store(m->invoice_payload, storer);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
if (has_shipping_option_id) {
|
2021-04-02 16:04:51 +02:00
|
|
|
store(m->shipping_option_id, storer);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
if (has_order_info) {
|
2019-09-18 01:42:38 +02:00
|
|
|
store(m->order_info, storer);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
if (has_telegram_payment_charge_id) {
|
|
|
|
store(m->telegram_payment_charge_id, storer);
|
|
|
|
}
|
|
|
|
if (has_provider_payment_charge_id) {
|
|
|
|
store(m->provider_payment_charge_id, storer);
|
|
|
|
}
|
|
|
|
if (has_invoice_message_id) {
|
|
|
|
store(m->invoice_message_id, storer);
|
|
|
|
}
|
2021-03-31 14:36:25 +02:00
|
|
|
if (has_invoice_dialog_id) {
|
|
|
|
store(m->invoice_dialog_id, storer);
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::ContactRegistered:
|
|
|
|
break;
|
|
|
|
case MessageContentType::ExpiredPhoto:
|
|
|
|
break;
|
|
|
|
case MessageContentType::ExpiredVideo:
|
|
|
|
break;
|
|
|
|
case MessageContentType::CustomServiceAction: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageCustomServiceAction *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
store(m->message, storer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::WebsiteConnected: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageWebsiteConnected *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
store(m->domain_name, storer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::PassportDataSent: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessagePassportDataSent *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
store(m->types, storer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::PassportDataReceived: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessagePassportDataReceived *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
store(m->values, storer);
|
|
|
|
store(m->credentials, storer);
|
|
|
|
break;
|
|
|
|
}
|
2019-02-19 14:45:32 +01:00
|
|
|
case MessageContentType::Poll: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessagePoll *>(content);
|
2019-02-19 14:45:32 +01:00
|
|
|
store(m->poll_id, storer);
|
|
|
|
break;
|
|
|
|
}
|
2020-03-29 23:34:37 +02:00
|
|
|
case MessageContentType::Dice: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageDice *>(content);
|
2020-04-18 07:45:41 +02:00
|
|
|
store(m->emoji, storer);
|
2020-03-29 23:34:37 +02:00
|
|
|
store(m->dice_value, storer);
|
2020-03-14 17:56:39 +01:00
|
|
|
break;
|
|
|
|
}
|
2020-10-29 20:25:58 +01:00
|
|
|
case MessageContentType::ProximityAlertTriggered: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageProximityAlertTriggered *>(content);
|
2020-10-30 23:38:11 +01:00
|
|
|
store(m->traveler_dialog_id, storer);
|
|
|
|
store(m->watcher_dialog_id, storer);
|
2020-10-19 19:44:09 +02:00
|
|
|
store(m->distance, storer);
|
|
|
|
break;
|
|
|
|
}
|
2020-11-24 12:33:16 +01:00
|
|
|
case MessageContentType::GroupCall: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageGroupCall *>(content);
|
2020-11-24 12:33:16 +01:00
|
|
|
bool has_duration = m->duration >= 0;
|
2021-04-05 23:24:05 +02:00
|
|
|
bool has_schedule_date = m->schedule_date > 0;
|
2020-11-24 12:33:16 +01:00
|
|
|
BEGIN_STORE_FLAGS();
|
|
|
|
STORE_FLAG(has_duration);
|
2021-04-05 23:24:05 +02:00
|
|
|
STORE_FLAG(has_schedule_date);
|
2020-11-24 12:33:16 +01:00
|
|
|
END_STORE_FLAGS();
|
2020-12-03 17:52:50 +01:00
|
|
|
store(m->input_group_call_id, storer);
|
2020-11-24 12:33:16 +01:00
|
|
|
if (has_duration) {
|
|
|
|
store(m->duration, storer);
|
|
|
|
}
|
2021-04-05 23:24:05 +02:00
|
|
|
if (has_schedule_date) {
|
|
|
|
store(m->schedule_date, storer);
|
|
|
|
}
|
2020-11-24 12:33:16 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::InviteToGroupCall: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageInviteToGroupCall *>(content);
|
2020-12-03 17:52:50 +01:00
|
|
|
store(m->input_group_call_id, storer);
|
2020-11-29 13:41:03 +01:00
|
|
|
store(m->user_ids, storer);
|
2020-11-24 12:33:16 +01:00
|
|
|
break;
|
|
|
|
}
|
2021-08-18 15:03:10 +02:00
|
|
|
case MessageContentType::ChatSetTheme: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageChatSetTheme *>(content);
|
2021-08-18 15:03:10 +02:00
|
|
|
store(m->emoji, storer);
|
|
|
|
break;
|
|
|
|
}
|
2022-03-28 09:01:39 +02:00
|
|
|
case MessageContentType::WebViewDataSent: {
|
|
|
|
const auto *m = static_cast<const MessageWebViewDataSent *>(content);
|
|
|
|
store(m->button_text, storer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::WebViewDataReceived: {
|
|
|
|
const auto *m = static_cast<const MessageWebViewDataReceived *>(content);
|
|
|
|
store(m->button_text, storer);
|
|
|
|
store(m->data, storer);
|
|
|
|
break;
|
|
|
|
}
|
2022-07-01 14:28:22 +02:00
|
|
|
case MessageContentType::GiftPremium: {
|
|
|
|
const auto *m = static_cast<const MessageGiftPremium *>(content);
|
2023-03-21 12:54:36 +01:00
|
|
|
bool has_crypto_amount = !m->crypto_currency.empty();
|
2022-07-01 14:28:22 +02:00
|
|
|
BEGIN_STORE_FLAGS();
|
2023-03-21 12:54:36 +01:00
|
|
|
STORE_FLAG(has_crypto_amount);
|
2022-07-01 14:28:22 +02:00
|
|
|
END_STORE_FLAGS();
|
|
|
|
store(m->currency, storer);
|
|
|
|
store(m->amount, storer);
|
|
|
|
store(m->months, storer);
|
2023-03-21 12:54:36 +01:00
|
|
|
if (has_crypto_amount) {
|
|
|
|
store(m->crypto_currency, storer);
|
|
|
|
store(m->crypto_amount, storer);
|
|
|
|
}
|
2022-07-01 14:28:22 +02:00
|
|
|
break;
|
|
|
|
}
|
2022-10-18 15:08:53 +02:00
|
|
|
case MessageContentType::TopicCreate: {
|
|
|
|
const auto *m = static_cast<const MessageTopicCreate *>(content);
|
|
|
|
store(m->title, storer);
|
|
|
|
store(m->icon, storer);
|
|
|
|
break;
|
|
|
|
}
|
2022-10-18 21:16:03 +02:00
|
|
|
case MessageContentType::TopicEdit: {
|
|
|
|
const auto *m = static_cast<const MessageTopicEdit *>(content);
|
|
|
|
store(m->edited_data, storer);
|
|
|
|
break;
|
|
|
|
}
|
2022-12-09 12:13:37 +01:00
|
|
|
case MessageContentType::SuggestProfilePhoto: {
|
|
|
|
const auto *m = static_cast<const MessageSuggestProfilePhoto *>(content);
|
|
|
|
store(m->photo, storer);
|
|
|
|
break;
|
|
|
|
}
|
2022-12-14 19:13:48 +01:00
|
|
|
case MessageContentType::WriteAccessAllowed:
|
|
|
|
break;
|
2023-01-10 14:20:30 +01:00
|
|
|
case MessageContentType::RequestedDialog: {
|
|
|
|
const auto *m = static_cast<const MessageRequestedDialog *>(content);
|
|
|
|
store(m->dialog_id, storer);
|
|
|
|
store(m->button_id, storer);
|
|
|
|
break;
|
|
|
|
}
|
2023-02-22 10:24:43 +01:00
|
|
|
case MessageContentType::WebViewWriteAccessAllowed: {
|
|
|
|
const auto *m = static_cast<const MessageWebViewWriteAccessAllowed *>(content);
|
|
|
|
store(m->web_app, storer);
|
|
|
|
break;
|
|
|
|
}
|
2023-04-10 13:12:35 +02:00
|
|
|
case MessageContentType::SetBackground: {
|
|
|
|
const auto *m = static_cast<const MessageSetBackground *>(content);
|
|
|
|
bool has_message_id = m->old_message_id.is_valid();
|
|
|
|
BEGIN_STORE_FLAGS();
|
|
|
|
STORE_FLAG(has_message_id);
|
|
|
|
END_STORE_FLAGS();
|
|
|
|
if (has_message_id) {
|
|
|
|
store(m->old_message_id, storer);
|
|
|
|
}
|
2023-04-10 15:32:59 +02:00
|
|
|
store(m->background_info, storer);
|
2023-04-10 13:12:35 +02:00
|
|
|
break;
|
|
|
|
}
|
2023-06-12 18:23:58 +02:00
|
|
|
case MessageContentType::Story: {
|
|
|
|
const auto *m = static_cast<const MessageStory *>(content);
|
|
|
|
BEGIN_STORE_FLAGS();
|
|
|
|
STORE_FLAG(m->via_mention);
|
|
|
|
END_STORE_FLAGS();
|
|
|
|
store(m->story_full_id, storer);
|
|
|
|
break;
|
|
|
|
}
|
2023-08-25 15:53:50 +02:00
|
|
|
case MessageContentType::WriteAccessAllowedByRequest:
|
|
|
|
break;
|
2023-09-29 16:55:03 +02:00
|
|
|
case MessageContentType::GiftCode: {
|
|
|
|
const auto *m = static_cast<const MessageGiftCode *>(content);
|
|
|
|
bool has_creator_dialog_id = m->creator_dialog_id.is_valid();
|
|
|
|
BEGIN_STORE_FLAGS();
|
|
|
|
STORE_FLAG(m->via_giveaway);
|
|
|
|
STORE_FLAG(has_creator_dialog_id);
|
|
|
|
END_STORE_FLAGS();
|
|
|
|
if (has_creator_dialog_id) {
|
|
|
|
store(m->creator_dialog_id, storer);
|
|
|
|
}
|
|
|
|
store(m->months, storer);
|
|
|
|
store(m->code, storer);
|
|
|
|
break;
|
|
|
|
}
|
2023-09-29 23:32:39 +02:00
|
|
|
case MessageContentType::Giveaway: {
|
|
|
|
const auto *m = static_cast<const MessageGiveaway *>(content);
|
|
|
|
BEGIN_STORE_FLAGS();
|
|
|
|
END_STORE_FLAGS();
|
2023-10-12 16:05:03 +02:00
|
|
|
store(m->giveaway_parameters, storer);
|
2023-09-29 23:32:39 +02:00
|
|
|
store(m->quantity, storer);
|
|
|
|
store(m->months, storer);
|
|
|
|
break;
|
|
|
|
}
|
2023-10-16 10:31:11 +02:00
|
|
|
case MessageContentType::GiveawayLaunch:
|
|
|
|
break;
|
2018-09-28 22:57:34 +02:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
static void parse_caption(FormattedText &caption, ParserT &parser) {
|
|
|
|
parse(caption.text, parser);
|
|
|
|
if (parser.version() >= static_cast<int32>(Version::AddCaptionEntities)) {
|
|
|
|
parse(caption.entities, parser);
|
2022-07-30 23:34:30 +02:00
|
|
|
remove_empty_entities(caption.entities);
|
2018-09-28 22:57:34 +02:00
|
|
|
} else {
|
2019-07-27 22:07:10 +02:00
|
|
|
if (!check_utf8(caption.text)) {
|
|
|
|
caption.text.clear();
|
|
|
|
}
|
2021-08-04 03:26:41 +02:00
|
|
|
caption.entities = find_entities(caption.text, false, true);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
static void parse(unique_ptr<MessageContent> &content, ParserT &parser) {
|
|
|
|
Td *td = parser.context()->td().get_actor_unsafe();
|
|
|
|
CHECK(td != nullptr);
|
|
|
|
|
|
|
|
MessageContentType content_type;
|
|
|
|
parse(content_type, parser);
|
|
|
|
|
|
|
|
bool is_bad = false;
|
|
|
|
switch (content_type) {
|
|
|
|
case MessageContentType::Animation: {
|
|
|
|
auto m = make_unique<MessageAnimation>();
|
|
|
|
m->file_id = td->animations_manager_->parse_animation(parser);
|
2022-12-26 12:20:48 +01:00
|
|
|
if (parser.version() >= static_cast<int32>(Version::AddMessageMediaSpoiler)) {
|
|
|
|
BEGIN_PARSE_FLAGS();
|
|
|
|
PARSE_FLAG(m->has_spoiler);
|
|
|
|
END_PARSE_FLAGS();
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
parse_caption(m->caption, parser);
|
|
|
|
is_bad = !m->file_id.is_valid();
|
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Audio: {
|
|
|
|
auto m = make_unique<MessageAudio>();
|
|
|
|
m->file_id = td->audios_manager_->parse_audio(parser);
|
|
|
|
parse_caption(m->caption, parser);
|
|
|
|
bool legacy_is_listened;
|
|
|
|
parse(legacy_is_listened, parser);
|
|
|
|
is_bad = !m->file_id.is_valid();
|
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Contact: {
|
|
|
|
auto m = make_unique<MessageContact>();
|
|
|
|
parse(m->contact, parser);
|
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Document: {
|
|
|
|
auto m = make_unique<MessageDocument>();
|
|
|
|
m->file_id = td->documents_manager_->parse_document(parser);
|
|
|
|
parse_caption(m->caption, parser);
|
|
|
|
is_bad = !m->file_id.is_valid();
|
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Game: {
|
|
|
|
auto m = make_unique<MessageGame>();
|
|
|
|
parse(m->game, parser);
|
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Invoice: {
|
|
|
|
auto m = make_unique<MessageInvoice>();
|
2021-03-31 00:20:40 +02:00
|
|
|
parse(m->input_invoice, parser);
|
2018-09-28 22:57:34 +02:00
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::LiveLocation: {
|
|
|
|
auto m = make_unique<MessageLiveLocation>();
|
|
|
|
parse(m->location, parser);
|
|
|
|
parse(m->period, parser);
|
2020-10-16 22:08:28 +02:00
|
|
|
if (parser.version() >= static_cast<int32>(Version::AddLiveLocationHeading)) {
|
|
|
|
parse(m->heading, parser);
|
|
|
|
} else {
|
|
|
|
m->heading = 0;
|
|
|
|
}
|
2020-10-29 20:25:58 +01:00
|
|
|
if (parser.version() >= static_cast<int32>(Version::AddLiveLocationProximityAlertDistance)) {
|
2020-10-30 13:51:20 +01:00
|
|
|
parse(m->proximity_alert_radius, parser);
|
2020-10-24 23:49:41 +02:00
|
|
|
} else {
|
2020-10-30 13:51:20 +01:00
|
|
|
m->proximity_alert_radius = 0;
|
2020-10-24 23:49:41 +02:00
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Location: {
|
|
|
|
auto m = make_unique<MessageLocation>();
|
|
|
|
parse(m->location, parser);
|
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Photo: {
|
|
|
|
auto m = make_unique<MessagePhoto>();
|
|
|
|
parse(m->photo, parser);
|
2022-09-22 17:25:20 +02:00
|
|
|
is_bad |= m->photo.is_bad();
|
2022-12-20 16:06:21 +01:00
|
|
|
if (parser.version() >= static_cast<int32>(Version::AddMessageMediaSpoiler)) {
|
|
|
|
BEGIN_PARSE_FLAGS();
|
|
|
|
PARSE_FLAG(m->has_spoiler);
|
|
|
|
END_PARSE_FLAGS();
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
parse_caption(m->caption, parser);
|
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Sticker: {
|
|
|
|
auto m = make_unique<MessageSticker>();
|
|
|
|
m->file_id = td->stickers_manager_->parse_sticker(false, parser);
|
2022-06-03 15:33:49 +02:00
|
|
|
if (parser.version() >= static_cast<int32>(Version::AddMessageStickerFlags)) {
|
|
|
|
BEGIN_PARSE_FLAGS();
|
|
|
|
PARSE_FLAG(m->is_premium);
|
|
|
|
END_PARSE_FLAGS();
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
is_bad = !m->file_id.is_valid();
|
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Text: {
|
|
|
|
auto m = make_unique<MessageText>();
|
2023-10-16 15:47:22 +02:00
|
|
|
bool has_web_page_id = true;
|
2023-10-16 21:33:53 +02:00
|
|
|
bool has_web_page_url = false;
|
2023-10-16 15:47:22 +02:00
|
|
|
if (parser.version() >= static_cast<int32>(Version::AddMessageTextFlags)) {
|
|
|
|
BEGIN_PARSE_FLAGS();
|
|
|
|
PARSE_FLAG(has_web_page_id);
|
|
|
|
PARSE_FLAG(m->force_small_media);
|
|
|
|
PARSE_FLAG(m->force_large_media);
|
2023-10-16 21:33:53 +02:00
|
|
|
PARSE_FLAG(has_web_page_url);
|
2023-10-19 12:03:27 +02:00
|
|
|
PARSE_FLAG(m->skip_web_page_confirmation);
|
2023-10-16 15:47:22 +02:00
|
|
|
END_PARSE_FLAGS();
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
parse(m->text, parser);
|
2023-10-16 15:47:22 +02:00
|
|
|
if (has_web_page_id) {
|
|
|
|
parse(m->web_page_id, parser);
|
|
|
|
}
|
2023-10-16 21:33:53 +02:00
|
|
|
if (has_web_page_url) {
|
|
|
|
parse(m->web_page_url, parser);
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
2018-12-25 18:47:37 +01:00
|
|
|
case MessageContentType::Unsupported: {
|
|
|
|
auto m = make_unique<MessageUnsupported>();
|
|
|
|
if (parser.version() >= static_cast<int32>(Version::AddMessageUnsupportedVersion)) {
|
|
|
|
parse(m->version, parser);
|
|
|
|
} else {
|
|
|
|
m->version = 0;
|
|
|
|
}
|
|
|
|
content = std::move(m);
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
2018-12-25 18:47:37 +01:00
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::Venue: {
|
|
|
|
auto m = make_unique<MessageVenue>();
|
|
|
|
parse(m->venue, parser);
|
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Video: {
|
|
|
|
auto m = make_unique<MessageVideo>();
|
|
|
|
m->file_id = td->videos_manager_->parse_video(parser);
|
2022-12-20 16:06:21 +01:00
|
|
|
if (parser.version() >= static_cast<int32>(Version::AddMessageMediaSpoiler)) {
|
|
|
|
BEGIN_PARSE_FLAGS();
|
|
|
|
PARSE_FLAG(m->has_spoiler);
|
|
|
|
END_PARSE_FLAGS();
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
parse_caption(m->caption, parser);
|
|
|
|
is_bad = !m->file_id.is_valid();
|
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::VideoNote: {
|
|
|
|
auto m = make_unique<MessageVideoNote>();
|
|
|
|
m->file_id = td->video_notes_manager_->parse_video_note(parser);
|
|
|
|
parse(m->is_viewed, parser);
|
|
|
|
is_bad = !m->file_id.is_valid();
|
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::VoiceNote: {
|
|
|
|
auto m = make_unique<MessageVoiceNote>();
|
|
|
|
m->file_id = td->voice_notes_manager_->parse_voice_note(parser);
|
|
|
|
parse_caption(m->caption, parser);
|
|
|
|
parse(m->is_listened, parser);
|
|
|
|
is_bad = !m->file_id.is_valid();
|
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::ChatCreate: {
|
|
|
|
auto m = make_unique<MessageChatCreate>();
|
|
|
|
parse(m->title, parser);
|
|
|
|
parse(m->participant_user_ids, parser);
|
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::ChatChangeTitle: {
|
|
|
|
auto m = make_unique<MessageChatChangeTitle>();
|
|
|
|
parse(m->title, parser);
|
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::ChatChangePhoto: {
|
|
|
|
auto m = make_unique<MessageChatChangePhoto>();
|
|
|
|
parse(m->photo, parser);
|
2022-06-05 21:51:13 +02:00
|
|
|
if (m->photo.is_empty()) {
|
|
|
|
is_bad = true;
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::ChatDeletePhoto:
|
|
|
|
content = make_unique<MessageChatDeletePhoto>();
|
|
|
|
break;
|
|
|
|
case MessageContentType::ChatDeleteHistory:
|
|
|
|
content = make_unique<MessageChatDeleteHistory>();
|
|
|
|
break;
|
|
|
|
case MessageContentType::ChatAddUsers: {
|
|
|
|
auto m = make_unique<MessageChatAddUsers>();
|
|
|
|
parse(m->user_ids, parser);
|
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
2021-10-09 14:04:17 +02:00
|
|
|
case MessageContentType::ChatJoinedByLink: {
|
|
|
|
auto m = make_unique<MessageChatJoinedByLink>();
|
|
|
|
if (parser.version() >= static_cast<int32>(Version::AddInviteLinksRequiringApproval)) {
|
|
|
|
BEGIN_PARSE_FLAGS();
|
|
|
|
PARSE_FLAG(m->is_approved);
|
|
|
|
END_PARSE_FLAGS();
|
|
|
|
} else {
|
|
|
|
m->is_approved = false;
|
|
|
|
}
|
|
|
|
content = std::move(m);
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
2021-10-09 14:04:17 +02:00
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::ChatDeleteUser: {
|
|
|
|
auto m = make_unique<MessageChatDeleteUser>();
|
|
|
|
parse(m->user_id, parser);
|
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::ChatMigrateTo: {
|
|
|
|
auto m = make_unique<MessageChatMigrateTo>();
|
|
|
|
parse(m->migrated_to_channel_id, parser);
|
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::ChannelCreate: {
|
|
|
|
auto m = make_unique<MessageChannelCreate>();
|
|
|
|
parse(m->title, parser);
|
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::ChannelMigrateFrom: {
|
|
|
|
auto m = make_unique<MessageChannelMigrateFrom>();
|
|
|
|
parse(m->title, parser);
|
|
|
|
parse(m->migrated_from_chat_id, parser);
|
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::PinMessage: {
|
|
|
|
auto m = make_unique<MessagePinMessage>();
|
|
|
|
parse(m->message_id, parser);
|
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::GameScore: {
|
|
|
|
auto m = make_unique<MessageGameScore>();
|
|
|
|
parse(m->game_message_id, parser);
|
|
|
|
parse(m->game_id, parser);
|
|
|
|
parse(m->score, parser);
|
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::ScreenshotTaken:
|
|
|
|
content = make_unique<MessageScreenshotTaken>();
|
|
|
|
break;
|
|
|
|
case MessageContentType::ChatSetTtl: {
|
|
|
|
auto m = make_unique<MessageChatSetTtl>();
|
2022-11-29 12:02:05 +01:00
|
|
|
bool has_from_user_id = false;
|
|
|
|
if (parser.version() >= static_cast<int32>(Version::AddMessageChatSetTtlFlags)) {
|
|
|
|
BEGIN_PARSE_FLAGS();
|
|
|
|
PARSE_FLAG(has_from_user_id);
|
|
|
|
END_PARSE_FLAGS();
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
parse(m->ttl, parser);
|
2022-11-29 12:02:05 +01:00
|
|
|
if (has_from_user_id) {
|
|
|
|
parse(m->from_user_id, parser);
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Call: {
|
|
|
|
auto m = make_unique<MessageCall>();
|
2019-06-08 11:26:35 +02:00
|
|
|
if (parser.version() >= static_cast<int32>(Version::AddVideoCallsSupport)) {
|
|
|
|
BEGIN_PARSE_FLAGS();
|
|
|
|
PARSE_FLAG(m->is_video);
|
|
|
|
END_PARSE_FLAGS();
|
|
|
|
} else {
|
|
|
|
m->is_video = false;
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
parse(m->call_id, parser);
|
|
|
|
parse(m->duration, parser);
|
|
|
|
parse(m->discard_reason, parser);
|
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::PaymentSuccessful: {
|
|
|
|
auto m = make_unique<MessagePaymentSuccessful>();
|
|
|
|
bool has_payload;
|
|
|
|
bool has_shipping_option_id;
|
|
|
|
bool has_order_info;
|
|
|
|
bool has_telegram_payment_charge_id;
|
|
|
|
bool has_provider_payment_charge_id;
|
|
|
|
bool has_invoice_message_id;
|
2021-04-02 16:04:51 +02:00
|
|
|
bool is_correctly_stored;
|
2021-03-31 14:36:25 +02:00
|
|
|
bool has_invoice_dialog_id;
|
2018-09-28 22:57:34 +02:00
|
|
|
BEGIN_PARSE_FLAGS();
|
|
|
|
PARSE_FLAG(has_payload);
|
|
|
|
PARSE_FLAG(has_shipping_option_id);
|
|
|
|
PARSE_FLAG(has_order_info);
|
|
|
|
PARSE_FLAG(has_telegram_payment_charge_id);
|
|
|
|
PARSE_FLAG(has_provider_payment_charge_id);
|
|
|
|
PARSE_FLAG(has_invoice_message_id);
|
2021-04-02 16:04:51 +02:00
|
|
|
PARSE_FLAG(is_correctly_stored);
|
2021-03-31 14:36:25 +02:00
|
|
|
PARSE_FLAG(has_invoice_dialog_id);
|
2022-05-30 15:35:25 +02:00
|
|
|
PARSE_FLAG(m->is_recurring);
|
|
|
|
PARSE_FLAG(m->is_first_recurring);
|
2018-09-28 22:57:34 +02:00
|
|
|
END_PARSE_FLAGS();
|
|
|
|
parse(m->currency, parser);
|
|
|
|
parse(m->total_amount, parser);
|
2021-04-02 16:04:51 +02:00
|
|
|
if (is_correctly_stored) {
|
|
|
|
if (has_payload) {
|
|
|
|
parse(m->invoice_payload, parser);
|
|
|
|
}
|
|
|
|
if (has_shipping_option_id) {
|
|
|
|
parse(m->shipping_option_id, parser);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (has_payload) {
|
|
|
|
parse(m->total_amount, parser);
|
|
|
|
}
|
|
|
|
if (has_shipping_option_id) {
|
|
|
|
parse(m->invoice_payload, parser);
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
if (has_order_info) {
|
2019-09-18 01:42:38 +02:00
|
|
|
parse(m->order_info, parser);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
if (has_telegram_payment_charge_id) {
|
|
|
|
parse(m->telegram_payment_charge_id, parser);
|
|
|
|
}
|
|
|
|
if (has_provider_payment_charge_id) {
|
|
|
|
parse(m->provider_payment_charge_id, parser);
|
|
|
|
}
|
|
|
|
if (has_invoice_message_id) {
|
|
|
|
parse(m->invoice_message_id, parser);
|
|
|
|
}
|
2021-03-31 14:36:25 +02:00
|
|
|
if (has_invoice_dialog_id) {
|
|
|
|
parse(m->invoice_dialog_id, parser);
|
|
|
|
}
|
2021-04-02 16:04:51 +02:00
|
|
|
if (is_correctly_stored) {
|
|
|
|
content = std::move(m);
|
|
|
|
} else {
|
|
|
|
content = make_unique<MessageUnsupported>(0);
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::ContactRegistered:
|
|
|
|
content = make_unique<MessageContactRegistered>();
|
|
|
|
break;
|
|
|
|
case MessageContentType::ExpiredPhoto:
|
|
|
|
content = make_unique<MessageExpiredPhoto>();
|
|
|
|
break;
|
|
|
|
case MessageContentType::ExpiredVideo:
|
|
|
|
content = make_unique<MessageExpiredVideo>();
|
|
|
|
break;
|
|
|
|
case MessageContentType::CustomServiceAction: {
|
|
|
|
auto m = make_unique<MessageCustomServiceAction>();
|
|
|
|
parse(m->message, parser);
|
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::WebsiteConnected: {
|
|
|
|
auto m = make_unique<MessageWebsiteConnected>();
|
|
|
|
parse(m->domain_name, parser);
|
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::PassportDataSent: {
|
|
|
|
auto m = make_unique<MessagePassportDataSent>();
|
|
|
|
parse(m->types, parser);
|
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::PassportDataReceived: {
|
|
|
|
auto m = make_unique<MessagePassportDataReceived>();
|
|
|
|
parse(m->values, parser);
|
|
|
|
parse(m->credentials, parser);
|
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
2019-02-19 14:45:32 +01:00
|
|
|
case MessageContentType::Poll: {
|
|
|
|
auto m = make_unique<MessagePoll>();
|
|
|
|
parse(m->poll_id, parser);
|
|
|
|
is_bad = !m->poll_id.is_valid();
|
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
2020-03-29 23:34:37 +02:00
|
|
|
case MessageContentType::Dice: {
|
|
|
|
auto m = make_unique<MessageDice>();
|
2020-04-18 07:45:41 +02:00
|
|
|
if (parser.version() >= static_cast<int32>(Version::AddDiceEmoji)) {
|
2021-09-20 12:45:49 +02:00
|
|
|
parse(m->emoji, parser);
|
|
|
|
remove_emoji_modifiers_in_place(m->emoji);
|
2020-04-18 07:45:41 +02:00
|
|
|
} else {
|
|
|
|
m->emoji = MessageDice::DEFAULT_EMOJI;
|
|
|
|
}
|
2020-03-29 23:34:37 +02:00
|
|
|
parse(m->dice_value, parser);
|
2020-04-19 08:47:37 +02:00
|
|
|
is_bad = !m->is_valid();
|
2020-03-14 17:56:39 +01:00
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
2020-10-29 20:25:58 +01:00
|
|
|
case MessageContentType::ProximityAlertTriggered: {
|
|
|
|
auto m = make_unique<MessageProximityAlertTriggered>();
|
2020-10-30 23:38:11 +01:00
|
|
|
parse(m->traveler_dialog_id, parser);
|
|
|
|
parse(m->watcher_dialog_id, parser);
|
2020-10-19 19:44:09 +02:00
|
|
|
parse(m->distance, parser);
|
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
2020-11-24 12:33:16 +01:00
|
|
|
case MessageContentType::GroupCall: {
|
|
|
|
auto m = make_unique<MessageGroupCall>();
|
|
|
|
bool has_duration;
|
2021-04-05 23:24:05 +02:00
|
|
|
bool has_schedule_date;
|
2020-11-24 12:33:16 +01:00
|
|
|
BEGIN_PARSE_FLAGS();
|
|
|
|
PARSE_FLAG(has_duration);
|
2021-04-05 23:24:05 +02:00
|
|
|
PARSE_FLAG(has_schedule_date);
|
2020-11-24 12:33:16 +01:00
|
|
|
END_PARSE_FLAGS();
|
2020-12-03 17:52:50 +01:00
|
|
|
parse(m->input_group_call_id, parser);
|
2020-11-24 12:33:16 +01:00
|
|
|
if (has_duration) {
|
|
|
|
parse(m->duration, parser);
|
|
|
|
}
|
2021-04-05 23:24:05 +02:00
|
|
|
if (has_schedule_date) {
|
|
|
|
parse(m->schedule_date, parser);
|
|
|
|
}
|
2020-11-24 12:33:16 +01:00
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::InviteToGroupCall: {
|
|
|
|
auto m = make_unique<MessageInviteToGroupCall>();
|
2020-12-03 17:52:50 +01:00
|
|
|
parse(m->input_group_call_id, parser);
|
2020-11-29 13:41:03 +01:00
|
|
|
parse(m->user_ids, parser);
|
2020-11-24 12:33:16 +01:00
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
2021-08-18 15:03:10 +02:00
|
|
|
case MessageContentType::ChatSetTheme: {
|
|
|
|
auto m = make_unique<MessageChatSetTheme>();
|
|
|
|
parse(m->emoji, parser);
|
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
2022-03-28 09:01:39 +02:00
|
|
|
case MessageContentType::WebViewDataSent: {
|
|
|
|
auto m = make_unique<MessageWebViewDataSent>();
|
|
|
|
parse(m->button_text, parser);
|
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::WebViewDataReceived: {
|
|
|
|
auto m = make_unique<MessageWebViewDataReceived>();
|
|
|
|
parse(m->button_text, parser);
|
|
|
|
parse(m->data, parser);
|
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
2022-07-01 14:28:22 +02:00
|
|
|
case MessageContentType::GiftPremium: {
|
|
|
|
auto m = make_unique<MessageGiftPremium>();
|
2023-03-21 12:54:36 +01:00
|
|
|
bool has_crypto_amount;
|
2022-07-01 14:28:22 +02:00
|
|
|
BEGIN_PARSE_FLAGS();
|
2023-03-21 12:54:36 +01:00
|
|
|
PARSE_FLAG(has_crypto_amount);
|
2022-07-01 14:28:22 +02:00
|
|
|
END_PARSE_FLAGS();
|
|
|
|
parse(m->currency, parser);
|
|
|
|
parse(m->amount, parser);
|
|
|
|
parse(m->months, parser);
|
2023-03-21 12:54:36 +01:00
|
|
|
if (has_crypto_amount) {
|
|
|
|
parse(m->crypto_currency, parser);
|
|
|
|
parse(m->crypto_amount, parser);
|
|
|
|
}
|
2022-07-01 14:28:22 +02:00
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
2022-10-18 15:08:53 +02:00
|
|
|
case MessageContentType::TopicCreate: {
|
|
|
|
auto m = make_unique<MessageTopicCreate>();
|
|
|
|
parse(m->title, parser);
|
|
|
|
parse(m->icon, parser);
|
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
2022-10-18 21:16:03 +02:00
|
|
|
case MessageContentType::TopicEdit: {
|
|
|
|
auto m = make_unique<MessageTopicEdit>();
|
|
|
|
parse(m->edited_data, parser);
|
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
2022-12-09 12:13:37 +01:00
|
|
|
case MessageContentType::SuggestProfilePhoto: {
|
|
|
|
auto m = make_unique<MessageSuggestProfilePhoto>();
|
|
|
|
parse(m->photo, parser);
|
|
|
|
if (m->photo.is_empty()) {
|
|
|
|
is_bad = true;
|
|
|
|
}
|
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
2022-12-14 19:13:48 +01:00
|
|
|
case MessageContentType::WriteAccessAllowed:
|
|
|
|
content = make_unique<MessageWriteAccessAllowed>();
|
|
|
|
break;
|
2023-01-10 14:20:30 +01:00
|
|
|
case MessageContentType::RequestedDialog: {
|
|
|
|
auto m = make_unique<MessageRequestedDialog>();
|
|
|
|
parse(m->dialog_id, parser);
|
|
|
|
parse(m->button_id, parser);
|
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
2023-02-22 10:24:43 +01:00
|
|
|
case MessageContentType::WebViewWriteAccessAllowed: {
|
|
|
|
auto m = make_unique<MessageWebViewWriteAccessAllowed>();
|
|
|
|
parse(m->web_app, parser);
|
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
2023-04-10 13:12:35 +02:00
|
|
|
case MessageContentType::SetBackground: {
|
|
|
|
auto m = make_unique<MessageSetBackground>();
|
|
|
|
bool has_message_id;
|
|
|
|
BEGIN_PARSE_FLAGS();
|
|
|
|
PARSE_FLAG(has_message_id);
|
|
|
|
END_PARSE_FLAGS();
|
|
|
|
if (has_message_id) {
|
|
|
|
parse(m->old_message_id, parser);
|
|
|
|
}
|
2023-04-10 15:32:59 +02:00
|
|
|
parse(m->background_info, parser);
|
2023-04-10 13:12:35 +02:00
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
2023-06-12 18:23:58 +02:00
|
|
|
case MessageContentType::Story: {
|
|
|
|
auto m = make_unique<MessageStory>();
|
|
|
|
BEGIN_PARSE_FLAGS();
|
|
|
|
PARSE_FLAG(m->via_mention);
|
|
|
|
END_PARSE_FLAGS();
|
|
|
|
parse(m->story_full_id, parser);
|
2023-08-10 19:22:12 +02:00
|
|
|
if (!m->story_full_id.is_server()) {
|
2023-07-23 00:41:59 +02:00
|
|
|
is_bad = true;
|
|
|
|
}
|
2023-06-12 18:23:58 +02:00
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
2023-08-25 15:53:50 +02:00
|
|
|
case MessageContentType::WriteAccessAllowedByRequest:
|
|
|
|
content = make_unique<MessageWriteAccessAllowedByRequest>();
|
|
|
|
break;
|
2023-09-29 16:55:03 +02:00
|
|
|
case MessageContentType::GiftCode: {
|
|
|
|
auto m = make_unique<MessageGiftCode>();
|
|
|
|
bool has_creator_dialog_id;
|
|
|
|
BEGIN_PARSE_FLAGS();
|
|
|
|
PARSE_FLAG(m->via_giveaway);
|
|
|
|
PARSE_FLAG(has_creator_dialog_id);
|
|
|
|
END_PARSE_FLAGS();
|
|
|
|
if (has_creator_dialog_id) {
|
|
|
|
parse(m->creator_dialog_id, parser);
|
|
|
|
}
|
|
|
|
parse(m->months, parser);
|
|
|
|
parse(m->code, parser);
|
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
2023-09-29 23:32:39 +02:00
|
|
|
case MessageContentType::Giveaway: {
|
|
|
|
auto m = make_unique<MessageGiveaway>();
|
|
|
|
BEGIN_PARSE_FLAGS();
|
|
|
|
END_PARSE_FLAGS();
|
2023-10-12 16:05:03 +02:00
|
|
|
parse(m->giveaway_parameters, parser);
|
2023-09-29 23:32:39 +02:00
|
|
|
parse(m->quantity, parser);
|
|
|
|
parse(m->months, parser);
|
2023-10-12 16:05:03 +02:00
|
|
|
if (!m->giveaway_parameters.is_valid()) {
|
|
|
|
is_bad = true;
|
2023-09-29 23:32:39 +02:00
|
|
|
}
|
|
|
|
content = std::move(m);
|
|
|
|
break;
|
|
|
|
}
|
2023-10-16 10:31:11 +02:00
|
|
|
case MessageContentType::GiveawayLaunch:
|
|
|
|
content = make_unique<MessageGiveawayLaunch>();
|
|
|
|
break;
|
2023-09-29 16:55:03 +02:00
|
|
|
|
2018-09-28 22:57:34 +02:00
|
|
|
default:
|
2023-07-03 14:46:31 +02:00
|
|
|
is_bad = true;
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
if (is_bad) {
|
|
|
|
LOG(ERROR) << "Load a message with an invalid content of type " << content_type;
|
2018-12-25 18:47:37 +01:00
|
|
|
content = make_unique<MessageUnsupported>(0);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void store_message_content(const MessageContent *content, LogEventStorerCalcLength &storer) {
|
|
|
|
store(content, storer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void store_message_content(const MessageContent *content, LogEventStorerUnsafe &storer) {
|
|
|
|
store(content, storer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void parse_message_content(unique_ptr<MessageContent> &content, LogEventParser &parser) {
|
|
|
|
parse(content, parser);
|
|
|
|
}
|
|
|
|
|
|
|
|
InlineMessageContent create_inline_message_content(Td *td, FileId file_id,
|
2021-03-31 01:02:53 +02:00
|
|
|
tl_object_ptr<telegram_api::BotInlineMessage> &&bot_inline_message,
|
2018-09-28 22:57:34 +02:00
|
|
|
int32 allowed_media_content_id, Photo *photo, Game *game) {
|
2021-03-31 01:02:53 +02:00
|
|
|
CHECK(bot_inline_message != nullptr);
|
2018-09-28 22:57:34 +02:00
|
|
|
CHECK((allowed_media_content_id == td_api::inputMessagePhoto::ID) == (photo != nullptr));
|
|
|
|
CHECK((allowed_media_content_id == td_api::inputMessageGame::ID) == (game != nullptr));
|
|
|
|
CHECK((allowed_media_content_id != td_api::inputMessagePhoto::ID &&
|
|
|
|
allowed_media_content_id != td_api::inputMessageGame::ID && allowed_media_content_id != -1) ==
|
|
|
|
file_id.is_valid());
|
|
|
|
|
|
|
|
InlineMessageContent result;
|
|
|
|
tl_object_ptr<telegram_api::ReplyMarkup> reply_markup;
|
|
|
|
result.disable_web_page_preview = false;
|
2021-03-31 01:02:53 +02:00
|
|
|
switch (bot_inline_message->get_id()) {
|
2018-09-28 22:57:34 +02:00
|
|
|
case telegram_api::botInlineMessageText::ID: {
|
2021-03-31 01:02:53 +02:00
|
|
|
auto inline_message = move_tl_object_as<telegram_api::botInlineMessageText>(bot_inline_message);
|
|
|
|
auto entities = get_message_entities(td->contacts_manager_.get(), std::move(inline_message->entities_),
|
2018-09-28 22:57:34 +02:00
|
|
|
"botInlineMessageText");
|
2021-07-26 21:48:33 +02:00
|
|
|
auto status = fix_formatted_text(inline_message->message_, entities, false, true, true, false, false);
|
2018-09-28 22:57:34 +02:00
|
|
|
if (status.is_error()) {
|
2021-03-31 01:02:53 +02:00
|
|
|
LOG(ERROR) << "Receive error " << status << " while parsing botInlineMessageText " << inline_message->message_;
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-11-01 19:53:23 +01:00
|
|
|
result.disable_web_page_preview = inline_message->no_webpage_;
|
2022-08-15 14:55:48 +02:00
|
|
|
FormattedText text{std::move(inline_message->message_), std::move(entities)};
|
2018-09-28 22:57:34 +02:00
|
|
|
WebPageId web_page_id;
|
|
|
|
if (!result.disable_web_page_preview) {
|
2022-08-15 14:55:48 +02:00
|
|
|
web_page_id = td->web_pages_manager_->get_web_page_by_url(get_first_url(text));
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
2023-10-19 12:03:27 +02:00
|
|
|
result.message_content =
|
|
|
|
td::make_unique<MessageText>(std::move(text), web_page_id, false, false, false, string());
|
2021-03-31 01:02:53 +02:00
|
|
|
reply_markup = std::move(inline_message->reply_markup_);
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
|
|
|
}
|
2023-10-17 00:55:37 +02:00
|
|
|
case telegram_api::botInlineMessageMediaWebPage::ID: {
|
|
|
|
auto inline_message = move_tl_object_as<telegram_api::botInlineMessageMediaWebPage>(bot_inline_message);
|
2023-10-17 01:07:40 +02:00
|
|
|
string web_page_url;
|
|
|
|
if (inline_message->manual_) {
|
|
|
|
web_page_url = std::move(inline_message->url_);
|
|
|
|
}
|
2023-10-17 00:55:37 +02:00
|
|
|
auto entities = get_message_entities(td->contacts_manager_.get(), std::move(inline_message->entities_),
|
|
|
|
"botInlineMessageMediaWebPage");
|
2023-10-17 01:07:40 +02:00
|
|
|
auto status =
|
|
|
|
fix_formatted_text(inline_message->message_, entities, !web_page_url.empty(), true, true, false, false);
|
2023-10-17 00:55:37 +02:00
|
|
|
if (status.is_error()) {
|
|
|
|
LOG(ERROR) << "Receive error " << status << " while parsing botInlineMessageMediaWebPage "
|
|
|
|
<< inline_message->message_;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
FormattedText text{std::move(inline_message->message_), std::move(entities)};
|
|
|
|
WebPageId web_page_id =
|
|
|
|
td->web_pages_manager_->get_web_page_by_url(web_page_url.empty() ? get_first_url(text) : web_page_url);
|
2023-10-19 12:03:27 +02:00
|
|
|
result.message_content = td::make_unique<MessageText>(
|
|
|
|
std::move(text), web_page_id, inline_message->force_small_media_, inline_message->force_large_media_,
|
|
|
|
inline_message->safe_, std::move(web_page_url));
|
2023-10-17 00:55:37 +02:00
|
|
|
reply_markup = std::move(inline_message->reply_markup_);
|
2023-09-28 15:13:36 +02:00
|
|
|
break;
|
2023-10-17 00:55:37 +02:00
|
|
|
}
|
2021-03-31 01:38:16 +02:00
|
|
|
case telegram_api::botInlineMessageMediaInvoice::ID: {
|
|
|
|
auto inline_message = move_tl_object_as<telegram_api::botInlineMessageMediaInvoice>(bot_inline_message);
|
|
|
|
reply_markup = std::move(inline_message->reply_markup_);
|
2022-09-23 11:52:54 +02:00
|
|
|
result.message_content = make_unique<MessageInvoice>(InputInvoice(std::move(inline_message), td, DialogId()));
|
2021-03-31 01:38:16 +02:00
|
|
|
break;
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
case telegram_api::botInlineMessageMediaGeo::ID: {
|
2021-03-31 01:02:53 +02:00
|
|
|
auto inline_message = move_tl_object_as<telegram_api::botInlineMessageMediaGeo>(bot_inline_message);
|
2022-12-18 20:15:57 +01:00
|
|
|
if (inline_message->period_ > 0) {
|
|
|
|
result.message_content =
|
2023-06-28 18:01:00 +02:00
|
|
|
make_unique<MessageLiveLocation>(Location(td, inline_message->geo_), inline_message->period_,
|
2022-12-18 20:15:57 +01:00
|
|
|
inline_message->heading_, inline_message->proximity_notification_radius_);
|
2018-09-28 22:57:34 +02:00
|
|
|
} else {
|
2023-06-28 18:01:00 +02:00
|
|
|
result.message_content = make_unique<MessageLocation>(Location(td, inline_message->geo_));
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
2021-03-31 01:02:53 +02:00
|
|
|
reply_markup = std::move(inline_message->reply_markup_);
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case telegram_api::botInlineMessageMediaVenue::ID: {
|
2021-03-31 01:02:53 +02:00
|
|
|
auto inline_message = move_tl_object_as<telegram_api::botInlineMessageMediaVenue>(bot_inline_message);
|
2018-09-28 22:57:34 +02:00
|
|
|
result.message_content = make_unique<MessageVenue>(
|
2023-06-28 18:01:00 +02:00
|
|
|
Venue(td, inline_message->geo_, std::move(inline_message->title_), std::move(inline_message->address_),
|
2021-03-31 01:02:53 +02:00
|
|
|
std::move(inline_message->provider_), std::move(inline_message->venue_id_),
|
|
|
|
std::move(inline_message->venue_type_)));
|
|
|
|
reply_markup = std::move(inline_message->reply_markup_);
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case telegram_api::botInlineMessageMediaContact::ID: {
|
2021-03-31 01:02:53 +02:00
|
|
|
auto inline_message = move_tl_object_as<telegram_api::botInlineMessageMediaContact>(bot_inline_message);
|
2018-09-28 22:57:34 +02:00
|
|
|
result.message_content = make_unique<MessageContact>(
|
2021-03-31 01:02:53 +02:00
|
|
|
Contact(std::move(inline_message->phone_number_), std::move(inline_message->first_name_),
|
|
|
|
std::move(inline_message->last_name_), std::move(inline_message->vcard_), UserId()));
|
|
|
|
reply_markup = std::move(inline_message->reply_markup_);
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case telegram_api::botInlineMessageMediaAuto::ID: {
|
2021-03-31 01:02:53 +02:00
|
|
|
auto inline_message = move_tl_object_as<telegram_api::botInlineMessageMediaAuto>(bot_inline_message);
|
|
|
|
auto caption =
|
|
|
|
get_message_text(td->contacts_manager_.get(), inline_message->message_, std::move(inline_message->entities_),
|
2021-07-26 21:48:33 +02:00
|
|
|
true, false, 0, false, "create_inline_message_content");
|
2018-09-28 22:57:34 +02:00
|
|
|
if (allowed_media_content_id == td_api::inputMessageAnimation::ID) {
|
2022-12-26 12:20:48 +01:00
|
|
|
result.message_content = make_unique<MessageAnimation>(file_id, std::move(caption), false);
|
2018-09-28 22:57:34 +02:00
|
|
|
} else if (allowed_media_content_id == td_api::inputMessageAudio::ID) {
|
|
|
|
result.message_content = make_unique<MessageAudio>(file_id, std::move(caption));
|
|
|
|
} else if (allowed_media_content_id == td_api::inputMessageDocument::ID) {
|
|
|
|
result.message_content = make_unique<MessageDocument>(file_id, std::move(caption));
|
|
|
|
} else if (allowed_media_content_id == td_api::inputMessageGame::ID) {
|
|
|
|
CHECK(game != nullptr);
|
|
|
|
// TODO game->set_short_name(std::move(caption));
|
|
|
|
result.message_content = make_unique<MessageGame>(std::move(*game));
|
|
|
|
} else if (allowed_media_content_id == td_api::inputMessagePhoto::ID) {
|
2022-12-20 16:06:21 +01:00
|
|
|
result.message_content = make_unique<MessagePhoto>(std::move(*photo), std::move(caption), false);
|
2018-09-28 22:57:34 +02:00
|
|
|
} else if (allowed_media_content_id == td_api::inputMessageSticker::ID) {
|
2022-06-03 15:33:49 +02:00
|
|
|
result.message_content = make_unique<MessageSticker>(file_id, false);
|
2018-09-28 22:57:34 +02:00
|
|
|
} else if (allowed_media_content_id == td_api::inputMessageVideo::ID) {
|
2022-12-20 16:06:21 +01:00
|
|
|
result.message_content = make_unique<MessageVideo>(file_id, std::move(caption), false);
|
2018-09-28 22:57:34 +02:00
|
|
|
} else if (allowed_media_content_id == td_api::inputMessageVoiceNote::ID) {
|
|
|
|
result.message_content = make_unique<MessageVoiceNote>(file_id, std::move(caption), true);
|
|
|
|
} else {
|
2021-03-31 01:02:53 +02:00
|
|
|
LOG(WARNING) << "Unallowed bot inline message " << to_string(inline_message);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
|
2021-03-31 01:02:53 +02:00
|
|
|
reply_markup = std::move(inline_message->reply_markup_);
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
result.message_reply_markup = get_reply_markup(std::move(reply_markup), td->auth_manager_->is_bot(), true, false);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
unique_ptr<MessageContent> create_text_message_content(string text, vector<MessageEntity> entities,
|
2023-10-16 15:47:22 +02:00
|
|
|
WebPageId web_page_id, bool force_small_media,
|
2023-10-19 12:03:27 +02:00
|
|
|
bool force_large_media, bool skip_confirmation,
|
|
|
|
string &&web_page_url) {
|
2023-10-16 21:33:53 +02:00
|
|
|
return td::make_unique<MessageText>(FormattedText{std::move(text), std::move(entities)}, web_page_id,
|
2023-10-19 12:03:27 +02:00
|
|
|
force_small_media, force_large_media, skip_confirmation, std::move(web_page_url));
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
unique_ptr<MessageContent> create_contact_registered_message_content() {
|
|
|
|
return make_unique<MessageContactRegistered>();
|
|
|
|
}
|
|
|
|
|
|
|
|
unique_ptr<MessageContent> create_screenshot_taken_message_content() {
|
|
|
|
return make_unique<MessageScreenshotTaken>();
|
|
|
|
}
|
|
|
|
|
2022-11-29 12:02:05 +01:00
|
|
|
unique_ptr<MessageContent> create_chat_set_ttl_message_content(int32 ttl, UserId from_user_id) {
|
|
|
|
return make_unique<MessageChatSetTtl>(ttl, from_user_id);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
|
2018-12-12 15:36:31 +01:00
|
|
|
static Result<InputMessageContent> create_input_message_content(
|
2018-09-28 22:57:34 +02:00
|
|
|
DialogId dialog_id, tl_object_ptr<td_api::InputMessageContent> &&input_message_content, Td *td,
|
2022-06-03 15:33:49 +02:00
|
|
|
FormattedText caption, FileId file_id, PhotoSize thumbnail, vector<FileId> sticker_file_ids, bool is_premium) {
|
2018-09-28 22:57:34 +02:00
|
|
|
CHECK(input_message_content != nullptr);
|
|
|
|
LOG(INFO) << "Create InputMessageContent with file " << file_id << " and thumbnail " << thumbnail.file_id;
|
|
|
|
|
|
|
|
FileView file_view;
|
|
|
|
string file_name;
|
|
|
|
string mime_type;
|
|
|
|
if (file_id.is_valid()) {
|
|
|
|
file_view = td->file_manager_->get_file_view(file_id);
|
2021-01-26 00:39:48 +01:00
|
|
|
auto suggested_path = file_view.suggested_path();
|
|
|
|
const PathView path_view(suggested_path);
|
2018-09-28 22:57:34 +02:00
|
|
|
file_name = path_view.file_name().str();
|
|
|
|
mime_type = MimeType::from_extension(path_view.extension());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool disable_web_page_preview = false;
|
|
|
|
bool clear_draft = false;
|
|
|
|
unique_ptr<MessageContent> content;
|
|
|
|
UserId via_bot_user_id;
|
2023-09-06 20:27:45 +02:00
|
|
|
td_api::object_ptr<td_api::MessageSelfDestructType> self_destruct_type;
|
2020-12-19 12:31:42 +01:00
|
|
|
string emoji;
|
2018-09-28 22:57:34 +02:00
|
|
|
bool is_bot = td->auth_manager_->is_bot();
|
2022-12-23 16:27:38 +01:00
|
|
|
bool is_secret = dialog_id.get_type() == DialogType::SecretChat;
|
2018-09-28 22:57:34 +02:00
|
|
|
switch (input_message_content->get_id()) {
|
|
|
|
case td_api::inputMessageText::ID: {
|
2022-07-22 17:11:55 +02:00
|
|
|
TRY_RESULT(input_message_text,
|
|
|
|
process_input_message_text(td, dialog_id, std::move(input_message_content), is_bot));
|
2023-10-16 21:33:53 +02:00
|
|
|
auto web_page_url = std::move(input_message_text.web_page_url);
|
2018-09-28 22:57:34 +02:00
|
|
|
disable_web_page_preview = input_message_text.disable_web_page_preview;
|
|
|
|
clear_draft = input_message_text.clear_draft;
|
|
|
|
|
2022-11-03 14:46:50 +01:00
|
|
|
if (is_bot && static_cast<int64>(utf8_length(input_message_text.text.text)) >
|
|
|
|
G()->get_option_integer("message_text_length_max")) {
|
|
|
|
return Status::Error(400, "Message is too long");
|
|
|
|
}
|
|
|
|
|
2018-09-28 22:57:34 +02:00
|
|
|
WebPageId web_page_id;
|
|
|
|
bool can_add_web_page_previews =
|
|
|
|
dialog_id.get_type() != DialogType::Channel ||
|
2019-03-22 13:23:44 +01:00
|
|
|
td->contacts_manager_->get_channel_permissions(dialog_id.get_channel_id()).can_add_web_page_previews();
|
2018-09-28 22:57:34 +02:00
|
|
|
if (!is_bot && !disable_web_page_preview && can_add_web_page_previews) {
|
2023-10-16 21:33:53 +02:00
|
|
|
web_page_id = td->web_pages_manager_->get_web_page_by_url(
|
|
|
|
web_page_url.empty() ? get_first_url(input_message_text.text) : web_page_url);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
2023-10-16 21:33:53 +02:00
|
|
|
content = td::make_unique<MessageText>(std::move(input_message_text.text), web_page_id,
|
|
|
|
input_message_text.force_small_media, input_message_text.force_large_media,
|
2023-10-19 12:03:27 +02:00
|
|
|
false, std::move(web_page_url));
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case td_api::inputMessageAnimation::ID: {
|
|
|
|
auto input_animation = static_cast<td_api::inputMessageAnimation *>(input_message_content.get());
|
|
|
|
|
2020-05-29 10:51:51 +02:00
|
|
|
bool has_stickers = !sticker_file_ids.empty();
|
2020-05-30 00:48:56 +02:00
|
|
|
td->animations_manager_->create_animation(
|
2020-07-07 10:41:01 +02:00
|
|
|
file_id, string(), thumbnail, AnimationSize(), has_stickers, std::move(sticker_file_ids),
|
|
|
|
std::move(file_name), std::move(mime_type), input_animation->duration_,
|
2022-05-26 16:13:31 +02:00
|
|
|
get_dimensions(input_animation->width_, input_animation->height_, nullptr), false);
|
2018-09-28 22:57:34 +02:00
|
|
|
|
2022-12-26 12:20:48 +01:00
|
|
|
content = make_unique<MessageAnimation>(file_id, std::move(caption), input_animation->has_spoiler_ && !is_secret);
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case td_api::inputMessageAudio::ID: {
|
|
|
|
auto input_audio = static_cast<td_api::inputMessageAudio *>(input_message_content.get());
|
|
|
|
|
|
|
|
if (!clean_input_string(input_audio->title_)) {
|
|
|
|
return Status::Error(400, "Audio title must be encoded in UTF-8");
|
|
|
|
}
|
|
|
|
if (!clean_input_string(input_audio->performer_)) {
|
|
|
|
return Status::Error(400, "Audio performer must be encoded in UTF-8");
|
|
|
|
}
|
|
|
|
|
2019-03-01 20:51:33 +01:00
|
|
|
td->audios_manager_->create_audio(file_id, string(), thumbnail, std::move(file_name), std::move(mime_type),
|
2018-09-28 22:57:34 +02:00
|
|
|
input_audio->duration_, std::move(input_audio->title_),
|
2022-04-15 14:30:51 +02:00
|
|
|
std::move(input_audio->performer_), 0, false);
|
2018-09-28 22:57:34 +02:00
|
|
|
|
|
|
|
content = make_unique<MessageAudio>(file_id, std::move(caption));
|
|
|
|
break;
|
|
|
|
}
|
2020-04-13 13:18:46 +02:00
|
|
|
case td_api::inputMessageDice::ID: {
|
2020-04-18 07:45:41 +02:00
|
|
|
auto input_dice = static_cast<td_api::inputMessageDice *>(input_message_content.get());
|
|
|
|
if (!clean_input_string(input_dice->emoji_)) {
|
|
|
|
return Status::Error(400, "Dice emoji must be encoded in UTF-8");
|
|
|
|
}
|
2021-09-20 12:45:49 +02:00
|
|
|
content = td::make_unique<MessageDice>(input_dice->emoji_, 0);
|
2020-04-13 13:18:46 +02:00
|
|
|
clear_draft = input_dice->clear_draft_;
|
2020-03-14 17:56:39 +01:00
|
|
|
break;
|
2020-04-13 13:18:46 +02:00
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
case td_api::inputMessageDocument::ID:
|
2019-03-01 20:51:33 +01:00
|
|
|
td->documents_manager_->create_document(file_id, string(), thumbnail, std::move(file_name), std::move(mime_type),
|
|
|
|
false);
|
2018-09-28 22:57:34 +02:00
|
|
|
|
|
|
|
content = make_unique<MessageDocument>(file_id, std::move(caption));
|
|
|
|
break;
|
|
|
|
case td_api::inputMessagePhoto::ID: {
|
|
|
|
auto input_photo = static_cast<td_api::inputMessagePhoto *>(input_message_content.get());
|
|
|
|
|
2023-09-06 20:27:45 +02:00
|
|
|
self_destruct_type = std::move(input_photo->self_destruct_type_);
|
2018-09-28 22:57:34 +02:00
|
|
|
|
2023-05-22 14:35:25 +02:00
|
|
|
TRY_RESULT(photo, create_photo(td->file_manager_.get(), file_id, std::move(thumbnail), input_photo->width_,
|
|
|
|
input_photo->height_, std::move(sticker_file_ids)));
|
2023-05-21 15:35:33 +02:00
|
|
|
|
2023-05-22 14:35:25 +02:00
|
|
|
content =
|
|
|
|
make_unique<MessagePhoto>(std::move(photo), std::move(caption), input_photo->has_spoiler_ && !is_secret);
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case td_api::inputMessageSticker::ID: {
|
|
|
|
auto input_sticker = static_cast<td_api::inputMessageSticker *>(input_message_content.get());
|
2020-12-19 12:31:42 +01:00
|
|
|
|
|
|
|
emoji = std::move(input_sticker->emoji_);
|
|
|
|
|
2022-04-26 15:01:29 +02:00
|
|
|
td->stickers_manager_->create_sticker(file_id, FileId(), string(), thumbnail,
|
2022-05-26 16:13:31 +02:00
|
|
|
get_dimensions(input_sticker->width_, input_sticker->height_, nullptr),
|
2022-07-14 16:11:36 +02:00
|
|
|
nullptr, nullptr, StickerFormat::Unknown, nullptr);
|
2018-09-28 22:57:34 +02:00
|
|
|
|
2022-06-03 15:33:49 +02:00
|
|
|
content = make_unique<MessageSticker>(file_id, is_premium);
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case td_api::inputMessageVideo::ID: {
|
|
|
|
auto input_video = static_cast<td_api::inputMessageVideo *>(input_message_content.get());
|
|
|
|
|
2023-09-06 20:27:45 +02:00
|
|
|
self_destruct_type = std::move(input_video->self_destruct_type_);
|
2018-09-28 22:57:34 +02:00
|
|
|
|
|
|
|
bool has_stickers = !sticker_file_ids.empty();
|
2023-05-19 13:57:57 +02:00
|
|
|
td->videos_manager_->create_video(file_id, string(), thumbnail, AnimationSize(), has_stickers,
|
|
|
|
std::move(sticker_file_ids), std::move(file_name), std::move(mime_type),
|
2023-06-05 13:33:00 +02:00
|
|
|
input_video->duration_, input_video->duration_,
|
2023-05-19 13:57:57 +02:00
|
|
|
get_dimensions(input_video->width_, input_video->height_, nullptr),
|
2023-06-23 15:06:02 +02:00
|
|
|
input_video->supports_streaming_, false, 0, false);
|
2018-09-28 22:57:34 +02:00
|
|
|
|
2022-12-23 16:27:38 +01:00
|
|
|
content = make_unique<MessageVideo>(file_id, std::move(caption), input_video->has_spoiler_ && !is_secret);
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case td_api::inputMessageVideoNote::ID: {
|
|
|
|
auto input_video_note = static_cast<td_api::inputMessageVideoNote *>(input_message_content.get());
|
|
|
|
|
|
|
|
auto length = input_video_note->length_;
|
|
|
|
if (length < 0 || length >= 640) {
|
|
|
|
return Status::Error(400, "Wrong video note length");
|
|
|
|
}
|
|
|
|
|
2019-03-01 20:51:33 +01:00
|
|
|
td->video_notes_manager_->create_video_note(file_id, string(), thumbnail, input_video_note->duration_,
|
2022-10-20 22:23:40 +02:00
|
|
|
get_dimensions(length, length, nullptr), string(), false);
|
2018-09-28 22:57:34 +02:00
|
|
|
|
|
|
|
content = make_unique<MessageVideoNote>(file_id, false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case td_api::inputMessageVoiceNote::ID: {
|
|
|
|
auto input_voice_note = static_cast<td_api::inputMessageVoiceNote *>(input_message_content.get());
|
|
|
|
|
|
|
|
td->voice_notes_manager_->create_voice_note(file_id, std::move(mime_type), input_voice_note->duration_,
|
|
|
|
std::move(input_voice_note->waveform_), false);
|
|
|
|
|
|
|
|
content = make_unique<MessageVoiceNote>(file_id, std::move(caption), false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case td_api::inputMessageLocation::ID: {
|
|
|
|
TRY_RESULT(location, process_input_message_location(std::move(input_message_content)));
|
2020-10-16 22:08:28 +02:00
|
|
|
if (location.live_period == 0) {
|
|
|
|
content = make_unique<MessageLocation>(std::move(location.location));
|
2018-09-28 22:57:34 +02:00
|
|
|
} else {
|
2020-10-24 23:49:41 +02:00
|
|
|
content = make_unique<MessageLiveLocation>(std::move(location.location), location.live_period, location.heading,
|
2020-10-30 13:51:20 +01:00
|
|
|
location.proximity_alert_radius);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case td_api::inputMessageVenue::ID: {
|
|
|
|
TRY_RESULT(venue, process_input_message_venue(std::move(input_message_content)));
|
|
|
|
content = make_unique<MessageVenue>(std::move(venue));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case td_api::inputMessageContact::ID: {
|
|
|
|
TRY_RESULT(contact, process_input_message_contact(std::move(input_message_content)));
|
|
|
|
content = make_unique<MessageContact>(std::move(contact));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case td_api::inputMessageGame::ID: {
|
|
|
|
TRY_RESULT(game, process_input_message_game(td->contacts_manager_.get(), std::move(input_message_content)));
|
|
|
|
via_bot_user_id = game.get_bot_user_id();
|
2018-10-08 16:21:56 +02:00
|
|
|
if (via_bot_user_id == td->contacts_manager_->get_my_id()) {
|
2018-09-28 22:57:34 +02:00
|
|
|
via_bot_user_id = UserId();
|
|
|
|
}
|
|
|
|
|
|
|
|
content = make_unique<MessageGame>(std::move(game));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case td_api::inputMessageInvoice::ID: {
|
|
|
|
if (!is_bot) {
|
|
|
|
return Status::Error(400, "Invoices can be sent only by bots");
|
|
|
|
}
|
|
|
|
|
2022-09-23 15:16:56 +02:00
|
|
|
TRY_RESULT(input_invoice, InputInvoice::process_input_message_invoice(std::move(input_message_content), td,
|
|
|
|
dialog_id, is_premium));
|
2021-03-31 00:20:40 +02:00
|
|
|
content = make_unique<MessageInvoice>(std::move(input_invoice));
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
|
|
|
}
|
2019-02-19 14:45:32 +01:00
|
|
|
case td_api::inputMessagePoll::ID: {
|
2020-07-04 01:19:38 +02:00
|
|
|
const size_t MAX_POLL_QUESTION_LENGTH = is_bot ? 300 : 255; // server-side limit
|
|
|
|
constexpr size_t MAX_POLL_OPTION_LENGTH = 100; // server-side limit
|
|
|
|
constexpr size_t MAX_POLL_OPTIONS = 10; // server-side limit
|
2019-02-19 14:45:32 +01:00
|
|
|
auto input_poll = static_cast<td_api::inputMessagePoll *>(input_message_content.get());
|
|
|
|
if (!clean_input_string(input_poll->question_)) {
|
|
|
|
return Status::Error(400, "Poll question must be encoded in UTF-8");
|
|
|
|
}
|
|
|
|
if (input_poll->question_.empty()) {
|
|
|
|
return Status::Error(400, "Poll question must be non-empty");
|
|
|
|
}
|
2020-01-05 22:32:26 +01:00
|
|
|
if (utf8_length(input_poll->question_) > MAX_POLL_QUESTION_LENGTH) {
|
2019-02-19 14:45:32 +01:00
|
|
|
return Status::Error(400, PSLICE() << "Poll question length must not exceed " << MAX_POLL_QUESTION_LENGTH);
|
|
|
|
}
|
2019-04-09 02:39:05 +02:00
|
|
|
if (input_poll->options_.size() <= 1) {
|
|
|
|
return Status::Error(400, "Poll must have at least 2 option");
|
2019-02-19 14:45:32 +01:00
|
|
|
}
|
2019-02-21 01:52:58 +01:00
|
|
|
if (input_poll->options_.size() > MAX_POLL_OPTIONS) {
|
2019-02-21 20:37:15 +01:00
|
|
|
return Status::Error(400, PSLICE() << "Poll can't have more than " << MAX_POLL_OPTIONS << " options");
|
2019-02-19 14:45:32 +01:00
|
|
|
}
|
2019-02-21 01:52:58 +01:00
|
|
|
for (auto &option : input_poll->options_) {
|
|
|
|
if (!clean_input_string(option)) {
|
|
|
|
return Status::Error(400, "Poll options must be encoded in UTF-8");
|
2019-02-19 14:45:32 +01:00
|
|
|
}
|
2019-02-21 01:52:58 +01:00
|
|
|
if (option.empty()) {
|
|
|
|
return Status::Error(400, "Poll options must be non-empty");
|
2019-02-19 14:45:32 +01:00
|
|
|
}
|
2020-01-05 22:32:26 +01:00
|
|
|
if (utf8_length(option) > MAX_POLL_OPTION_LENGTH) {
|
2019-02-21 01:52:58 +01:00
|
|
|
return Status::Error(400, PSLICE() << "Poll options length must not exceed " << MAX_POLL_OPTION_LENGTH);
|
2019-02-19 14:45:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-11 01:46:26 +01:00
|
|
|
bool allow_multiple_answers = false;
|
|
|
|
bool is_quiz = false;
|
|
|
|
int32 correct_option_id = -1;
|
2020-04-03 22:39:50 +02:00
|
|
|
FormattedText explanation;
|
2020-01-11 01:46:26 +01:00
|
|
|
if (input_poll->type_ == nullptr) {
|
2020-05-18 21:54:18 +02:00
|
|
|
return Status::Error(400, "Poll type must be non-empty");
|
2020-01-11 01:46:26 +01:00
|
|
|
}
|
|
|
|
switch (input_poll->type_->get_id()) {
|
|
|
|
case td_api::pollTypeRegular::ID: {
|
|
|
|
auto type = td_api::move_object_as<td_api::pollTypeRegular>(input_poll->type_);
|
|
|
|
allow_multiple_answers = type->allow_multiple_answers_;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case td_api::pollTypeQuiz::ID: {
|
|
|
|
auto type = td_api::move_object_as<td_api::pollTypeQuiz>(input_poll->type_);
|
|
|
|
is_quiz = true;
|
|
|
|
correct_option_id = type->correct_option_id_;
|
|
|
|
if (correct_option_id < 0 || correct_option_id >= static_cast<int32>(input_poll->options_.size())) {
|
|
|
|
return Status::Error(400, "Wrong correct option ID specified");
|
|
|
|
}
|
2020-04-03 22:39:50 +02:00
|
|
|
auto r_explanation =
|
2022-08-15 15:26:51 +02:00
|
|
|
get_formatted_text(td, dialog_id, std::move(type->explanation_), is_bot, true, true, false);
|
2020-04-03 22:39:50 +02:00
|
|
|
if (r_explanation.is_error()) {
|
|
|
|
return r_explanation.move_as_error();
|
|
|
|
}
|
|
|
|
explanation = r_explanation.move_as_ok();
|
2020-01-11 01:46:26 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
2020-04-03 23:05:35 +02:00
|
|
|
int32 open_period = is_bot ? input_poll->open_period_ : 0;
|
2020-04-03 15:50:10 +02:00
|
|
|
int32 close_date = is_bot ? input_poll->close_date_ : 0;
|
2020-04-03 23:05:35 +02:00
|
|
|
if (open_period != 0) {
|
2020-04-03 15:50:10 +02:00
|
|
|
close_date = 0;
|
|
|
|
}
|
2020-01-23 01:53:58 +01:00
|
|
|
bool is_closed = is_bot ? input_poll->is_closed_ : false;
|
2020-04-03 22:39:50 +02:00
|
|
|
content = make_unique<MessagePoll>(
|
|
|
|
td->poll_manager_->create_poll(std::move(input_poll->question_), std::move(input_poll->options_),
|
|
|
|
input_poll->is_anonymous_, allow_multiple_answers, is_quiz, correct_option_id,
|
2020-04-03 23:05:35 +02:00
|
|
|
std::move(explanation), open_period, close_date, is_closed));
|
2019-02-19 14:45:32 +01:00
|
|
|
break;
|
|
|
|
}
|
2023-06-12 18:23:58 +02:00
|
|
|
case td_api::inputMessageStory::ID: {
|
|
|
|
auto input_story = static_cast<td_api::inputMessageStory *>(input_message_content.get());
|
2023-06-27 20:51:36 +02:00
|
|
|
DialogId story_sender_dialog_id(input_story->story_sender_chat_id_);
|
2023-06-12 18:23:58 +02:00
|
|
|
StoryId story_id(input_story->story_id_);
|
2023-06-27 20:51:36 +02:00
|
|
|
StoryFullId story_full_id(story_sender_dialog_id, story_id);
|
2023-08-15 21:45:37 +02:00
|
|
|
if (!td->story_manager_->have_story_force(story_full_id)) {
|
2023-06-12 18:23:58 +02:00
|
|
|
return Status::Error(400, "Story not found");
|
|
|
|
}
|
2023-08-10 19:22:12 +02:00
|
|
|
if (!story_id.is_server()) {
|
|
|
|
return Status::Error(400, "Story can't be forwarded");
|
|
|
|
}
|
2023-08-15 21:45:37 +02:00
|
|
|
if (td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read) == nullptr) {
|
|
|
|
return Status::Error(400, "Can't access the story");
|
2023-06-12 18:23:58 +02:00
|
|
|
}
|
|
|
|
content = make_unique<MessageStory>(story_full_id, false);
|
|
|
|
break;
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
2023-08-29 17:51:57 +02:00
|
|
|
|
2023-09-06 20:27:45 +02:00
|
|
|
if (self_destruct_type != nullptr && dialog_id.get_type() != DialogType::User) {
|
|
|
|
return Status::Error(400, "Messages can self-destruct only in can be specified only in private chats");
|
2023-08-29 17:51:57 +02:00
|
|
|
}
|
2023-09-06 20:27:45 +02:00
|
|
|
int32 ttl = 0;
|
|
|
|
if (self_destruct_type != nullptr) {
|
|
|
|
switch (self_destruct_type->get_id()) {
|
|
|
|
case td_api::messageSelfDestructTypeTimer::ID: {
|
|
|
|
ttl = static_cast<const td_api::messageSelfDestructTypeTimer *>(self_destruct_type.get())->self_destruct_time_;
|
|
|
|
|
|
|
|
static constexpr int32 MAX_PRIVATE_MESSAGE_TTL = 60; // server side limit
|
|
|
|
if (ttl <= 0 || ttl > MAX_PRIVATE_MESSAGE_TTL) {
|
|
|
|
return Status::Error(400, "Invalid message content self-destruct time specified");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case td_api::messageSelfDestructTypeImmediately::ID:
|
|
|
|
ttl = 0x7FFFFFFF;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
2023-08-29 17:51:57 +02:00
|
|
|
}
|
|
|
|
|
2020-12-19 12:31:42 +01:00
|
|
|
return InputMessageContent{std::move(content), disable_web_page_preview, clear_draft, ttl,
|
|
|
|
via_bot_user_id, std::move(emoji)};
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
|
2018-12-12 15:36:31 +01:00
|
|
|
Result<InputMessageContent> get_input_message_content(
|
2022-06-03 15:33:49 +02:00
|
|
|
DialogId dialog_id, tl_object_ptr<td_api::InputMessageContent> &&input_message_content, Td *td, bool is_premium) {
|
2019-02-15 19:49:02 +01:00
|
|
|
LOG(INFO) << "Get input message content from " << to_string(input_message_content);
|
2023-05-25 20:25:16 +02:00
|
|
|
if (input_message_content == nullptr) {
|
|
|
|
return Status::Error(400, "Input message content must be non-empty");
|
|
|
|
}
|
2019-02-15 19:49:02 +01:00
|
|
|
|
2023-05-21 22:28:34 +02:00
|
|
|
td_api::object_ptr<td_api::InputFile> input_file;
|
|
|
|
auto file_type = FileType::None;
|
|
|
|
auto allow_get_by_hash = false;
|
|
|
|
td_api::object_ptr<td_api::inputThumbnail> input_thumbnail;
|
2018-12-12 15:36:31 +01:00
|
|
|
vector<FileId> sticker_file_ids;
|
|
|
|
switch (input_message_content->get_id()) {
|
|
|
|
case td_api::inputMessageAnimation::ID: {
|
|
|
|
auto input_message = static_cast<td_api::inputMessageAnimation *>(input_message_content.get());
|
2023-05-21 22:28:34 +02:00
|
|
|
file_type = FileType::Animation;
|
|
|
|
input_file = std::move(input_message->animation_);
|
|
|
|
allow_get_by_hash = true;
|
2018-12-12 15:36:31 +01:00
|
|
|
input_thumbnail = std::move(input_message->thumbnail_);
|
2020-05-29 10:51:51 +02:00
|
|
|
if (!input_message->added_sticker_file_ids_.empty()) {
|
|
|
|
sticker_file_ids = td->stickers_manager_->get_attached_sticker_file_ids(input_message->added_sticker_file_ids_);
|
|
|
|
}
|
2018-12-12 15:36:31 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case td_api::inputMessageAudio::ID: {
|
|
|
|
auto input_message = static_cast<td_api::inputMessageAudio *>(input_message_content.get());
|
2023-05-21 22:28:34 +02:00
|
|
|
file_type = FileType::Audio;
|
|
|
|
input_file = std::move(input_message->audio_);
|
2018-12-12 15:36:31 +01:00
|
|
|
input_thumbnail = std::move(input_message->album_cover_thumbnail_);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case td_api::inputMessageDocument::ID: {
|
|
|
|
auto input_message = static_cast<td_api::inputMessageDocument *>(input_message_content.get());
|
2023-05-21 22:28:34 +02:00
|
|
|
file_type = input_message->disable_content_type_detection_ ? FileType::DocumentAsFile : FileType::Document;
|
|
|
|
input_file = std::move(input_message->document_);
|
|
|
|
allow_get_by_hash = true;
|
2018-12-12 15:36:31 +01:00
|
|
|
input_thumbnail = std::move(input_message->thumbnail_);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case td_api::inputMessagePhoto::ID: {
|
|
|
|
auto input_message = static_cast<td_api::inputMessagePhoto *>(input_message_content.get());
|
2023-05-21 22:28:34 +02:00
|
|
|
file_type = FileType::Photo;
|
|
|
|
input_file = std::move(input_message->photo_);
|
2018-12-12 15:36:31 +01:00
|
|
|
input_thumbnail = std::move(input_message->thumbnail_);
|
|
|
|
if (!input_message->added_sticker_file_ids_.empty()) {
|
|
|
|
sticker_file_ids = td->stickers_manager_->get_attached_sticker_file_ids(input_message->added_sticker_file_ids_);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case td_api::inputMessageSticker::ID: {
|
|
|
|
auto input_message = static_cast<td_api::inputMessageSticker *>(input_message_content.get());
|
2023-05-21 22:28:34 +02:00
|
|
|
file_type = FileType::Sticker;
|
|
|
|
input_file = std::move(input_message->sticker_);
|
2018-12-12 15:36:31 +01:00
|
|
|
input_thumbnail = std::move(input_message->thumbnail_);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case td_api::inputMessageVideo::ID: {
|
|
|
|
auto input_message = static_cast<td_api::inputMessageVideo *>(input_message_content.get());
|
2023-05-21 22:28:34 +02:00
|
|
|
file_type = FileType::Video;
|
|
|
|
input_file = std::move(input_message->video_);
|
2018-12-12 15:36:31 +01:00
|
|
|
input_thumbnail = std::move(input_message->thumbnail_);
|
|
|
|
if (!input_message->added_sticker_file_ids_.empty()) {
|
|
|
|
sticker_file_ids = td->stickers_manager_->get_attached_sticker_file_ids(input_message->added_sticker_file_ids_);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case td_api::inputMessageVideoNote::ID: {
|
|
|
|
auto input_message = static_cast<td_api::inputMessageVideoNote *>(input_message_content.get());
|
2023-05-21 22:28:34 +02:00
|
|
|
file_type = FileType::VideoNote;
|
|
|
|
input_file = std::move(input_message->video_note_);
|
2018-12-12 15:36:31 +01:00
|
|
|
input_thumbnail = std::move(input_message->thumbnail_);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case td_api::inputMessageVoiceNote::ID: {
|
|
|
|
auto input_message = static_cast<td_api::inputMessageVoiceNote *>(input_message_content.get());
|
2023-05-21 22:28:34 +02:00
|
|
|
file_type = FileType::VoiceNote;
|
|
|
|
input_file = std::move(input_message->voice_note_);
|
2018-12-12 15:36:31 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2023-05-21 22:28:34 +02:00
|
|
|
// TODO path of files must be stored in bytes instead of UTF-8 string
|
|
|
|
|
|
|
|
bool is_secret = dialog_id.get_type() == DialogType::SecretChat;
|
2018-12-12 15:36:31 +01:00
|
|
|
|
|
|
|
FileId file_id;
|
2023-05-21 22:28:34 +02:00
|
|
|
if (file_type != FileType::None) {
|
|
|
|
TRY_RESULT_ASSIGN(file_id, td->file_manager_->get_input_file_id(file_type, input_file, dialog_id, false, is_secret,
|
|
|
|
allow_get_by_hash));
|
2018-12-12 15:36:31 +01:00
|
|
|
CHECK(file_id.is_valid());
|
|
|
|
}
|
|
|
|
|
2022-11-03 14:46:50 +01:00
|
|
|
bool is_bot = td->auth_manager_->is_bot();
|
|
|
|
TRY_RESULT(caption, get_formatted_text(td, dialog_id, extract_input_caption(input_message_content), is_bot, true,
|
|
|
|
false, false));
|
|
|
|
if (is_bot && static_cast<int64>(utf8_length(caption.text)) > G()->get_option_integer("message_caption_length_max")) {
|
|
|
|
return Status::Error(400, "Message caption is too long");
|
|
|
|
}
|
2023-05-21 22:05:28 +02:00
|
|
|
return create_input_message_content(
|
|
|
|
dialog_id, std::move(input_message_content), td, std::move(caption), file_id,
|
|
|
|
get_input_thumbnail_photo_size(td->file_manager_.get(), input_thumbnail.get(), dialog_id, is_secret),
|
|
|
|
std::move(sticker_file_ids), is_premium);
|
2018-12-12 15:36:31 +01:00
|
|
|
}
|
|
|
|
|
2022-05-08 22:54:04 +02:00
|
|
|
bool can_have_input_media(const Td *td, const MessageContent *content, bool is_server) {
|
2020-01-16 04:10:08 +01:00
|
|
|
switch (content->get_type()) {
|
|
|
|
case MessageContentType::Game:
|
2022-05-08 22:54:04 +02:00
|
|
|
return is_server || static_cast<const MessageGame *>(content)->game.has_input_media();
|
2020-01-16 04:10:08 +01:00
|
|
|
case MessageContentType::Poll:
|
|
|
|
return td->poll_manager_->has_input_media(static_cast<const MessagePoll *>(content)->poll_id);
|
2023-06-12 18:23:58 +02:00
|
|
|
case MessageContentType::Story: {
|
|
|
|
auto story_full_id = static_cast<const MessageStory *>(content)->story_full_id;
|
|
|
|
auto dialog_id = story_full_id.get_dialog_id();
|
2023-09-23 15:33:34 +02:00
|
|
|
return td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read) != nullptr;
|
2023-06-12 18:23:58 +02:00
|
|
|
}
|
2023-10-13 11:47:34 +02:00
|
|
|
case MessageContentType::Giveaway:
|
|
|
|
return is_server;
|
2020-01-16 04:10:08 +01:00
|
|
|
case MessageContentType::Unsupported:
|
|
|
|
case MessageContentType::ChatCreate:
|
|
|
|
case MessageContentType::ChatChangeTitle:
|
|
|
|
case MessageContentType::ChatChangePhoto:
|
|
|
|
case MessageContentType::ChatDeletePhoto:
|
|
|
|
case MessageContentType::ChatDeleteHistory:
|
|
|
|
case MessageContentType::ChatAddUsers:
|
|
|
|
case MessageContentType::ChatJoinedByLink:
|
|
|
|
case MessageContentType::ChatDeleteUser:
|
|
|
|
case MessageContentType::ChatMigrateTo:
|
|
|
|
case MessageContentType::ChannelCreate:
|
|
|
|
case MessageContentType::ChannelMigrateFrom:
|
|
|
|
case MessageContentType::PinMessage:
|
|
|
|
case MessageContentType::GameScore:
|
|
|
|
case MessageContentType::ScreenshotTaken:
|
|
|
|
case MessageContentType::ChatSetTtl:
|
|
|
|
case MessageContentType::Call:
|
|
|
|
case MessageContentType::PaymentSuccessful:
|
|
|
|
case MessageContentType::ContactRegistered:
|
|
|
|
case MessageContentType::ExpiredPhoto:
|
|
|
|
case MessageContentType::ExpiredVideo:
|
|
|
|
case MessageContentType::CustomServiceAction:
|
|
|
|
case MessageContentType::WebsiteConnected:
|
|
|
|
case MessageContentType::PassportDataSent:
|
|
|
|
case MessageContentType::PassportDataReceived:
|
2020-10-29 20:25:58 +01:00
|
|
|
case MessageContentType::ProximityAlertTriggered:
|
2020-11-24 12:33:16 +01:00
|
|
|
case MessageContentType::GroupCall:
|
|
|
|
case MessageContentType::InviteToGroupCall:
|
2021-08-18 15:03:10 +02:00
|
|
|
case MessageContentType::ChatSetTheme:
|
2022-03-28 09:01:39 +02:00
|
|
|
case MessageContentType::WebViewDataSent:
|
|
|
|
case MessageContentType::WebViewDataReceived:
|
2022-07-01 14:28:22 +02:00
|
|
|
case MessageContentType::GiftPremium:
|
2022-10-18 15:08:53 +02:00
|
|
|
case MessageContentType::TopicCreate:
|
2022-10-18 21:16:03 +02:00
|
|
|
case MessageContentType::TopicEdit:
|
2022-12-09 12:13:37 +01:00
|
|
|
case MessageContentType::SuggestProfilePhoto:
|
2022-12-14 19:13:48 +01:00
|
|
|
case MessageContentType::WriteAccessAllowed:
|
2023-01-10 14:20:30 +01:00
|
|
|
case MessageContentType::RequestedDialog:
|
2023-02-22 10:24:43 +01:00
|
|
|
case MessageContentType::WebViewWriteAccessAllowed:
|
2023-04-10 13:12:35 +02:00
|
|
|
case MessageContentType::SetBackground:
|
2023-08-25 15:53:50 +02:00
|
|
|
case MessageContentType::WriteAccessAllowedByRequest:
|
2023-09-29 16:55:03 +02:00
|
|
|
case MessageContentType::GiftCode:
|
2023-10-16 10:31:11 +02:00
|
|
|
case MessageContentType::GiveawayLaunch:
|
2020-01-16 04:10:08 +01:00
|
|
|
return false;
|
|
|
|
case MessageContentType::Animation:
|
|
|
|
case MessageContentType::Audio:
|
|
|
|
case MessageContentType::Contact:
|
2020-03-29 23:34:37 +02:00
|
|
|
case MessageContentType::Dice:
|
2020-01-16 04:10:08 +01:00
|
|
|
case MessageContentType::Document:
|
|
|
|
case MessageContentType::Invoice:
|
|
|
|
case MessageContentType::LiveLocation:
|
|
|
|
case MessageContentType::Location:
|
|
|
|
case MessageContentType::Photo:
|
|
|
|
case MessageContentType::Sticker:
|
|
|
|
case MessageContentType::Text:
|
|
|
|
case MessageContentType::Venue:
|
|
|
|
case MessageContentType::Video:
|
|
|
|
case MessageContentType::VideoNote:
|
|
|
|
case MessageContentType::VoiceNote:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-28 22:57:34 +02:00
|
|
|
SecretInputMedia get_secret_input_media(const MessageContent *content, Td *td,
|
|
|
|
tl_object_ptr<telegram_api::InputEncryptedFile> input_file,
|
2022-05-11 06:46:06 +02:00
|
|
|
BufferSlice thumbnail, int32 layer) {
|
2018-09-28 22:57:34 +02:00
|
|
|
switch (content->get_type()) {
|
|
|
|
case MessageContentType::Animation: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageAnimation *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
return td->animations_manager_->get_secret_input_media(m->file_id, std::move(input_file), m->caption.text,
|
2022-05-11 06:46:06 +02:00
|
|
|
std::move(thumbnail), layer);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case MessageContentType::Audio: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageAudio *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
return td->audios_manager_->get_secret_input_media(m->file_id, std::move(input_file), m->caption.text,
|
2022-05-11 06:46:06 +02:00
|
|
|
std::move(thumbnail), layer);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case MessageContentType::Contact: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageContact *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
return m->contact.get_secret_input_media_contact();
|
|
|
|
}
|
|
|
|
case MessageContentType::Document: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageDocument *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
return td->documents_manager_->get_secret_input_media(m->file_id, std::move(input_file), m->caption.text,
|
2022-05-11 06:46:06 +02:00
|
|
|
std::move(thumbnail), layer);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case MessageContentType::Location: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageLocation *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
return m->location.get_secret_input_media_geo_point();
|
|
|
|
}
|
|
|
|
case MessageContentType::Photo: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessagePhoto *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
return photo_get_secret_input_media(td->file_manager_.get(), m->photo, std::move(input_file), m->caption.text,
|
|
|
|
std::move(thumbnail));
|
|
|
|
}
|
|
|
|
case MessageContentType::Sticker: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageSticker *>(content);
|
2022-05-11 06:46:06 +02:00
|
|
|
return td->stickers_manager_->get_secret_input_media(m->file_id, std::move(input_file), std::move(thumbnail),
|
|
|
|
layer);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case MessageContentType::Text: {
|
|
|
|
CHECK(input_file == nullptr);
|
|
|
|
CHECK(thumbnail.empty());
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageText *>(content);
|
2023-10-16 23:37:44 +02:00
|
|
|
if (m->web_page_url.empty()) {
|
2023-10-16 22:18:43 +02:00
|
|
|
return SecretInputMedia{};
|
|
|
|
}
|
2023-10-16 23:37:44 +02:00
|
|
|
return SecretInputMedia{nullptr, make_tl_object<secret_api::decryptedMessageMediaWebPage>(m->web_page_url)};
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case MessageContentType::Venue: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageVenue *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
return m->venue.get_secret_input_media_venue();
|
|
|
|
}
|
|
|
|
case MessageContentType::Video: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageVideo *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
return td->videos_manager_->get_secret_input_media(m->file_id, std::move(input_file), m->caption.text,
|
2022-05-11 06:46:06 +02:00
|
|
|
std::move(thumbnail), layer);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case MessageContentType::VideoNote: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageVideoNote *>(content);
|
2022-05-11 06:46:06 +02:00
|
|
|
return td->video_notes_manager_->get_secret_input_media(m->file_id, std::move(input_file), std::move(thumbnail),
|
|
|
|
layer);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case MessageContentType::VoiceNote: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageVoiceNote *>(content);
|
2022-05-11 06:46:06 +02:00
|
|
|
return td->voice_notes_manager_->get_secret_input_media(m->file_id, std::move(input_file), m->caption.text,
|
|
|
|
layer);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
2020-01-16 04:10:08 +01:00
|
|
|
case MessageContentType::Call:
|
2020-03-29 23:34:37 +02:00
|
|
|
case MessageContentType::Dice:
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::Game:
|
|
|
|
case MessageContentType::Invoice:
|
2020-01-16 04:10:08 +01:00
|
|
|
case MessageContentType::LiveLocation:
|
|
|
|
case MessageContentType::Poll:
|
2023-06-12 18:23:58 +02:00
|
|
|
case MessageContentType::Story:
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::Unsupported:
|
|
|
|
case MessageContentType::ChatCreate:
|
|
|
|
case MessageContentType::ChatChangeTitle:
|
|
|
|
case MessageContentType::ChatChangePhoto:
|
|
|
|
case MessageContentType::ChatDeletePhoto:
|
|
|
|
case MessageContentType::ChatDeleteHistory:
|
|
|
|
case MessageContentType::ChatAddUsers:
|
|
|
|
case MessageContentType::ChatJoinedByLink:
|
|
|
|
case MessageContentType::ChatDeleteUser:
|
|
|
|
case MessageContentType::ChatMigrateTo:
|
|
|
|
case MessageContentType::ChannelCreate:
|
|
|
|
case MessageContentType::ChannelMigrateFrom:
|
|
|
|
case MessageContentType::PinMessage:
|
|
|
|
case MessageContentType::GameScore:
|
|
|
|
case MessageContentType::ScreenshotTaken:
|
|
|
|
case MessageContentType::ChatSetTtl:
|
|
|
|
case MessageContentType::PaymentSuccessful:
|
|
|
|
case MessageContentType::ContactRegistered:
|
|
|
|
case MessageContentType::ExpiredPhoto:
|
|
|
|
case MessageContentType::ExpiredVideo:
|
|
|
|
case MessageContentType::CustomServiceAction:
|
|
|
|
case MessageContentType::WebsiteConnected:
|
|
|
|
case MessageContentType::PassportDataSent:
|
|
|
|
case MessageContentType::PassportDataReceived:
|
2020-10-29 20:25:58 +01:00
|
|
|
case MessageContentType::ProximityAlertTriggered:
|
2020-11-24 12:33:16 +01:00
|
|
|
case MessageContentType::GroupCall:
|
|
|
|
case MessageContentType::InviteToGroupCall:
|
2021-08-18 15:03:10 +02:00
|
|
|
case MessageContentType::ChatSetTheme:
|
2022-03-28 09:01:39 +02:00
|
|
|
case MessageContentType::WebViewDataSent:
|
|
|
|
case MessageContentType::WebViewDataReceived:
|
2022-07-01 14:28:22 +02:00
|
|
|
case MessageContentType::GiftPremium:
|
2022-10-18 15:08:53 +02:00
|
|
|
case MessageContentType::TopicCreate:
|
2022-10-18 21:16:03 +02:00
|
|
|
case MessageContentType::TopicEdit:
|
2022-12-09 12:13:37 +01:00
|
|
|
case MessageContentType::SuggestProfilePhoto:
|
2022-12-14 19:13:48 +01:00
|
|
|
case MessageContentType::WriteAccessAllowed:
|
2023-01-10 14:20:30 +01:00
|
|
|
case MessageContentType::RequestedDialog:
|
2023-02-22 10:24:43 +01:00
|
|
|
case MessageContentType::WebViewWriteAccessAllowed:
|
2023-04-10 13:12:35 +02:00
|
|
|
case MessageContentType::SetBackground:
|
2023-08-25 15:53:50 +02:00
|
|
|
case MessageContentType::WriteAccessAllowedByRequest:
|
2023-09-29 16:55:03 +02:00
|
|
|
case MessageContentType::GiftCode:
|
2023-09-29 23:32:39 +02:00
|
|
|
case MessageContentType::Giveaway:
|
2023-10-16 10:31:11 +02:00
|
|
|
case MessageContentType::GiveawayLaunch:
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
return SecretInputMedia{};
|
|
|
|
}
|
|
|
|
|
2019-10-09 01:59:25 +02:00
|
|
|
static tl_object_ptr<telegram_api::InputMedia> get_input_media_impl(
|
|
|
|
const MessageContent *content, Td *td, tl_object_ptr<telegram_api::InputFile> input_file,
|
2020-12-19 12:31:42 +01:00
|
|
|
tl_object_ptr<telegram_api::InputFile> input_thumbnail, int32 ttl, const string &emoji) {
|
2022-05-08 22:54:04 +02:00
|
|
|
if (!can_have_input_media(td, content, false)) {
|
2020-01-16 04:10:08 +01:00
|
|
|
return nullptr;
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
switch (content->get_type()) {
|
|
|
|
case MessageContentType::Animation: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageAnimation *>(content);
|
2022-12-26 12:20:48 +01:00
|
|
|
return td->animations_manager_->get_input_media(m->file_id, std::move(input_file), std::move(input_thumbnail),
|
|
|
|
m->has_spoiler);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case MessageContentType::Audio: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageAudio *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
return td->audios_manager_->get_input_media(m->file_id, std::move(input_file), std::move(input_thumbnail));
|
|
|
|
}
|
|
|
|
case MessageContentType::Contact: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageContact *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
return m->contact.get_input_media_contact();
|
|
|
|
}
|
2020-04-18 07:45:41 +02:00
|
|
|
case MessageContentType::Dice: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageDice *>(content);
|
2020-04-18 07:45:41 +02:00
|
|
|
return make_tl_object<telegram_api::inputMediaDice>(m->emoji);
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::Document: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageDocument *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
return td->documents_manager_->get_input_media(m->file_id, std::move(input_file), std::move(input_thumbnail));
|
|
|
|
}
|
|
|
|
case MessageContentType::Game: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageGame *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
return m->game.get_input_media_game(td);
|
|
|
|
}
|
|
|
|
case MessageContentType::Invoice: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageInvoice *>(content);
|
2022-09-23 15:16:56 +02:00
|
|
|
return m->input_invoice.get_input_media_invoice(td, std::move(input_file), std::move(input_thumbnail));
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case MessageContentType::LiveLocation: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageLiveLocation *>(content);
|
2019-02-18 01:27:35 +01:00
|
|
|
int32 flags = telegram_api::inputMediaGeoLive::PERIOD_MASK;
|
2020-10-24 23:49:41 +02:00
|
|
|
if (m->heading != 0) {
|
|
|
|
flags |= telegram_api::inputMediaGeoLive::HEADING_MASK;
|
|
|
|
}
|
|
|
|
flags |= telegram_api::inputMediaGeoLive::PROXIMITY_NOTIFICATION_RADIUS_MASK;
|
2019-02-18 01:27:35 +01:00
|
|
|
return make_tl_object<telegram_api::inputMediaGeoLive>(flags, false /*ignored*/,
|
2020-10-24 23:49:41 +02:00
|
|
|
m->location.get_input_geo_point(), m->heading, m->period,
|
2020-10-30 13:51:20 +01:00
|
|
|
m->proximity_alert_radius);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case MessageContentType::Location: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageLocation *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
return m->location.get_input_media_geo_point();
|
|
|
|
}
|
|
|
|
case MessageContentType::Photo: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessagePhoto *>(content);
|
2022-12-20 16:06:21 +01:00
|
|
|
return photo_get_input_media(td->file_manager_.get(), m->photo, std::move(input_file), ttl, m->has_spoiler);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
2020-01-16 03:18:06 +01:00
|
|
|
case MessageContentType::Poll: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessagePoll *>(content);
|
2020-01-16 03:18:06 +01:00
|
|
|
return td->poll_manager_->get_input_media(m->poll_id);
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::Sticker: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageSticker *>(content);
|
2020-12-19 12:31:42 +01:00
|
|
|
return td->stickers_manager_->get_input_media(m->file_id, std::move(input_file), std::move(input_thumbnail),
|
|
|
|
emoji);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
2023-06-12 18:23:58 +02:00
|
|
|
case MessageContentType::Story: {
|
|
|
|
const auto *m = static_cast<const MessageStory *>(content);
|
|
|
|
return td->story_manager_->get_input_media(m->story_full_id);
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::Venue: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageVenue *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
return m->venue.get_input_media_venue();
|
|
|
|
}
|
|
|
|
case MessageContentType::Video: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageVideo *>(content);
|
2022-12-20 16:06:21 +01:00
|
|
|
return td->videos_manager_->get_input_media(m->file_id, std::move(input_file), std::move(input_thumbnail), ttl,
|
|
|
|
m->has_spoiler);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case MessageContentType::VideoNote: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageVideoNote *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
return td->video_notes_manager_->get_input_media(m->file_id, std::move(input_file), std::move(input_thumbnail));
|
|
|
|
}
|
|
|
|
case MessageContentType::VoiceNote: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageVoiceNote *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
return td->voice_notes_manager_->get_input_media(m->file_id, std::move(input_file));
|
|
|
|
}
|
|
|
|
case MessageContentType::Text:
|
|
|
|
case MessageContentType::Unsupported:
|
|
|
|
case MessageContentType::ChatCreate:
|
|
|
|
case MessageContentType::ChatChangeTitle:
|
|
|
|
case MessageContentType::ChatChangePhoto:
|
|
|
|
case MessageContentType::ChatDeletePhoto:
|
|
|
|
case MessageContentType::ChatDeleteHistory:
|
|
|
|
case MessageContentType::ChatAddUsers:
|
|
|
|
case MessageContentType::ChatJoinedByLink:
|
|
|
|
case MessageContentType::ChatDeleteUser:
|
|
|
|
case MessageContentType::ChatMigrateTo:
|
|
|
|
case MessageContentType::ChannelCreate:
|
|
|
|
case MessageContentType::ChannelMigrateFrom:
|
|
|
|
case MessageContentType::PinMessage:
|
|
|
|
case MessageContentType::GameScore:
|
|
|
|
case MessageContentType::ScreenshotTaken:
|
|
|
|
case MessageContentType::ChatSetTtl:
|
|
|
|
case MessageContentType::Call:
|
|
|
|
case MessageContentType::PaymentSuccessful:
|
|
|
|
case MessageContentType::ContactRegistered:
|
|
|
|
case MessageContentType::ExpiredPhoto:
|
|
|
|
case MessageContentType::ExpiredVideo:
|
|
|
|
case MessageContentType::CustomServiceAction:
|
|
|
|
case MessageContentType::WebsiteConnected:
|
|
|
|
case MessageContentType::PassportDataSent:
|
|
|
|
case MessageContentType::PassportDataReceived:
|
2020-10-29 20:25:58 +01:00
|
|
|
case MessageContentType::ProximityAlertTriggered:
|
2020-11-24 12:33:16 +01:00
|
|
|
case MessageContentType::GroupCall:
|
|
|
|
case MessageContentType::InviteToGroupCall:
|
2021-08-18 15:03:10 +02:00
|
|
|
case MessageContentType::ChatSetTheme:
|
2022-03-28 09:01:39 +02:00
|
|
|
case MessageContentType::WebViewDataSent:
|
|
|
|
case MessageContentType::WebViewDataReceived:
|
2022-07-01 14:28:22 +02:00
|
|
|
case MessageContentType::GiftPremium:
|
2022-10-18 15:08:53 +02:00
|
|
|
case MessageContentType::TopicCreate:
|
2022-10-18 21:16:03 +02:00
|
|
|
case MessageContentType::TopicEdit:
|
2022-12-09 12:13:37 +01:00
|
|
|
case MessageContentType::SuggestProfilePhoto:
|
2022-12-14 19:13:48 +01:00
|
|
|
case MessageContentType::WriteAccessAllowed:
|
2023-01-10 14:20:30 +01:00
|
|
|
case MessageContentType::RequestedDialog:
|
2023-02-22 10:24:43 +01:00
|
|
|
case MessageContentType::WebViewWriteAccessAllowed:
|
2023-04-10 13:12:35 +02:00
|
|
|
case MessageContentType::SetBackground:
|
2023-08-25 15:53:50 +02:00
|
|
|
case MessageContentType::WriteAccessAllowedByRequest:
|
2023-09-29 16:55:03 +02:00
|
|
|
case MessageContentType::GiftCode:
|
2023-09-29 23:32:39 +02:00
|
|
|
case MessageContentType::Giveaway:
|
2023-10-16 10:31:11 +02:00
|
|
|
case MessageContentType::GiveawayLaunch:
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-01-25 02:38:11 +01:00
|
|
|
tl_object_ptr<telegram_api::InputMedia> get_input_media(const MessageContent *content, Td *td,
|
|
|
|
tl_object_ptr<telegram_api::InputFile> input_file,
|
|
|
|
tl_object_ptr<telegram_api::InputFile> input_thumbnail,
|
2019-10-09 01:59:25 +02:00
|
|
|
FileId file_id, FileId thumbnail_file_id, int32 ttl,
|
2023-02-27 00:12:21 +01:00
|
|
|
const string &emoji, bool force) {
|
2019-01-25 02:38:11 +01:00
|
|
|
bool had_input_file = input_file != nullptr;
|
|
|
|
bool had_input_thumbnail = input_thumbnail != nullptr;
|
2023-02-27 00:12:21 +01:00
|
|
|
auto input_media = get_input_media_impl(content, td, std::move(input_file), std::move(input_thumbnail), ttl, emoji);
|
2019-01-25 15:33:24 +01:00
|
|
|
auto was_uploaded = FileManager::extract_was_uploaded(input_media);
|
2019-01-25 02:38:11 +01:00
|
|
|
if (had_input_file) {
|
2019-01-25 15:33:24 +01:00
|
|
|
if (!was_uploaded) {
|
2019-01-25 02:38:11 +01:00
|
|
|
// if we had InputFile, but has failed to use it, then we need to immediately cancel file upload
|
|
|
|
// so the next upload with the same file can succeed
|
|
|
|
CHECK(file_id.is_valid());
|
2019-01-25 02:52:38 +01:00
|
|
|
td->file_manager_->cancel_upload(file_id);
|
2019-01-25 02:38:11 +01:00
|
|
|
if (had_input_thumbnail) {
|
|
|
|
CHECK(thumbnail_file_id.is_valid());
|
2019-01-25 02:52:38 +01:00
|
|
|
td->file_manager_->cancel_upload(thumbnail_file_id);
|
2019-01-25 02:38:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
CHECK(!had_input_thumbnail);
|
|
|
|
}
|
2019-01-25 15:33:24 +01:00
|
|
|
if (!was_uploaded) {
|
|
|
|
auto file_reference = FileManager::extract_file_reference(input_media);
|
2020-05-04 23:37:27 +02:00
|
|
|
if (file_reference == FileReferenceView::invalid_file_reference()) {
|
|
|
|
if (!force) {
|
|
|
|
LOG(INFO) << "File " << file_id << " has invalid file reference";
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
LOG(ERROR) << "File " << file_id << " has invalid file reference, but we forced to use it";
|
2019-01-25 15:33:24 +01:00
|
|
|
}
|
|
|
|
}
|
2019-01-25 02:38:11 +01:00
|
|
|
return input_media;
|
|
|
|
}
|
|
|
|
|
2020-12-19 12:31:42 +01:00
|
|
|
tl_object_ptr<telegram_api::InputMedia> get_input_media(const MessageContent *content, Td *td, int32 ttl,
|
|
|
|
const string &emoji, bool force) {
|
|
|
|
auto input_media = get_input_media_impl(content, td, nullptr, nullptr, ttl, emoji);
|
2019-01-25 04:01:09 +01:00
|
|
|
auto file_reference = FileManager::extract_file_reference(input_media);
|
2020-05-04 23:37:27 +02:00
|
|
|
if (file_reference == FileReferenceView::invalid_file_reference()) {
|
2020-05-07 00:50:47 +02:00
|
|
|
auto file_id = get_message_content_any_file_id(content);
|
2020-05-04 23:37:27 +02:00
|
|
|
if (!force) {
|
|
|
|
LOG(INFO) << "File " << file_id << " has invalid file reference";
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
LOG(ERROR) << "File " << file_id << " has invalid file reference, but we forced to use it";
|
2019-01-25 04:01:09 +01:00
|
|
|
}
|
|
|
|
return input_media;
|
2019-01-25 02:38:11 +01:00
|
|
|
}
|
|
|
|
|
2021-01-22 15:09:08 +01:00
|
|
|
tl_object_ptr<telegram_api::InputMedia> get_fake_input_media(Td *td, tl_object_ptr<telegram_api::InputFile> input_file,
|
|
|
|
FileId file_id) {
|
|
|
|
FileView file_view = td->file_manager_->get_file_view(file_id);
|
|
|
|
auto file_type = file_view.get_type();
|
2022-04-21 20:54:33 +02:00
|
|
|
if (is_document_file_type(file_type)) {
|
|
|
|
vector<tl_object_ptr<telegram_api::DocumentAttribute>> attributes;
|
|
|
|
auto file_path = file_view.suggested_path();
|
|
|
|
const PathView path_view(file_path);
|
|
|
|
Slice file_name = path_view.file_name();
|
|
|
|
if (!file_name.empty()) {
|
|
|
|
attributes.push_back(make_tl_object<telegram_api::documentAttributeFilename>(file_name.str()));
|
|
|
|
}
|
|
|
|
string mime_type = MimeType::from_extension(path_view.extension());
|
|
|
|
int32 flags = 0;
|
2023-05-25 13:19:54 +02:00
|
|
|
if (file_type == FileType::Video || file_type == FileType::VideoStory) {
|
2022-04-21 20:54:33 +02:00
|
|
|
flags |= telegram_api::inputMediaUploadedDocument::NOSOUND_VIDEO_MASK;
|
|
|
|
}
|
|
|
|
if (file_type == FileType::DocumentAsFile) {
|
|
|
|
flags |= telegram_api::inputMediaUploadedDocument::FORCE_FILE_MASK;
|
|
|
|
}
|
|
|
|
return make_tl_object<telegram_api::inputMediaUploadedDocument>(
|
2022-12-08 18:58:37 +01:00
|
|
|
flags, false /*ignored*/, false /*ignored*/, false /*ignored*/, std::move(input_file), nullptr, mime_type,
|
|
|
|
std::move(attributes), vector<tl_object_ptr<telegram_api::InputDocument>>(), 0);
|
2022-04-21 20:54:33 +02:00
|
|
|
} else {
|
2023-05-25 13:19:54 +02:00
|
|
|
CHECK(file_type == FileType::Photo || file_type == FileType::PhotoStory);
|
2022-12-15 20:41:55 +01:00
|
|
|
int32 flags = 0;
|
2022-04-21 20:54:33 +02:00
|
|
|
return make_tl_object<telegram_api::inputMediaUploadedPhoto>(
|
2022-12-15 20:41:55 +01:00
|
|
|
flags, false /*ignored*/, std::move(input_file), vector<tl_object_ptr<telegram_api::InputDocument>>(), 0);
|
2021-01-22 15:09:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-16 19:41:39 +02:00
|
|
|
tl_object_ptr<telegram_api::InputMedia> get_message_content_input_media_web_page(const Td *td,
|
|
|
|
const MessageContent *content) {
|
|
|
|
CHECK(content != nullptr);
|
|
|
|
if (content->get_type() != MessageContentType::Text) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
auto *text = static_cast<const MessageText *>(content);
|
2023-10-16 22:06:48 +02:00
|
|
|
if (text->web_page_url.empty()) {
|
2023-10-16 19:41:39 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
int32 flags = 0;
|
|
|
|
if (text->force_small_media) {
|
|
|
|
flags |= telegram_api::inputMediaWebPage::FORCE_SMALL_MEDIA_MASK;
|
|
|
|
}
|
|
|
|
if (text->force_large_media) {
|
|
|
|
flags |= telegram_api::inputMediaWebPage::FORCE_LARGE_MEDIA_MASK;
|
|
|
|
}
|
|
|
|
if (!text->text.text.empty()) {
|
|
|
|
flags |= telegram_api::inputMediaWebPage::OPTIONAL_MASK;
|
|
|
|
}
|
2023-10-16 22:06:48 +02:00
|
|
|
return telegram_api::make_object<telegram_api::inputMediaWebPage>(flags, false /*ignored*/, false /*ignored*/,
|
|
|
|
false /*ignored*/, text->web_page_url);
|
2023-10-16 19:41:39 +02:00
|
|
|
}
|
|
|
|
|
2018-09-28 22:57:34 +02:00
|
|
|
void delete_message_content_thumbnail(MessageContent *content, Td *td) {
|
|
|
|
switch (content->get_type()) {
|
|
|
|
case MessageContentType::Animation: {
|
2021-10-19 17:11:16 +02:00
|
|
|
auto *m = static_cast<MessageAnimation *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
return td->animations_manager_->delete_animation_thumbnail(m->file_id);
|
|
|
|
}
|
|
|
|
case MessageContentType::Audio: {
|
2021-10-19 17:11:16 +02:00
|
|
|
auto *m = static_cast<MessageAudio *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
return td->audios_manager_->delete_audio_thumbnail(m->file_id);
|
|
|
|
}
|
|
|
|
case MessageContentType::Document: {
|
2021-10-19 17:11:16 +02:00
|
|
|
auto *m = static_cast<MessageDocument *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
return td->documents_manager_->delete_document_thumbnail(m->file_id);
|
|
|
|
}
|
2022-09-22 17:05:58 +02:00
|
|
|
case MessageContentType::Invoice: {
|
|
|
|
auto *m = static_cast<MessageInvoice *>(content);
|
2022-09-23 11:52:54 +02:00
|
|
|
return m->input_invoice.delete_thumbnail(td);
|
2022-09-22 17:05:58 +02:00
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::Photo: {
|
2021-10-19 17:11:16 +02:00
|
|
|
auto *m = static_cast<MessagePhoto *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
return photo_delete_thumbnail(m->photo);
|
|
|
|
}
|
|
|
|
case MessageContentType::Sticker: {
|
2021-10-19 17:11:16 +02:00
|
|
|
auto *m = static_cast<MessageSticker *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
return td->stickers_manager_->delete_sticker_thumbnail(m->file_id);
|
|
|
|
}
|
|
|
|
case MessageContentType::Video: {
|
2021-10-19 17:11:16 +02:00
|
|
|
auto *m = static_cast<MessageVideo *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
return td->videos_manager_->delete_video_thumbnail(m->file_id);
|
|
|
|
}
|
|
|
|
case MessageContentType::VideoNote: {
|
2021-10-19 17:11:16 +02:00
|
|
|
auto *m = static_cast<MessageVideoNote *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
return td->video_notes_manager_->delete_video_note_thumbnail(m->file_id);
|
|
|
|
}
|
|
|
|
case MessageContentType::Contact:
|
2020-03-29 23:34:37 +02:00
|
|
|
case MessageContentType::Dice:
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::Game:
|
|
|
|
case MessageContentType::LiveLocation:
|
|
|
|
case MessageContentType::Location:
|
2023-06-12 18:23:58 +02:00
|
|
|
case MessageContentType::Story:
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::Venue:
|
|
|
|
case MessageContentType::VoiceNote:
|
|
|
|
case MessageContentType::Text:
|
|
|
|
case MessageContentType::Unsupported:
|
|
|
|
case MessageContentType::ChatCreate:
|
|
|
|
case MessageContentType::ChatChangeTitle:
|
|
|
|
case MessageContentType::ChatChangePhoto:
|
|
|
|
case MessageContentType::ChatDeletePhoto:
|
|
|
|
case MessageContentType::ChatDeleteHistory:
|
|
|
|
case MessageContentType::ChatAddUsers:
|
|
|
|
case MessageContentType::ChatJoinedByLink:
|
|
|
|
case MessageContentType::ChatDeleteUser:
|
|
|
|
case MessageContentType::ChatMigrateTo:
|
|
|
|
case MessageContentType::ChannelCreate:
|
|
|
|
case MessageContentType::ChannelMigrateFrom:
|
|
|
|
case MessageContentType::PinMessage:
|
|
|
|
case MessageContentType::GameScore:
|
|
|
|
case MessageContentType::ScreenshotTaken:
|
|
|
|
case MessageContentType::ChatSetTtl:
|
|
|
|
case MessageContentType::Call:
|
|
|
|
case MessageContentType::PaymentSuccessful:
|
|
|
|
case MessageContentType::ContactRegistered:
|
|
|
|
case MessageContentType::ExpiredPhoto:
|
|
|
|
case MessageContentType::ExpiredVideo:
|
|
|
|
case MessageContentType::CustomServiceAction:
|
|
|
|
case MessageContentType::WebsiteConnected:
|
|
|
|
case MessageContentType::PassportDataSent:
|
|
|
|
case MessageContentType::PassportDataReceived:
|
2019-02-19 14:45:32 +01:00
|
|
|
case MessageContentType::Poll:
|
2020-10-29 20:25:58 +01:00
|
|
|
case MessageContentType::ProximityAlertTriggered:
|
2020-11-24 12:33:16 +01:00
|
|
|
case MessageContentType::GroupCall:
|
|
|
|
case MessageContentType::InviteToGroupCall:
|
2021-08-18 15:03:10 +02:00
|
|
|
case MessageContentType::ChatSetTheme:
|
2022-03-28 09:01:39 +02:00
|
|
|
case MessageContentType::WebViewDataSent:
|
|
|
|
case MessageContentType::WebViewDataReceived:
|
2022-07-01 14:28:22 +02:00
|
|
|
case MessageContentType::GiftPremium:
|
2022-10-18 15:08:53 +02:00
|
|
|
case MessageContentType::TopicCreate:
|
2022-10-18 21:16:03 +02:00
|
|
|
case MessageContentType::TopicEdit:
|
2022-12-09 12:13:37 +01:00
|
|
|
case MessageContentType::SuggestProfilePhoto:
|
2022-12-14 19:13:48 +01:00
|
|
|
case MessageContentType::WriteAccessAllowed:
|
2023-01-10 14:20:30 +01:00
|
|
|
case MessageContentType::RequestedDialog:
|
2023-02-22 10:24:43 +01:00
|
|
|
case MessageContentType::WebViewWriteAccessAllowed:
|
2023-04-10 13:12:35 +02:00
|
|
|
case MessageContentType::SetBackground:
|
2023-08-25 15:53:50 +02:00
|
|
|
case MessageContentType::WriteAccessAllowedByRequest:
|
2023-09-29 16:55:03 +02:00
|
|
|
case MessageContentType::GiftCode:
|
2023-09-29 23:32:39 +02:00
|
|
|
case MessageContentType::Giveaway:
|
2023-10-16 10:31:11 +02:00
|
|
|
case MessageContentType::GiveawayLaunch:
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-13 01:59:33 +02:00
|
|
|
Status can_send_message_content(DialogId dialog_id, const MessageContent *content, bool is_forward, const Td *td) {
|
|
|
|
auto dialog_type = dialog_id.get_type();
|
|
|
|
RestrictedRights permissions = [&] {
|
|
|
|
switch (dialog_type) {
|
|
|
|
case DialogType::User:
|
|
|
|
return td->contacts_manager_->get_user_default_permissions(dialog_id.get_user_id());
|
|
|
|
case DialogType::Chat:
|
2022-03-18 15:50:55 +01:00
|
|
|
return td->contacts_manager_->get_chat_permissions(dialog_id.get_chat_id()).get_effective_restricted_rights();
|
2021-04-13 01:59:33 +02:00
|
|
|
case DialogType::Channel:
|
2022-03-18 15:50:55 +01:00
|
|
|
return td->contacts_manager_->get_channel_permissions(dialog_id.get_channel_id())
|
|
|
|
.get_effective_restricted_rights();
|
2021-04-13 01:59:33 +02:00
|
|
|
case DialogType::SecretChat:
|
|
|
|
return td->contacts_manager_->get_secret_chat_default_permissions(dialog_id.get_secret_chat_id());
|
|
|
|
case DialogType::None:
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return td->contacts_manager_->get_user_default_permissions(UserId());
|
|
|
|
}
|
|
|
|
}();
|
|
|
|
|
2021-06-10 01:42:30 +02:00
|
|
|
auto content_type = content->get_type();
|
2021-04-13 01:59:33 +02:00
|
|
|
switch (content_type) {
|
|
|
|
case MessageContentType::Animation:
|
|
|
|
if (!permissions.can_send_animations()) {
|
|
|
|
return Status::Error(400, "Not enough rights to send animations to the chat");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MessageContentType::Audio:
|
2023-01-06 12:16:34 +01:00
|
|
|
if (!permissions.can_send_audios()) {
|
2021-04-13 01:59:33 +02:00
|
|
|
return Status::Error(400, "Not enough rights to send music to the chat");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MessageContentType::Contact:
|
|
|
|
if (!permissions.can_send_messages()) {
|
|
|
|
return Status::Error(400, "Not enough rights to send contacts to the chat");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MessageContentType::Dice:
|
|
|
|
if (!permissions.can_send_stickers()) {
|
|
|
|
return Status::Error(400, "Not enough rights to send dice to the chat");
|
|
|
|
}
|
|
|
|
if (dialog_type == DialogType::SecretChat) {
|
|
|
|
return Status::Error(400, "Dice can't be sent to secret chats");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MessageContentType::Document:
|
2023-01-06 12:16:34 +01:00
|
|
|
if (!permissions.can_send_documents()) {
|
2021-04-13 01:59:33 +02:00
|
|
|
return Status::Error(400, "Not enough rights to send documents to the chat");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MessageContentType::Game:
|
2022-04-04 14:35:09 +02:00
|
|
|
if (dialog_type == DialogType::Channel &&
|
2022-04-04 14:48:33 +02:00
|
|
|
td->contacts_manager_->is_broadcast_channel(dialog_id.get_channel_id())) {
|
2021-04-13 01:59:33 +02:00
|
|
|
// return Status::Error(400, "Games can't be sent to channel chats");
|
|
|
|
}
|
|
|
|
if (dialog_type == DialogType::SecretChat) {
|
|
|
|
return Status::Error(400, "Games can't be sent to secret chats");
|
|
|
|
}
|
|
|
|
if (!permissions.can_send_games()) {
|
|
|
|
return Status::Error(400, "Not enough rights to send games to the chat");
|
|
|
|
}
|
|
|
|
break;
|
2023-10-13 11:47:34 +02:00
|
|
|
case MessageContentType::Giveaway:
|
|
|
|
if (!permissions.can_send_messages()) {
|
|
|
|
return Status::Error(400, "Not enough rights to send giveaways to the chat");
|
|
|
|
}
|
|
|
|
if (dialog_type == DialogType::SecretChat) {
|
|
|
|
return Status::Error(400, "Giveaways can't be sent to secret chats");
|
|
|
|
}
|
|
|
|
break;
|
2021-04-13 01:59:33 +02:00
|
|
|
case MessageContentType::Invoice:
|
|
|
|
if (!permissions.can_send_messages()) {
|
|
|
|
return Status::Error(400, "Not enough rights to send invoice messages to the chat");
|
|
|
|
}
|
|
|
|
if (dialog_type == DialogType::SecretChat) {
|
|
|
|
return Status::Error(400, "Invoice messages can't be sent to secret chats");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MessageContentType::LiveLocation:
|
|
|
|
if (!permissions.can_send_messages()) {
|
|
|
|
return Status::Error(400, "Not enough rights to send live locations to the chat");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MessageContentType::Location:
|
|
|
|
if (!permissions.can_send_messages()) {
|
|
|
|
return Status::Error(400, "Not enough rights to send locations to the chat");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MessageContentType::Photo:
|
2023-01-06 12:16:34 +01:00
|
|
|
if (!permissions.can_send_photos()) {
|
2021-04-13 01:59:33 +02:00
|
|
|
return Status::Error(400, "Not enough rights to send photos to the chat");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MessageContentType::Poll:
|
|
|
|
if (!permissions.can_send_polls()) {
|
|
|
|
return Status::Error(400, "Not enough rights to send polls to the chat");
|
|
|
|
}
|
|
|
|
if (dialog_type == DialogType::Channel &&
|
2022-04-04 14:48:33 +02:00
|
|
|
td->contacts_manager_->is_broadcast_channel(dialog_id.get_channel_id()) &&
|
2021-04-13 01:59:33 +02:00
|
|
|
!td->poll_manager_->get_poll_is_anonymous(static_cast<const MessagePoll *>(content)->poll_id)) {
|
|
|
|
return Status::Error(400, "Non-anonymous polls can't be sent to channel chats");
|
|
|
|
}
|
|
|
|
if (dialog_type == DialogType::User && !is_forward && !td->auth_manager_->is_bot() &&
|
|
|
|
!td->contacts_manager_->is_user_bot(dialog_id.get_user_id())) {
|
|
|
|
return Status::Error(400, "Polls can't be sent to the private chat");
|
|
|
|
}
|
|
|
|
if (dialog_type == DialogType::SecretChat) {
|
|
|
|
return Status::Error(400, "Polls can't be sent to secret chats");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MessageContentType::Sticker:
|
2023-06-12 18:23:58 +02:00
|
|
|
if (!permissions.can_send_messages()) {
|
2021-04-13 01:59:33 +02:00
|
|
|
return Status::Error(400, "Not enough rights to send stickers to the chat");
|
|
|
|
}
|
2022-07-22 15:11:33 +02:00
|
|
|
if (get_message_content_sticker_type(td, content) == StickerType::CustomEmoji) {
|
2022-07-18 13:51:37 +02:00
|
|
|
return Status::Error(400, "Can't send emoji stickers in messages");
|
|
|
|
}
|
2021-04-13 01:59:33 +02:00
|
|
|
break;
|
2023-06-12 18:23:58 +02:00
|
|
|
case MessageContentType::Story:
|
|
|
|
if (!permissions.can_send_photos() || !permissions.can_send_videos()) {
|
|
|
|
return Status::Error(400, "Not enough rights to send stories to the chat");
|
|
|
|
}
|
2023-10-14 01:47:49 +02:00
|
|
|
if (dialog_type == DialogType::SecretChat) {
|
|
|
|
return Status::Error(400, "Story messages can't be sent to secret chats");
|
|
|
|
}
|
2023-06-12 18:23:58 +02:00
|
|
|
break;
|
2021-04-13 01:59:33 +02:00
|
|
|
case MessageContentType::Text:
|
|
|
|
if (!permissions.can_send_messages()) {
|
|
|
|
return Status::Error(400, "Not enough rights to send text messages to the chat");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MessageContentType::Venue:
|
|
|
|
if (!permissions.can_send_messages()) {
|
|
|
|
return Status::Error(400, "Not enough rights to send venues to the chat");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MessageContentType::Video:
|
2023-01-06 12:16:34 +01:00
|
|
|
if (!permissions.can_send_videos()) {
|
2021-04-13 01:59:33 +02:00
|
|
|
return Status::Error(400, "Not enough rights to send videos to the chat");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MessageContentType::VideoNote:
|
2023-01-06 12:16:34 +01:00
|
|
|
if (!permissions.can_send_video_notes()) {
|
2021-04-13 01:59:33 +02:00
|
|
|
return Status::Error(400, "Not enough rights to send video notes to the chat");
|
|
|
|
}
|
2022-07-17 16:15:48 +02:00
|
|
|
if (dialog_type == DialogType::User &&
|
|
|
|
td->contacts_manager_->get_user_voice_messages_forbidden(dialog_id.get_user_id())) {
|
|
|
|
return Status::Error(400, "User restricted receiving of voice messages");
|
|
|
|
}
|
2021-04-13 01:59:33 +02:00
|
|
|
break;
|
|
|
|
case MessageContentType::VoiceNote:
|
2023-01-06 12:16:34 +01:00
|
|
|
if (!permissions.can_send_voice_notes()) {
|
2021-04-13 01:59:33 +02:00
|
|
|
return Status::Error(400, "Not enough rights to send voice notes to the chat");
|
|
|
|
}
|
2022-07-17 16:15:48 +02:00
|
|
|
if (dialog_type == DialogType::User &&
|
|
|
|
td->contacts_manager_->get_user_voice_messages_forbidden(dialog_id.get_user_id())) {
|
|
|
|
return Status::Error(400, "User restricted receiving of video messages");
|
|
|
|
}
|
2021-04-13 01:59:33 +02:00
|
|
|
break;
|
|
|
|
case MessageContentType::None:
|
|
|
|
case MessageContentType::ChatCreate:
|
|
|
|
case MessageContentType::ChatChangeTitle:
|
|
|
|
case MessageContentType::ChatChangePhoto:
|
|
|
|
case MessageContentType::ChatDeletePhoto:
|
|
|
|
case MessageContentType::ChatDeleteHistory:
|
|
|
|
case MessageContentType::ChatAddUsers:
|
|
|
|
case MessageContentType::ChatJoinedByLink:
|
|
|
|
case MessageContentType::ChatDeleteUser:
|
|
|
|
case MessageContentType::ChatMigrateTo:
|
|
|
|
case MessageContentType::ChannelCreate:
|
|
|
|
case MessageContentType::ChannelMigrateFrom:
|
|
|
|
case MessageContentType::PinMessage:
|
|
|
|
case MessageContentType::GameScore:
|
|
|
|
case MessageContentType::ScreenshotTaken:
|
|
|
|
case MessageContentType::ChatSetTtl:
|
|
|
|
case MessageContentType::Unsupported:
|
|
|
|
case MessageContentType::Call:
|
|
|
|
case MessageContentType::PaymentSuccessful:
|
|
|
|
case MessageContentType::ContactRegistered:
|
|
|
|
case MessageContentType::ExpiredPhoto:
|
|
|
|
case MessageContentType::ExpiredVideo:
|
|
|
|
case MessageContentType::CustomServiceAction:
|
|
|
|
case MessageContentType::WebsiteConnected:
|
|
|
|
case MessageContentType::PassportDataSent:
|
|
|
|
case MessageContentType::PassportDataReceived:
|
|
|
|
case MessageContentType::ProximityAlertTriggered:
|
|
|
|
case MessageContentType::GroupCall:
|
|
|
|
case MessageContentType::InviteToGroupCall:
|
2021-08-18 15:03:10 +02:00
|
|
|
case MessageContentType::ChatSetTheme:
|
2022-03-28 09:01:39 +02:00
|
|
|
case MessageContentType::WebViewDataSent:
|
|
|
|
case MessageContentType::WebViewDataReceived:
|
2022-07-01 14:28:22 +02:00
|
|
|
case MessageContentType::GiftPremium:
|
2022-10-18 15:08:53 +02:00
|
|
|
case MessageContentType::TopicCreate:
|
2022-10-18 21:16:03 +02:00
|
|
|
case MessageContentType::TopicEdit:
|
2022-12-09 12:13:37 +01:00
|
|
|
case MessageContentType::SuggestProfilePhoto:
|
2022-12-14 19:13:48 +01:00
|
|
|
case MessageContentType::WriteAccessAllowed:
|
2023-01-10 14:20:30 +01:00
|
|
|
case MessageContentType::RequestedDialog:
|
2023-02-22 10:24:43 +01:00
|
|
|
case MessageContentType::WebViewWriteAccessAllowed:
|
2023-04-10 13:12:35 +02:00
|
|
|
case MessageContentType::SetBackground:
|
2023-08-25 15:53:50 +02:00
|
|
|
case MessageContentType::WriteAccessAllowedByRequest:
|
2023-09-29 16:55:03 +02:00
|
|
|
case MessageContentType::GiftCode:
|
2023-10-16 10:31:11 +02:00
|
|
|
case MessageContentType::GiveawayLaunch:
|
2021-04-13 01:59:33 +02:00
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
2018-09-28 22:57:34 +02:00
|
|
|
bool can_forward_message_content(const MessageContent *content) {
|
|
|
|
auto content_type = content->get_type();
|
|
|
|
if (content_type == MessageContentType::Text) {
|
|
|
|
auto *text = static_cast<const MessageText *>(content);
|
2023-10-16 15:47:22 +02:00
|
|
|
// text must be non-empty if there is no link preview
|
2023-10-16 21:33:53 +02:00
|
|
|
return !is_empty_string(text->text.text) || text->web_page_id.is_valid() || !text->web_page_url.empty();
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
2019-02-25 17:19:01 +01:00
|
|
|
if (content_type == MessageContentType::Poll) {
|
|
|
|
auto *poll = static_cast<const MessagePoll *>(content);
|
|
|
|
return !PollManager::is_local_poll_id(poll->poll_id);
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
|
|
|
|
return !is_service_message_content(content_type) && content_type != MessageContentType::Unsupported &&
|
|
|
|
content_type != MessageContentType::ExpiredPhoto && content_type != MessageContentType::ExpiredVideo;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool update_opened_message_content(MessageContent *content) {
|
|
|
|
switch (content->get_type()) {
|
|
|
|
case MessageContentType::VideoNote: {
|
|
|
|
auto video_note_content = static_cast<MessageVideoNote *>(content);
|
|
|
|
if (video_note_content->is_viewed) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
video_note_content->is_viewed = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case MessageContentType::VoiceNote: {
|
|
|
|
auto voice_note_content = static_cast<MessageVoiceNote *>(content);
|
|
|
|
if (voice_note_content->is_listened) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
voice_note_content->is_listened = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-08 01:05:55 +02:00
|
|
|
static int32 get_message_content_text_index_mask(const MessageContent *content) {
|
|
|
|
const FormattedText *text = get_message_content_text(content);
|
|
|
|
if (text == nullptr || content->get_type() == MessageContentType::Game) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto &entity : text->entities) {
|
|
|
|
if (entity.type == MessageEntity::Type::Url || entity.type == MessageEntity::Type::EmailAddress ||
|
|
|
|
entity.type == MessageEntity::Type::TextUrl) {
|
2020-08-22 09:05:51 +02:00
|
|
|
return message_search_filter_index_mask(MessageSearchFilter::Url);
|
2019-09-08 01:05:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-10-19 13:31:18 +02:00
|
|
|
static int32 get_message_content_media_index_mask(const MessageContent *content, const Td *td, bool is_outgoing) {
|
2018-09-28 22:57:34 +02:00
|
|
|
switch (content->get_type()) {
|
|
|
|
case MessageContentType::Animation:
|
2020-08-22 09:05:51 +02:00
|
|
|
return message_search_filter_index_mask(MessageSearchFilter::Animation);
|
2020-10-19 13:31:18 +02:00
|
|
|
case MessageContentType::Audio:
|
|
|
|
return message_search_filter_index_mask(MessageSearchFilter::Audio);
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::Document:
|
2020-08-22 09:05:51 +02:00
|
|
|
return message_search_filter_index_mask(MessageSearchFilter::Document);
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::Photo:
|
2020-08-22 09:05:51 +02:00
|
|
|
return message_search_filter_index_mask(MessageSearchFilter::Photo) |
|
|
|
|
message_search_filter_index_mask(MessageSearchFilter::PhotoAndVideo);
|
2020-10-19 13:31:18 +02:00
|
|
|
case MessageContentType::Video:
|
|
|
|
return message_search_filter_index_mask(MessageSearchFilter::Video) |
|
|
|
|
message_search_filter_index_mask(MessageSearchFilter::PhotoAndVideo);
|
|
|
|
case MessageContentType::VideoNote:
|
|
|
|
return message_search_filter_index_mask(MessageSearchFilter::VideoNote) |
|
|
|
|
message_search_filter_index_mask(MessageSearchFilter::VoiceAndVideoNote);
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::VoiceNote:
|
2020-08-22 09:05:51 +02:00
|
|
|
return message_search_filter_index_mask(MessageSearchFilter::VoiceNote) |
|
|
|
|
message_search_filter_index_mask(MessageSearchFilter::VoiceAndVideoNote);
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::ChatChangePhoto:
|
2020-08-22 09:05:51 +02:00
|
|
|
return message_search_filter_index_mask(MessageSearchFilter::ChatPhoto);
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::Call: {
|
2020-08-22 09:05:51 +02:00
|
|
|
int32 index_mask = message_search_filter_index_mask(MessageSearchFilter::Call);
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageCall *>(content);
|
|
|
|
if (!is_outgoing &&
|
|
|
|
(m->discard_reason == CallDiscardReason::Declined || m->discard_reason == CallDiscardReason::Missed)) {
|
2020-08-22 09:05:51 +02:00
|
|
|
index_mask |= message_search_filter_index_mask(MessageSearchFilter::MissedCall);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
return index_mask;
|
|
|
|
}
|
2019-09-08 01:05:55 +02:00
|
|
|
case MessageContentType::Text:
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::Contact:
|
|
|
|
case MessageContentType::Game:
|
|
|
|
case MessageContentType::Invoice:
|
|
|
|
case MessageContentType::LiveLocation:
|
|
|
|
case MessageContentType::Location:
|
|
|
|
case MessageContentType::Sticker:
|
2023-06-12 18:23:58 +02:00
|
|
|
case MessageContentType::Story:
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::Unsupported:
|
|
|
|
case MessageContentType::Venue:
|
|
|
|
case MessageContentType::ChatCreate:
|
|
|
|
case MessageContentType::ChatChangeTitle:
|
|
|
|
case MessageContentType::ChatDeletePhoto:
|
|
|
|
case MessageContentType::ChatDeleteHistory:
|
|
|
|
case MessageContentType::ChatAddUsers:
|
|
|
|
case MessageContentType::ChatJoinedByLink:
|
|
|
|
case MessageContentType::ChatDeleteUser:
|
|
|
|
case MessageContentType::ChatMigrateTo:
|
|
|
|
case MessageContentType::ChannelCreate:
|
|
|
|
case MessageContentType::ChannelMigrateFrom:
|
|
|
|
case MessageContentType::PinMessage:
|
|
|
|
case MessageContentType::GameScore:
|
|
|
|
case MessageContentType::ScreenshotTaken:
|
|
|
|
case MessageContentType::ChatSetTtl:
|
|
|
|
case MessageContentType::PaymentSuccessful:
|
|
|
|
case MessageContentType::ContactRegistered:
|
|
|
|
case MessageContentType::ExpiredPhoto:
|
|
|
|
case MessageContentType::ExpiredVideo:
|
|
|
|
case MessageContentType::CustomServiceAction:
|
|
|
|
case MessageContentType::WebsiteConnected:
|
|
|
|
case MessageContentType::PassportDataSent:
|
|
|
|
case MessageContentType::PassportDataReceived:
|
2019-02-19 14:45:32 +01:00
|
|
|
case MessageContentType::Poll:
|
2020-03-29 23:34:37 +02:00
|
|
|
case MessageContentType::Dice:
|
2020-10-29 20:25:58 +01:00
|
|
|
case MessageContentType::ProximityAlertTriggered:
|
2020-11-24 12:33:16 +01:00
|
|
|
case MessageContentType::GroupCall:
|
|
|
|
case MessageContentType::InviteToGroupCall:
|
2021-08-18 15:03:10 +02:00
|
|
|
case MessageContentType::ChatSetTheme:
|
2022-03-28 09:01:39 +02:00
|
|
|
case MessageContentType::WebViewDataSent:
|
|
|
|
case MessageContentType::WebViewDataReceived:
|
2022-07-01 14:28:22 +02:00
|
|
|
case MessageContentType::GiftPremium:
|
2022-10-18 15:08:53 +02:00
|
|
|
case MessageContentType::TopicCreate:
|
2022-10-18 21:16:03 +02:00
|
|
|
case MessageContentType::TopicEdit:
|
2022-12-09 12:13:37 +01:00
|
|
|
case MessageContentType::SuggestProfilePhoto:
|
2022-12-14 19:13:48 +01:00
|
|
|
case MessageContentType::WriteAccessAllowed:
|
2023-01-10 14:20:30 +01:00
|
|
|
case MessageContentType::RequestedDialog:
|
2023-02-22 10:24:43 +01:00
|
|
|
case MessageContentType::WebViewWriteAccessAllowed:
|
2023-04-10 13:12:35 +02:00
|
|
|
case MessageContentType::SetBackground:
|
2023-08-25 15:53:50 +02:00
|
|
|
case MessageContentType::WriteAccessAllowedByRequest:
|
2023-09-29 16:55:03 +02:00
|
|
|
case MessageContentType::GiftCode:
|
2023-09-29 23:32:39 +02:00
|
|
|
case MessageContentType::Giveaway:
|
2023-10-16 10:31:11 +02:00
|
|
|
case MessageContentType::GiveawayLaunch:
|
2018-09-28 22:57:34 +02:00
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-10-19 13:31:18 +02:00
|
|
|
int32 get_message_content_index_mask(const MessageContent *content, const Td *td, bool is_outgoing) {
|
|
|
|
return get_message_content_text_index_mask(content) | get_message_content_media_index_mask(content, td, is_outgoing);
|
2019-09-08 01:05:55 +02:00
|
|
|
}
|
|
|
|
|
2022-07-22 15:11:33 +02:00
|
|
|
StickerType get_message_content_sticker_type(const Td *td, const MessageContent *content) {
|
|
|
|
CHECK(content->get_type() == MessageContentType::Sticker);
|
|
|
|
return td->stickers_manager_->get_sticker_type(static_cast<const MessageSticker *>(content)->file_id);
|
|
|
|
}
|
|
|
|
|
2018-09-28 22:57:34 +02:00
|
|
|
MessageId get_message_content_pinned_message_id(const MessageContent *content) {
|
|
|
|
switch (content->get_type()) {
|
|
|
|
case MessageContentType::PinMessage:
|
|
|
|
return static_cast<const MessagePinMessage *>(content)->message_id;
|
|
|
|
default:
|
|
|
|
return MessageId();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-10 16:23:21 +02:00
|
|
|
BackgroundInfo get_message_content_background_info(const MessageContent *content) {
|
|
|
|
switch (content->get_type()) {
|
|
|
|
case MessageContentType::SetBackground:
|
|
|
|
return static_cast<const MessageSetBackground *>(content)->background_info;
|
|
|
|
default:
|
|
|
|
return BackgroundInfo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-23 17:47:32 +02:00
|
|
|
string get_message_content_theme_name(const MessageContent *content) {
|
|
|
|
switch (content->get_type()) {
|
|
|
|
case MessageContentType::ChatSetTheme:
|
|
|
|
return static_cast<const MessageChatSetTheme *>(content)->emoji;
|
|
|
|
default:
|
|
|
|
return string();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-21 18:11:17 +02:00
|
|
|
MessageFullId get_message_content_replied_message_id(DialogId dialog_id, const MessageContent *content) {
|
2018-09-28 22:57:34 +02:00
|
|
|
switch (content->get_type()) {
|
|
|
|
case MessageContentType::PinMessage:
|
2021-03-31 14:36:25 +02:00
|
|
|
return {dialog_id, static_cast<const MessagePinMessage *>(content)->message_id};
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::GameScore:
|
2021-03-31 14:36:25 +02:00
|
|
|
return {dialog_id, static_cast<const MessageGameScore *>(content)->game_message_id};
|
|
|
|
case MessageContentType::PaymentSuccessful: {
|
|
|
|
auto *m = static_cast<const MessagePaymentSuccessful *>(content);
|
2021-04-07 21:58:40 +02:00
|
|
|
if (!m->invoice_message_id.is_valid()) {
|
2023-09-21 18:11:17 +02:00
|
|
|
return MessageFullId();
|
2021-04-07 21:58:40 +02:00
|
|
|
}
|
|
|
|
|
2021-03-31 14:36:25 +02:00
|
|
|
auto reply_in_dialog_id = m->invoice_dialog_id.is_valid() ? m->invoice_dialog_id : dialog_id;
|
|
|
|
return {reply_in_dialog_id, m->invoice_message_id};
|
|
|
|
}
|
2023-04-10 13:12:35 +02:00
|
|
|
case MessageContentType::SetBackground: {
|
|
|
|
auto *m = static_cast<const MessageSetBackground *>(content);
|
|
|
|
if (!m->old_message_id.is_valid()) {
|
2023-09-21 18:11:17 +02:00
|
|
|
return MessageFullId();
|
2023-04-10 13:12:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return {dialog_id, m->old_message_id};
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
default:
|
2023-09-21 18:11:17 +02:00
|
|
|
return MessageFullId();
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-11 04:37:53 +02:00
|
|
|
std::pair<InputGroupCallId, bool> get_message_content_group_call_info(const MessageContent *content) {
|
|
|
|
CHECK(content->get_type() == MessageContentType::GroupCall);
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageGroupCall *>(content);
|
|
|
|
return {m->input_group_call_id, m->duration >= 0};
|
2021-04-11 04:37:53 +02:00
|
|
|
}
|
|
|
|
|
2023-06-13 16:14:19 +02:00
|
|
|
vector<UserId> get_message_content_min_user_ids(const Td *td, const MessageContent *message_content) {
|
2023-06-13 12:46:12 +02:00
|
|
|
switch (message_content->get_type()) {
|
|
|
|
case MessageContentType::Text: {
|
2023-06-13 16:14:19 +02:00
|
|
|
const auto *content = static_cast<const MessageText *>(message_content);
|
|
|
|
if (content->web_page_id.is_valid()) {
|
|
|
|
return td->web_pages_manager_->get_web_page_user_ids(content->web_page_id);
|
|
|
|
}
|
2023-06-13 12:46:12 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Animation:
|
|
|
|
break;
|
|
|
|
case MessageContentType::Audio:
|
|
|
|
break;
|
|
|
|
case MessageContentType::Contact: {
|
|
|
|
const auto *content = static_cast<const MessageContact *>(message_content);
|
2023-07-14 13:04:16 +02:00
|
|
|
auto user_id = content->contact.get_user_id();
|
|
|
|
if (user_id.is_valid()) {
|
|
|
|
return {user_id};
|
|
|
|
}
|
|
|
|
break;
|
2023-06-13 12:46:12 +02:00
|
|
|
}
|
|
|
|
case MessageContentType::Document:
|
|
|
|
break;
|
|
|
|
case MessageContentType::Game: {
|
2023-07-14 13:04:16 +02:00
|
|
|
// not supported server-side
|
2023-06-13 12:46:12 +02:00
|
|
|
// const auto *content = static_cast<const MessageGame *>(message_content);
|
|
|
|
// return {content->game.get_bot_user_id())};
|
2023-07-14 13:04:16 +02:00
|
|
|
break;
|
2023-06-13 12:46:12 +02:00
|
|
|
}
|
|
|
|
case MessageContentType::Invoice:
|
|
|
|
break;
|
|
|
|
case MessageContentType::LiveLocation:
|
|
|
|
break;
|
|
|
|
case MessageContentType::Location:
|
|
|
|
break;
|
|
|
|
case MessageContentType::Photo:
|
|
|
|
break;
|
|
|
|
case MessageContentType::Sticker:
|
|
|
|
break;
|
|
|
|
case MessageContentType::Venue:
|
|
|
|
break;
|
|
|
|
case MessageContentType::Video:
|
|
|
|
break;
|
|
|
|
case MessageContentType::VideoNote:
|
|
|
|
break;
|
|
|
|
case MessageContentType::VoiceNote:
|
|
|
|
break;
|
|
|
|
case MessageContentType::ChatCreate: {
|
|
|
|
const auto *content = static_cast<const MessageChatCreate *>(message_content);
|
|
|
|
return content->participant_user_ids;
|
|
|
|
}
|
|
|
|
case MessageContentType::ChatChangeTitle:
|
|
|
|
break;
|
|
|
|
case MessageContentType::ChatChangePhoto:
|
|
|
|
break;
|
|
|
|
case MessageContentType::ChatDeletePhoto:
|
|
|
|
break;
|
|
|
|
case MessageContentType::ChatDeleteHistory:
|
|
|
|
break;
|
|
|
|
case MessageContentType::ChatAddUsers: {
|
|
|
|
const auto *content = static_cast<const MessageChatAddUsers *>(message_content);
|
|
|
|
return content->user_ids;
|
|
|
|
}
|
|
|
|
case MessageContentType::ChatJoinedByLink:
|
|
|
|
break;
|
|
|
|
case MessageContentType::ChatDeleteUser: {
|
|
|
|
const auto *content = static_cast<const MessageChatDeleteUser *>(message_content);
|
|
|
|
return {content->user_id};
|
|
|
|
}
|
|
|
|
case MessageContentType::ChatMigrateTo:
|
|
|
|
break;
|
|
|
|
case MessageContentType::ChannelCreate:
|
|
|
|
break;
|
|
|
|
case MessageContentType::ChannelMigrateFrom:
|
|
|
|
break;
|
|
|
|
case MessageContentType::PinMessage:
|
|
|
|
break;
|
|
|
|
case MessageContentType::GameScore:
|
|
|
|
break;
|
|
|
|
case MessageContentType::ScreenshotTaken:
|
|
|
|
break;
|
|
|
|
case MessageContentType::ChatSetTtl:
|
|
|
|
// the content->from_user_id user can't be min
|
|
|
|
break;
|
|
|
|
case MessageContentType::Unsupported:
|
|
|
|
break;
|
|
|
|
case MessageContentType::Call:
|
|
|
|
break;
|
|
|
|
case MessageContentType::PaymentSuccessful:
|
|
|
|
break;
|
|
|
|
case MessageContentType::ContactRegistered:
|
|
|
|
break;
|
|
|
|
case MessageContentType::ExpiredPhoto:
|
|
|
|
break;
|
|
|
|
case MessageContentType::ExpiredVideo:
|
|
|
|
break;
|
|
|
|
case MessageContentType::CustomServiceAction:
|
|
|
|
break;
|
|
|
|
case MessageContentType::WebsiteConnected:
|
|
|
|
break;
|
|
|
|
case MessageContentType::PassportDataSent:
|
|
|
|
break;
|
|
|
|
case MessageContentType::PassportDataReceived:
|
|
|
|
break;
|
|
|
|
case MessageContentType::Poll:
|
|
|
|
break;
|
|
|
|
case MessageContentType::Dice:
|
|
|
|
break;
|
|
|
|
case MessageContentType::ProximityAlertTriggered:
|
|
|
|
break;
|
|
|
|
case MessageContentType::GroupCall:
|
|
|
|
break;
|
|
|
|
case MessageContentType::InviteToGroupCall: {
|
|
|
|
const auto *content = static_cast<const MessageInviteToGroupCall *>(message_content);
|
|
|
|
return content->user_ids;
|
|
|
|
}
|
|
|
|
case MessageContentType::ChatSetTheme:
|
|
|
|
break;
|
|
|
|
case MessageContentType::WebViewDataSent:
|
|
|
|
break;
|
|
|
|
case MessageContentType::WebViewDataReceived:
|
|
|
|
break;
|
|
|
|
case MessageContentType::GiftPremium:
|
|
|
|
break;
|
|
|
|
case MessageContentType::TopicCreate:
|
|
|
|
break;
|
|
|
|
case MessageContentType::TopicEdit:
|
|
|
|
break;
|
|
|
|
case MessageContentType::SuggestProfilePhoto:
|
|
|
|
break;
|
|
|
|
case MessageContentType::WriteAccessAllowed:
|
|
|
|
break;
|
|
|
|
case MessageContentType::RequestedDialog:
|
|
|
|
break;
|
|
|
|
case MessageContentType::WebViewWriteAccessAllowed:
|
|
|
|
break;
|
|
|
|
case MessageContentType::SetBackground:
|
|
|
|
break;
|
|
|
|
case MessageContentType::Story: {
|
|
|
|
const auto *content = static_cast<const MessageStory *>(message_content);
|
2023-07-14 13:04:16 +02:00
|
|
|
auto dialog_id = content->story_full_id.get_dialog_id();
|
|
|
|
if (dialog_id.get_type() == DialogType::User) {
|
|
|
|
return {dialog_id.get_user_id()};
|
2023-06-13 12:46:12 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2023-08-25 15:53:50 +02:00
|
|
|
case MessageContentType::WriteAccessAllowedByRequest:
|
|
|
|
break;
|
2023-09-29 16:55:03 +02:00
|
|
|
case MessageContentType::GiftCode:
|
|
|
|
break;
|
2023-09-29 23:32:39 +02:00
|
|
|
case MessageContentType::Giveaway:
|
|
|
|
break;
|
2023-10-16 10:31:11 +02:00
|
|
|
case MessageContentType::GiveawayLaunch:
|
|
|
|
break;
|
2023-04-12 00:33:48 +02:00
|
|
|
default:
|
2023-06-13 12:46:12 +02:00
|
|
|
UNREACHABLE();
|
|
|
|
break;
|
2023-04-12 00:33:48 +02:00
|
|
|
}
|
2023-06-13 12:46:12 +02:00
|
|
|
return {};
|
2023-04-12 00:33:48 +02:00
|
|
|
}
|
|
|
|
|
2019-03-12 14:20:53 +01:00
|
|
|
vector<UserId> get_message_content_added_user_ids(const MessageContent *content) {
|
|
|
|
CHECK(content->get_type() == MessageContentType::ChatAddUsers);
|
|
|
|
return static_cast<const MessageChatAddUsers *>(content)->user_ids;
|
|
|
|
}
|
|
|
|
|
2018-09-28 22:57:34 +02:00
|
|
|
UserId get_message_content_deleted_user_id(const MessageContent *content) {
|
|
|
|
switch (content->get_type()) {
|
|
|
|
case MessageContentType::ChatDeleteUser:
|
|
|
|
return static_cast<const MessageChatDeleteUser *>(content)->user_id;
|
|
|
|
default:
|
|
|
|
return UserId();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int32 get_message_content_live_location_period(const MessageContent *content) {
|
|
|
|
switch (content->get_type()) {
|
|
|
|
case MessageContentType::LiveLocation:
|
|
|
|
return static_cast<const MessageLiveLocation *>(content)->period;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-19 14:15:37 +01:00
|
|
|
bool get_message_content_poll_is_anonymous(const Td *td, const MessageContent *content) {
|
|
|
|
switch (content->get_type()) {
|
|
|
|
case MessageContentType::Poll:
|
|
|
|
return td->poll_manager_->get_poll_is_anonymous(static_cast<const MessagePoll *>(content)->poll_id);
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-22 16:09:55 +01:00
|
|
|
bool get_message_content_poll_is_closed(const Td *td, const MessageContent *content) {
|
|
|
|
switch (content->get_type()) {
|
|
|
|
case MessageContentType::Poll:
|
|
|
|
return td->poll_manager_->get_poll_is_closed(static_cast<const MessagePoll *>(content)->poll_id);
|
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-01 17:11:30 +02:00
|
|
|
const Venue *get_message_content_venue(const MessageContent *content) {
|
|
|
|
switch (content->get_type()) {
|
|
|
|
case MessageContentType::Venue:
|
|
|
|
return &static_cast<const MessageVenue *>(content)->venue;
|
|
|
|
default:
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-28 00:35:07 +01:00
|
|
|
bool has_message_content_web_page(const MessageContent *content) {
|
2020-03-27 23:49:59 +01:00
|
|
|
if (content->get_type() == MessageContentType::Text) {
|
|
|
|
return static_cast<const MessageText *>(content)->web_page_id.is_valid();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-01-27 00:55:18 +01:00
|
|
|
void remove_message_content_web_page(MessageContent *content) {
|
2018-09-28 22:57:34 +02:00
|
|
|
CHECK(content->get_type() == MessageContentType::Text);
|
2023-10-16 15:47:22 +02:00
|
|
|
auto message_text = static_cast<MessageText *>(content);
|
|
|
|
message_text->web_page_id = WebPageId();
|
|
|
|
message_text->force_small_media = false;
|
|
|
|
message_text->force_large_media = false;
|
2023-10-19 12:03:27 +02:00
|
|
|
message_text->skip_web_page_confirmation = false;
|
2023-10-16 21:33:53 +02:00
|
|
|
message_text->web_page_url = string();
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
|
2021-07-26 03:50:08 +02:00
|
|
|
bool can_message_content_have_media_timestamp(const MessageContent *content) {
|
|
|
|
CHECK(content != nullptr);
|
|
|
|
switch (content->get_type()) {
|
|
|
|
case MessageContentType::Audio:
|
2023-06-13 17:20:26 +02:00
|
|
|
case MessageContentType::Story:
|
2021-07-26 03:50:08 +02:00
|
|
|
case MessageContentType::Video:
|
|
|
|
case MessageContentType::VideoNote:
|
|
|
|
case MessageContentType::VoiceNote:
|
|
|
|
return true;
|
2022-09-22 17:05:58 +02:00
|
|
|
case MessageContentType::Invoice: {
|
|
|
|
const auto *m = static_cast<const MessageInvoice *>(content);
|
2022-09-23 11:52:54 +02:00
|
|
|
return m->input_invoice.has_media_timestamp();
|
2022-09-22 17:05:58 +02:00
|
|
|
}
|
2021-07-26 03:50:08 +02:00
|
|
|
default:
|
|
|
|
return has_message_content_web_page(content);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-21 18:11:17 +02:00
|
|
|
void set_message_content_poll_answer(Td *td, const MessageContent *content, MessageFullId message_full_id,
|
2019-02-21 13:23:05 +01:00
|
|
|
vector<int32> &&option_ids, Promise<Unit> &&promise) {
|
|
|
|
CHECK(content->get_type() == MessageContentType::Poll);
|
2023-09-21 18:11:17 +02:00
|
|
|
td->poll_manager_->set_poll_answer(static_cast<const MessagePoll *>(content)->poll_id, message_full_id,
|
2019-02-21 13:23:05 +01:00
|
|
|
std::move(option_ids), std::move(promise));
|
|
|
|
}
|
|
|
|
|
2023-09-21 18:11:17 +02:00
|
|
|
void get_message_content_poll_voters(Td *td, const MessageContent *content, MessageFullId message_full_id,
|
2020-01-18 05:01:05 +01:00
|
|
|
int32 option_id, int32 offset, int32 limit,
|
2023-04-25 15:41:04 +02:00
|
|
|
Promise<td_api::object_ptr<td_api::messageSenders>> &&promise) {
|
2020-01-13 19:21:58 +01:00
|
|
|
CHECK(content->get_type() == MessageContentType::Poll);
|
2023-09-21 18:11:17 +02:00
|
|
|
td->poll_manager_->get_poll_voters(static_cast<const MessagePoll *>(content)->poll_id, message_full_id, option_id,
|
2020-01-18 05:01:05 +01:00
|
|
|
offset, limit, std::move(promise));
|
2020-01-13 19:21:58 +01:00
|
|
|
}
|
|
|
|
|
2023-09-21 18:11:17 +02:00
|
|
|
void stop_message_content_poll(Td *td, const MessageContent *content, MessageFullId message_full_id,
|
2019-04-12 01:10:33 +02:00
|
|
|
unique_ptr<ReplyMarkup> &&reply_markup, Promise<Unit> &&promise) {
|
2019-02-22 16:09:55 +01:00
|
|
|
CHECK(content->get_type() == MessageContentType::Poll);
|
2023-09-21 18:11:17 +02:00
|
|
|
td->poll_manager_->stop_poll(static_cast<const MessagePoll *>(content)->poll_id, message_full_id,
|
2020-01-13 19:21:58 +01:00
|
|
|
std::move(reply_markup), std::move(promise));
|
2019-02-22 16:09:55 +01:00
|
|
|
}
|
|
|
|
|
2019-02-19 16:52:09 +01:00
|
|
|
static void merge_location_access_hash(const Location &first, const Location &second) {
|
2018-09-28 22:57:34 +02:00
|
|
|
if (second.get_access_hash() != 0) {
|
|
|
|
first.set_access_hash(second.get_access_hash());
|
|
|
|
} else {
|
|
|
|
second.set_access_hash(first.get_access_hash());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool need_message_text_changed_warning(const MessageText *old_content, const MessageText *new_content) {
|
|
|
|
if (new_content->text.text == "Unsupported characters" ||
|
2022-10-06 17:31:01 +02:00
|
|
|
new_content->text.text == "This channel is blocked because it was used to spread pornographic content." ||
|
|
|
|
begins_with(new_content->text.text,
|
|
|
|
"This group has been temporarily suspended to give its moderators time to clean up after users who "
|
|
|
|
"posted illegal pornographic content.")) {
|
2022-08-08 15:42:26 +02:00
|
|
|
// message contained unsupported characters or is restricted, text is replaced
|
2018-09-28 22:57:34 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (/* old_message->message_id.is_yet_unsent() && */ !old_content->text.entities.empty() &&
|
|
|
|
old_content->text.entities[0].offset == 0 &&
|
2022-08-08 15:42:26 +02:00
|
|
|
(new_content->text.entities.empty() || new_content->text.entities[0] != old_content->text.entities[0]) &&
|
2018-09-28 22:57:34 +02:00
|
|
|
old_content->text.text != new_content->text.text && ends_with(old_content->text.text, new_content->text.text)) {
|
2022-08-08 15:42:26 +02:00
|
|
|
// server has deleted first entity and left-trimed the message
|
2018-09-28 22:57:34 +02:00
|
|
|
return false;
|
|
|
|
}
|
2019-12-25 18:17:17 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool need_message_entities_changed_warning(const vector<MessageEntity> &old_entities,
|
|
|
|
const vector<MessageEntity> &new_entities) {
|
|
|
|
size_t old_pos = 0;
|
|
|
|
size_t new_pos = 0;
|
|
|
|
// compare entities, skipping some known to be different
|
|
|
|
while (old_pos < old_entities.size() || new_pos < new_entities.size()) {
|
|
|
|
// TODO remove after find_phone_numbers is implemented
|
|
|
|
while (new_pos < new_entities.size() && new_entities[new_pos].type == MessageEntity::Type::PhoneNumber) {
|
|
|
|
new_pos++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (old_pos < old_entities.size() && new_pos < new_entities.size() &&
|
|
|
|
old_entities[old_pos] == new_entities[new_pos]) {
|
|
|
|
old_pos++;
|
|
|
|
new_pos++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-07-21 13:10:26 +02:00
|
|
|
if (old_pos < old_entities.size() && (old_entities[old_pos].type == MessageEntity::Type::MentionName ||
|
|
|
|
old_entities[old_pos].type == MessageEntity::Type::CustomEmoji)) {
|
2022-08-08 15:42:26 +02:00
|
|
|
// server can delete some MentionName and CustomEmoji entities
|
2019-12-25 18:17:17 +01:00
|
|
|
old_pos++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (old_pos < old_entities.size() || new_pos < new_entities.size()) {
|
|
|
|
return true;
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
}
|
2019-12-25 18:17:17 +01:00
|
|
|
|
|
|
|
return false;
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
|
2019-02-19 16:52:09 +01:00
|
|
|
void merge_message_contents(Td *td, const MessageContent *old_content, MessageContent *new_content,
|
2018-09-28 22:57:34 +02:00
|
|
|
bool need_message_changed_warning, DialogId dialog_id, bool need_merge_files,
|
|
|
|
bool &is_content_changed, bool &need_update) {
|
|
|
|
MessageContentType content_type = new_content->get_type();
|
|
|
|
CHECK(old_content->get_type() == content_type);
|
|
|
|
|
|
|
|
switch (content_type) {
|
|
|
|
case MessageContentType::Text: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *old_ = static_cast<const MessageText *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageText *>(new_content);
|
2021-08-13 12:03:55 +02:00
|
|
|
auto get_content_object = [td, dialog_id](const MessageContent *content) {
|
2023-10-17 15:20:45 +02:00
|
|
|
return to_string(
|
|
|
|
get_message_content_object(content, td, dialog_id, -1, false, false, std::numeric_limits<int32>::max()));
|
2021-08-13 12:03:55 +02:00
|
|
|
};
|
2018-09-28 22:57:34 +02:00
|
|
|
if (old_->text.text != new_->text.text) {
|
|
|
|
if (need_message_changed_warning && need_message_text_changed_warning(old_, new_)) {
|
2021-08-13 12:03:55 +02:00
|
|
|
LOG(ERROR) << "Message text has changed in " << get_content_object(old_content) << ". New content is "
|
|
|
|
<< get_content_object(new_content);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
if (old_->text.entities != new_->text.entities) {
|
|
|
|
const int32 MAX_CUSTOM_ENTITIES_COUNT = 100; // server-side limit
|
|
|
|
if (need_message_changed_warning && need_message_text_changed_warning(old_, new_) &&
|
2019-12-25 18:17:17 +01:00
|
|
|
old_->text.entities.size() <= MAX_CUSTOM_ENTITIES_COUNT &&
|
2023-05-01 12:44:41 +02:00
|
|
|
need_message_entities_changed_warning(old_->text.entities, new_->text.entities) &&
|
|
|
|
td->option_manager_->get_option_integer("session_count") <= 1) {
|
2021-12-02 12:15:37 +01:00
|
|
|
LOG(WARNING) << "Entities have changed in " << get_content_object(old_content) << ". New content is "
|
2021-08-13 12:03:55 +02:00
|
|
|
<< get_content_object(new_content);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
need_update = true;
|
|
|
|
}
|
2023-10-16 15:47:22 +02:00
|
|
|
if (old_->web_page_id != new_->web_page_id || old_->force_small_media != new_->force_small_media ||
|
2023-10-19 12:03:27 +02:00
|
|
|
old_->force_large_media != new_->force_large_media ||
|
|
|
|
old_->skip_web_page_confirmation != new_->skip_web_page_confirmation) {
|
2018-09-28 22:57:34 +02:00
|
|
|
LOG(INFO) << "Old: " << old_->web_page_id << ", new: " << new_->web_page_id;
|
|
|
|
is_content_changed = true;
|
|
|
|
need_update |= td->web_pages_manager_->have_web_page(old_->web_page_id) ||
|
|
|
|
td->web_pages_manager_->have_web_page(new_->web_page_id);
|
|
|
|
}
|
2023-10-16 21:33:53 +02:00
|
|
|
if (old_->web_page_url != new_->web_page_url) {
|
2023-10-16 16:36:45 +02:00
|
|
|
need_update = true;
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Animation: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *old_ = static_cast<const MessageAnimation *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageAnimation *>(new_content);
|
2022-06-03 15:33:49 +02:00
|
|
|
if (old_->file_id != new_->file_id) {
|
2021-08-26 17:50:28 +02:00
|
|
|
if (need_merge_files) {
|
2022-08-03 20:38:03 +02:00
|
|
|
td->animations_manager_->merge_animations(new_->file_id, old_->file_id);
|
2021-08-26 17:50:28 +02:00
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
need_update = true;
|
|
|
|
}
|
2022-12-26 12:20:48 +01:00
|
|
|
if (old_->caption != new_->caption || old_->has_spoiler != new_->has_spoiler) {
|
2018-09-28 22:57:34 +02:00
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Audio: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *old_ = static_cast<const MessageAudio *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageAudio *>(new_content);
|
2022-06-03 15:33:49 +02:00
|
|
|
if (old_->file_id != new_->file_id) {
|
2021-08-26 17:50:28 +02:00
|
|
|
if (need_merge_files) {
|
2022-08-03 20:38:03 +02:00
|
|
|
td->audios_manager_->merge_audios(new_->file_id, old_->file_id);
|
2021-08-26 17:50:28 +02:00
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
if (old_->caption != new_->caption) {
|
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Contact: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *old_ = static_cast<const MessageContact *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageContact *>(new_content);
|
2018-09-28 22:57:34 +02:00
|
|
|
if (old_->contact != new_->contact) {
|
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Document: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *old_ = static_cast<const MessageDocument *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageDocument *>(new_content);
|
2022-06-03 15:33:49 +02:00
|
|
|
if (old_->file_id != new_->file_id) {
|
2021-08-26 17:50:28 +02:00
|
|
|
if (need_merge_files) {
|
2022-08-03 20:38:03 +02:00
|
|
|
td->documents_manager_->merge_documents(new_->file_id, old_->file_id);
|
2021-08-26 17:50:28 +02:00
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
if (old_->caption != new_->caption) {
|
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Game: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *old_ = static_cast<const MessageGame *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageGame *>(new_content);
|
2018-09-28 22:57:34 +02:00
|
|
|
if (old_->game != new_->game) {
|
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Invoice: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *old_ = static_cast<const MessageInvoice *>(old_content);
|
2022-09-22 05:39:40 +02:00
|
|
|
auto *new_ = static_cast<MessageInvoice *>(new_content);
|
2022-09-24 21:42:47 +02:00
|
|
|
new_->input_invoice.update_from(old_->input_invoice);
|
2021-03-31 00:20:40 +02:00
|
|
|
if (old_->input_invoice != new_->input_invoice) {
|
2018-09-28 22:57:34 +02:00
|
|
|
need_update = true;
|
2022-09-24 21:55:03 +02:00
|
|
|
} else if (old_->input_invoice.is_equal_but_different(new_->input_invoice)) {
|
2022-09-22 14:30:12 +02:00
|
|
|
is_content_changed = true;
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::LiveLocation: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *old_ = static_cast<const MessageLiveLocation *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageLiveLocation *>(new_content);
|
2018-09-28 22:57:34 +02:00
|
|
|
if (old_->location != new_->location) {
|
|
|
|
need_update = true;
|
|
|
|
}
|
2020-10-24 23:49:41 +02:00
|
|
|
if (old_->period != new_->period || old_->heading != new_->heading ||
|
2020-10-30 13:51:20 +01:00
|
|
|
old_->proximity_alert_radius != new_->proximity_alert_radius) {
|
2018-09-28 22:57:34 +02:00
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
if (old_->location.get_access_hash() != new_->location.get_access_hash()) {
|
|
|
|
is_content_changed = true;
|
|
|
|
merge_location_access_hash(old_->location, new_->location);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Location: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *old_ = static_cast<const MessageLocation *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageLocation *>(new_content);
|
2018-09-28 22:57:34 +02:00
|
|
|
if (old_->location != new_->location) {
|
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
if (old_->location.get_access_hash() != new_->location.get_access_hash()) {
|
|
|
|
is_content_changed = true;
|
|
|
|
merge_location_access_hash(old_->location, new_->location);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Photo: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *old_ = static_cast<const MessagePhoto *>(old_content);
|
|
|
|
auto *new_ = static_cast<MessagePhoto *>(new_content);
|
2023-05-18 16:03:56 +02:00
|
|
|
merge_photos(td, &old_->photo, &new_->photo, dialog_id, need_merge_files, is_content_changed, need_update);
|
2022-12-26 12:20:48 +01:00
|
|
|
if (old_->caption != new_->caption || old_->has_spoiler != new_->has_spoiler) {
|
2018-09-28 22:57:34 +02:00
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Sticker: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *old_ = static_cast<const MessageSticker *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageSticker *>(new_content);
|
2022-06-03 15:33:49 +02:00
|
|
|
if (old_->file_id != new_->file_id) {
|
2021-08-26 17:50:28 +02:00
|
|
|
if (need_merge_files) {
|
2022-08-03 20:38:03 +02:00
|
|
|
td->stickers_manager_->merge_stickers(new_->file_id, old_->file_id);
|
2021-08-26 17:50:28 +02:00
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
need_update = true;
|
|
|
|
}
|
2022-06-03 15:33:49 +02:00
|
|
|
if (old_->is_premium != new_->is_premium) {
|
|
|
|
need_update = true;
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Venue: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *old_ = static_cast<const MessageVenue *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageVenue *>(new_content);
|
2018-09-28 22:57:34 +02:00
|
|
|
if (old_->venue != new_->venue) {
|
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
if (old_->venue.location().get_access_hash() != new_->venue.location().get_access_hash()) {
|
|
|
|
is_content_changed = true;
|
|
|
|
merge_location_access_hash(old_->venue.location(), new_->venue.location());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Video: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *old_ = static_cast<const MessageVideo *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageVideo *>(new_content);
|
2022-06-03 15:33:49 +02:00
|
|
|
if (old_->file_id != new_->file_id) {
|
2021-08-26 17:50:28 +02:00
|
|
|
if (need_merge_files) {
|
2022-08-03 20:38:03 +02:00
|
|
|
td->videos_manager_->merge_videos(new_->file_id, old_->file_id);
|
2021-08-26 17:50:28 +02:00
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
need_update = true;
|
|
|
|
}
|
2022-12-20 16:06:21 +01:00
|
|
|
if (old_->caption != new_->caption || old_->has_spoiler != new_->has_spoiler) {
|
2018-09-28 22:57:34 +02:00
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::VideoNote: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *old_ = static_cast<const MessageVideoNote *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageVideoNote *>(new_content);
|
2022-06-03 15:33:49 +02:00
|
|
|
if (old_->file_id != new_->file_id) {
|
2021-08-26 17:50:28 +02:00
|
|
|
if (need_merge_files) {
|
2022-08-03 20:38:03 +02:00
|
|
|
td->video_notes_manager_->merge_video_notes(new_->file_id, old_->file_id);
|
2021-08-26 17:50:28 +02:00
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
if (old_->is_viewed != new_->is_viewed) {
|
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::VoiceNote: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *old_ = static_cast<const MessageVoiceNote *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageVoiceNote *>(new_content);
|
2022-06-03 15:33:49 +02:00
|
|
|
if (old_->file_id != new_->file_id) {
|
2021-08-26 17:50:28 +02:00
|
|
|
if (need_merge_files) {
|
2022-08-03 20:38:03 +02:00
|
|
|
td->voice_notes_manager_->merge_voice_notes(new_->file_id, old_->file_id);
|
2021-08-26 17:50:28 +02:00
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
need_update = true;
|
|
|
|
}
|
2022-03-28 09:01:39 +02:00
|
|
|
if (old_->caption != new_->caption || old_->is_listened != new_->is_listened) {
|
2018-09-28 22:57:34 +02:00
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::ChatCreate: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *old_ = static_cast<const MessageChatCreate *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageChatCreate *>(new_content);
|
2018-09-28 22:57:34 +02:00
|
|
|
if (old_->title != new_->title || old_->participant_user_ids != new_->participant_user_ids) {
|
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::ChatChangeTitle: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *old_ = static_cast<const MessageChatChangeTitle *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageChatChangeTitle *>(new_content);
|
2018-09-28 22:57:34 +02:00
|
|
|
if (old_->title != new_->title) {
|
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::ChatChangePhoto: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *old_ = static_cast<const MessageChatChangePhoto *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageChatChangePhoto *>(new_content);
|
2018-09-28 22:57:34 +02:00
|
|
|
if (old_->photo != new_->photo) {
|
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::ChatDeletePhoto:
|
|
|
|
break;
|
|
|
|
case MessageContentType::ChatDeleteHistory:
|
|
|
|
break;
|
|
|
|
case MessageContentType::ChatAddUsers: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *old_ = static_cast<const MessageChatAddUsers *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageChatAddUsers *>(new_content);
|
2018-09-28 22:57:34 +02:00
|
|
|
if (old_->user_ids != new_->user_ids) {
|
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2021-10-09 14:04:17 +02:00
|
|
|
case MessageContentType::ChatJoinedByLink: {
|
|
|
|
auto old_ = static_cast<const MessageChatJoinedByLink *>(old_content);
|
|
|
|
auto new_ = static_cast<const MessageChatJoinedByLink *>(new_content);
|
|
|
|
if (old_->is_approved != new_->is_approved) {
|
|
|
|
need_update = true;
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
2021-10-09 14:04:17 +02:00
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::ChatDeleteUser: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *old_ = static_cast<const MessageChatDeleteUser *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageChatDeleteUser *>(new_content);
|
2018-09-28 22:57:34 +02:00
|
|
|
if (old_->user_id != new_->user_id) {
|
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::ChatMigrateTo: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *old_ = static_cast<const MessageChatMigrateTo *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageChatMigrateTo *>(new_content);
|
2018-09-28 22:57:34 +02:00
|
|
|
if (old_->migrated_to_channel_id != new_->migrated_to_channel_id) {
|
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::ChannelCreate: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *old_ = static_cast<const MessageChannelCreate *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageChannelCreate *>(new_content);
|
2018-09-28 22:57:34 +02:00
|
|
|
if (old_->title != new_->title) {
|
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::ChannelMigrateFrom: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *old_ = static_cast<const MessageChannelMigrateFrom *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageChannelMigrateFrom *>(new_content);
|
2018-09-28 22:57:34 +02:00
|
|
|
if (old_->title != new_->title || old_->migrated_from_chat_id != new_->migrated_from_chat_id) {
|
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::PinMessage: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *old_ = static_cast<const MessagePinMessage *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessagePinMessage *>(new_content);
|
2018-09-28 22:57:34 +02:00
|
|
|
if (old_->message_id != new_->message_id) {
|
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::GameScore: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *old_ = static_cast<const MessageGameScore *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageGameScore *>(new_content);
|
2018-09-28 22:57:34 +02:00
|
|
|
if (old_->game_message_id != new_->game_message_id || old_->game_id != new_->game_id ||
|
|
|
|
old_->score != new_->score) {
|
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::ScreenshotTaken:
|
|
|
|
break;
|
|
|
|
case MessageContentType::ChatSetTtl: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *old_ = static_cast<const MessageChatSetTtl *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageChatSetTtl *>(new_content);
|
2018-09-28 22:57:34 +02:00
|
|
|
if (old_->ttl != new_->ttl) {
|
2022-12-28 19:59:41 +01:00
|
|
|
LOG(ERROR) << "Message auto-delete time has changed from " << old_->ttl << " to " << new_->ttl;
|
2022-11-29 12:02:05 +01:00
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
if (old_->from_user_id != new_->from_user_id) {
|
2018-09-28 22:57:34 +02:00
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Call: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *old_ = static_cast<const MessageCall *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageCall *>(new_content);
|
2022-11-29 12:02:05 +01:00
|
|
|
if (old_->call_id != new_->call_id) {
|
2018-09-28 22:57:34 +02:00
|
|
|
is_content_changed = true;
|
|
|
|
}
|
2022-11-29 12:02:05 +01:00
|
|
|
if (old_->duration != new_->duration || old_->discard_reason != new_->discard_reason ||
|
|
|
|
old_->is_video != new_->is_video) {
|
2018-09-28 22:57:34 +02:00
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::PaymentSuccessful: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *old_ = static_cast<const MessagePaymentSuccessful *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessagePaymentSuccessful *>(new_content);
|
2021-03-31 14:36:25 +02:00
|
|
|
if (old_->invoice_dialog_id != new_->invoice_dialog_id || old_->invoice_message_id != new_->invoice_message_id ||
|
|
|
|
old_->currency != new_->currency || old_->total_amount != new_->total_amount ||
|
|
|
|
old_->invoice_payload != new_->invoice_payload || old_->shipping_option_id != new_->shipping_option_id ||
|
2018-09-28 22:57:34 +02:00
|
|
|
old_->telegram_payment_charge_id != new_->telegram_payment_charge_id ||
|
|
|
|
old_->provider_payment_charge_id != new_->provider_payment_charge_id ||
|
|
|
|
((old_->order_info != nullptr || new_->order_info != nullptr) &&
|
2022-07-13 23:13:52 +02:00
|
|
|
(old_->order_info == nullptr || new_->order_info == nullptr || *old_->order_info != *new_->order_info)) ||
|
|
|
|
old_->is_recurring != new_->is_recurring || old_->is_first_recurring != new_->is_first_recurring) {
|
2018-09-28 22:57:34 +02:00
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::ContactRegistered:
|
|
|
|
break;
|
|
|
|
case MessageContentType::ExpiredPhoto:
|
|
|
|
break;
|
|
|
|
case MessageContentType::ExpiredVideo:
|
|
|
|
break;
|
|
|
|
case MessageContentType::CustomServiceAction: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *old_ = static_cast<const MessageCustomServiceAction *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageCustomServiceAction *>(new_content);
|
2018-09-28 22:57:34 +02:00
|
|
|
if (old_->message != new_->message) {
|
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::WebsiteConnected: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *old_ = static_cast<const MessageWebsiteConnected *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageWebsiteConnected *>(new_content);
|
2018-09-28 22:57:34 +02:00
|
|
|
if (old_->domain_name != new_->domain_name) {
|
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::PassportDataSent: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *old_ = static_cast<const MessagePassportDataSent *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessagePassportDataSent *>(new_content);
|
2018-09-28 22:57:34 +02:00
|
|
|
if (old_->types != new_->types) {
|
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::PassportDataReceived: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *old_ = static_cast<const MessagePassportDataReceived *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessagePassportDataReceived *>(new_content);
|
2022-03-28 09:01:39 +02:00
|
|
|
if (old_->values != new_->values || old_->credentials != new_->credentials) {
|
2018-09-28 22:57:34 +02:00
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2019-02-19 14:45:32 +01:00
|
|
|
case MessageContentType::Poll: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *old_ = static_cast<const MessagePoll *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessagePoll *>(new_content);
|
2019-02-19 14:45:32 +01:00
|
|
|
if (old_->poll_id != new_->poll_id) {
|
2019-08-09 19:28:49 +02:00
|
|
|
need_update = true;
|
2019-02-19 14:45:32 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2020-03-29 23:34:37 +02:00
|
|
|
case MessageContentType::Dice: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *old_ = static_cast<const MessageDice *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageDice *>(new_content);
|
2020-04-18 07:45:41 +02:00
|
|
|
if (old_->emoji != new_->emoji || old_->dice_value != new_->dice_value) {
|
2020-03-14 17:56:39 +01:00
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2020-10-29 20:25:58 +01:00
|
|
|
case MessageContentType::ProximityAlertTriggered: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *old_ = static_cast<const MessageProximityAlertTriggered *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageProximityAlertTriggered *>(new_content);
|
2020-10-30 23:38:11 +01:00
|
|
|
if (old_->traveler_dialog_id != new_->traveler_dialog_id || old_->watcher_dialog_id != new_->watcher_dialog_id ||
|
|
|
|
old_->distance != new_->distance) {
|
2020-10-19 19:44:09 +02:00
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2020-11-24 12:33:16 +01:00
|
|
|
case MessageContentType::GroupCall: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *old_ = static_cast<const MessageGroupCall *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageGroupCall *>(new_content);
|
2021-04-05 23:24:05 +02:00
|
|
|
if (old_->input_group_call_id != new_->input_group_call_id || old_->duration != new_->duration ||
|
|
|
|
old_->schedule_date != new_->schedule_date) {
|
2020-11-24 12:33:16 +01:00
|
|
|
need_update = true;
|
|
|
|
}
|
2020-12-03 17:52:50 +01:00
|
|
|
if (!old_->input_group_call_id.is_identical(new_->input_group_call_id)) {
|
2020-11-25 15:04:32 +01:00
|
|
|
is_content_changed = true;
|
|
|
|
}
|
2020-11-24 12:33:16 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::InviteToGroupCall: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *old_ = static_cast<const MessageInviteToGroupCall *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageInviteToGroupCall *>(new_content);
|
2020-12-03 17:52:50 +01:00
|
|
|
if (old_->input_group_call_id != new_->input_group_call_id || old_->user_ids != new_->user_ids) {
|
2020-11-24 12:33:16 +01:00
|
|
|
need_update = true;
|
|
|
|
}
|
2020-12-03 17:52:50 +01:00
|
|
|
if (!old_->input_group_call_id.is_identical(new_->input_group_call_id)) {
|
2020-11-25 15:04:32 +01:00
|
|
|
is_content_changed = true;
|
|
|
|
}
|
2020-11-24 12:33:16 +01:00
|
|
|
break;
|
|
|
|
}
|
2021-08-18 15:03:10 +02:00
|
|
|
case MessageContentType::ChatSetTheme: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *old_ = static_cast<const MessageChatSetTheme *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageChatSetTheme *>(new_content);
|
2021-08-18 15:03:10 +02:00
|
|
|
if (old_->emoji != new_->emoji) {
|
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2022-03-28 09:01:39 +02:00
|
|
|
case MessageContentType::WebViewDataSent: {
|
|
|
|
const auto *old_ = static_cast<const MessageWebViewDataSent *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageWebViewDataSent *>(new_content);
|
|
|
|
if (old_->button_text != new_->button_text) {
|
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::WebViewDataReceived: {
|
|
|
|
const auto *old_ = static_cast<const MessageWebViewDataReceived *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageWebViewDataReceived *>(new_content);
|
|
|
|
if (old_->button_text != new_->button_text || old_->data != new_->data) {
|
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2022-07-01 14:28:22 +02:00
|
|
|
case MessageContentType::GiftPremium: {
|
|
|
|
const auto *old_ = static_cast<const MessageGiftPremium *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageGiftPremium *>(new_content);
|
2023-03-21 12:54:36 +01:00
|
|
|
if (old_->currency != new_->currency || old_->amount != new_->amount ||
|
|
|
|
old_->crypto_currency != new_->crypto_currency || old_->crypto_amount != new_->crypto_amount ||
|
|
|
|
old_->months != new_->months) {
|
2022-07-01 14:28:22 +02:00
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2022-10-18 15:08:53 +02:00
|
|
|
case MessageContentType::TopicCreate: {
|
|
|
|
const auto *old_ = static_cast<const MessageTopicCreate *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageTopicCreate *>(new_content);
|
|
|
|
if (old_->title != new_->title || old_->icon != new_->icon) {
|
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2022-10-18 21:16:03 +02:00
|
|
|
case MessageContentType::TopicEdit: {
|
|
|
|
const auto *old_ = static_cast<const MessageTopicEdit *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageTopicEdit *>(new_content);
|
|
|
|
if (old_->edited_data != new_->edited_data) {
|
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2018-12-25 18:47:37 +01:00
|
|
|
case MessageContentType::Unsupported: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *old_ = static_cast<const MessageUnsupported *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageUnsupported *>(new_content);
|
2018-12-25 18:47:37 +01:00
|
|
|
if (old_->version != new_->version) {
|
|
|
|
is_content_changed = true;
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
2018-12-25 18:47:37 +01:00
|
|
|
}
|
2022-12-09 12:13:37 +01:00
|
|
|
case MessageContentType::SuggestProfilePhoto: {
|
|
|
|
const auto *old_ = static_cast<const MessageSuggestProfilePhoto *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageSuggestProfilePhoto *>(new_content);
|
|
|
|
if (old_->photo != new_->photo) {
|
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2022-12-14 19:13:48 +01:00
|
|
|
case MessageContentType::WriteAccessAllowed:
|
|
|
|
break;
|
2023-01-10 14:20:30 +01:00
|
|
|
case MessageContentType::RequestedDialog: {
|
|
|
|
const auto *old_ = static_cast<const MessageRequestedDialog *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageRequestedDialog *>(new_content);
|
|
|
|
if (old_->dialog_id != new_->dialog_id || old_->button_id != new_->button_id) {
|
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2023-02-22 10:24:43 +01:00
|
|
|
case MessageContentType::WebViewWriteAccessAllowed: {
|
|
|
|
const auto *old_ = static_cast<const MessageWebViewWriteAccessAllowed *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageWebViewWriteAccessAllowed *>(new_content);
|
|
|
|
if (old_->web_app != new_->web_app) {
|
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2023-04-10 13:12:35 +02:00
|
|
|
case MessageContentType::SetBackground: {
|
|
|
|
const auto *old_ = static_cast<const MessageSetBackground *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageSetBackground *>(new_content);
|
2023-04-10 15:32:59 +02:00
|
|
|
if (old_->old_message_id != new_->old_message_id || old_->background_info != new_->background_info) {
|
2023-04-10 13:12:35 +02:00
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2023-06-12 18:23:58 +02:00
|
|
|
case MessageContentType::Story: {
|
|
|
|
const auto *old_ = static_cast<const MessageStory *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageStory *>(new_content);
|
|
|
|
if (old_->story_full_id != new_->story_full_id || old_->via_mention != new_->via_mention) {
|
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2023-08-25 15:53:50 +02:00
|
|
|
case MessageContentType::WriteAccessAllowedByRequest:
|
|
|
|
break;
|
2023-09-29 16:55:03 +02:00
|
|
|
case MessageContentType::GiftCode: {
|
|
|
|
const auto *old_ = static_cast<const MessageGiftCode *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageGiftCode *>(new_content);
|
|
|
|
if (old_->creator_dialog_id != new_->creator_dialog_id || old_->months != new_->months ||
|
|
|
|
old_->via_giveaway != new_->via_giveaway || old_->code != new_->code) {
|
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2023-09-29 23:32:39 +02:00
|
|
|
case MessageContentType::Giveaway: {
|
|
|
|
const auto *old_ = static_cast<const MessageGiveaway *>(old_content);
|
|
|
|
const auto *new_ = static_cast<const MessageGiveaway *>(new_content);
|
2023-10-12 16:05:03 +02:00
|
|
|
if (old_->giveaway_parameters != new_->giveaway_parameters || old_->quantity != new_->quantity ||
|
|
|
|
old_->months != new_->months) {
|
2023-09-29 23:32:39 +02:00
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2023-10-16 10:31:11 +02:00
|
|
|
case MessageContentType::GiveawayLaunch:
|
|
|
|
break;
|
2018-09-28 22:57:34 +02:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool merge_message_content_file_id(Td *td, MessageContent *message_content, FileId new_file_id) {
|
|
|
|
if (!new_file_id.is_valid()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-09-22 17:25:20 +02:00
|
|
|
// secret chats only
|
2018-09-28 22:57:34 +02:00
|
|
|
LOG(INFO) << "Merge message content of a message with file " << new_file_id;
|
|
|
|
MessageContentType content_type = message_content->get_type();
|
|
|
|
switch (content_type) {
|
|
|
|
case MessageContentType::Animation: {
|
|
|
|
auto content = static_cast<MessageAnimation *>(message_content);
|
|
|
|
if (new_file_id != content->file_id) {
|
2022-08-03 20:38:03 +02:00
|
|
|
td->animations_manager_->merge_animations(new_file_id, content->file_id);
|
2018-09-28 22:57:34 +02:00
|
|
|
content->file_id = new_file_id;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Audio: {
|
|
|
|
auto content = static_cast<MessageAudio *>(message_content);
|
|
|
|
if (new_file_id != content->file_id) {
|
2022-08-03 20:38:03 +02:00
|
|
|
td->audios_manager_->merge_audios(new_file_id, content->file_id);
|
2018-09-28 22:57:34 +02:00
|
|
|
content->file_id = new_file_id;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Document: {
|
|
|
|
auto content = static_cast<MessageDocument *>(message_content);
|
|
|
|
if (new_file_id != content->file_id) {
|
2022-08-03 20:38:03 +02:00
|
|
|
td->documents_manager_->merge_documents(new_file_id, content->file_id);
|
2018-09-28 22:57:34 +02:00
|
|
|
content->file_id = new_file_id;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Photo: {
|
|
|
|
auto content = static_cast<MessagePhoto *>(message_content);
|
|
|
|
Photo *photo = &content->photo;
|
|
|
|
if (!photo->photos.empty() && photo->photos.back().type == 'i') {
|
|
|
|
FileId &old_file_id = photo->photos.back().file_id;
|
|
|
|
if (old_file_id != new_file_id) {
|
|
|
|
LOG_STATUS(td->file_manager_->merge(new_file_id, old_file_id));
|
|
|
|
old_file_id = new_file_id;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Sticker: {
|
|
|
|
auto content = static_cast<MessageSticker *>(message_content);
|
|
|
|
if (new_file_id != content->file_id) {
|
2022-08-03 20:38:03 +02:00
|
|
|
td->stickers_manager_->merge_stickers(new_file_id, content->file_id);
|
2018-09-28 22:57:34 +02:00
|
|
|
content->file_id = new_file_id;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Video: {
|
|
|
|
auto content = static_cast<MessageVideo *>(message_content);
|
|
|
|
if (new_file_id != content->file_id) {
|
2022-08-03 20:38:03 +02:00
|
|
|
td->videos_manager_->merge_videos(new_file_id, content->file_id);
|
2018-09-28 22:57:34 +02:00
|
|
|
content->file_id = new_file_id;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::VideoNote: {
|
|
|
|
auto content = static_cast<MessageVideoNote *>(message_content);
|
|
|
|
if (new_file_id != content->file_id) {
|
2022-08-03 20:38:03 +02:00
|
|
|
td->video_notes_manager_->merge_video_notes(new_file_id, content->file_id);
|
2018-09-28 22:57:34 +02:00
|
|
|
content->file_id = new_file_id;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::VoiceNote: {
|
|
|
|
auto content = static_cast<MessageVoiceNote *>(message_content);
|
|
|
|
if (new_file_id != content->file_id) {
|
2022-08-03 20:38:03 +02:00
|
|
|
td->voice_notes_manager_->merge_voice_notes(new_file_id, content->file_id);
|
2018-09-28 22:57:34 +02:00
|
|
|
content->file_id = new_file_id;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Contact:
|
|
|
|
case MessageContentType::Game:
|
|
|
|
case MessageContentType::Invoice:
|
|
|
|
case MessageContentType::LiveLocation:
|
|
|
|
case MessageContentType::Location:
|
2023-06-12 18:23:58 +02:00
|
|
|
case MessageContentType::Story:
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::Text:
|
|
|
|
case MessageContentType::Venue:
|
|
|
|
case MessageContentType::ChatCreate:
|
|
|
|
case MessageContentType::ChatChangeTitle:
|
|
|
|
case MessageContentType::ChatChangePhoto:
|
|
|
|
case MessageContentType::ChatDeletePhoto:
|
|
|
|
case MessageContentType::ChatDeleteHistory:
|
|
|
|
case MessageContentType::ChatAddUsers:
|
|
|
|
case MessageContentType::ChatJoinedByLink:
|
|
|
|
case MessageContentType::ChatDeleteUser:
|
|
|
|
case MessageContentType::ChatMigrateTo:
|
|
|
|
case MessageContentType::ChannelCreate:
|
|
|
|
case MessageContentType::ChannelMigrateFrom:
|
|
|
|
case MessageContentType::PinMessage:
|
|
|
|
case MessageContentType::GameScore:
|
|
|
|
case MessageContentType::ScreenshotTaken:
|
|
|
|
case MessageContentType::ChatSetTtl:
|
|
|
|
case MessageContentType::Unsupported:
|
|
|
|
case MessageContentType::Call:
|
|
|
|
case MessageContentType::PaymentSuccessful:
|
|
|
|
case MessageContentType::ContactRegistered:
|
|
|
|
case MessageContentType::ExpiredPhoto:
|
|
|
|
case MessageContentType::ExpiredVideo:
|
|
|
|
case MessageContentType::CustomServiceAction:
|
|
|
|
case MessageContentType::WebsiteConnected:
|
|
|
|
case MessageContentType::PassportDataSent:
|
|
|
|
case MessageContentType::PassportDataReceived:
|
2019-02-19 14:45:32 +01:00
|
|
|
case MessageContentType::Poll:
|
2020-03-29 23:34:37 +02:00
|
|
|
case MessageContentType::Dice:
|
2020-10-29 20:25:58 +01:00
|
|
|
case MessageContentType::ProximityAlertTriggered:
|
2020-11-24 12:33:16 +01:00
|
|
|
case MessageContentType::GroupCall:
|
|
|
|
case MessageContentType::InviteToGroupCall:
|
2021-08-18 15:03:10 +02:00
|
|
|
case MessageContentType::ChatSetTheme:
|
2022-03-28 09:01:39 +02:00
|
|
|
case MessageContentType::WebViewDataSent:
|
|
|
|
case MessageContentType::WebViewDataReceived:
|
2022-07-01 14:28:22 +02:00
|
|
|
case MessageContentType::GiftPremium:
|
2022-10-18 15:08:53 +02:00
|
|
|
case MessageContentType::TopicCreate:
|
2022-10-18 21:16:03 +02:00
|
|
|
case MessageContentType::TopicEdit:
|
2022-12-09 12:13:37 +01:00
|
|
|
case MessageContentType::SuggestProfilePhoto:
|
2022-12-14 19:13:48 +01:00
|
|
|
case MessageContentType::WriteAccessAllowed:
|
2023-01-10 14:20:30 +01:00
|
|
|
case MessageContentType::RequestedDialog:
|
2023-02-22 10:24:43 +01:00
|
|
|
case MessageContentType::WebViewWriteAccessAllowed:
|
2023-04-10 13:12:35 +02:00
|
|
|
case MessageContentType::SetBackground:
|
2023-08-25 15:53:50 +02:00
|
|
|
case MessageContentType::WriteAccessAllowedByRequest:
|
2023-09-29 16:55:03 +02:00
|
|
|
case MessageContentType::GiftCode:
|
2023-09-29 23:32:39 +02:00
|
|
|
case MessageContentType::Giveaway:
|
2023-10-16 10:31:11 +02:00
|
|
|
case MessageContentType::GiveawayLaunch:
|
2018-09-28 22:57:34 +02:00
|
|
|
LOG(ERROR) << "Receive new file " << new_file_id << " in a sent message of the type " << content_type;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-10-04 15:08:51 +02:00
|
|
|
static bool can_be_animated_emoji(const FormattedText &text) {
|
2022-08-05 16:58:16 +02:00
|
|
|
if (!is_emoji(text.text)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (text.entities.empty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (text.entities.size() == 1 && text.entities[0].type == MessageEntity::Type::CustomEmoji &&
|
|
|
|
text.entities[0].offset == 0 && static_cast<size_t>(text.entities[0].length) == utf8_utf16_length(text.text) &&
|
2022-10-03 00:26:32 +02:00
|
|
|
text.entities[0].custom_emoji_id.is_valid()) {
|
2022-08-05 16:58:16 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-10-03 00:26:32 +02:00
|
|
|
static CustomEmojiId get_custom_emoji_id(const FormattedText &text) {
|
|
|
|
return text.entities.empty() ? CustomEmojiId() : text.entities[0].custom_emoji_id;
|
2021-10-04 15:08:51 +02:00
|
|
|
}
|
|
|
|
|
2023-09-21 18:11:17 +02:00
|
|
|
void register_message_content(Td *td, const MessageContent *content, MessageFullId message_full_id,
|
2020-02-22 17:21:58 +01:00
|
|
|
const char *source) {
|
2019-02-19 16:42:59 +01:00
|
|
|
switch (content->get_type()) {
|
2021-10-04 15:08:51 +02:00
|
|
|
case MessageContentType::Text: {
|
|
|
|
auto text = static_cast<const MessageText *>(content);
|
|
|
|
if (text->web_page_id.is_valid()) {
|
2023-09-21 18:11:17 +02:00
|
|
|
td->web_pages_manager_->register_web_page(text->web_page_id, message_full_id, source);
|
2021-10-04 15:08:51 +02:00
|
|
|
} else if (can_be_animated_emoji(text->text)) {
|
2023-09-21 18:11:17 +02:00
|
|
|
td->stickers_manager_->register_emoji(text->text.text, get_custom_emoji_id(text->text), message_full_id,
|
2022-08-05 16:58:16 +02:00
|
|
|
source);
|
2021-10-04 15:08:51 +02:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2022-10-19 17:30:25 +02:00
|
|
|
case MessageContentType::VideoNote:
|
|
|
|
return td->video_notes_manager_->register_video_note(static_cast<const MessageVideoNote *>(content)->file_id,
|
2023-09-21 18:11:17 +02:00
|
|
|
message_full_id, source);
|
2022-05-25 18:39:15 +02:00
|
|
|
case MessageContentType::VoiceNote:
|
|
|
|
return td->voice_notes_manager_->register_voice_note(static_cast<const MessageVoiceNote *>(content)->file_id,
|
2023-09-21 18:11:17 +02:00
|
|
|
message_full_id, source);
|
2019-02-19 16:42:59 +01:00
|
|
|
case MessageContentType::Poll:
|
2023-09-21 18:11:17 +02:00
|
|
|
return td->poll_manager_->register_poll(static_cast<const MessagePoll *>(content)->poll_id, message_full_id,
|
2020-02-22 17:21:58 +01:00
|
|
|
source);
|
2020-04-19 23:41:26 +02:00
|
|
|
case MessageContentType::Dice: {
|
|
|
|
auto dice = static_cast<const MessageDice *>(content);
|
2023-09-21 18:11:17 +02:00
|
|
|
return td->stickers_manager_->register_dice(dice->emoji, dice->dice_value, message_full_id, source);
|
2020-04-19 23:41:26 +02:00
|
|
|
}
|
2022-07-22 12:30:24 +02:00
|
|
|
case MessageContentType::GiftPremium:
|
2022-07-22 14:01:44 +02:00
|
|
|
return td->stickers_manager_->register_premium_gift(static_cast<const MessageGiftPremium *>(content)->months,
|
2023-09-21 18:11:17 +02:00
|
|
|
message_full_id, source);
|
2023-10-13 15:06:55 +02:00
|
|
|
case MessageContentType::GiftCode:
|
|
|
|
return td->stickers_manager_->register_premium_gift(static_cast<const MessageGiftCode *>(content)->months,
|
|
|
|
message_full_id, source);
|
2022-12-23 11:19:56 +01:00
|
|
|
case MessageContentType::SuggestProfilePhoto:
|
|
|
|
return td->contacts_manager_->register_suggested_profile_photo(
|
|
|
|
static_cast<const MessageSuggestProfilePhoto *>(content)->photo);
|
2023-06-13 17:20:26 +02:00
|
|
|
case MessageContentType::Story:
|
|
|
|
return td->story_manager_->register_story(static_cast<const MessageStory *>(content)->story_full_id,
|
2023-09-21 18:11:17 +02:00
|
|
|
message_full_id, source);
|
2019-02-19 16:42:59 +01:00
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-25 01:50:23 +01:00
|
|
|
void reregister_message_content(Td *td, const MessageContent *old_content, const MessageContent *new_content,
|
2023-09-21 18:11:17 +02:00
|
|
|
MessageFullId message_full_id, const char *source) {
|
2020-01-25 01:50:23 +01:00
|
|
|
auto old_content_type = old_content->get_type();
|
|
|
|
auto new_content_type = new_content->get_type();
|
|
|
|
if (old_content_type == new_content_type) {
|
|
|
|
switch (old_content_type) {
|
2021-10-04 15:08:51 +02:00
|
|
|
case MessageContentType::Text: {
|
|
|
|
auto old_text = static_cast<const MessageText *>(old_content);
|
|
|
|
auto new_text = static_cast<const MessageText *>(new_content);
|
|
|
|
if (old_text->web_page_id == new_text->web_page_id &&
|
|
|
|
(old_text->text == new_text->text ||
|
|
|
|
(!can_be_animated_emoji(old_text->text) && !can_be_animated_emoji(new_text->text)))) {
|
2020-01-27 00:55:18 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
2021-10-04 15:08:51 +02:00
|
|
|
}
|
2022-10-19 17:30:25 +02:00
|
|
|
case MessageContentType::VideoNote:
|
|
|
|
if (static_cast<const MessageVideoNote *>(old_content)->file_id ==
|
|
|
|
static_cast<const MessageVideoNote *>(new_content)->file_id) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
2022-05-25 18:39:15 +02:00
|
|
|
case MessageContentType::VoiceNote:
|
|
|
|
if (static_cast<const MessageVoiceNote *>(old_content)->file_id ==
|
|
|
|
static_cast<const MessageVoiceNote *>(new_content)->file_id) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
2020-01-25 01:50:23 +01:00
|
|
|
case MessageContentType::Poll:
|
|
|
|
if (static_cast<const MessagePoll *>(old_content)->poll_id ==
|
|
|
|
static_cast<const MessagePoll *>(new_content)->poll_id) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
2020-04-19 23:41:26 +02:00
|
|
|
case MessageContentType::Dice:
|
|
|
|
if (static_cast<const MessageDice *>(old_content)->emoji ==
|
|
|
|
static_cast<const MessageDice *>(new_content)->emoji &&
|
|
|
|
static_cast<const MessageDice *>(old_content)->dice_value ==
|
|
|
|
static_cast<const MessageDice *>(new_content)->dice_value) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
2022-07-22 12:30:24 +02:00
|
|
|
case MessageContentType::GiftPremium:
|
|
|
|
if (static_cast<const MessageGiftPremium *>(old_content)->months ==
|
|
|
|
static_cast<const MessageGiftPremium *>(new_content)->months) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
2023-10-13 15:06:55 +02:00
|
|
|
case MessageContentType::GiftCode:
|
|
|
|
if (static_cast<const MessageGiftCode *>(old_content)->months ==
|
|
|
|
static_cast<const MessageGiftCode *>(new_content)->months) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
2023-06-13 17:20:26 +02:00
|
|
|
case MessageContentType::Story:
|
|
|
|
if (static_cast<const MessageStory *>(old_content)->story_full_id ==
|
|
|
|
static_cast<const MessageStory *>(new_content)->story_full_id) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
2020-01-25 01:50:23 +01:00
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2023-09-21 18:11:17 +02:00
|
|
|
unregister_message_content(td, old_content, message_full_id, source);
|
|
|
|
register_message_content(td, new_content, message_full_id, source);
|
2020-01-25 01:50:23 +01:00
|
|
|
}
|
|
|
|
|
2023-09-21 18:11:17 +02:00
|
|
|
void unregister_message_content(Td *td, const MessageContent *content, MessageFullId message_full_id,
|
2020-02-22 17:21:58 +01:00
|
|
|
const char *source) {
|
2019-02-19 16:42:59 +01:00
|
|
|
switch (content->get_type()) {
|
2021-10-04 15:08:51 +02:00
|
|
|
case MessageContentType::Text: {
|
|
|
|
auto text = static_cast<const MessageText *>(content);
|
|
|
|
if (text->web_page_id.is_valid()) {
|
2023-09-21 18:11:17 +02:00
|
|
|
td->web_pages_manager_->unregister_web_page(text->web_page_id, message_full_id, source);
|
2021-10-04 15:08:51 +02:00
|
|
|
} else if (can_be_animated_emoji(text->text)) {
|
2023-09-21 18:11:17 +02:00
|
|
|
td->stickers_manager_->unregister_emoji(text->text.text, get_custom_emoji_id(text->text), message_full_id,
|
2022-08-05 16:58:16 +02:00
|
|
|
source);
|
2021-10-04 15:08:51 +02:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2022-10-19 17:30:25 +02:00
|
|
|
case MessageContentType::VideoNote:
|
|
|
|
return td->video_notes_manager_->unregister_video_note(static_cast<const MessageVideoNote *>(content)->file_id,
|
2023-09-21 18:11:17 +02:00
|
|
|
message_full_id, source);
|
2022-05-25 18:39:15 +02:00
|
|
|
case MessageContentType::VoiceNote:
|
|
|
|
return td->voice_notes_manager_->unregister_voice_note(static_cast<const MessageVoiceNote *>(content)->file_id,
|
2023-09-21 18:11:17 +02:00
|
|
|
message_full_id, source);
|
2019-02-19 16:42:59 +01:00
|
|
|
case MessageContentType::Poll:
|
2023-09-21 18:11:17 +02:00
|
|
|
return td->poll_manager_->unregister_poll(static_cast<const MessagePoll *>(content)->poll_id, message_full_id,
|
2020-02-22 17:21:58 +01:00
|
|
|
source);
|
2020-04-19 23:41:26 +02:00
|
|
|
case MessageContentType::Dice: {
|
|
|
|
auto dice = static_cast<const MessageDice *>(content);
|
2023-09-21 18:11:17 +02:00
|
|
|
return td->stickers_manager_->unregister_dice(dice->emoji, dice->dice_value, message_full_id, source);
|
2020-04-19 23:41:26 +02:00
|
|
|
}
|
2022-07-22 12:30:24 +02:00
|
|
|
case MessageContentType::GiftPremium:
|
2022-07-22 14:01:44 +02:00
|
|
|
return td->stickers_manager_->unregister_premium_gift(static_cast<const MessageGiftPremium *>(content)->months,
|
2023-09-21 18:11:17 +02:00
|
|
|
message_full_id, source);
|
2023-10-13 15:06:55 +02:00
|
|
|
case MessageContentType::GiftCode:
|
|
|
|
return td->stickers_manager_->unregister_premium_gift(static_cast<const MessageGiftCode *>(content)->months,
|
|
|
|
message_full_id, source);
|
2023-06-13 17:20:26 +02:00
|
|
|
case MessageContentType::Story:
|
|
|
|
return td->story_manager_->unregister_story(static_cast<const MessageStory *>(content)->story_full_id,
|
2023-09-21 18:11:17 +02:00
|
|
|
message_full_id, source);
|
2019-02-19 16:42:59 +01:00
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-28 22:57:34 +02:00
|
|
|
template <class ToT, class FromT>
|
|
|
|
static tl_object_ptr<ToT> secret_to_telegram(FromT &from);
|
|
|
|
|
2020-08-25 14:09:24 +02:00
|
|
|
// photoSizeEmpty type:string = PhotoSize;
|
2018-09-28 22:57:34 +02:00
|
|
|
static auto secret_to_telegram(secret_api::photoSizeEmpty &empty) {
|
|
|
|
if (!clean_input_string(empty.type_)) {
|
|
|
|
empty.type_.clear();
|
|
|
|
}
|
|
|
|
return make_tl_object<telegram_api::photoSizeEmpty>(empty.type_);
|
|
|
|
}
|
|
|
|
|
2020-08-25 14:09:24 +02:00
|
|
|
// photoSize type:string location:FileLocation w:int h:int size:int = PhotoSize;
|
2018-09-28 22:57:34 +02:00
|
|
|
static auto secret_to_telegram(secret_api::photoSize &photo_size) {
|
|
|
|
if (!clean_input_string(photo_size.type_)) {
|
|
|
|
photo_size.type_.clear();
|
|
|
|
}
|
2021-04-16 16:43:51 +02:00
|
|
|
return make_tl_object<telegram_api::photoSize>(photo_size.type_, photo_size.w_, photo_size.h_, photo_size.size_);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
|
2020-08-25 14:09:24 +02:00
|
|
|
// photoCachedSize type:string location:FileLocation w:int h:int bytes:bytes = PhotoSize;
|
2018-09-28 22:57:34 +02:00
|
|
|
static auto secret_to_telegram(secret_api::photoCachedSize &photo_size) {
|
|
|
|
if (!clean_input_string(photo_size.type_)) {
|
|
|
|
photo_size.type_.clear();
|
|
|
|
}
|
2021-04-16 16:43:51 +02:00
|
|
|
return make_tl_object<telegram_api::photoCachedSize>(photo_size.type_, photo_size.w_, photo_size.h_,
|
|
|
|
photo_size.bytes_.clone());
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
|
2020-08-25 14:09:24 +02:00
|
|
|
// documentAttributeImageSize w:int h:int = DocumentAttribute;
|
2018-09-28 22:57:34 +02:00
|
|
|
static auto secret_to_telegram(secret_api::documentAttributeImageSize &image_size) {
|
|
|
|
return make_tl_object<telegram_api::documentAttributeImageSize>(image_size.w_, image_size.h_);
|
|
|
|
}
|
|
|
|
|
2020-08-25 14:09:24 +02:00
|
|
|
// documentAttributeAnimated = DocumentAttribute;
|
2018-09-28 22:57:34 +02:00
|
|
|
static auto secret_to_telegram(secret_api::documentAttributeAnimated &animated) {
|
|
|
|
return make_tl_object<telegram_api::documentAttributeAnimated>();
|
|
|
|
}
|
|
|
|
|
2020-08-25 14:09:24 +02:00
|
|
|
// documentAttributeSticker23 = DocumentAttribute;
|
2018-09-28 22:57:34 +02:00
|
|
|
static auto secret_to_telegram(secret_api::documentAttributeSticker23 &sticker) {
|
|
|
|
return make_tl_object<telegram_api::documentAttributeSticker>(
|
2023-06-23 15:28:48 +02:00
|
|
|
0, false, "", make_tl_object<telegram_api::inputStickerSetEmpty>(), nullptr);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
2020-05-05 18:41:01 +02:00
|
|
|
|
2018-09-28 22:57:34 +02:00
|
|
|
static auto secret_to_telegram(secret_api::inputStickerSetEmpty &sticker_set) {
|
|
|
|
return make_tl_object<telegram_api::inputStickerSetEmpty>();
|
|
|
|
}
|
2020-05-05 18:41:01 +02:00
|
|
|
|
2018-09-28 22:57:34 +02:00
|
|
|
static auto secret_to_telegram(secret_api::inputStickerSetShortName &sticker_set) {
|
|
|
|
if (!clean_input_string(sticker_set.short_name_)) {
|
|
|
|
sticker_set.short_name_.clear();
|
|
|
|
}
|
|
|
|
return make_tl_object<telegram_api::inputStickerSetShortName>(sticker_set.short_name_);
|
|
|
|
}
|
|
|
|
|
2020-08-25 14:09:24 +02:00
|
|
|
// documentAttributeSticker alt:string stickerset:InputStickerSet = DocumentAttribute;
|
2018-09-28 22:57:34 +02:00
|
|
|
static auto secret_to_telegram(secret_api::documentAttributeSticker &sticker) {
|
|
|
|
if (!clean_input_string(sticker.alt_)) {
|
|
|
|
sticker.alt_.clear();
|
|
|
|
}
|
|
|
|
return make_tl_object<telegram_api::documentAttributeSticker>(
|
2023-06-23 15:28:48 +02:00
|
|
|
0, false, sticker.alt_, secret_to_telegram<telegram_api::InputStickerSet>(*sticker.stickerset_), nullptr);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
|
2022-09-28 11:17:04 +02:00
|
|
|
// documentAttributeVideo23 duration:int w:int h:int = DocumentAttribute;
|
|
|
|
static auto secret_to_telegram(secret_api::documentAttributeVideo23 &video) {
|
2023-06-23 15:28:48 +02:00
|
|
|
return make_tl_object<telegram_api::documentAttributeVideo>(0, false, false, false, video.duration_, video.w_,
|
|
|
|
video.h_, 0);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
|
2020-08-25 14:09:24 +02:00
|
|
|
// documentAttributeFilename file_name:string = DocumentAttribute;
|
2018-09-28 22:57:34 +02:00
|
|
|
static auto secret_to_telegram(secret_api::documentAttributeFilename &filename) {
|
|
|
|
if (!clean_input_string(filename.file_name_)) {
|
|
|
|
filename.file_name_.clear();
|
|
|
|
}
|
|
|
|
return make_tl_object<telegram_api::documentAttributeFilename>(filename.file_name_);
|
|
|
|
}
|
|
|
|
|
2022-09-28 11:17:04 +02:00
|
|
|
// documentAttributeVideo flags:# round_message:flags.0?true duration:int w:int h:int = DocumentAttribute;
|
|
|
|
static auto secret_to_telegram(secret_api::documentAttributeVideo &video) {
|
2018-09-28 22:57:34 +02:00
|
|
|
return make_tl_object<telegram_api::documentAttributeVideo>(
|
2022-12-18 20:15:57 +01:00
|
|
|
video.round_message_ ? telegram_api::documentAttributeVideo::ROUND_MESSAGE_MASK : 0, video.round_message_, false,
|
2023-06-23 15:28:48 +02:00
|
|
|
false, video.duration_, video.w_, video.h_, 0);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static auto telegram_documentAttributeAudio(bool is_voice_note, int duration, string title, string performer,
|
|
|
|
BufferSlice waveform) {
|
|
|
|
if (!clean_input_string(title)) {
|
|
|
|
title.clear();
|
|
|
|
}
|
|
|
|
if (!clean_input_string(performer)) {
|
|
|
|
performer.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
int32 flags = 0;
|
|
|
|
if (is_voice_note) {
|
|
|
|
flags |= telegram_api::documentAttributeAudio::VOICE_MASK;
|
|
|
|
}
|
|
|
|
if (!title.empty()) {
|
|
|
|
flags |= telegram_api::documentAttributeAudio::TITLE_MASK;
|
|
|
|
}
|
|
|
|
if (!performer.empty()) {
|
|
|
|
flags |= telegram_api::documentAttributeAudio::PERFORMER_MASK;
|
|
|
|
}
|
2021-10-19 17:11:16 +02:00
|
|
|
if (!waveform.empty()) {
|
2018-09-28 22:57:34 +02:00
|
|
|
flags |= telegram_api::documentAttributeAudio::WAVEFORM_MASK;
|
|
|
|
}
|
|
|
|
return make_tl_object<telegram_api::documentAttributeAudio>(flags, is_voice_note, duration, std::move(title),
|
|
|
|
std::move(performer), std::move(waveform));
|
|
|
|
}
|
|
|
|
|
2020-08-25 14:09:24 +02:00
|
|
|
// documentAttributeAudio23 duration:int = DocumentAttribute;
|
2018-09-28 22:57:34 +02:00
|
|
|
static auto secret_to_telegram(secret_api::documentAttributeAudio23 &audio) {
|
|
|
|
return telegram_documentAttributeAudio(false, audio.duration_, "", "", Auto());
|
|
|
|
}
|
2020-08-25 14:09:24 +02:00
|
|
|
// documentAttributeAudio45 duration:int title:string performer:string = DocumentAttribute;
|
2018-09-28 22:57:34 +02:00
|
|
|
static auto secret_to_telegram(secret_api::documentAttributeAudio45 &audio) {
|
|
|
|
return telegram_documentAttributeAudio(false, audio.duration_, audio.title_, audio.performer_, Auto());
|
|
|
|
}
|
|
|
|
|
2020-08-25 14:09:24 +02:00
|
|
|
// documentAttributeAudio flags:# voice:flags.10?true duration:int title:flags.0?string
|
2018-09-28 22:57:34 +02:00
|
|
|
// performer:flags.1?string waveform:flags.2?bytes = DocumentAttribute;
|
|
|
|
static auto secret_to_telegram(secret_api::documentAttributeAudio &audio) {
|
2022-12-18 20:15:57 +01:00
|
|
|
return telegram_documentAttributeAudio(audio.voice_, audio.duration_, audio.title_, audio.performer_,
|
|
|
|
audio.waveform_.clone());
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static auto secret_to_telegram(std::vector<tl_object_ptr<secret_api::DocumentAttribute>> &attributes) {
|
|
|
|
std::vector<tl_object_ptr<telegram_api::DocumentAttribute>> res;
|
|
|
|
for (auto &attribute : attributes) {
|
|
|
|
auto telegram_attribute = secret_to_telegram<telegram_api::DocumentAttribute>(*attribute);
|
|
|
|
if (telegram_attribute) {
|
|
|
|
res.push_back(std::move(telegram_attribute));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2020-08-25 14:09:24 +02:00
|
|
|
// decryptedMessageMediaExternalDocument id:long access_hash:long date:int mime_type:string size:int
|
2018-09-28 22:57:34 +02:00
|
|
|
// thumb:PhotoSize dc_id:int attributes:Vector<DocumentAttribute> = DecryptedMessageMedia;
|
|
|
|
static auto secret_to_telegram_document(secret_api::decryptedMessageMediaExternalDocument &from) {
|
|
|
|
if (!clean_input_string(from.mime_type_)) {
|
|
|
|
from.mime_type_.clear();
|
|
|
|
}
|
2019-03-15 14:52:55 +01:00
|
|
|
vector<telegram_api::object_ptr<telegram_api::PhotoSize>> thumbnails;
|
|
|
|
thumbnails.push_back(secret_to_telegram<telegram_api::PhotoSize>(*from.thumb_));
|
2021-11-01 18:48:06 +01:00
|
|
|
return make_tl_object<telegram_api::document>(0, from.id_, from.access_hash_, BufferSlice(), from.date_,
|
|
|
|
from.mime_type_, from.size_, std::move(thumbnails), Auto(), from.dc_id_,
|
|
|
|
secret_to_telegram(from.attributes_));
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class ToT, class FromT>
|
|
|
|
static tl_object_ptr<ToT> secret_to_telegram(FromT &from) {
|
|
|
|
tl_object_ptr<ToT> res;
|
|
|
|
downcast_call(from, [&](auto &p) { res = secret_to_telegram(p); });
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2019-04-09 17:38:57 +02:00
|
|
|
static unique_ptr<MessageContent> get_document_message_content(Document &&parsed_document, FormattedText &&caption,
|
2022-12-20 16:06:21 +01:00
|
|
|
bool is_opened, bool is_premium, bool has_spoiler) {
|
2019-04-09 17:38:57 +02:00
|
|
|
auto file_id = parsed_document.file_id;
|
2019-04-09 22:39:41 +02:00
|
|
|
if (!parsed_document.empty()) {
|
2018-09-28 22:57:34 +02:00
|
|
|
CHECK(file_id.is_valid());
|
|
|
|
}
|
2019-04-09 17:38:57 +02:00
|
|
|
switch (parsed_document.type) {
|
|
|
|
case Document::Type::Animation:
|
2022-12-26 12:20:48 +01:00
|
|
|
return make_unique<MessageAnimation>(file_id, std::move(caption), has_spoiler);
|
2019-04-09 17:38:57 +02:00
|
|
|
case Document::Type::Audio:
|
2018-09-28 22:57:34 +02:00
|
|
|
return make_unique<MessageAudio>(file_id, std::move(caption));
|
2019-04-09 17:38:57 +02:00
|
|
|
case Document::Type::General:
|
2018-09-28 22:57:34 +02:00
|
|
|
return make_unique<MessageDocument>(file_id, std::move(caption));
|
2019-04-09 17:38:57 +02:00
|
|
|
case Document::Type::Sticker:
|
2022-06-03 15:33:49 +02:00
|
|
|
return make_unique<MessageSticker>(file_id, is_premium);
|
2019-04-09 17:38:57 +02:00
|
|
|
case Document::Type::Unknown:
|
2018-09-28 22:57:34 +02:00
|
|
|
return make_unique<MessageUnsupported>();
|
2019-04-09 17:38:57 +02:00
|
|
|
case Document::Type::Video:
|
2022-12-20 16:06:21 +01:00
|
|
|
return make_unique<MessageVideo>(file_id, std::move(caption), has_spoiler);
|
2019-04-09 17:38:57 +02:00
|
|
|
case Document::Type::VideoNote:
|
2018-09-28 22:57:34 +02:00
|
|
|
return make_unique<MessageVideoNote>(file_id, is_opened);
|
2019-04-09 17:38:57 +02:00
|
|
|
case Document::Type::VoiceNote:
|
2018-09-28 22:57:34 +02:00
|
|
|
return make_unique<MessageVoiceNote>(file_id, std::move(caption), is_opened);
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static unique_ptr<MessageContent> get_document_message_content(Td *td, tl_object_ptr<telegram_api::document> &&document,
|
|
|
|
DialogId owner_dialog_id, FormattedText &&caption,
|
2022-12-20 16:06:21 +01:00
|
|
|
bool is_opened, bool is_premium, bool has_spoiler,
|
2018-09-28 22:57:34 +02:00
|
|
|
MultiPromiseActor *load_data_multipromise_ptr) {
|
|
|
|
return get_document_message_content(
|
|
|
|
td->documents_manager_->on_get_document(std::move(document), owner_dialog_id, load_data_multipromise_ptr),
|
2022-12-20 16:06:21 +01:00
|
|
|
std::move(caption), is_opened, is_premium, has_spoiler);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
unique_ptr<MessageContent> get_secret_message_content(
|
2021-08-01 05:17:51 +02:00
|
|
|
Td *td, string message_text, unique_ptr<EncryptedFile> file,
|
2022-07-01 14:04:11 +02:00
|
|
|
tl_object_ptr<secret_api::DecryptedMessageMedia> &&media_ptr,
|
2018-09-28 22:57:34 +02:00
|
|
|
vector<tl_object_ptr<secret_api::MessageEntity>> &&secret_entities, DialogId owner_dialog_id,
|
2022-06-03 16:31:48 +02:00
|
|
|
MultiPromiseActor &load_data_multipromise, bool is_premium) {
|
2022-07-01 14:04:11 +02:00
|
|
|
int32 constructor_id = media_ptr == nullptr ? secret_api::decryptedMessageMediaEmpty::ID : media_ptr->get_id();
|
2020-02-24 22:30:47 +01:00
|
|
|
auto caption = [&] {
|
|
|
|
switch (constructor_id) {
|
|
|
|
case secret_api::decryptedMessageMediaVideo::ID: {
|
2022-07-01 14:04:11 +02:00
|
|
|
auto media = static_cast<secret_api::decryptedMessageMediaVideo *>(media_ptr.get());
|
|
|
|
return std::move(media->caption_);
|
2020-02-24 22:30:47 +01:00
|
|
|
}
|
|
|
|
case secret_api::decryptedMessageMediaPhoto::ID: {
|
2022-07-01 14:04:11 +02:00
|
|
|
auto media = static_cast<secret_api::decryptedMessageMediaPhoto *>(media_ptr.get());
|
|
|
|
return std::move(media->caption_);
|
2020-02-24 22:30:47 +01:00
|
|
|
}
|
2022-05-11 06:46:06 +02:00
|
|
|
case secret_api::decryptedMessageMediaDocument46::ID: {
|
2022-07-01 14:04:11 +02:00
|
|
|
auto media = static_cast<secret_api::decryptedMessageMediaDocument46 *>(media_ptr.get());
|
|
|
|
return std::move(media->caption_);
|
2022-05-11 06:46:06 +02:00
|
|
|
}
|
2020-02-24 22:30:47 +01:00
|
|
|
case secret_api::decryptedMessageMediaDocument::ID: {
|
2022-07-01 14:04:11 +02:00
|
|
|
auto media = static_cast<secret_api::decryptedMessageMediaDocument *>(media_ptr.get());
|
|
|
|
return std::move(media->caption_);
|
2020-02-24 22:30:47 +01:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
return string();
|
|
|
|
}
|
|
|
|
}();
|
|
|
|
if (!clean_input_string(caption)) {
|
|
|
|
caption.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (message_text.empty()) {
|
|
|
|
message_text = std::move(caption);
|
|
|
|
} else if (!caption.empty()) {
|
|
|
|
message_text = message_text + "\n\n" + caption;
|
|
|
|
}
|
|
|
|
|
2022-07-27 22:47:16 +02:00
|
|
|
auto entities = get_message_entities(td, std::move(secret_entities), is_premium, load_data_multipromise);
|
2021-08-04 03:26:41 +02:00
|
|
|
auto status = fix_formatted_text(message_text, entities, true, false, true, td->auth_manager_->is_bot(), false);
|
2018-09-28 22:57:34 +02:00
|
|
|
if (status.is_error()) {
|
|
|
|
LOG(WARNING) << "Receive error " << status << " while parsing secret message \"" << message_text
|
|
|
|
<< "\" with entities " << format::as_array(entities);
|
|
|
|
if (!clean_input_string(message_text)) {
|
|
|
|
message_text.clear();
|
|
|
|
}
|
2021-08-04 03:26:41 +02:00
|
|
|
entities = find_entities(message_text, true, td->auth_manager_->is_bot());
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// support of old layer and old constructions
|
|
|
|
switch (constructor_id) {
|
2022-05-11 06:46:06 +02:00
|
|
|
case secret_api::decryptedMessageMediaDocument46::ID: {
|
2022-07-01 14:04:11 +02:00
|
|
|
auto media = move_tl_object_as<secret_api::decryptedMessageMediaDocument46>(media_ptr);
|
|
|
|
media_ptr = make_tl_object<secret_api::decryptedMessageMediaDocument>(
|
|
|
|
std::move(media->thumb_), media->thumb_w_, media->thumb_h_, media->mime_type_, media->size_,
|
|
|
|
std::move(media->key_), std::move(media->iv_), std::move(media->attributes_), string());
|
2022-05-11 06:46:06 +02:00
|
|
|
|
|
|
|
constructor_id = secret_api::decryptedMessageMediaDocument::ID;
|
|
|
|
break;
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
case secret_api::decryptedMessageMediaVideo::ID: {
|
2022-07-01 14:04:11 +02:00
|
|
|
auto media = move_tl_object_as<secret_api::decryptedMessageMediaVideo>(media_ptr);
|
2022-05-11 06:46:06 +02:00
|
|
|
vector<tl_object_ptr<secret_api::DocumentAttribute>> attributes;
|
2018-09-28 22:57:34 +02:00
|
|
|
attributes.emplace_back(
|
2022-09-28 11:17:04 +02:00
|
|
|
make_tl_object<secret_api::documentAttributeVideo>(0, false, media->duration_, media->w_, media->h_));
|
2022-07-01 14:04:11 +02:00
|
|
|
media_ptr = make_tl_object<secret_api::decryptedMessageMediaDocument>(
|
|
|
|
std::move(media->thumb_), media->thumb_w_, media->thumb_h_, media->mime_type_, media->size_,
|
|
|
|
std::move(media->key_), std::move(media->iv_), std::move(attributes), string());
|
2018-09-28 22:57:34 +02:00
|
|
|
|
|
|
|
constructor_id = secret_api::decryptedMessageMediaDocument::ID;
|
|
|
|
break;
|
|
|
|
}
|
2021-10-19 17:11:16 +02:00
|
|
|
default:
|
|
|
|
break;
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool is_media_empty = false;
|
|
|
|
switch (constructor_id) {
|
|
|
|
case secret_api::decryptedMessageMediaEmpty::ID:
|
2020-02-24 22:06:29 +01:00
|
|
|
if (message_text.empty()) {
|
|
|
|
LOG(ERROR) << "Receive empty message text and media";
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
is_media_empty = true;
|
|
|
|
break;
|
|
|
|
case secret_api::decryptedMessageMediaGeoPoint::ID: {
|
2022-07-01 14:04:11 +02:00
|
|
|
auto media = move_tl_object_as<secret_api::decryptedMessageMediaGeoPoint>(media_ptr);
|
2018-09-28 22:57:34 +02:00
|
|
|
|
2022-07-01 14:04:11 +02:00
|
|
|
auto m = make_unique<MessageLocation>(Location(media));
|
2018-09-28 22:57:34 +02:00
|
|
|
if (m->location.empty()) {
|
|
|
|
is_media_empty = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::move(m);
|
|
|
|
}
|
|
|
|
case secret_api::decryptedMessageMediaVenue::ID: {
|
2022-07-01 14:04:11 +02:00
|
|
|
auto media = move_tl_object_as<secret_api::decryptedMessageMediaVenue>(media_ptr);
|
2018-09-28 22:57:34 +02:00
|
|
|
|
2022-07-01 14:04:11 +02:00
|
|
|
if (!clean_input_string(media->title_)) {
|
|
|
|
media->title_.clear();
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
2022-07-01 14:04:11 +02:00
|
|
|
if (!clean_input_string(media->address_)) {
|
|
|
|
media->address_.clear();
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
2022-07-01 14:04:11 +02:00
|
|
|
if (!clean_input_string(media->provider_)) {
|
|
|
|
media->provider_.clear();
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
2022-07-01 14:04:11 +02:00
|
|
|
if (!clean_input_string(media->venue_id_)) {
|
|
|
|
media->venue_id_.clear();
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
|
2023-06-28 18:01:00 +02:00
|
|
|
auto m = make_unique<MessageVenue>(Venue(Location(td, media->lat_, media->long_, 0.0, 0),
|
|
|
|
std::move(media->title_), std::move(media->address_),
|
|
|
|
std::move(media->provider_), std::move(media->venue_id_), string()));
|
2018-09-28 22:57:34 +02:00
|
|
|
if (m->venue.empty()) {
|
|
|
|
is_media_empty = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::move(m);
|
|
|
|
}
|
|
|
|
case secret_api::decryptedMessageMediaContact::ID: {
|
2022-07-01 14:04:11 +02:00
|
|
|
auto media = move_tl_object_as<secret_api::decryptedMessageMediaContact>(media_ptr);
|
|
|
|
if (!clean_input_string(media->phone_number_)) {
|
|
|
|
media->phone_number_.clear();
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
2022-07-01 14:04:11 +02:00
|
|
|
if (!clean_input_string(media->first_name_)) {
|
|
|
|
media->first_name_.clear();
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
2022-07-01 14:04:11 +02:00
|
|
|
if (!clean_input_string(media->last_name_)) {
|
|
|
|
media->last_name_.clear();
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
2022-07-01 14:04:11 +02:00
|
|
|
return make_unique<MessageContact>(Contact(std::move(media->phone_number_), std::move(media->first_name_),
|
|
|
|
std::move(media->last_name_), string(), UserId()));
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case secret_api::decryptedMessageMediaWebPage::ID: {
|
2022-07-01 14:04:11 +02:00
|
|
|
auto media = move_tl_object_as<secret_api::decryptedMessageMediaWebPage>(media_ptr);
|
|
|
|
if (!clean_input_string(media->url_)) {
|
|
|
|
media->url_.clear();
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
2022-07-01 14:04:11 +02:00
|
|
|
auto r_http_url = parse_url(media->url_);
|
2018-09-28 22:57:34 +02:00
|
|
|
if (r_http_url.is_error()) {
|
|
|
|
is_media_empty = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
auto url = r_http_url.ok().get_url();
|
|
|
|
|
2023-10-16 21:33:53 +02:00
|
|
|
auto result = td::make_unique<MessageText>(FormattedText{std::move(message_text), std::move(entities)},
|
2023-10-19 12:03:27 +02:00
|
|
|
WebPageId(), false, false, false, url);
|
2021-10-07 11:49:46 +02:00
|
|
|
td->web_pages_manager_->get_web_page_by_url(
|
|
|
|
url,
|
|
|
|
PromiseCreator::lambda([&web_page_id = result->web_page_id, promise = load_data_multipromise.get_promise()](
|
|
|
|
Result<WebPageId> r_web_page_id) mutable {
|
|
|
|
if (r_web_page_id.is_ok()) {
|
|
|
|
web_page_id = r_web_page_id.move_as_ok();
|
|
|
|
}
|
|
|
|
promise.set_value(Unit());
|
|
|
|
}));
|
2018-09-28 22:57:34 +02:00
|
|
|
return std::move(result);
|
|
|
|
}
|
|
|
|
case secret_api::decryptedMessageMediaExternalDocument::ID: {
|
2022-07-01 14:04:11 +02:00
|
|
|
auto media = move_tl_object_as<secret_api::decryptedMessageMediaExternalDocument>(media_ptr);
|
|
|
|
return get_document_message_content(td, secret_to_telegram_document(*media), owner_dialog_id,
|
2022-06-03 16:31:48 +02:00
|
|
|
FormattedText{std::move(message_text), std::move(entities)}, false,
|
2022-12-20 16:06:21 +01:00
|
|
|
is_premium, false, &load_data_multipromise);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
2021-10-21 11:51:16 +02:00
|
|
|
default:
|
|
|
|
break;
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
if (file == nullptr && !is_media_empty) {
|
2023-02-26 11:08:03 +01:00
|
|
|
LOG(ERROR) << "Receive secret message with media, but without a file";
|
2018-09-28 22:57:34 +02:00
|
|
|
is_media_empty = true;
|
|
|
|
}
|
|
|
|
if (is_media_empty) {
|
2023-10-19 12:03:27 +02:00
|
|
|
return create_text_message_content(std::move(message_text), std::move(entities), WebPageId(), false, false, false,
|
2023-10-16 21:33:53 +02:00
|
|
|
string());
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
switch (constructor_id) {
|
|
|
|
case secret_api::decryptedMessageMediaPhoto::ID: {
|
2022-07-01 14:04:11 +02:00
|
|
|
auto media = move_tl_object_as<secret_api::decryptedMessageMediaPhoto>(media_ptr);
|
2018-09-28 22:57:34 +02:00
|
|
|
return make_unique<MessagePhoto>(
|
2022-07-01 14:04:11 +02:00
|
|
|
get_encrypted_file_photo(td->file_manager_.get(), std::move(file), std::move(media), owner_dialog_id),
|
2022-12-20 16:06:21 +01:00
|
|
|
FormattedText{std::move(message_text), std::move(entities)}, false);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case secret_api::decryptedMessageMediaDocument::ID: {
|
2022-07-01 14:04:11 +02:00
|
|
|
auto media = move_tl_object_as<secret_api::decryptedMessageMediaDocument>(media_ptr);
|
|
|
|
if (!clean_input_string(media->mime_type_)) {
|
|
|
|
media->mime_type_.clear();
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
2022-07-01 14:04:11 +02:00
|
|
|
auto attributes = secret_to_telegram(media->attributes_);
|
2020-05-05 18:41:01 +02:00
|
|
|
for (auto &attribute : attributes) {
|
|
|
|
CHECK(attribute != nullptr);
|
|
|
|
if (attribute->get_id() == telegram_api::documentAttributeSticker::ID) {
|
|
|
|
auto attribute_sticker = static_cast<telegram_api::documentAttributeSticker *>(attribute.get());
|
|
|
|
CHECK(attribute_sticker->stickerset_ != nullptr);
|
|
|
|
if (attribute_sticker->stickerset_->get_id() != telegram_api::inputStickerSetEmpty::ID) {
|
|
|
|
attribute_sticker->stickerset_ = make_tl_object<telegram_api::inputStickerSetEmpty>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-01 14:04:11 +02:00
|
|
|
media->attributes_.clear();
|
2020-02-24 22:30:47 +01:00
|
|
|
auto document = td->documents_manager_->on_get_document(
|
2022-07-01 14:04:11 +02:00
|
|
|
{std::move(file), std::move(media), std::move(attributes)}, owner_dialog_id);
|
2022-06-03 15:33:49 +02:00
|
|
|
return get_document_message_content(std::move(document), {std::move(message_text), std::move(entities)}, false,
|
2022-12-20 16:06:21 +01:00
|
|
|
false, false);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
default:
|
2022-07-01 14:04:11 +02:00
|
|
|
LOG(ERROR) << "Unsupported: " << to_string(media_ptr);
|
2018-09-28 22:57:34 +02:00
|
|
|
return make_unique<MessageUnsupported>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unique_ptr<MessageContent> get_message_content(Td *td, FormattedText message,
|
2022-07-01 14:04:11 +02:00
|
|
|
tl_object_ptr<telegram_api::MessageMedia> &&media_ptr,
|
2018-09-28 22:57:34 +02:00
|
|
|
DialogId owner_dialog_id, bool is_content_read, UserId via_bot_user_id,
|
2022-08-01 13:45:44 +02:00
|
|
|
int32 *ttl, bool *disable_web_page_preview, const char *source) {
|
2022-07-01 14:04:11 +02:00
|
|
|
if (!td->auth_manager_->was_authorized() && !G()->close_flag() && media_ptr != nullptr &&
|
|
|
|
media_ptr->get_id() != telegram_api::messageMediaEmpty::ID) {
|
2022-08-01 13:45:44 +02:00
|
|
|
LOG(ERROR) << "Receive without authorization from " << source << ": " << to_string(media_ptr);
|
2022-07-01 14:04:11 +02:00
|
|
|
media_ptr = nullptr;
|
2020-03-30 00:48:44 +02:00
|
|
|
}
|
2021-11-03 22:21:27 +01:00
|
|
|
if (disable_web_page_preview != nullptr) {
|
|
|
|
*disable_web_page_preview = false;
|
|
|
|
}
|
2020-03-30 00:48:44 +02:00
|
|
|
|
2022-07-01 14:04:11 +02:00
|
|
|
int32 constructor_id = media_ptr == nullptr ? telegram_api::messageMediaEmpty::ID : media_ptr->get_id();
|
2018-09-28 22:57:34 +02:00
|
|
|
switch (constructor_id) {
|
|
|
|
case telegram_api::messageMediaEmpty::ID:
|
2020-02-24 22:06:29 +01:00
|
|
|
if (message.text.empty()) {
|
2022-08-01 13:45:44 +02:00
|
|
|
LOG(ERROR) << "Receive empty message text and media from " << source;
|
2020-02-24 22:06:29 +01:00
|
|
|
}
|
2021-11-03 22:21:27 +01:00
|
|
|
if (disable_web_page_preview != nullptr) {
|
|
|
|
*disable_web_page_preview = true;
|
|
|
|
}
|
2023-10-19 12:03:27 +02:00
|
|
|
return td::make_unique<MessageText>(std::move(message), WebPageId(), false, false, false, string());
|
2018-09-28 22:57:34 +02:00
|
|
|
case telegram_api::messageMediaPhoto::ID: {
|
2022-07-01 14:04:11 +02:00
|
|
|
auto media = move_tl_object_as<telegram_api::messageMediaPhoto>(media_ptr);
|
|
|
|
if (media->photo_ == nullptr) {
|
|
|
|
if ((media->flags_ & telegram_api::messageMediaPhoto::TTL_SECONDS_MASK) == 0) {
|
2022-12-28 19:59:41 +01:00
|
|
|
LOG(ERROR) << "Receive messageMediaPhoto without photo and self-destruct timer from " << source << ": "
|
2022-08-01 13:45:44 +02:00
|
|
|
<< oneline(to_string(media));
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return make_unique<MessageExpiredPhoto>();
|
|
|
|
}
|
|
|
|
|
2023-01-20 15:31:33 +01:00
|
|
|
auto photo = get_photo(td, std::move(media->photo_), owner_dialog_id);
|
2020-06-23 20:04:26 +02:00
|
|
|
if (photo.is_empty()) {
|
2018-09-28 22:57:34 +02:00
|
|
|
return make_unique<MessageExpiredPhoto>();
|
|
|
|
}
|
|
|
|
|
2022-07-01 14:04:11 +02:00
|
|
|
if (ttl != nullptr && (media->flags_ & telegram_api::messageMediaPhoto::TTL_SECONDS_MASK) != 0) {
|
|
|
|
*ttl = media->ttl_seconds_;
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
2022-12-20 16:06:21 +01:00
|
|
|
return make_unique<MessagePhoto>(std::move(photo), std::move(message), media->spoiler_);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
2020-03-14 17:56:39 +01:00
|
|
|
case telegram_api::messageMediaDice::ID: {
|
2022-07-01 14:04:11 +02:00
|
|
|
auto media = move_tl_object_as<telegram_api::messageMediaDice>(media_ptr);
|
2020-03-14 17:56:39 +01:00
|
|
|
|
2022-07-01 14:04:11 +02:00
|
|
|
auto m = td::make_unique<MessageDice>(media->emoticon_, media->value_);
|
2020-04-19 08:47:37 +02:00
|
|
|
if (!m->is_valid()) {
|
2020-03-14 17:56:39 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::move(m);
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
case telegram_api::messageMediaGeo::ID: {
|
2022-07-01 14:04:11 +02:00
|
|
|
auto media = move_tl_object_as<telegram_api::messageMediaGeo>(media_ptr);
|
2018-09-28 22:57:34 +02:00
|
|
|
|
2023-06-28 18:01:00 +02:00
|
|
|
auto m = make_unique<MessageLocation>(Location(td, media->geo_));
|
2018-09-28 22:57:34 +02:00
|
|
|
if (m->location.empty()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::move(m);
|
|
|
|
}
|
|
|
|
case telegram_api::messageMediaGeoLive::ID: {
|
2022-07-01 14:04:11 +02:00
|
|
|
auto media = move_tl_object_as<telegram_api::messageMediaGeoLive>(media_ptr);
|
2023-06-28 18:01:00 +02:00
|
|
|
auto location = Location(td, media->geo_);
|
2018-09-28 22:57:34 +02:00
|
|
|
if (location.empty()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-07-01 14:04:11 +02:00
|
|
|
int32 period = media->period_;
|
2018-09-28 22:57:34 +02:00
|
|
|
if (period <= 0) {
|
2022-08-01 13:45:44 +02:00
|
|
|
LOG(ERROR) << "Receive wrong live location period = " << period << " from " << source;
|
2018-09-28 22:57:34 +02:00
|
|
|
return make_unique<MessageLocation>(std::move(location));
|
|
|
|
}
|
2022-07-01 14:04:11 +02:00
|
|
|
return make_unique<MessageLiveLocation>(std::move(location), period, media->heading_,
|
|
|
|
media->proximity_notification_radius_);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case telegram_api::messageMediaVenue::ID: {
|
2022-07-01 14:04:11 +02:00
|
|
|
auto media = move_tl_object_as<telegram_api::messageMediaVenue>(media_ptr);
|
2023-06-28 18:01:00 +02:00
|
|
|
auto m = make_unique<MessageVenue>(Venue(td, media->geo_, std::move(media->title_), std::move(media->address_),
|
2022-07-01 14:04:11 +02:00
|
|
|
std::move(media->provider_), std::move(media->venue_id_),
|
|
|
|
std::move(media->venue_type_)));
|
2018-09-28 22:57:34 +02:00
|
|
|
if (m->venue.empty()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::move(m);
|
|
|
|
}
|
|
|
|
case telegram_api::messageMediaContact::ID: {
|
2022-07-01 14:04:11 +02:00
|
|
|
auto media = move_tl_object_as<telegram_api::messageMediaContact>(media_ptr);
|
|
|
|
if (media->user_id_ != 0) {
|
|
|
|
td->contacts_manager_->get_user_id_object(UserId(media->user_id_),
|
2020-11-24 15:29:09 +01:00
|
|
|
"MessageMediaContact"); // to ensure updateUser
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
2022-07-01 14:04:11 +02:00
|
|
|
return make_unique<MessageContact>(Contact(std::move(media->phone_number_), std::move(media->first_name_),
|
|
|
|
std::move(media->last_name_), std::move(media->vcard_),
|
|
|
|
UserId(media->user_id_)));
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case telegram_api::messageMediaDocument::ID: {
|
2022-07-01 14:04:11 +02:00
|
|
|
auto media = move_tl_object_as<telegram_api::messageMediaDocument>(media_ptr);
|
|
|
|
if (media->document_ == nullptr) {
|
|
|
|
if ((media->flags_ & telegram_api::messageMediaDocument::TTL_SECONDS_MASK) == 0) {
|
2022-12-28 19:59:41 +01:00
|
|
|
LOG(ERROR) << "Receive messageMediaDocument without document and self-destruct timer from " << source << ": "
|
2022-08-01 13:45:44 +02:00
|
|
|
<< oneline(to_string(media));
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return make_unique<MessageExpiredVideo>();
|
|
|
|
}
|
|
|
|
|
2022-07-01 14:04:11 +02:00
|
|
|
auto document_ptr = std::move(media->document_);
|
2018-09-28 22:57:34 +02:00
|
|
|
int32 document_id = document_ptr->get_id();
|
|
|
|
if (document_id == telegram_api::documentEmpty::ID) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
CHECK(document_id == telegram_api::document::ID);
|
|
|
|
|
2022-07-01 14:04:11 +02:00
|
|
|
if (ttl != nullptr && (media->flags_ & telegram_api::messageMediaDocument::TTL_SECONDS_MASK) != 0) {
|
|
|
|
*ttl = media->ttl_seconds_;
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
return get_document_message_content(td, move_tl_object_as<telegram_api::document>(document_ptr), owner_dialog_id,
|
2022-12-20 16:06:21 +01:00
|
|
|
std::move(message), is_content_read, !media->nopremium_, media->spoiler_,
|
|
|
|
nullptr);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case telegram_api::messageMediaGame::ID: {
|
2022-07-01 14:04:11 +02:00
|
|
|
auto media = move_tl_object_as<telegram_api::messageMediaGame>(media_ptr);
|
2018-09-28 22:57:34 +02:00
|
|
|
|
2022-09-22 00:46:12 +02:00
|
|
|
auto m = make_unique<MessageGame>(
|
|
|
|
Game(td, via_bot_user_id, std::move(media->game_), std::move(message), owner_dialog_id));
|
2021-09-02 15:35:56 +02:00
|
|
|
if (m->game.is_empty()) {
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return std::move(m);
|
|
|
|
}
|
2021-03-31 00:20:40 +02:00
|
|
|
case telegram_api::messageMediaInvoice::ID:
|
2022-09-23 11:52:54 +02:00
|
|
|
return td::make_unique<MessageInvoice>(InputInvoice(
|
2022-09-22 00:46:12 +02:00
|
|
|
move_tl_object_as<telegram_api::messageMediaInvoice>(media_ptr), td, owner_dialog_id, std::move(message)));
|
2018-09-28 22:57:34 +02:00
|
|
|
case telegram_api::messageMediaWebPage::ID: {
|
2022-07-01 14:04:11 +02:00
|
|
|
auto media = move_tl_object_as<telegram_api::messageMediaWebPage>(media_ptr);
|
2021-11-03 22:21:27 +01:00
|
|
|
if (disable_web_page_preview != nullptr) {
|
2022-07-01 14:04:11 +02:00
|
|
|
*disable_web_page_preview = (media->webpage_ == nullptr);
|
2021-11-03 22:21:27 +01:00
|
|
|
}
|
2023-10-16 21:33:53 +02:00
|
|
|
string web_page_url;
|
|
|
|
if (media->manual_) {
|
|
|
|
web_page_url = WebPagesManager::get_web_page_url(media->webpage_);
|
2023-10-16 22:09:17 +02:00
|
|
|
if (web_page_url.empty()) {
|
|
|
|
LOG(ERROR) << "Have no URL in manual link preview";
|
|
|
|
}
|
2023-10-16 21:33:53 +02:00
|
|
|
}
|
2022-07-01 14:04:11 +02:00
|
|
|
auto web_page_id = td->web_pages_manager_->on_get_web_page(std::move(media->webpage_), owner_dialog_id);
|
2023-10-16 21:33:53 +02:00
|
|
|
return td::make_unique<MessageText>(std::move(message), web_page_id, media->force_small_media_,
|
2023-10-19 12:03:27 +02:00
|
|
|
media->force_large_media_, media->safe_, std::move(web_page_url));
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
2019-02-19 14:45:32 +01:00
|
|
|
case telegram_api::messageMediaPoll::ID: {
|
2022-07-01 14:04:11 +02:00
|
|
|
auto media = move_tl_object_as<telegram_api::messageMediaPoll>(media_ptr);
|
2022-08-01 13:45:44 +02:00
|
|
|
auto poll_id =
|
|
|
|
td->poll_manager_->on_get_poll(PollId(), std::move(media->poll_), std::move(media->results_), source);
|
2019-02-19 14:45:32 +01:00
|
|
|
if (!poll_id.is_valid()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return make_unique<MessagePoll>(poll_id);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
2023-06-12 18:23:58 +02:00
|
|
|
case telegram_api::messageMediaStory::ID: {
|
|
|
|
auto media = move_tl_object_as<telegram_api::messageMediaStory>(media_ptr);
|
2023-08-15 21:45:37 +02:00
|
|
|
auto dialog_id = DialogId(media->peer_);
|
2023-06-12 18:23:58 +02:00
|
|
|
auto story_id = StoryId(media->id_);
|
2023-07-23 00:41:59 +02:00
|
|
|
auto story_full_id = StoryFullId(dialog_id, story_id);
|
2023-08-10 19:22:12 +02:00
|
|
|
if (!story_full_id.is_server()) {
|
2023-06-12 18:23:58 +02:00
|
|
|
LOG(ERROR) << "Receive " << to_string(media);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (media->story_ != nullptr) {
|
|
|
|
auto actual_story_id = td->story_manager_->on_get_story(dialog_id, std::move(media->story_));
|
|
|
|
if (story_id != actual_story_id) {
|
|
|
|
LOG(ERROR) << "Receive " << actual_story_id << " instead of " << story_id;
|
|
|
|
}
|
|
|
|
}
|
2023-07-10 15:39:49 +02:00
|
|
|
td->messages_manager_->force_create_dialog(dialog_id, "messageMediaStory");
|
2023-06-12 18:23:58 +02:00
|
|
|
return make_unique<MessageStory>(story_full_id, media->via_mention_);
|
|
|
|
}
|
2023-09-29 23:32:39 +02:00
|
|
|
case telegram_api::messageMediaGiveaway::ID: {
|
|
|
|
auto media = move_tl_object_as<telegram_api::messageMediaGiveaway>(media_ptr);
|
|
|
|
vector<ChannelId> channel_ids;
|
|
|
|
for (auto channel : media->channels_) {
|
|
|
|
ChannelId channel_id(channel);
|
|
|
|
if (channel_id.is_valid()) {
|
|
|
|
channel_ids.push_back(channel_id);
|
|
|
|
td->messages_manager_->force_create_dialog(DialogId(channel_id), "messageMediaGiveaway", true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (channel_ids.empty() || media->quantity_ <= 0 || media->months_ <= 0 || media->until_date_ < 0) {
|
|
|
|
LOG(ERROR) << "Receive " << to_string(media);
|
|
|
|
break;
|
|
|
|
}
|
2023-10-12 16:05:03 +02:00
|
|
|
auto boosted_channel_id = channel_ids[0];
|
|
|
|
channel_ids.erase(channel_ids.begin());
|
2023-10-12 17:58:40 +02:00
|
|
|
return td::make_unique<MessageGiveaway>(
|
|
|
|
GiveawayParameters{boosted_channel_id, std::move(channel_ids), media->only_new_subscribers_,
|
|
|
|
media->until_date_, std::move(media->countries_iso2_)},
|
|
|
|
media->quantity_, media->months_);
|
2023-09-29 23:32:39 +02:00
|
|
|
}
|
2019-02-19 14:45:32 +01:00
|
|
|
case telegram_api::messageMediaUnsupported::ID:
|
|
|
|
return make_unique<MessageUnsupported>();
|
2018-09-28 22:57:34 +02:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
// explicit empty media message
|
2021-11-03 22:21:27 +01:00
|
|
|
if (disable_web_page_preview != nullptr) {
|
|
|
|
*disable_web_page_preview = true;
|
|
|
|
}
|
2023-10-19 12:03:27 +02:00
|
|
|
return td::make_unique<MessageText>(std::move(message), WebPageId(), false, false, false, string());
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const MessageContent *content,
|
2020-08-09 13:18:08 +02:00
|
|
|
MessageContentDupType type, MessageCopyOptions &©_options) {
|
2018-09-28 22:57:34 +02:00
|
|
|
CHECK(content != nullptr);
|
2020-08-09 13:18:08 +02:00
|
|
|
if (copy_options.send_copy) {
|
2022-05-08 22:54:04 +02:00
|
|
|
CHECK(type == MessageContentDupType::Copy || type == MessageContentDupType::ServerCopy);
|
2020-08-09 13:18:08 +02:00
|
|
|
}
|
2020-01-16 04:10:08 +01:00
|
|
|
if (type != MessageContentDupType::Forward && type != MessageContentDupType::SendViaBot &&
|
2022-05-08 22:54:04 +02:00
|
|
|
!can_have_input_media(td, content, type == MessageContentDupType::ServerCopy)) {
|
2020-01-16 04:10:08 +01:00
|
|
|
return nullptr;
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
|
|
|
|
bool to_secret = dialog_id.get_type() == DialogType::SecretChat;
|
|
|
|
auto fix_file_id = [dialog_id, to_secret, file_manager = td->file_manager_.get()](FileId file_id) {
|
|
|
|
auto file_view = file_manager->get_file_view(file_id);
|
|
|
|
if (to_secret && !file_view.is_encrypted_secret()) {
|
2023-05-24 14:28:40 +02:00
|
|
|
file_id = file_manager->copy_file_id(file_id, FileType::Encrypted, dialog_id, "copy message content to secret");
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
2022-11-21 09:40:43 +01:00
|
|
|
return file_manager->dup_file_id(file_id, "dup_message_content");
|
2018-09-28 22:57:34 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
FileId thumbnail_file_id;
|
|
|
|
if (to_secret) {
|
|
|
|
thumbnail_file_id = get_message_content_thumbnail_file_id(content, td);
|
|
|
|
}
|
2022-05-08 22:54:04 +02:00
|
|
|
auto replace_caption = (type == MessageContentDupType::Copy || type == MessageContentDupType::ServerCopy) &&
|
|
|
|
copy_options.replace_caption;
|
2018-09-28 22:57:34 +02:00
|
|
|
switch (content->get_type()) {
|
|
|
|
case MessageContentType::Animation: {
|
|
|
|
auto result = make_unique<MessageAnimation>(*static_cast<const MessageAnimation *>(content));
|
2020-08-11 09:35:19 +02:00
|
|
|
if (replace_caption) {
|
|
|
|
result->caption = std::move(copy_options.new_caption);
|
2019-08-09 16:41:26 +02:00
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
if (td->documents_manager_->has_input_media(result->file_id, thumbnail_file_id, to_secret)) {
|
|
|
|
return std::move(result);
|
|
|
|
}
|
|
|
|
result->file_id = td->animations_manager_->dup_animation(fix_file_id(result->file_id), result->file_id);
|
|
|
|
CHECK(result->file_id.is_valid());
|
|
|
|
return std::move(result);
|
|
|
|
}
|
|
|
|
case MessageContentType::Audio: {
|
|
|
|
auto result = make_unique<MessageAudio>(*static_cast<const MessageAudio *>(content));
|
2020-08-11 09:35:19 +02:00
|
|
|
if (replace_caption) {
|
|
|
|
result->caption = std::move(copy_options.new_caption);
|
2019-08-09 16:41:26 +02:00
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
if (td->documents_manager_->has_input_media(result->file_id, thumbnail_file_id, to_secret)) {
|
|
|
|
return std::move(result);
|
|
|
|
}
|
|
|
|
result->file_id = td->audios_manager_->dup_audio(fix_file_id(result->file_id), result->file_id);
|
|
|
|
CHECK(result->file_id.is_valid());
|
|
|
|
return std::move(result);
|
|
|
|
}
|
|
|
|
case MessageContentType::Contact:
|
|
|
|
return make_unique<MessageContact>(*static_cast<const MessageContact *>(content));
|
2020-04-18 07:45:41 +02:00
|
|
|
case MessageContentType::Dice: {
|
|
|
|
auto result = td::make_unique<MessageDice>(*static_cast<const MessageDice *>(content));
|
2020-03-14 17:56:39 +01:00
|
|
|
if (type != MessageContentDupType::Forward) {
|
2020-04-18 07:45:41 +02:00
|
|
|
result->dice_value = 0;
|
2020-03-14 17:56:39 +01:00
|
|
|
}
|
2020-04-18 07:45:41 +02:00
|
|
|
return std::move(result);
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::Document: {
|
|
|
|
auto result = make_unique<MessageDocument>(*static_cast<const MessageDocument *>(content));
|
2020-08-11 09:35:19 +02:00
|
|
|
if (replace_caption) {
|
|
|
|
result->caption = std::move(copy_options.new_caption);
|
2019-08-09 16:41:26 +02:00
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
if (td->documents_manager_->has_input_media(result->file_id, thumbnail_file_id, to_secret)) {
|
|
|
|
return std::move(result);
|
|
|
|
}
|
|
|
|
result->file_id = td->documents_manager_->dup_document(fix_file_id(result->file_id), result->file_id);
|
|
|
|
CHECK(result->file_id.is_valid());
|
|
|
|
return std::move(result);
|
|
|
|
}
|
2020-01-16 04:10:08 +01:00
|
|
|
case MessageContentType::Game:
|
|
|
|
return make_unique<MessageGame>(*static_cast<const MessageGame *>(content));
|
2023-10-13 11:47:34 +02:00
|
|
|
case MessageContentType::Giveaway:
|
2023-10-14 21:04:47 +02:00
|
|
|
if (type != MessageContentDupType::Forward) {
|
2023-10-13 11:47:34 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return make_unique<MessageGiveaway>(*static_cast<const MessageGiveaway *>(content));
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::Invoice:
|
2021-04-13 16:29:49 +02:00
|
|
|
if (type == MessageContentDupType::Copy) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
return make_unique<MessageInvoice>(*static_cast<const MessageInvoice *>(content));
|
|
|
|
case MessageContentType::LiveLocation:
|
2020-01-15 00:44:24 +01:00
|
|
|
if (!to_secret && (type == MessageContentDupType::Send || type == MessageContentDupType::SendViaBot)) {
|
2018-09-28 22:57:34 +02:00
|
|
|
return make_unique<MessageLiveLocation>(*static_cast<const MessageLiveLocation *>(content));
|
2020-01-15 00:44:24 +01:00
|
|
|
} else {
|
|
|
|
return make_unique<MessageLocation>(Location(static_cast<const MessageLiveLocation *>(content)->location));
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case MessageContentType::Location:
|
|
|
|
return make_unique<MessageLocation>(*static_cast<const MessageLocation *>(content));
|
|
|
|
case MessageContentType::Photo: {
|
|
|
|
auto result = make_unique<MessagePhoto>(*static_cast<const MessagePhoto *>(content));
|
2020-08-11 09:35:19 +02:00
|
|
|
if (replace_caption) {
|
|
|
|
result->caption = std::move(copy_options.new_caption);
|
2019-08-09 16:41:26 +02:00
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
|
2019-09-02 02:51:41 +02:00
|
|
|
CHECK(!result->photo.photos.empty());
|
|
|
|
if ((result->photo.photos.size() > 2 || result->photo.photos.back().type != 'i') && !to_secret) {
|
2018-09-28 22:57:34 +02:00
|
|
|
// already sent photo
|
2020-05-07 14:43:53 +02:00
|
|
|
// having remote location is not enough to have InputMedia, because the file may not have valid file_reference
|
|
|
|
// also file_id needs to be duped, because upload can be called to repair the file_reference and every upload
|
|
|
|
// request must have unique file_id
|
|
|
|
if (!td->auth_manager_->is_bot()) {
|
|
|
|
result->photo.photos.back().file_id = fix_file_id(result->photo.photos.back().file_id);
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
return std::move(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find 'i' or largest
|
|
|
|
PhotoSize photo;
|
|
|
|
for (const auto &size : result->photo.photos) {
|
|
|
|
if (size.type == 'i') {
|
|
|
|
photo = size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (photo.type == 0) {
|
|
|
|
for (const auto &size : result->photo.photos) {
|
|
|
|
if (photo.type == 0 || photo < size) {
|
|
|
|
photo = size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find 't' or smallest
|
|
|
|
PhotoSize thumbnail;
|
|
|
|
for (const auto &size : result->photo.photos) {
|
|
|
|
if (size.type == 't') {
|
|
|
|
thumbnail = size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (thumbnail.type == 0) {
|
|
|
|
for (const auto &size : result->photo.photos) {
|
|
|
|
if (size.type != photo.type && (thumbnail.type == 0 || size < thumbnail)) {
|
|
|
|
thumbnail = size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result->photo.photos.clear();
|
2023-07-05 14:40:08 +02:00
|
|
|
result->photo.animations.clear();
|
|
|
|
result->photo.sticker_photo_size = nullptr;
|
|
|
|
|
2021-10-17 12:07:20 +02:00
|
|
|
bool has_thumbnail = thumbnail.type != 0;
|
|
|
|
if (has_thumbnail) {
|
2018-09-28 22:57:34 +02:00
|
|
|
thumbnail.type = 't';
|
|
|
|
result->photo.photos.push_back(std::move(thumbnail));
|
|
|
|
}
|
|
|
|
photo.type = 'i';
|
|
|
|
result->photo.photos.push_back(std::move(photo));
|
|
|
|
|
2020-05-03 14:44:33 +02:00
|
|
|
if (photo_has_input_media(td->file_manager_.get(), result->photo, to_secret, td->auth_manager_->is_bot())) {
|
2018-09-28 22:57:34 +02:00
|
|
|
return std::move(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
result->photo.photos.back().file_id = fix_file_id(result->photo.photos.back().file_id);
|
2021-10-17 12:07:20 +02:00
|
|
|
if (has_thumbnail) {
|
2022-11-21 09:40:43 +01:00
|
|
|
result->photo.photos[0].file_id =
|
|
|
|
td->file_manager_->dup_file_id(result->photo.photos[0].file_id, "dup_message_content photo");
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
return std::move(result);
|
|
|
|
}
|
2020-01-16 04:10:08 +01:00
|
|
|
case MessageContentType::Poll:
|
2022-05-08 22:54:04 +02:00
|
|
|
if (type == MessageContentDupType::Copy || type == MessageContentDupType::ServerCopy) {
|
2021-09-05 22:11:25 +02:00
|
|
|
return make_unique<MessagePoll>(
|
|
|
|
td->poll_manager_->dup_poll(static_cast<const MessagePoll *>(content)->poll_id));
|
|
|
|
} else {
|
|
|
|
return make_unique<MessagePoll>(*static_cast<const MessagePoll *>(content));
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::Sticker: {
|
|
|
|
auto result = make_unique<MessageSticker>(*static_cast<const MessageSticker *>(content));
|
2022-08-18 16:00:18 +02:00
|
|
|
result->is_premium = td->option_manager_->get_option_boolean("is_premium");
|
2018-09-28 22:57:34 +02:00
|
|
|
if (td->stickers_manager_->has_input_media(result->file_id, to_secret)) {
|
|
|
|
return std::move(result);
|
|
|
|
}
|
|
|
|
result->file_id = td->stickers_manager_->dup_sticker(fix_file_id(result->file_id), result->file_id);
|
|
|
|
CHECK(result->file_id.is_valid());
|
|
|
|
return std::move(result);
|
|
|
|
}
|
2023-06-12 18:23:58 +02:00
|
|
|
case MessageContentType::Story:
|
|
|
|
return make_unique<MessageStory>(static_cast<const MessageStory *>(content)->story_full_id, false);
|
2022-07-22 15:47:58 +02:00
|
|
|
case MessageContentType::Text: {
|
2023-10-16 21:33:53 +02:00
|
|
|
auto result = td::make_unique<MessageText>(*static_cast<const MessageText *>(content));
|
2022-07-22 15:47:58 +02:00
|
|
|
if (type == MessageContentDupType::Copy || type == MessageContentDupType::ServerCopy) {
|
2022-07-27 19:35:40 +02:00
|
|
|
remove_unallowed_entities(td, result->text, dialog_id);
|
2022-07-22 15:47:58 +02:00
|
|
|
}
|
2022-09-14 18:02:49 +02:00
|
|
|
return std::move(result);
|
2022-07-22 15:47:58 +02:00
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::Venue:
|
|
|
|
return make_unique<MessageVenue>(*static_cast<const MessageVenue *>(content));
|
|
|
|
case MessageContentType::Video: {
|
|
|
|
auto result = make_unique<MessageVideo>(*static_cast<const MessageVideo *>(content));
|
2020-08-11 09:35:19 +02:00
|
|
|
if (replace_caption) {
|
|
|
|
result->caption = std::move(copy_options.new_caption);
|
2019-08-09 16:41:26 +02:00
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
if (td->documents_manager_->has_input_media(result->file_id, thumbnail_file_id, to_secret)) {
|
|
|
|
return std::move(result);
|
|
|
|
}
|
|
|
|
result->file_id = td->videos_manager_->dup_video(fix_file_id(result->file_id), result->file_id);
|
|
|
|
CHECK(result->file_id.is_valid());
|
|
|
|
return std::move(result);
|
|
|
|
}
|
|
|
|
case MessageContentType::VideoNote: {
|
|
|
|
auto result = make_unique<MessageVideoNote>(*static_cast<const MessageVideoNote *>(content));
|
|
|
|
result->is_viewed = false;
|
|
|
|
if (td->documents_manager_->has_input_media(result->file_id, thumbnail_file_id, to_secret)) {
|
|
|
|
return std::move(result);
|
|
|
|
}
|
|
|
|
result->file_id = td->video_notes_manager_->dup_video_note(fix_file_id(result->file_id), result->file_id);
|
|
|
|
CHECK(result->file_id.is_valid());
|
|
|
|
return std::move(result);
|
|
|
|
}
|
|
|
|
case MessageContentType::VoiceNote: {
|
|
|
|
auto result = make_unique<MessageVoiceNote>(*static_cast<const MessageVoiceNote *>(content));
|
2020-08-11 09:35:19 +02:00
|
|
|
if (replace_caption) {
|
|
|
|
result->caption = std::move(copy_options.new_caption);
|
2019-08-09 16:41:26 +02:00
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
result->is_listened = false;
|
|
|
|
if (td->documents_manager_->has_input_media(result->file_id, thumbnail_file_id, to_secret)) {
|
|
|
|
return std::move(result);
|
|
|
|
}
|
|
|
|
result->file_id = td->voice_notes_manager_->dup_voice_note(fix_file_id(result->file_id), result->file_id);
|
|
|
|
CHECK(result->file_id.is_valid());
|
|
|
|
return std::move(result);
|
|
|
|
}
|
|
|
|
case MessageContentType::Unsupported:
|
|
|
|
case MessageContentType::ChatCreate:
|
|
|
|
case MessageContentType::ChatChangeTitle:
|
|
|
|
case MessageContentType::ChatChangePhoto:
|
|
|
|
case MessageContentType::ChatDeletePhoto:
|
|
|
|
case MessageContentType::ChatDeleteHistory:
|
|
|
|
case MessageContentType::ChatAddUsers:
|
|
|
|
case MessageContentType::ChatJoinedByLink:
|
|
|
|
case MessageContentType::ChatDeleteUser:
|
|
|
|
case MessageContentType::ChatMigrateTo:
|
|
|
|
case MessageContentType::ChannelCreate:
|
|
|
|
case MessageContentType::ChannelMigrateFrom:
|
|
|
|
case MessageContentType::PinMessage:
|
|
|
|
case MessageContentType::GameScore:
|
|
|
|
case MessageContentType::ScreenshotTaken:
|
|
|
|
case MessageContentType::ChatSetTtl:
|
|
|
|
case MessageContentType::Call:
|
|
|
|
case MessageContentType::PaymentSuccessful:
|
|
|
|
case MessageContentType::ContactRegistered:
|
|
|
|
case MessageContentType::ExpiredPhoto:
|
|
|
|
case MessageContentType::ExpiredVideo:
|
|
|
|
case MessageContentType::CustomServiceAction:
|
|
|
|
case MessageContentType::WebsiteConnected:
|
|
|
|
case MessageContentType::PassportDataSent:
|
|
|
|
case MessageContentType::PassportDataReceived:
|
2020-10-29 20:25:58 +01:00
|
|
|
case MessageContentType::ProximityAlertTriggered:
|
2020-11-24 12:33:16 +01:00
|
|
|
case MessageContentType::GroupCall:
|
|
|
|
case MessageContentType::InviteToGroupCall:
|
2021-08-18 15:03:10 +02:00
|
|
|
case MessageContentType::ChatSetTheme:
|
2022-03-28 09:01:39 +02:00
|
|
|
case MessageContentType::WebViewDataSent:
|
|
|
|
case MessageContentType::WebViewDataReceived:
|
2022-07-01 14:28:22 +02:00
|
|
|
case MessageContentType::GiftPremium:
|
2022-10-18 15:08:53 +02:00
|
|
|
case MessageContentType::TopicCreate:
|
2022-10-18 21:16:03 +02:00
|
|
|
case MessageContentType::TopicEdit:
|
2022-12-09 12:13:37 +01:00
|
|
|
case MessageContentType::SuggestProfilePhoto:
|
2022-12-14 19:13:48 +01:00
|
|
|
case MessageContentType::WriteAccessAllowed:
|
2023-01-10 14:20:30 +01:00
|
|
|
case MessageContentType::RequestedDialog:
|
2023-02-22 10:24:43 +01:00
|
|
|
case MessageContentType::WebViewWriteAccessAllowed:
|
2023-04-10 13:12:35 +02:00
|
|
|
case MessageContentType::SetBackground:
|
2023-08-25 15:53:50 +02:00
|
|
|
case MessageContentType::WriteAccessAllowedByRequest:
|
2023-09-29 16:55:03 +02:00
|
|
|
case MessageContentType::GiftCode:
|
2023-10-16 10:31:11 +02:00
|
|
|
case MessageContentType::GiveawayLaunch:
|
2018-09-28 22:57:34 +02:00
|
|
|
return nullptr;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
UNREACHABLE();
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-07-01 14:04:11 +02:00
|
|
|
unique_ptr<MessageContent> get_action_message_content(Td *td, tl_object_ptr<telegram_api::MessageAction> &&action_ptr,
|
2021-03-31 14:36:25 +02:00
|
|
|
DialogId owner_dialog_id, DialogId reply_in_dialog_id,
|
|
|
|
MessageId reply_to_message_id) {
|
2022-07-01 14:04:11 +02:00
|
|
|
CHECK(action_ptr != nullptr);
|
2018-09-28 22:57:34 +02:00
|
|
|
|
2022-07-01 14:04:11 +02:00
|
|
|
switch (action_ptr->get_id()) {
|
2018-09-28 22:57:34 +02:00
|
|
|
case telegram_api::messageActionEmpty::ID:
|
|
|
|
LOG(ERROR) << "Receive empty message action in " << owner_dialog_id;
|
|
|
|
break;
|
|
|
|
case telegram_api::messageActionChatCreate::ID: {
|
2022-07-01 14:04:11 +02:00
|
|
|
auto action = move_tl_object_as<telegram_api::messageActionChatCreate>(action_ptr);
|
2018-09-28 22:57:34 +02:00
|
|
|
|
|
|
|
vector<UserId> participant_user_ids;
|
2022-07-01 14:04:11 +02:00
|
|
|
participant_user_ids.reserve(action->users_.size());
|
|
|
|
for (auto &user : action->users_) {
|
2018-09-28 22:57:34 +02:00
|
|
|
UserId user_id(user);
|
|
|
|
if (user_id.is_valid()) {
|
|
|
|
participant_user_ids.push_back(user_id);
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Receive messageActionChatCreate with invalid " << user_id << " in " << owner_dialog_id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-01 14:04:11 +02:00
|
|
|
return td::make_unique<MessageChatCreate>(std::move(action->title_), std::move(participant_user_ids));
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case telegram_api::messageActionChatEditTitle::ID: {
|
2022-07-01 14:04:11 +02:00
|
|
|
auto action = move_tl_object_as<telegram_api::messageActionChatEditTitle>(action_ptr);
|
|
|
|
return td::make_unique<MessageChatChangeTitle>(std::move(action->title_));
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case telegram_api::messageActionChatEditPhoto::ID: {
|
2022-07-01 14:04:11 +02:00
|
|
|
auto action = move_tl_object_as<telegram_api::messageActionChatEditPhoto>(action_ptr);
|
2023-01-20 15:31:33 +01:00
|
|
|
auto photo = get_photo(td, std::move(action->photo_), owner_dialog_id);
|
2020-06-23 20:04:26 +02:00
|
|
|
if (photo.is_empty()) {
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
|
|
|
}
|
2019-06-17 01:41:57 +02:00
|
|
|
return make_unique<MessageChatChangePhoto>(std::move(photo));
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case telegram_api::messageActionChatDeletePhoto::ID: {
|
|
|
|
return make_unique<MessageChatDeletePhoto>();
|
|
|
|
}
|
|
|
|
case telegram_api::messageActionHistoryClear::ID: {
|
|
|
|
return make_unique<MessageChatDeleteHistory>();
|
|
|
|
}
|
|
|
|
case telegram_api::messageActionChatAddUser::ID: {
|
2022-07-01 14:04:11 +02:00
|
|
|
auto action = move_tl_object_as<telegram_api::messageActionChatAddUser>(action_ptr);
|
2018-09-28 22:57:34 +02:00
|
|
|
|
|
|
|
vector<UserId> user_ids;
|
2022-07-01 14:04:11 +02:00
|
|
|
user_ids.reserve(action->users_.size());
|
|
|
|
for (auto &user : action->users_) {
|
2018-09-28 22:57:34 +02:00
|
|
|
UserId user_id(user);
|
|
|
|
if (user_id.is_valid()) {
|
|
|
|
user_ids.push_back(user_id);
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Receive messageActionChatAddUser with invalid " << user_id << " in " << owner_dialog_id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return td::make_unique<MessageChatAddUsers>(std::move(user_ids));
|
|
|
|
}
|
|
|
|
case telegram_api::messageActionChatJoinedByLink::ID:
|
2021-10-09 14:04:17 +02:00
|
|
|
return make_unique<MessageChatJoinedByLink>(false);
|
2018-09-28 22:57:34 +02:00
|
|
|
case telegram_api::messageActionChatDeleteUser::ID: {
|
2022-07-01 14:04:11 +02:00
|
|
|
auto action = move_tl_object_as<telegram_api::messageActionChatDeleteUser>(action_ptr);
|
2018-09-28 22:57:34 +02:00
|
|
|
|
2022-07-01 14:04:11 +02:00
|
|
|
UserId user_id(action->user_id_);
|
2018-09-28 22:57:34 +02:00
|
|
|
if (!user_id.is_valid()) {
|
|
|
|
LOG(ERROR) << "Receive messageActionChatDeleteUser with invalid " << user_id << " in " << owner_dialog_id;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return make_unique<MessageChatDeleteUser>(user_id);
|
|
|
|
}
|
|
|
|
case telegram_api::messageActionChatMigrateTo::ID: {
|
2022-07-01 14:04:11 +02:00
|
|
|
auto action = move_tl_object_as<telegram_api::messageActionChatMigrateTo>(action_ptr);
|
2018-09-28 22:57:34 +02:00
|
|
|
|
2022-07-01 14:04:11 +02:00
|
|
|
ChannelId migrated_to_channel_id(action->channel_id_);
|
2018-09-28 22:57:34 +02:00
|
|
|
if (!migrated_to_channel_id.is_valid()) {
|
|
|
|
LOG(ERROR) << "Receive messageActionChatMigrateTo with invalid " << migrated_to_channel_id << " in "
|
|
|
|
<< owner_dialog_id;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return make_unique<MessageChatMigrateTo>(migrated_to_channel_id);
|
|
|
|
}
|
|
|
|
case telegram_api::messageActionChannelCreate::ID: {
|
2022-07-01 14:04:11 +02:00
|
|
|
auto action = move_tl_object_as<telegram_api::messageActionChannelCreate>(action_ptr);
|
|
|
|
return td::make_unique<MessageChannelCreate>(std::move(action->title_));
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case telegram_api::messageActionChannelMigrateFrom::ID: {
|
2022-07-01 14:04:11 +02:00
|
|
|
auto action = move_tl_object_as<telegram_api::messageActionChannelMigrateFrom>(action_ptr);
|
|
|
|
ChatId chat_id(action->chat_id_);
|
2018-09-28 22:57:34 +02:00
|
|
|
LOG_IF(ERROR, !chat_id.is_valid()) << "Receive messageActionChannelMigrateFrom with invalid " << chat_id << " in "
|
|
|
|
<< owner_dialog_id;
|
|
|
|
|
2022-07-01 14:04:11 +02:00
|
|
|
return td::make_unique<MessageChannelMigrateFrom>(std::move(action->title_), chat_id);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case telegram_api::messageActionPinMessage::ID: {
|
2021-03-31 14:36:25 +02:00
|
|
|
if (reply_in_dialog_id.is_valid() && reply_in_dialog_id != owner_dialog_id) {
|
|
|
|
LOG(ERROR) << "Receive pinned message with " << reply_to_message_id << " in " << owner_dialog_id
|
|
|
|
<< " in another " << reply_in_dialog_id;
|
|
|
|
reply_to_message_id = MessageId();
|
|
|
|
reply_in_dialog_id = DialogId();
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
if (!reply_to_message_id.is_valid()) {
|
2018-12-25 03:45:36 +01:00
|
|
|
// possible in basic groups
|
|
|
|
LOG(INFO) << "Receive pinned message with " << reply_to_message_id << " in " << owner_dialog_id;
|
2018-09-28 22:57:34 +02:00
|
|
|
reply_to_message_id = MessageId();
|
|
|
|
}
|
|
|
|
return make_unique<MessagePinMessage>(reply_to_message_id);
|
|
|
|
}
|
|
|
|
case telegram_api::messageActionGameScore::ID: {
|
2021-03-31 14:36:25 +02:00
|
|
|
if (reply_in_dialog_id.is_valid() && reply_in_dialog_id != owner_dialog_id) {
|
|
|
|
LOG(ERROR) << "Receive game score with " << reply_to_message_id << " in " << owner_dialog_id << " in another "
|
|
|
|
<< reply_in_dialog_id;
|
|
|
|
reply_to_message_id = MessageId();
|
|
|
|
reply_in_dialog_id = DialogId();
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
if (!reply_to_message_id.is_valid()) {
|
2018-12-25 03:45:36 +01:00
|
|
|
// possible in basic groups
|
|
|
|
LOG(INFO) << "Receive game score with " << reply_to_message_id << " in " << owner_dialog_id;
|
2018-09-28 22:57:34 +02:00
|
|
|
reply_to_message_id = MessageId();
|
|
|
|
}
|
2022-07-01 14:04:11 +02:00
|
|
|
auto action = move_tl_object_as<telegram_api::messageActionGameScore>(action_ptr);
|
|
|
|
return make_unique<MessageGameScore>(reply_to_message_id, action->game_id_, action->score_);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case telegram_api::messageActionPhoneCall::ID: {
|
2022-07-01 14:04:11 +02:00
|
|
|
auto action = move_tl_object_as<telegram_api::messageActionPhoneCall>(action_ptr);
|
2022-12-18 20:15:57 +01:00
|
|
|
auto duration = action->duration_;
|
2021-02-16 13:15:45 +01:00
|
|
|
if (duration < 0) {
|
2022-07-01 14:04:11 +02:00
|
|
|
LOG(ERROR) << "Receive invalid " << oneline(to_string(action));
|
2021-02-16 13:15:45 +01:00
|
|
|
break;
|
|
|
|
}
|
2022-07-01 14:04:11 +02:00
|
|
|
return make_unique<MessageCall>(action->call_id_, duration, get_call_discard_reason(action->reason_),
|
|
|
|
action->video_);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case telegram_api::messageActionPaymentSent::ID: {
|
2021-04-07 21:58:40 +02:00
|
|
|
if (td->auth_manager_->is_bot()) {
|
|
|
|
LOG(ERROR) << "Receive MessageActionPaymentSent in " << owner_dialog_id;
|
|
|
|
break;
|
|
|
|
}
|
2022-07-01 14:04:11 +02:00
|
|
|
auto action = move_tl_object_as<telegram_api::messageActionPaymentSent>(action_ptr);
|
2018-09-28 22:57:34 +02:00
|
|
|
if (!reply_to_message_id.is_valid()) {
|
2022-06-06 16:44:38 +02:00
|
|
|
if (reply_to_message_id != MessageId()) {
|
2023-10-18 18:12:31 +02:00
|
|
|
LOG(ERROR) << "Receive successful payment message with " << reply_to_message_id << " in " << owner_dialog_id;
|
2022-05-11 17:52:45 +02:00
|
|
|
}
|
2022-06-06 17:01:44 +02:00
|
|
|
reply_in_dialog_id = DialogId();
|
2018-09-28 22:57:34 +02:00
|
|
|
reply_to_message_id = MessageId();
|
|
|
|
}
|
2022-07-30 02:58:46 +02:00
|
|
|
if (action->total_amount_ <= 0 || !check_currency_amount(action->total_amount_)) {
|
|
|
|
LOG(ERROR) << "Receive invalid total amount " << action->total_amount_;
|
|
|
|
action->total_amount_ = 0;
|
|
|
|
}
|
2022-05-30 15:35:25 +02:00
|
|
|
return td::make_unique<MessagePaymentSuccessful>(
|
2022-07-01 14:04:11 +02:00
|
|
|
reply_in_dialog_id, reply_to_message_id, std::move(action->currency_), action->total_amount_,
|
|
|
|
std::move(action->invoice_slug_), action->recurring_used_, action->recurring_init_);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case telegram_api::messageActionPaymentSentMe::ID: {
|
2021-04-07 21:58:40 +02:00
|
|
|
if (!td->auth_manager_->is_bot()) {
|
|
|
|
LOG(ERROR) << "Receive MessageActionPaymentSentMe in " << owner_dialog_id;
|
|
|
|
break;
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
2022-07-01 14:04:11 +02:00
|
|
|
auto action = move_tl_object_as<telegram_api::messageActionPaymentSentMe>(action_ptr);
|
2022-07-30 02:58:46 +02:00
|
|
|
if (action->total_amount_ <= 0 || !check_currency_amount(action->total_amount_)) {
|
|
|
|
LOG(ERROR) << "Receive invalid total amount " << action->total_amount_;
|
|
|
|
action->total_amount_ = 0;
|
|
|
|
}
|
2022-07-01 14:04:11 +02:00
|
|
|
auto result = td::make_unique<MessagePaymentSuccessful>(DialogId(), MessageId(), std::move(action->currency_),
|
|
|
|
action->total_amount_, action->payload_.as_slice().str(),
|
|
|
|
action->recurring_used_, action->recurring_init_);
|
|
|
|
result->shipping_option_id = std::move(action->shipping_option_id_);
|
|
|
|
result->order_info = get_order_info(std::move(action->info_));
|
|
|
|
result->telegram_payment_charge_id = std::move(action->charge_->id_);
|
|
|
|
result->provider_payment_charge_id = std::move(action->charge_->provider_charge_id_);
|
2018-09-28 22:57:34 +02:00
|
|
|
return std::move(result);
|
|
|
|
}
|
|
|
|
case telegram_api::messageActionScreenshotTaken::ID: {
|
|
|
|
return make_unique<MessageScreenshotTaken>();
|
|
|
|
}
|
|
|
|
case telegram_api::messageActionCustomAction::ID: {
|
2022-07-01 14:04:11 +02:00
|
|
|
auto action = move_tl_object_as<telegram_api::messageActionCustomAction>(action_ptr);
|
|
|
|
return td::make_unique<MessageCustomServiceAction>(std::move(action->message_));
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case telegram_api::messageActionBotAllowed::ID: {
|
2022-07-01 14:04:11 +02:00
|
|
|
auto action = move_tl_object_as<telegram_api::messageActionBotAllowed>(action_ptr);
|
2023-02-07 12:01:45 +01:00
|
|
|
if (action->attach_menu_) {
|
|
|
|
return td::make_unique<MessageWriteAccessAllowed>();
|
|
|
|
}
|
|
|
|
if (!action->domain_.empty()) {
|
|
|
|
return td::make_unique<MessageWebsiteConnected>(std::move(action->domain_));
|
|
|
|
}
|
2023-02-22 10:24:43 +01:00
|
|
|
if (action->app_ != nullptr && action->app_->get_id() == telegram_api::botApp::ID) {
|
|
|
|
return td::make_unique<MessageWebViewWriteAccessAllowed>(
|
|
|
|
WebApp(td, telegram_api::move_object_as<telegram_api::botApp>(action->app_), owner_dialog_id));
|
|
|
|
}
|
2023-08-25 15:53:50 +02:00
|
|
|
if (action->from_request_) {
|
|
|
|
return td::make_unique<MessageWriteAccessAllowedByRequest>();
|
|
|
|
}
|
2023-02-07 12:01:45 +01:00
|
|
|
return td::make_unique<MessageUnsupported>();
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case telegram_api::messageActionSecureValuesSent::ID: {
|
|
|
|
LOG_IF(ERROR, td->auth_manager_->is_bot()) << "Receive MessageActionSecureValuesSent in " << owner_dialog_id;
|
2022-07-01 14:04:11 +02:00
|
|
|
auto action = move_tl_object_as<telegram_api::messageActionSecureValuesSent>(action_ptr);
|
|
|
|
return td::make_unique<MessagePassportDataSent>(get_secure_value_types(action->types_));
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case telegram_api::messageActionSecureValuesSentMe::ID: {
|
|
|
|
LOG_IF(ERROR, !td->auth_manager_->is_bot()) << "Receive MessageActionSecureValuesSentMe in " << owner_dialog_id;
|
2022-07-01 14:04:11 +02:00
|
|
|
auto action = move_tl_object_as<telegram_api::messageActionSecureValuesSentMe>(action_ptr);
|
2018-09-28 22:57:34 +02:00
|
|
|
return td::make_unique<MessagePassportDataReceived>(
|
2022-07-01 14:04:11 +02:00
|
|
|
get_encrypted_secure_values(td->file_manager_.get(), std::move(action->values_)),
|
|
|
|
get_encrypted_secure_credentials(std::move(action->credentials_)));
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
2019-02-13 17:05:34 +01:00
|
|
|
case telegram_api::messageActionContactSignUp::ID: {
|
|
|
|
LOG_IF(ERROR, td->auth_manager_->is_bot()) << "Receive ContactRegistered in " << owner_dialog_id;
|
|
|
|
return td::make_unique<MessageContactRegistered>();
|
|
|
|
}
|
2020-10-19 19:44:09 +02:00
|
|
|
case telegram_api::messageActionGeoProximityReached::ID: {
|
2022-07-01 14:04:11 +02:00
|
|
|
auto action = move_tl_object_as<telegram_api::messageActionGeoProximityReached>(action_ptr);
|
|
|
|
DialogId traveler_id(action->from_id_);
|
|
|
|
DialogId watcher_id(action->to_id_);
|
|
|
|
int32 distance = action->distance_;
|
2020-10-30 23:38:11 +01:00
|
|
|
if (!traveler_id.is_valid() || !watcher_id.is_valid() || distance < 0) {
|
2022-07-01 14:04:11 +02:00
|
|
|
LOG(ERROR) << "Receive invalid " << oneline(to_string(action));
|
2020-10-19 19:44:09 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-10-30 23:38:11 +01:00
|
|
|
return make_unique<MessageProximityAlertTriggered>(traveler_id, watcher_id, distance);
|
2020-10-19 19:44:09 +02:00
|
|
|
}
|
2020-11-24 12:33:16 +01:00
|
|
|
case telegram_api::messageActionGroupCall::ID: {
|
2022-07-01 14:04:11 +02:00
|
|
|
auto action = move_tl_object_as<telegram_api::messageActionGroupCall>(action_ptr);
|
2020-11-24 12:33:16 +01:00
|
|
|
int32 duration = -1;
|
2022-07-01 14:04:11 +02:00
|
|
|
if ((action->flags_ & telegram_api::messageActionGroupCall::DURATION_MASK) != 0) {
|
|
|
|
duration = action->duration_;
|
2020-11-24 12:33:16 +01:00
|
|
|
if (duration < 0) {
|
2022-07-01 14:04:11 +02:00
|
|
|
LOG(ERROR) << "Receive invalid " << oneline(to_string(action));
|
2020-11-24 12:33:16 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-07-01 14:04:11 +02:00
|
|
|
return make_unique<MessageGroupCall>(InputGroupCallId(action->call_), duration, -1);
|
2020-11-24 12:33:16 +01:00
|
|
|
}
|
|
|
|
case telegram_api::messageActionInviteToGroupCall::ID: {
|
2022-07-01 14:04:11 +02:00
|
|
|
auto action = move_tl_object_as<telegram_api::messageActionInviteToGroupCall>(action_ptr);
|
2020-11-29 13:41:03 +01:00
|
|
|
|
|
|
|
vector<UserId> user_ids;
|
2022-07-01 14:04:11 +02:00
|
|
|
user_ids.reserve(action->users_.size());
|
|
|
|
for (auto &user : action->users_) {
|
2020-11-29 13:41:03 +01:00
|
|
|
UserId user_id(user);
|
|
|
|
if (user_id.is_valid()) {
|
|
|
|
user_ids.push_back(user_id);
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Receive messageActionInviteToGroupCall with invalid " << user_id << " in " << owner_dialog_id;
|
|
|
|
}
|
2020-11-24 12:33:16 +01:00
|
|
|
}
|
|
|
|
|
2022-07-01 14:04:11 +02:00
|
|
|
return td::make_unique<MessageInviteToGroupCall>(InputGroupCallId(action->call_), std::move(user_ids));
|
2020-11-24 12:33:16 +01:00
|
|
|
}
|
2021-02-16 13:15:45 +01:00
|
|
|
case telegram_api::messageActionSetMessagesTTL::ID: {
|
2022-07-01 14:04:11 +02:00
|
|
|
auto action = move_tl_object_as<telegram_api::messageActionSetMessagesTTL>(action_ptr);
|
2022-11-29 12:02:05 +01:00
|
|
|
UserId from_user_id(action->auto_setting_from_);
|
|
|
|
if (action->period_ < 0 || !(from_user_id == UserId() || from_user_id.is_valid())) {
|
|
|
|
LOG(ERROR) << "Receive invalid " << oneline(to_string(action));
|
2021-02-16 13:15:45 +01:00
|
|
|
break;
|
|
|
|
}
|
2022-11-29 12:02:05 +01:00
|
|
|
return make_unique<MessageChatSetTtl>(action->period_, from_user_id);
|
2021-02-16 13:15:45 +01:00
|
|
|
}
|
2021-03-26 16:15:21 +01:00
|
|
|
case telegram_api::messageActionGroupCallScheduled::ID: {
|
2022-07-01 14:04:11 +02:00
|
|
|
auto action = move_tl_object_as<telegram_api::messageActionGroupCallScheduled>(action_ptr);
|
|
|
|
if (action->schedule_date_ <= 0) {
|
|
|
|
LOG(ERROR) << "Receive wrong schedule_date = " << action->schedule_date_;
|
2021-04-05 23:24:05 +02:00
|
|
|
break;
|
|
|
|
}
|
2022-07-01 14:04:11 +02:00
|
|
|
return make_unique<MessageGroupCall>(InputGroupCallId(action->call_), -1, action->schedule_date_);
|
2021-03-26 16:15:21 +01:00
|
|
|
}
|
2021-08-18 15:03:10 +02:00
|
|
|
case telegram_api::messageActionSetChatTheme::ID: {
|
2022-07-01 14:04:11 +02:00
|
|
|
auto action = move_tl_object_as<telegram_api::messageActionSetChatTheme>(action_ptr);
|
|
|
|
return td::make_unique<MessageChatSetTheme>(std::move(action->emoticon_));
|
2021-08-18 15:03:10 +02:00
|
|
|
}
|
2021-10-08 12:45:10 +02:00
|
|
|
case telegram_api::messageActionChatJoinedByRequest::ID:
|
2021-10-09 14:04:17 +02:00
|
|
|
return make_unique<MessageChatJoinedByLink>(true);
|
2022-03-28 09:01:39 +02:00
|
|
|
case telegram_api::messageActionWebViewDataSent::ID: {
|
|
|
|
if (td->auth_manager_->is_bot()) {
|
|
|
|
LOG(ERROR) << "Receive messageActionWebViewDataSent in " << owner_dialog_id;
|
|
|
|
break;
|
|
|
|
}
|
2022-07-01 14:04:11 +02:00
|
|
|
auto action = move_tl_object_as<telegram_api::messageActionWebViewDataSent>(action_ptr);
|
|
|
|
return td::make_unique<MessageWebViewDataSent>(std::move(action->text_));
|
2022-03-28 09:01:39 +02:00
|
|
|
}
|
|
|
|
case telegram_api::messageActionWebViewDataSentMe::ID: {
|
|
|
|
if (!td->auth_manager_->is_bot()) {
|
|
|
|
LOG(ERROR) << "Receive messageActionWebViewDataSentMe in " << owner_dialog_id;
|
|
|
|
break;
|
|
|
|
}
|
2022-07-01 14:04:11 +02:00
|
|
|
auto action = move_tl_object_as<telegram_api::messageActionWebViewDataSentMe>(action_ptr);
|
|
|
|
return td::make_unique<MessageWebViewDataReceived>(std::move(action->text_), std::move(action->data_));
|
2022-03-28 09:01:39 +02:00
|
|
|
}
|
2022-07-01 14:28:22 +02:00
|
|
|
case telegram_api::messageActionGiftPremium::ID: {
|
|
|
|
auto action = move_tl_object_as<telegram_api::messageActionGiftPremium>(action_ptr);
|
2022-07-30 02:58:46 +02:00
|
|
|
if (action->amount_ <= 0 || !check_currency_amount(action->amount_)) {
|
|
|
|
LOG(ERROR) << "Receive invalid premium gift price " << action->amount_;
|
|
|
|
action->amount_ = 0;
|
|
|
|
}
|
2023-03-21 12:54:36 +01:00
|
|
|
if (action->crypto_currency_.empty()) {
|
|
|
|
if (action->crypto_amount_ != 0) {
|
|
|
|
LOG(ERROR) << "Receive premium gift crypto price " << action->crypto_amount_ << " without currency";
|
|
|
|
action->crypto_amount_ = 0;
|
|
|
|
}
|
|
|
|
} else if (action->crypto_amount_ <= 0) {
|
|
|
|
LOG(ERROR) << "Receive invalid premium gift crypto price " << action->crypto_amount_;
|
|
|
|
action->crypto_amount_ = 0;
|
|
|
|
}
|
|
|
|
return td::make_unique<MessageGiftPremium>(std::move(action->currency_), action->amount_,
|
|
|
|
std::move(action->crypto_currency_), action->crypto_amount_,
|
|
|
|
action->months_);
|
2022-07-01 14:28:22 +02:00
|
|
|
}
|
2022-10-07 17:04:00 +02:00
|
|
|
case telegram_api::messageActionTopicCreate::ID: {
|
|
|
|
auto action = move_tl_object_as<telegram_api::messageActionTopicCreate>(action_ptr);
|
2022-10-18 15:08:53 +02:00
|
|
|
return td::make_unique<MessageTopicCreate>(std::move(action->title_),
|
|
|
|
ForumTopicIcon(action->icon_color_, action->icon_emoji_id_));
|
2022-10-07 17:04:00 +02:00
|
|
|
}
|
|
|
|
case telegram_api::messageActionTopicEdit::ID: {
|
|
|
|
auto action = move_tl_object_as<telegram_api::messageActionTopicEdit>(action_ptr);
|
2022-10-18 21:16:03 +02:00
|
|
|
auto edit_icon_custom_emoji_id = (action->flags_ & telegram_api::messageActionTopicEdit::ICON_EMOJI_ID_MASK) != 0;
|
|
|
|
auto edit_is_closed = (action->flags_ & telegram_api::messageActionTopicEdit::CLOSED_MASK) != 0;
|
2022-11-30 13:39:29 +01:00
|
|
|
auto edit_is_hidden = (action->flags_ & telegram_api::messageActionTopicEdit::HIDDEN_MASK) != 0;
|
|
|
|
return td::make_unique<MessageTopicEdit>(
|
|
|
|
ForumTopicEditedData{std::move(action->title_), edit_icon_custom_emoji_id, action->icon_emoji_id_,
|
|
|
|
edit_is_closed, action->closed_, edit_is_hidden, action->hidden_});
|
2022-10-07 17:04:00 +02:00
|
|
|
}
|
2022-12-08 18:58:37 +01:00
|
|
|
case telegram_api::messageActionSuggestProfilePhoto::ID: {
|
|
|
|
auto action = move_tl_object_as<telegram_api::messageActionSuggestProfilePhoto>(action_ptr);
|
2023-01-20 15:31:33 +01:00
|
|
|
auto photo = get_photo(td, std::move(action->photo_), owner_dialog_id);
|
2022-12-08 18:58:37 +01:00
|
|
|
if (photo.is_empty()) {
|
|
|
|
break;
|
|
|
|
}
|
2022-12-09 12:13:37 +01:00
|
|
|
return make_unique<MessageSuggestProfilePhoto>(std::move(photo));
|
2022-12-08 18:58:37 +01:00
|
|
|
}
|
2023-01-10 14:20:30 +01:00
|
|
|
case telegram_api::messageActionRequestedPeer::ID: {
|
|
|
|
auto action = move_tl_object_as<telegram_api::messageActionRequestedPeer>(action_ptr);
|
|
|
|
DialogId dialog_id(action->peer_);
|
|
|
|
if (!dialog_id.is_valid()) {
|
|
|
|
LOG(ERROR) << "Receive invalid " << oneline(to_string(action));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return make_unique<MessageRequestedDialog>(dialog_id, action->button_id_);
|
|
|
|
}
|
2023-04-10 13:12:35 +02:00
|
|
|
case telegram_api::messageActionSetChatWallPaper::ID: {
|
|
|
|
auto action = move_tl_object_as<telegram_api::messageActionSetChatWallPaper>(action_ptr);
|
2023-04-10 15:32:59 +02:00
|
|
|
BackgroundInfo background_info(td, std::move(action->wallpaper_));
|
|
|
|
if (!background_info.is_valid()) {
|
2023-04-10 13:12:35 +02:00
|
|
|
break;
|
|
|
|
}
|
2023-04-10 15:32:59 +02:00
|
|
|
return make_unique<MessageSetBackground>(MessageId(), std::move(background_info));
|
2023-04-10 13:12:35 +02:00
|
|
|
}
|
|
|
|
case telegram_api::messageActionSetSameChatWallPaper::ID: {
|
|
|
|
if (reply_in_dialog_id.is_valid() && reply_in_dialog_id != owner_dialog_id) {
|
|
|
|
LOG(ERROR) << "Receive old background message with " << reply_to_message_id << " in " << owner_dialog_id
|
|
|
|
<< " in another " << reply_in_dialog_id;
|
|
|
|
reply_to_message_id = MessageId();
|
|
|
|
reply_in_dialog_id = DialogId();
|
|
|
|
}
|
|
|
|
auto action = move_tl_object_as<telegram_api::messageActionSetSameChatWallPaper>(action_ptr);
|
2023-04-10 15:32:59 +02:00
|
|
|
BackgroundInfo background_info(td, std::move(action->wallpaper_));
|
|
|
|
if (!background_info.is_valid()) {
|
2023-04-10 13:12:35 +02:00
|
|
|
break;
|
|
|
|
}
|
2023-04-10 15:32:59 +02:00
|
|
|
return make_unique<MessageSetBackground>(reply_to_message_id, std::move(background_info));
|
2023-04-10 13:12:35 +02:00
|
|
|
}
|
2023-09-28 15:13:36 +02:00
|
|
|
case telegram_api::messageActionGiveawayLaunch::ID:
|
|
|
|
return make_unique<MessageUnsupported>();
|
2023-09-29 16:55:03 +02:00
|
|
|
case telegram_api::messageActionGiftCode::ID: {
|
|
|
|
auto action = move_tl_object_as<telegram_api::messageActionGiftCode>(action_ptr);
|
|
|
|
DialogId dialog_id;
|
|
|
|
if (action->boost_peer_ != nullptr) {
|
|
|
|
dialog_id = DialogId(action->boost_peer_);
|
|
|
|
if (!dialog_id.is_valid()) {
|
|
|
|
LOG(ERROR) << "Receive invalid " << oneline(to_string(action));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dialog_id.get_type() != DialogType::User) {
|
|
|
|
td->messages_manager_->force_create_dialog(dialog_id, "messageActionGiftCode", true);
|
|
|
|
}
|
|
|
|
return td::make_unique<MessageGiftCode>(dialog_id, action->months_, action->via_giveaway_,
|
|
|
|
std::move(action->slug_));
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
// explicit empty or wrong action
|
2023-10-19 12:03:27 +02:00
|
|
|
return td::make_unique<MessageText>(FormattedText(), WebPageId(), false, false, false, string());
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageContent *content, Td *td,
|
2021-03-31 14:36:25 +02:00
|
|
|
DialogId dialog_id, int32 message_date,
|
2021-08-04 08:28:53 +02:00
|
|
|
bool is_content_secret, bool skip_bot_commands,
|
2023-10-17 15:20:45 +02:00
|
|
|
int32 max_media_timestamp) {
|
2018-09-28 22:57:34 +02:00
|
|
|
CHECK(content != nullptr);
|
|
|
|
switch (content->get_type()) {
|
|
|
|
case MessageContentType::Animation: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageAnimation *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
return make_tl_object<td_api::messageAnimation>(
|
2021-08-28 13:16:29 +02:00
|
|
|
td->animations_manager_->get_animation_object(m->file_id),
|
2022-12-26 12:20:48 +01:00
|
|
|
get_formatted_text_object(m->caption, skip_bot_commands, max_media_timestamp), m->has_spoiler,
|
|
|
|
is_content_secret);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case MessageContentType::Audio: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageAudio *>(content);
|
2021-08-04 08:28:53 +02:00
|
|
|
return make_tl_object<td_api::messageAudio>(
|
|
|
|
td->audios_manager_->get_audio_object(m->file_id),
|
|
|
|
get_formatted_text_object(m->caption, skip_bot_commands, max_media_timestamp));
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case MessageContentType::Contact: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageContact *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
return make_tl_object<td_api::messageContact>(m->contact.get_contact_object());
|
|
|
|
}
|
|
|
|
case MessageContentType::Document: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageDocument *>(content);
|
2020-05-31 21:22:15 +02:00
|
|
|
return make_tl_object<td_api::messageDocument>(
|
|
|
|
td->documents_manager_->get_document_object(m->file_id, PhotoFormat::Jpeg),
|
2021-08-04 08:28:53 +02:00
|
|
|
get_formatted_text_object(m->caption, skip_bot_commands, max_media_timestamp));
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case MessageContentType::Game: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageGame *>(content);
|
2021-07-22 04:39:16 +02:00
|
|
|
return make_tl_object<td_api::messageGame>(m->game.get_game_object(td, skip_bot_commands));
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case MessageContentType::Invoice: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageInvoice *>(content);
|
2022-09-23 11:52:54 +02:00
|
|
|
return m->input_invoice.get_message_invoice_object(td, skip_bot_commands, max_media_timestamp);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case MessageContentType::LiveLocation: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageLiveLocation *>(content);
|
2023-10-04 11:24:58 +02:00
|
|
|
auto passed = max(G()->unix_time() - message_date, 0);
|
2020-10-16 22:08:28 +02:00
|
|
|
auto expires_in = max(0, m->period - passed);
|
|
|
|
auto heading = expires_in == 0 ? 0 : m->heading;
|
2020-10-30 13:51:20 +01:00
|
|
|
auto proximity_alert_radius = expires_in == 0 ? 0 : m->proximity_alert_radius;
|
2020-10-24 23:49:41 +02:00
|
|
|
return make_tl_object<td_api::messageLocation>(m->location.get_location_object(), m->period, expires_in, heading,
|
2020-10-30 13:51:20 +01:00
|
|
|
proximity_alert_radius);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case MessageContentType::Location: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageLocation *>(content);
|
2020-10-24 23:49:41 +02:00
|
|
|
return make_tl_object<td_api::messageLocation>(m->location.get_location_object(), 0, 0, 0, 0);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case MessageContentType::Photo: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessagePhoto *>(content);
|
2022-06-05 21:39:03 +02:00
|
|
|
auto photo = get_photo_object(td->file_manager_.get(), m->photo);
|
|
|
|
if (photo == nullptr) {
|
|
|
|
LOG(ERROR) << "Have empty " << m->photo;
|
|
|
|
return make_tl_object<td_api::messageExpiredPhoto>();
|
|
|
|
}
|
|
|
|
auto caption = get_formatted_text_object(m->caption, skip_bot_commands, max_media_timestamp);
|
2022-12-20 16:06:21 +01:00
|
|
|
return make_tl_object<td_api::messagePhoto>(std::move(photo), std::move(caption), m->has_spoiler,
|
|
|
|
is_content_secret);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case MessageContentType::Sticker: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageSticker *>(content);
|
2022-06-03 15:33:49 +02:00
|
|
|
auto sticker = td->stickers_manager_->get_sticker_object(m->file_id);
|
|
|
|
CHECK(sticker != nullptr);
|
2022-12-21 21:25:31 +01:00
|
|
|
auto is_premium =
|
2022-12-26 21:33:01 +01:00
|
|
|
m->is_premium && sticker->full_type_->get_id() == td_api::stickerFullTypeRegular::ID &&
|
|
|
|
static_cast<const td_api::stickerFullTypeRegular *>(sticker->full_type_.get())->premium_animation_ != nullptr;
|
2022-06-03 15:33:49 +02:00
|
|
|
return make_tl_object<td_api::messageSticker>(std::move(sticker), is_premium);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case MessageContentType::Text: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageText *>(content);
|
2021-10-04 15:08:51 +02:00
|
|
|
if (can_be_animated_emoji(m->text) && !m->web_page_id.is_valid()) {
|
2022-08-05 16:58:16 +02:00
|
|
|
auto animated_emoji =
|
|
|
|
td->stickers_manager_->get_animated_emoji_object(m->text.text, get_custom_emoji_id(m->text));
|
2021-10-26 15:15:01 +02:00
|
|
|
if (animated_emoji != nullptr) {
|
|
|
|
return td_api::make_object<td_api::messageAnimatedEmoji>(std::move(animated_emoji), m->text.text);
|
|
|
|
}
|
2021-10-04 15:08:51 +02:00
|
|
|
}
|
2023-10-19 12:20:48 +02:00
|
|
|
auto web_page = td->web_pages_manager_->get_web_page_object(m->web_page_id, m->force_small_media,
|
|
|
|
m->force_large_media, m->skip_web_page_confirmation);
|
|
|
|
if (web_page != nullptr && !web_page->skip_confirmation_ && is_visible_url(m->text, web_page->url_)) {
|
|
|
|
web_page->skip_confirmation_ = true;
|
|
|
|
}
|
2021-08-04 08:28:53 +02:00
|
|
|
return make_tl_object<td_api::messageText>(
|
2023-10-19 12:20:48 +02:00
|
|
|
get_formatted_text_object(m->text, skip_bot_commands, max_media_timestamp), std::move(web_page),
|
2023-10-17 15:20:45 +02:00
|
|
|
m->web_page_url);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
2018-12-25 18:47:37 +01:00
|
|
|
case MessageContentType::Unsupported:
|
2018-09-28 22:57:34 +02:00
|
|
|
return make_tl_object<td_api::messageUnsupported>();
|
|
|
|
case MessageContentType::Venue: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageVenue *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
return make_tl_object<td_api::messageVenue>(m->venue.get_venue_object());
|
|
|
|
}
|
|
|
|
case MessageContentType::Video: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageVideo *>(content);
|
2021-08-04 08:28:53 +02:00
|
|
|
return make_tl_object<td_api::messageVideo>(
|
|
|
|
td->videos_manager_->get_video_object(m->file_id),
|
2022-12-20 16:06:21 +01:00
|
|
|
get_formatted_text_object(m->caption, skip_bot_commands, max_media_timestamp), m->has_spoiler,
|
|
|
|
is_content_secret);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case MessageContentType::VideoNote: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageVideoNote *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
return make_tl_object<td_api::messageVideoNote>(td->video_notes_manager_->get_video_note_object(m->file_id),
|
|
|
|
m->is_viewed, is_content_secret);
|
|
|
|
}
|
|
|
|
case MessageContentType::VoiceNote: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageVoiceNote *>(content);
|
2021-08-04 08:28:53 +02:00
|
|
|
return make_tl_object<td_api::messageVoiceNote>(
|
|
|
|
td->voice_notes_manager_->get_voice_note_object(m->file_id),
|
|
|
|
get_formatted_text_object(m->caption, skip_bot_commands, max_media_timestamp), m->is_listened);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case MessageContentType::ChatCreate: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageChatCreate *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
return make_tl_object<td_api::messageBasicGroupChatCreate>(
|
2020-01-12 02:40:17 +01:00
|
|
|
m->title, td->contacts_manager_->get_user_ids_object(m->participant_user_ids, "MessageChatCreate"));
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case MessageContentType::ChatChangeTitle: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageChatChangeTitle *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
return make_tl_object<td_api::messageChatChangeTitle>(m->title);
|
|
|
|
}
|
|
|
|
case MessageContentType::ChatChangePhoto: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageChatChangePhoto *>(content);
|
2022-06-05 21:51:13 +02:00
|
|
|
auto photo = get_chat_photo_object(td->file_manager_.get(), m->photo);
|
|
|
|
if (photo == nullptr) {
|
|
|
|
LOG(ERROR) << "Have empty chat " << m->photo;
|
|
|
|
return make_tl_object<td_api::messageChatDeletePhoto>();
|
|
|
|
}
|
|
|
|
return make_tl_object<td_api::messageChatChangePhoto>(std::move(photo));
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case MessageContentType::ChatDeletePhoto:
|
|
|
|
return make_tl_object<td_api::messageChatDeletePhoto>();
|
|
|
|
case MessageContentType::ChatDeleteHistory:
|
|
|
|
return make_tl_object<td_api::messageUnsupported>();
|
|
|
|
case MessageContentType::ChatAddUsers: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageChatAddUsers *>(content);
|
2020-01-12 02:40:17 +01:00
|
|
|
return make_tl_object<td_api::messageChatAddMembers>(
|
|
|
|
td->contacts_manager_->get_user_ids_object(m->user_ids, "MessageChatAddUsers"));
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
2021-10-09 14:04:17 +02:00
|
|
|
case MessageContentType::ChatJoinedByLink: {
|
|
|
|
const MessageChatJoinedByLink *m = static_cast<const MessageChatJoinedByLink *>(content);
|
2021-11-01 15:22:42 +01:00
|
|
|
if (m->is_approved) {
|
|
|
|
return make_tl_object<td_api::messageChatJoinByRequest>();
|
|
|
|
}
|
|
|
|
return make_tl_object<td_api::messageChatJoinByLink>();
|
2021-10-09 14:04:17 +02:00
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::ChatDeleteUser: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageChatDeleteUser *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
return make_tl_object<td_api::messageChatDeleteMember>(
|
2020-11-24 15:29:09 +01:00
|
|
|
td->contacts_manager_->get_user_id_object(m->user_id, "MessageChatDeleteMember"));
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case MessageContentType::ChatMigrateTo: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageChatMigrateTo *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
return make_tl_object<td_api::messageChatUpgradeTo>(
|
2020-11-24 15:29:09 +01:00
|
|
|
td->contacts_manager_->get_supergroup_id_object(m->migrated_to_channel_id, "MessageChatUpgradeTo"));
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case MessageContentType::ChannelCreate: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageChannelCreate *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
return make_tl_object<td_api::messageSupergroupChatCreate>(m->title);
|
|
|
|
}
|
|
|
|
case MessageContentType::ChannelMigrateFrom: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageChannelMigrateFrom *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
return make_tl_object<td_api::messageChatUpgradeFrom>(
|
|
|
|
m->title,
|
2020-11-24 15:29:09 +01:00
|
|
|
td->contacts_manager_->get_basic_group_id_object(m->migrated_from_chat_id, "MessageChatUpgradeFrom"));
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case MessageContentType::PinMessage: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessagePinMessage *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
return make_tl_object<td_api::messagePinMessage>(m->message_id.get());
|
|
|
|
}
|
|
|
|
case MessageContentType::GameScore: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageGameScore *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
return make_tl_object<td_api::messageGameScore>(m->game_message_id.get(), m->game_id, m->score);
|
|
|
|
}
|
|
|
|
case MessageContentType::ScreenshotTaken:
|
|
|
|
return make_tl_object<td_api::messageScreenshotTaken>();
|
|
|
|
case MessageContentType::ChatSetTtl: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageChatSetTtl *>(content);
|
2022-12-28 19:46:16 +01:00
|
|
|
return make_tl_object<td_api::messageChatSetMessageAutoDeleteTime>(
|
2022-11-29 12:02:05 +01:00
|
|
|
m->ttl, td->contacts_manager_->get_user_id_object(m->from_user_id, "MessageChatSetTtl"));
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case MessageContentType::Call: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageCall *>(content);
|
2020-08-05 21:10:33 +02:00
|
|
|
return make_tl_object<td_api::messageCall>(m->is_video, get_call_discard_reason_object(m->discard_reason),
|
|
|
|
m->duration);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case MessageContentType::PaymentSuccessful: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessagePaymentSuccessful *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
if (td->auth_manager_->is_bot()) {
|
|
|
|
return make_tl_object<td_api::messagePaymentSuccessfulBot>(
|
2022-05-30 15:35:25 +02:00
|
|
|
m->currency, m->total_amount, m->is_recurring, m->is_first_recurring, m->invoice_payload,
|
|
|
|
m->shipping_option_id, get_order_info_object(m->order_info), m->telegram_payment_charge_id,
|
|
|
|
m->provider_payment_charge_id);
|
2018-09-28 22:57:34 +02:00
|
|
|
} else {
|
2021-04-07 21:58:40 +02:00
|
|
|
auto invoice_dialog_id = m->invoice_dialog_id.is_valid() ? m->invoice_dialog_id : dialog_id;
|
2023-04-13 21:41:22 +02:00
|
|
|
return make_tl_object<td_api::messagePaymentSuccessful>(
|
|
|
|
td->messages_manager_->get_chat_id_object(invoice_dialog_id, "messagePaymentSuccessful"),
|
|
|
|
m->invoice_message_id.get(), m->currency, m->total_amount, m->is_recurring, m->is_first_recurring,
|
|
|
|
m->invoice_payload);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
case MessageContentType::ContactRegistered:
|
|
|
|
return make_tl_object<td_api::messageContactRegistered>();
|
|
|
|
case MessageContentType::ExpiredPhoto:
|
|
|
|
return make_tl_object<td_api::messageExpiredPhoto>();
|
|
|
|
case MessageContentType::ExpiredVideo:
|
|
|
|
return make_tl_object<td_api::messageExpiredVideo>();
|
|
|
|
case MessageContentType::CustomServiceAction: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageCustomServiceAction *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
return make_tl_object<td_api::messageCustomServiceAction>(m->message);
|
|
|
|
}
|
|
|
|
case MessageContentType::WebsiteConnected: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageWebsiteConnected *>(content);
|
2023-09-28 14:15:00 +02:00
|
|
|
return td_api::make_object<td_api::messageBotWriteAccessAllowed>(
|
|
|
|
td_api::make_object<td_api::botWriteAccessAllowReasonConnectedWebsite>(m->domain_name));
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case MessageContentType::PassportDataSent: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessagePassportDataSent *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
return make_tl_object<td_api::messagePassportDataSent>(get_passport_element_types_object(m->types));
|
|
|
|
}
|
|
|
|
case MessageContentType::PassportDataReceived: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessagePassportDataReceived *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
return make_tl_object<td_api::messagePassportDataReceived>(
|
|
|
|
get_encrypted_passport_element_object(td->file_manager_.get(), m->values),
|
|
|
|
get_encrypted_credentials_object(m->credentials));
|
|
|
|
}
|
2019-02-19 14:45:32 +01:00
|
|
|
case MessageContentType::Poll: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessagePoll *>(content);
|
2019-02-19 14:45:32 +01:00
|
|
|
return make_tl_object<td_api::messagePoll>(td->poll_manager_->get_poll_object(m->poll_id));
|
|
|
|
}
|
2020-03-29 23:34:37 +02:00
|
|
|
case MessageContentType::Dice: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageDice *>(content);
|
2020-10-15 14:59:51 +02:00
|
|
|
auto initial_state = td->stickers_manager_->get_dice_stickers_object(m->emoji, 0);
|
2020-04-19 23:41:26 +02:00
|
|
|
auto final_state =
|
2020-10-15 14:59:51 +02:00
|
|
|
m->dice_value == 0 ? nullptr : td->stickers_manager_->get_dice_stickers_object(m->emoji, m->dice_value);
|
2020-04-21 18:08:01 +02:00
|
|
|
auto success_animation_frame_number =
|
|
|
|
td->stickers_manager_->get_dice_success_animation_frame_number(m->emoji, m->dice_value);
|
2020-04-19 23:41:26 +02:00
|
|
|
return make_tl_object<td_api::messageDice>(std::move(initial_state), std::move(final_state), m->emoji,
|
2020-04-21 18:08:01 +02:00
|
|
|
m->dice_value, success_animation_frame_number);
|
2020-03-14 17:56:39 +01:00
|
|
|
}
|
2020-10-29 20:25:58 +01:00
|
|
|
case MessageContentType::ProximityAlertTriggered: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageProximityAlertTriggered *>(content);
|
2020-10-29 20:25:58 +01:00
|
|
|
return make_tl_object<td_api::messageProximityAlertTriggered>(
|
2021-11-14 23:18:47 +01:00
|
|
|
get_message_sender_object(td, m->traveler_dialog_id, "messageProximityAlertTriggered 1"),
|
|
|
|
get_message_sender_object(td, m->watcher_dialog_id, "messageProximityAlertTriggered 2"), m->distance);
|
2020-10-19 19:44:09 +02:00
|
|
|
}
|
2020-11-24 15:29:09 +01:00
|
|
|
case MessageContentType::GroupCall: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageGroupCall *>(content);
|
2020-12-14 20:22:20 +01:00
|
|
|
if (m->duration >= 0) {
|
2021-10-14 14:44:21 +02:00
|
|
|
return make_tl_object<td_api::messageVideoChatEnded>(m->duration);
|
2020-12-14 20:22:20 +01:00
|
|
|
} else {
|
2021-04-05 23:24:05 +02:00
|
|
|
auto group_call_id = td->group_call_manager_->get_group_call_id(m->input_group_call_id, DialogId()).get();
|
|
|
|
if (m->schedule_date > 0) {
|
2021-10-14 14:44:21 +02:00
|
|
|
return make_tl_object<td_api::messageVideoChatScheduled>(group_call_id, m->schedule_date);
|
2021-04-05 23:24:05 +02:00
|
|
|
} else {
|
2021-10-14 14:44:21 +02:00
|
|
|
return make_tl_object<td_api::messageVideoChatStarted>(group_call_id);
|
2021-04-05 23:24:05 +02:00
|
|
|
}
|
2020-12-14 20:22:20 +01:00
|
|
|
}
|
2020-11-24 15:29:09 +01:00
|
|
|
}
|
|
|
|
case MessageContentType::InviteToGroupCall: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageInviteToGroupCall *>(content);
|
2021-10-14 14:44:21 +02:00
|
|
|
return make_tl_object<td_api::messageInviteVideoChatParticipants>(
|
2020-12-13 12:52:07 +01:00
|
|
|
td->group_call_manager_->get_group_call_id(m->input_group_call_id, DialogId()).get(),
|
2020-11-29 13:41:03 +01:00
|
|
|
td->contacts_manager_->get_user_ids_object(m->user_ids, "MessageInviteToGroupCall"));
|
2020-11-24 15:29:09 +01:00
|
|
|
}
|
2021-08-18 15:03:10 +02:00
|
|
|
case MessageContentType::ChatSetTheme: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageChatSetTheme *>(content);
|
2021-08-18 15:03:10 +02:00
|
|
|
return make_tl_object<td_api::messageChatSetTheme>(m->emoji);
|
|
|
|
}
|
2022-03-28 09:01:39 +02:00
|
|
|
case MessageContentType::WebViewDataSent: {
|
|
|
|
const auto *m = static_cast<const MessageWebViewDataSent *>(content);
|
2022-03-31 15:42:59 +02:00
|
|
|
return make_tl_object<td_api::messageWebAppDataSent>(m->button_text);
|
2022-03-28 09:01:39 +02:00
|
|
|
}
|
|
|
|
case MessageContentType::WebViewDataReceived: {
|
|
|
|
const auto *m = static_cast<const MessageWebViewDataReceived *>(content);
|
2022-03-31 15:42:59 +02:00
|
|
|
return make_tl_object<td_api::messageWebAppDataReceived>(m->button_text, m->data);
|
2022-03-28 09:01:39 +02:00
|
|
|
}
|
2022-07-01 14:28:22 +02:00
|
|
|
case MessageContentType::GiftPremium: {
|
|
|
|
const auto *m = static_cast<const MessageGiftPremium *>(content);
|
2023-04-03 20:20:41 +02:00
|
|
|
int64 gifter_user_id = 0;
|
|
|
|
if (dialog_id.get_type() == DialogType::User) {
|
|
|
|
auto user_id = dialog_id.get_user_id();
|
|
|
|
if (user_id != ContactsManager::get_service_notifications_user_id() &&
|
|
|
|
!td->contacts_manager_->is_user_bot(user_id) && !td->contacts_manager_->is_user_support(user_id)) {
|
|
|
|
gifter_user_id = td->contacts_manager_->get_user_id_object(user_id, "MessageGiftPremium");
|
|
|
|
}
|
|
|
|
}
|
2022-07-22 14:01:44 +02:00
|
|
|
return make_tl_object<td_api::messageGiftedPremium>(
|
2023-04-03 20:20:41 +02:00
|
|
|
gifter_user_id, m->currency, m->amount, m->crypto_currency, m->crypto_amount, m->months,
|
2023-03-21 12:54:36 +01:00
|
|
|
td->stickers_manager_->get_premium_gift_sticker_object(m->months));
|
2022-07-01 14:28:22 +02:00
|
|
|
}
|
2022-10-18 15:08:53 +02:00
|
|
|
case MessageContentType::TopicCreate: {
|
|
|
|
const auto *m = static_cast<const MessageTopicCreate *>(content);
|
|
|
|
return td_api::make_object<td_api::messageForumTopicCreated>(m->title, m->icon.get_forum_topic_icon_object());
|
|
|
|
}
|
2022-10-18 21:16:03 +02:00
|
|
|
case MessageContentType::TopicEdit: {
|
|
|
|
const auto *m = static_cast<const MessageTopicEdit *>(content);
|
2022-10-27 18:40:37 +02:00
|
|
|
return m->edited_data.get_message_content_object();
|
2022-10-18 21:16:03 +02:00
|
|
|
}
|
2022-12-09 12:13:37 +01:00
|
|
|
case MessageContentType::SuggestProfilePhoto: {
|
|
|
|
const auto *m = static_cast<const MessageSuggestProfilePhoto *>(content);
|
|
|
|
auto photo = get_chat_photo_object(td->file_manager_.get(), m->photo);
|
|
|
|
if (photo == nullptr) {
|
|
|
|
LOG(ERROR) << "Have empty suggested profile " << m->photo;
|
|
|
|
return make_tl_object<td_api::messageUnsupported>();
|
|
|
|
}
|
|
|
|
return make_tl_object<td_api::messageSuggestProfilePhoto>(std::move(photo));
|
|
|
|
}
|
2022-12-14 19:13:48 +01:00
|
|
|
case MessageContentType::WriteAccessAllowed:
|
2023-09-28 14:15:00 +02:00
|
|
|
return td_api::make_object<td_api::messageBotWriteAccessAllowed>(
|
|
|
|
td_api::make_object<td_api::botWriteAccessAllowReasonAddedToAttachmentMenu>());
|
2023-01-10 14:20:30 +01:00
|
|
|
case MessageContentType::RequestedDialog: {
|
|
|
|
const auto *m = static_cast<const MessageRequestedDialog *>(content);
|
2023-01-11 18:03:43 +01:00
|
|
|
if (m->dialog_id.get_type() == DialogType::User) {
|
2023-04-03 17:00:44 +02:00
|
|
|
int64 user_id;
|
|
|
|
if (td->auth_manager_->is_bot()) {
|
|
|
|
user_id = m->dialog_id.get_user_id().get();
|
|
|
|
} else {
|
|
|
|
user_id = td->contacts_manager_->get_user_id_object(m->dialog_id.get_user_id(), "MessageRequestedDialog");
|
|
|
|
}
|
|
|
|
return make_tl_object<td_api::messageUserShared>(user_id, m->button_id);
|
2023-01-11 18:03:43 +01:00
|
|
|
}
|
2023-04-13 21:41:22 +02:00
|
|
|
int64 chat_id;
|
|
|
|
if (td->auth_manager_->is_bot()) {
|
|
|
|
chat_id = m->dialog_id.get();
|
|
|
|
} else {
|
|
|
|
chat_id = td->messages_manager_->get_chat_id_object(m->dialog_id, "messageChatShared");
|
|
|
|
}
|
|
|
|
return make_tl_object<td_api::messageChatShared>(chat_id, m->button_id);
|
2023-01-10 14:20:30 +01:00
|
|
|
}
|
2023-02-22 10:24:43 +01:00
|
|
|
case MessageContentType::WebViewWriteAccessAllowed: {
|
|
|
|
const auto *m = static_cast<const MessageWebViewWriteAccessAllowed *>(content);
|
2023-09-28 14:15:00 +02:00
|
|
|
return td_api::make_object<td_api::messageBotWriteAccessAllowed>(
|
|
|
|
td_api::make_object<td_api::botWriteAccessAllowReasonLaunchedWebApp>(m->web_app.get_web_app_object(td)));
|
2023-02-22 10:24:43 +01:00
|
|
|
}
|
2023-04-10 13:12:35 +02:00
|
|
|
case MessageContentType::SetBackground: {
|
|
|
|
const auto *m = static_cast<const MessageSetBackground *>(content);
|
2023-04-10 15:32:59 +02:00
|
|
|
return td_api::make_object<td_api::messageChatSetBackground>(m->old_message_id.get(),
|
2023-04-10 17:45:26 +02:00
|
|
|
m->background_info.get_chat_background_object(td));
|
2023-04-10 13:12:35 +02:00
|
|
|
}
|
2023-06-12 18:23:58 +02:00
|
|
|
case MessageContentType::Story: {
|
|
|
|
const auto *m = static_cast<const MessageStory *>(content);
|
|
|
|
return td_api::make_object<td_api::messageStory>(
|
2023-06-27 20:51:36 +02:00
|
|
|
td->messages_manager_->get_chat_id_object(m->story_full_id.get_dialog_id(), "messageStory"),
|
2023-06-12 18:23:58 +02:00
|
|
|
m->story_full_id.get_story_id().get(), m->via_mention);
|
|
|
|
}
|
2023-08-25 15:53:50 +02:00
|
|
|
case MessageContentType::WriteAccessAllowedByRequest:
|
2023-09-28 14:15:00 +02:00
|
|
|
return td_api::make_object<td_api::messageBotWriteAccessAllowed>(
|
|
|
|
td_api::make_object<td_api::botWriteAccessAllowReasonAcceptedRequest>());
|
2023-09-29 16:55:03 +02:00
|
|
|
case MessageContentType::GiftCode: {
|
|
|
|
const auto *m = static_cast<const MessageGiftCode *>(content);
|
|
|
|
return td_api::make_object<td_api::messagePremiumGiftCode>(
|
|
|
|
get_message_sender_object(td, m->creator_dialog_id, "messagePremiumGiftCode"), m->via_giveaway, m->months,
|
2023-10-13 15:06:55 +02:00
|
|
|
td->stickers_manager_->get_premium_gift_sticker_object(m->months), m->code);
|
2023-09-29 16:55:03 +02:00
|
|
|
}
|
2023-09-29 23:32:39 +02:00
|
|
|
case MessageContentType::Giveaway: {
|
|
|
|
const auto *m = static_cast<const MessageGiveaway *>(content);
|
2023-10-12 16:05:03 +02:00
|
|
|
return td_api::make_object<td_api::messagePremiumGiveaway>(
|
|
|
|
m->giveaway_parameters.get_premium_giveaway_parameters_object(td), m->quantity, m->months);
|
2023-09-29 23:32:39 +02:00
|
|
|
}
|
2023-10-16 10:31:11 +02:00
|
|
|
case MessageContentType::GiveawayLaunch:
|
|
|
|
return td_api::make_object<td_api::messagePremiumGiveawayCreated>();
|
2018-09-28 22:57:34 +02:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
UNREACHABLE();
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2021-08-09 18:37:47 +02:00
|
|
|
FormattedText *get_message_content_text_mutable(MessageContent *content) {
|
|
|
|
return const_cast<FormattedText *>(get_message_content_text(content));
|
|
|
|
}
|
|
|
|
|
2018-09-28 22:57:34 +02:00
|
|
|
const FormattedText *get_message_content_text(const MessageContent *content) {
|
|
|
|
switch (content->get_type()) {
|
|
|
|
case MessageContentType::Text:
|
|
|
|
return &static_cast<const MessageText *>(content)->text;
|
|
|
|
case MessageContentType::Game:
|
|
|
|
return &static_cast<const MessageGame *>(content)->game.get_text();
|
|
|
|
default:
|
|
|
|
return get_message_content_caption(content);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const FormattedText *get_message_content_caption(const MessageContent *content) {
|
|
|
|
switch (content->get_type()) {
|
|
|
|
case MessageContentType::Animation:
|
|
|
|
return &static_cast<const MessageAnimation *>(content)->caption;
|
|
|
|
case MessageContentType::Audio:
|
|
|
|
return &static_cast<const MessageAudio *>(content)->caption;
|
|
|
|
case MessageContentType::Document:
|
|
|
|
return &static_cast<const MessageDocument *>(content)->caption;
|
2022-09-22 17:05:58 +02:00
|
|
|
case MessageContentType::Invoice:
|
2022-09-23 11:52:54 +02:00
|
|
|
return static_cast<const MessageInvoice *>(content)->input_invoice.get_caption();
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::Photo:
|
|
|
|
return &static_cast<const MessagePhoto *>(content)->caption;
|
|
|
|
case MessageContentType::Video:
|
|
|
|
return &static_cast<const MessageVideo *>(content)->caption;
|
|
|
|
case MessageContentType::VoiceNote:
|
|
|
|
return &static_cast<const MessageVoiceNote *>(content)->caption;
|
|
|
|
default:
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-30 00:39:31 +01:00
|
|
|
bool get_message_content_has_spoiler(const MessageContent *content) {
|
|
|
|
switch (content->get_type()) {
|
|
|
|
case MessageContentType::Animation:
|
|
|
|
return static_cast<const MessageAnimation *>(content)->has_spoiler;
|
|
|
|
case MessageContentType::Photo:
|
|
|
|
return static_cast<const MessagePhoto *>(content)->has_spoiler;
|
|
|
|
case MessageContentType::Video:
|
|
|
|
return static_cast<const MessageVideo *>(content)->has_spoiler;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_message_content_has_spoiler(MessageContent *content, bool has_spoiler) {
|
|
|
|
switch (content->get_type()) {
|
|
|
|
case MessageContentType::Animation:
|
|
|
|
static_cast<MessageAnimation *>(content)->has_spoiler = has_spoiler;
|
|
|
|
break;
|
|
|
|
case MessageContentType::Photo:
|
|
|
|
static_cast<MessagePhoto *>(content)->has_spoiler = has_spoiler;
|
|
|
|
break;
|
|
|
|
case MessageContentType::Video:
|
|
|
|
static_cast<MessageVideo *>(content)->has_spoiler = has_spoiler;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-28 22:57:34 +02:00
|
|
|
int32 get_message_content_duration(const MessageContent *content, const Td *td) {
|
|
|
|
CHECK(content != nullptr);
|
|
|
|
switch (content->get_type()) {
|
|
|
|
case MessageContentType::Animation: {
|
|
|
|
auto animation_file_id = static_cast<const MessageAnimation *>(content)->file_id;
|
|
|
|
return td->animations_manager_->get_animation_duration(animation_file_id);
|
|
|
|
}
|
2021-08-05 01:09:04 +02:00
|
|
|
case MessageContentType::Audio: {
|
|
|
|
auto audio_file_id = static_cast<const MessageAudio *>(content)->file_id;
|
|
|
|
return td->audios_manager_->get_audio_duration(audio_file_id);
|
|
|
|
}
|
2022-09-22 17:05:58 +02:00
|
|
|
case MessageContentType::Invoice:
|
2022-09-23 11:52:54 +02:00
|
|
|
return static_cast<const MessageInvoice *>(content)->input_invoice.get_duration(td);
|
2021-08-05 01:09:04 +02:00
|
|
|
case MessageContentType::Video: {
|
|
|
|
auto video_file_id = static_cast<const MessageVideo *>(content)->file_id;
|
|
|
|
return td->videos_manager_->get_video_duration(video_file_id);
|
|
|
|
}
|
|
|
|
case MessageContentType::VideoNote: {
|
|
|
|
auto video_note_file_id = static_cast<const MessageVideoNote *>(content)->file_id;
|
|
|
|
return td->video_notes_manager_->get_video_note_duration(video_note_file_id);
|
|
|
|
}
|
|
|
|
case MessageContentType::VoiceNote: {
|
|
|
|
auto voice_file_id = static_cast<const MessageVoiceNote *>(content)->file_id;
|
|
|
|
return td->voice_notes_manager_->get_voice_note_duration(voice_file_id);
|
|
|
|
}
|
|
|
|
default:
|
2023-05-24 15:23:05 +02:00
|
|
|
return -1;
|
2021-08-05 01:09:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int32 get_message_content_media_duration(const MessageContent *content, const Td *td) {
|
|
|
|
CHECK(content != nullptr);
|
|
|
|
switch (content->get_type()) {
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::Audio: {
|
|
|
|
auto audio_file_id = static_cast<const MessageAudio *>(content)->file_id;
|
|
|
|
return td->audios_manager_->get_audio_duration(audio_file_id);
|
|
|
|
}
|
2022-09-22 17:05:58 +02:00
|
|
|
case MessageContentType::Invoice:
|
2022-09-23 11:52:54 +02:00
|
|
|
return static_cast<const MessageInvoice *>(content)->input_invoice.get_duration(td);
|
2023-06-13 17:20:26 +02:00
|
|
|
case MessageContentType::Story: {
|
|
|
|
auto story_full_id = static_cast<const MessageStory *>(content)->story_full_id;
|
|
|
|
return td->story_manager_->get_story_duration(story_full_id);
|
|
|
|
}
|
2021-07-26 03:33:56 +02:00
|
|
|
case MessageContentType::Text: {
|
|
|
|
auto web_page_id = static_cast<const MessageText *>(content)->web_page_id;
|
2021-08-05 01:09:04 +02:00
|
|
|
return td->web_pages_manager_->get_web_page_media_duration(web_page_id);
|
2021-07-26 03:33:56 +02:00
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::Video: {
|
|
|
|
auto video_file_id = static_cast<const MessageVideo *>(content)->file_id;
|
|
|
|
return td->videos_manager_->get_video_duration(video_file_id);
|
|
|
|
}
|
|
|
|
case MessageContentType::VideoNote: {
|
|
|
|
auto video_note_file_id = static_cast<const MessageVideoNote *>(content)->file_id;
|
|
|
|
return td->video_notes_manager_->get_video_note_duration(video_note_file_id);
|
|
|
|
}
|
|
|
|
case MessageContentType::VoiceNote: {
|
|
|
|
auto voice_file_id = static_cast<const MessageVoiceNote *>(content)->file_id;
|
|
|
|
return td->voice_notes_manager_->get_voice_note_duration(voice_file_id);
|
|
|
|
}
|
|
|
|
default:
|
2021-08-05 01:09:04 +02:00
|
|
|
return -1;
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-23 15:16:56 +02:00
|
|
|
const Photo *get_message_content_photo(const MessageContent *content) {
|
|
|
|
switch (content->get_type()) {
|
|
|
|
case MessageContentType::Photo:
|
|
|
|
return &static_cast<const MessagePhoto *>(content)->photo;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-08-09 16:41:26 +02:00
|
|
|
FileId get_message_content_upload_file_id(const MessageContent *content) {
|
2018-09-28 22:57:34 +02:00
|
|
|
switch (content->get_type()) {
|
|
|
|
case MessageContentType::Animation:
|
|
|
|
return static_cast<const MessageAnimation *>(content)->file_id;
|
|
|
|
case MessageContentType::Audio:
|
|
|
|
return static_cast<const MessageAudio *>(content)->file_id;
|
|
|
|
case MessageContentType::Document:
|
|
|
|
return static_cast<const MessageDocument *>(content)->file_id;
|
2022-09-22 17:05:58 +02:00
|
|
|
case MessageContentType::Invoice:
|
2022-09-23 11:52:54 +02:00
|
|
|
return static_cast<const MessageInvoice *>(content)->input_invoice.get_upload_file_id();
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::Photo:
|
2022-09-22 17:25:20 +02:00
|
|
|
return get_photo_upload_file_id(static_cast<const MessagePhoto *>(content)->photo);
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::Sticker:
|
|
|
|
return static_cast<const MessageSticker *>(content)->file_id;
|
|
|
|
case MessageContentType::Video:
|
|
|
|
return static_cast<const MessageVideo *>(content)->file_id;
|
|
|
|
case MessageContentType::VideoNote:
|
|
|
|
return static_cast<const MessageVideoNote *>(content)->file_id;
|
|
|
|
case MessageContentType::VoiceNote:
|
|
|
|
return static_cast<const MessageVoiceNote *>(content)->file_id;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return FileId();
|
|
|
|
}
|
|
|
|
|
2019-08-09 16:41:26 +02:00
|
|
|
FileId get_message_content_any_file_id(const MessageContent *content) {
|
|
|
|
FileId result = get_message_content_upload_file_id(content);
|
2022-09-22 17:05:58 +02:00
|
|
|
if (!result.is_valid()) {
|
|
|
|
if (content->get_type() == MessageContentType::Photo) {
|
2022-09-22 17:25:20 +02:00
|
|
|
result = get_photo_any_file_id(static_cast<const MessagePhoto *>(content)->photo);
|
2022-09-22 17:05:58 +02:00
|
|
|
} else if (content->get_type() == MessageContentType::Invoice) {
|
2022-09-23 11:52:54 +02:00
|
|
|
result = static_cast<const MessageInvoice *>(content)->input_invoice.get_any_file_id();
|
2019-08-09 16:41:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-09-28 22:57:34 +02:00
|
|
|
void update_message_content_file_id_remote(MessageContent *content, FileId file_id) {
|
|
|
|
if (file_id.get_remote() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2020-02-26 16:15:19 +01:00
|
|
|
FileId *old_file_id = [&] {
|
2018-09-28 22:57:34 +02:00
|
|
|
switch (content->get_type()) {
|
|
|
|
case MessageContentType::Animation:
|
|
|
|
return &static_cast<MessageAnimation *>(content)->file_id;
|
|
|
|
case MessageContentType::Audio:
|
|
|
|
return &static_cast<MessageAudio *>(content)->file_id;
|
|
|
|
case MessageContentType::Document:
|
|
|
|
return &static_cast<MessageDocument *>(content)->file_id;
|
|
|
|
case MessageContentType::Sticker:
|
|
|
|
return &static_cast<MessageSticker *>(content)->file_id;
|
|
|
|
case MessageContentType::Video:
|
|
|
|
return &static_cast<MessageVideo *>(content)->file_id;
|
|
|
|
case MessageContentType::VideoNote:
|
|
|
|
return &static_cast<MessageVideoNote *>(content)->file_id;
|
|
|
|
case MessageContentType::VoiceNote:
|
|
|
|
return &static_cast<MessageVoiceNote *>(content)->file_id;
|
|
|
|
default:
|
|
|
|
return static_cast<FileId *>(nullptr);
|
|
|
|
}
|
|
|
|
}();
|
|
|
|
if (old_file_id != nullptr && *old_file_id == file_id && old_file_id->get_remote() == 0) {
|
|
|
|
*old_file_id = file_id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FileId get_message_content_thumbnail_file_id(const MessageContent *content, const Td *td) {
|
|
|
|
switch (content->get_type()) {
|
|
|
|
case MessageContentType::Animation:
|
|
|
|
return td->animations_manager_->get_animation_thumbnail_file_id(
|
|
|
|
static_cast<const MessageAnimation *>(content)->file_id);
|
|
|
|
case MessageContentType::Audio:
|
|
|
|
return td->audios_manager_->get_audio_thumbnail_file_id(static_cast<const MessageAudio *>(content)->file_id);
|
|
|
|
case MessageContentType::Document:
|
|
|
|
return td->documents_manager_->get_document_thumbnail_file_id(
|
|
|
|
static_cast<const MessageDocument *>(content)->file_id);
|
2022-09-22 17:05:58 +02:00
|
|
|
case MessageContentType::Invoice:
|
2022-09-23 11:52:54 +02:00
|
|
|
return static_cast<const MessageInvoice *>(content)->input_invoice.get_thumbnail_file_id(td);
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::Photo:
|
2022-09-22 17:25:20 +02:00
|
|
|
return get_photo_thumbnail_file_id(static_cast<const MessagePhoto *>(content)->photo);
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::Sticker:
|
|
|
|
return td->stickers_manager_->get_sticker_thumbnail_file_id(
|
|
|
|
static_cast<const MessageSticker *>(content)->file_id);
|
|
|
|
case MessageContentType::Video:
|
|
|
|
return td->videos_manager_->get_video_thumbnail_file_id(static_cast<const MessageVideo *>(content)->file_id);
|
|
|
|
case MessageContentType::VideoNote:
|
|
|
|
return td->video_notes_manager_->get_video_note_thumbnail_file_id(
|
|
|
|
static_cast<const MessageVideoNote *>(content)->file_id);
|
|
|
|
case MessageContentType::VoiceNote:
|
|
|
|
return FileId();
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return FileId();
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<FileId> get_message_content_file_ids(const MessageContent *content, const Td *td) {
|
|
|
|
switch (content->get_type()) {
|
|
|
|
case MessageContentType::Photo:
|
2019-01-06 00:15:07 +01:00
|
|
|
return photo_get_file_ids(static_cast<const MessagePhoto *>(content)->photo);
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::Animation:
|
|
|
|
case MessageContentType::Audio:
|
|
|
|
case MessageContentType::Document:
|
2022-08-05 21:59:39 +02:00
|
|
|
case MessageContentType::Sticker:
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::Video:
|
|
|
|
case MessageContentType::VideoNote:
|
|
|
|
case MessageContentType::VoiceNote: {
|
2022-08-05 21:59:39 +02:00
|
|
|
auto document_type = [&] {
|
|
|
|
switch (content->get_type()) {
|
|
|
|
case MessageContentType::Animation:
|
|
|
|
return Document::Type::Animation;
|
|
|
|
case MessageContentType::Audio:
|
|
|
|
return Document::Type::Audio;
|
|
|
|
case MessageContentType::Document:
|
|
|
|
return Document::Type::General;
|
|
|
|
case MessageContentType::Sticker:
|
|
|
|
return Document::Type::Sticker;
|
|
|
|
case MessageContentType::Video:
|
|
|
|
return Document::Type::Video;
|
|
|
|
case MessageContentType::VideoNote:
|
|
|
|
return Document::Type::VideoNote;
|
|
|
|
case MessageContentType::VoiceNote:
|
|
|
|
return Document::Type::VoiceNote;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return Document::Type::Unknown;
|
|
|
|
}
|
|
|
|
}();
|
|
|
|
return Document(document_type, get_message_content_upload_file_id(content)).get_file_ids(td);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
2019-01-06 00:15:07 +01:00
|
|
|
case MessageContentType::Game:
|
2019-02-28 19:40:57 +01:00
|
|
|
return static_cast<const MessageGame *>(content)->game.get_file_ids(td);
|
2019-01-06 00:34:26 +01:00
|
|
|
case MessageContentType::Invoice:
|
2022-09-23 11:52:54 +02:00
|
|
|
return static_cast<const MessageInvoice *>(content)->input_invoice.get_file_ids(td);
|
2019-01-06 00:34:26 +01:00
|
|
|
case MessageContentType::ChatChangePhoto:
|
|
|
|
return photo_get_file_ids(static_cast<const MessageChatChangePhoto *>(content)->photo);
|
|
|
|
case MessageContentType::PassportDataReceived: {
|
|
|
|
vector<FileId> result;
|
|
|
|
for (auto &value : static_cast<const MessagePassportDataReceived *>(content)->values) {
|
|
|
|
auto process_encrypted_secure_file = [&result](const EncryptedSecureFile &file) {
|
|
|
|
if (file.file.file_id.is_valid()) {
|
|
|
|
result.push_back(file.file.file_id);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
for (auto &file : value.files) {
|
|
|
|
process_encrypted_secure_file(file);
|
|
|
|
}
|
|
|
|
process_encrypted_secure_file(value.front_side);
|
|
|
|
process_encrypted_secure_file(value.reverse_side);
|
|
|
|
process_encrypted_secure_file(value.selfie);
|
|
|
|
for (auto &file : value.translations) {
|
|
|
|
process_encrypted_secure_file(file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2022-12-09 12:13:37 +01:00
|
|
|
case MessageContentType::SuggestProfilePhoto:
|
|
|
|
return photo_get_file_ids(static_cast<const MessageSuggestProfilePhoto *>(content)->photo);
|
2023-02-22 10:24:43 +01:00
|
|
|
case MessageContentType::WebViewWriteAccessAllowed:
|
|
|
|
return static_cast<const MessageWebViewWriteAccessAllowed *>(content)->web_app.get_file_ids(td);
|
2023-04-10 13:12:35 +02:00
|
|
|
case MessageContentType::SetBackground:
|
|
|
|
// background file references are repaired independently
|
|
|
|
return {};
|
2023-06-12 18:23:58 +02:00
|
|
|
case MessageContentType::Story:
|
|
|
|
// story file references are repaired independently
|
|
|
|
return {};
|
2018-09-28 22:57:34 +02:00
|
|
|
default:
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-22 21:39:47 +02:00
|
|
|
StoryFullId get_message_content_story_full_id(const Td *td, const MessageContent *content) {
|
|
|
|
CHECK(content != nullptr);
|
|
|
|
switch (content->get_type()) {
|
|
|
|
case MessageContentType::Text:
|
|
|
|
return td->web_pages_manager_->get_web_page_story_full_id(static_cast<const MessageText *>(content)->web_page_id);
|
|
|
|
case MessageContentType::Story:
|
|
|
|
return static_cast<const MessageStory *>(content)->story_full_id;
|
|
|
|
default:
|
|
|
|
return StoryFullId();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-28 22:57:34 +02:00
|
|
|
string get_message_content_search_text(const Td *td, const MessageContent *content) {
|
|
|
|
switch (content->get_type()) {
|
|
|
|
case MessageContentType::Text: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *text = static_cast<const MessageText *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
if (!text->web_page_id.is_valid()) {
|
|
|
|
return text->text.text;
|
|
|
|
}
|
2022-09-22 17:05:58 +02:00
|
|
|
return PSTRING() << text->text.text << ' ' << td->web_pages_manager_->get_web_page_search_text(text->web_page_id);
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case MessageContentType::Animation: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *animation = static_cast<const MessageAnimation *>(content);
|
2022-09-22 17:05:58 +02:00
|
|
|
return PSTRING() << td->animations_manager_->get_animation_search_text(animation->file_id) << ' '
|
2018-09-28 22:57:34 +02:00
|
|
|
<< animation->caption.text;
|
|
|
|
}
|
|
|
|
case MessageContentType::Audio: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *audio = static_cast<const MessageAudio *>(content);
|
2022-09-22 17:05:58 +02:00
|
|
|
return PSTRING() << td->audios_manager_->get_audio_search_text(audio->file_id) << ' ' << audio->caption.text;
|
2018-09-28 22:57:34 +02:00
|
|
|
}
|
|
|
|
case MessageContentType::Document: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *document = static_cast<const MessageDocument *>(content);
|
2022-09-22 17:05:58 +02:00
|
|
|
return PSTRING() << td->documents_manager_->get_document_search_text(document->file_id) << ' '
|
2018-09-28 22:57:34 +02:00
|
|
|
<< document->caption.text;
|
|
|
|
}
|
2022-09-22 17:05:58 +02:00
|
|
|
case MessageContentType::Invoice: {
|
|
|
|
const auto *invoice = static_cast<const MessageInvoice *>(content);
|
2022-09-23 11:52:54 +02:00
|
|
|
return invoice->input_invoice.get_caption()->text;
|
2022-09-22 17:05:58 +02:00
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::Photo: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *photo = static_cast<const MessagePhoto *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
return photo->caption.text;
|
|
|
|
}
|
|
|
|
case MessageContentType::Video: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *video = static_cast<const MessageVideo *>(content);
|
2018-09-28 22:57:34 +02:00
|
|
|
return PSTRING() << td->videos_manager_->get_video_search_text(video->file_id) << " " << video->caption.text;
|
|
|
|
}
|
2019-03-03 04:36:30 +01:00
|
|
|
case MessageContentType::Poll: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *poll = static_cast<const MessagePoll *>(content);
|
2019-03-03 04:36:30 +01:00
|
|
|
return td->poll_manager_->get_poll_search_text(poll->poll_id);
|
|
|
|
}
|
2022-11-17 11:22:24 +01:00
|
|
|
case MessageContentType::TopicCreate: {
|
|
|
|
const auto *topic_create = static_cast<const MessageTopicCreate *>(content);
|
|
|
|
return topic_create->title;
|
|
|
|
}
|
|
|
|
case MessageContentType::TopicEdit: {
|
|
|
|
const auto *topic_edit = static_cast<const MessageTopicEdit *>(content);
|
|
|
|
return topic_edit->edited_data.get_title();
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::Contact:
|
|
|
|
case MessageContentType::Game:
|
|
|
|
case MessageContentType::LiveLocation:
|
|
|
|
case MessageContentType::Location:
|
|
|
|
case MessageContentType::Sticker:
|
2023-06-12 18:23:58 +02:00
|
|
|
case MessageContentType::Story:
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::Unsupported:
|
|
|
|
case MessageContentType::Venue:
|
|
|
|
case MessageContentType::VideoNote:
|
|
|
|
case MessageContentType::VoiceNote:
|
|
|
|
case MessageContentType::ChatCreate:
|
|
|
|
case MessageContentType::ChatChangeTitle:
|
|
|
|
case MessageContentType::ChatChangePhoto:
|
|
|
|
case MessageContentType::ChatDeletePhoto:
|
|
|
|
case MessageContentType::ChatDeleteHistory:
|
|
|
|
case MessageContentType::ChatAddUsers:
|
|
|
|
case MessageContentType::ChatJoinedByLink:
|
|
|
|
case MessageContentType::ChatDeleteUser:
|
|
|
|
case MessageContentType::ChatMigrateTo:
|
|
|
|
case MessageContentType::ChannelCreate:
|
|
|
|
case MessageContentType::ChannelMigrateFrom:
|
|
|
|
case MessageContentType::PinMessage:
|
|
|
|
case MessageContentType::GameScore:
|
|
|
|
case MessageContentType::ScreenshotTaken:
|
|
|
|
case MessageContentType::ChatSetTtl:
|
|
|
|
case MessageContentType::Call:
|
|
|
|
case MessageContentType::PaymentSuccessful:
|
2020-01-16 04:10:08 +01:00
|
|
|
case MessageContentType::ContactRegistered:
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::ExpiredPhoto:
|
|
|
|
case MessageContentType::ExpiredVideo:
|
|
|
|
case MessageContentType::CustomServiceAction:
|
|
|
|
case MessageContentType::WebsiteConnected:
|
|
|
|
case MessageContentType::PassportDataSent:
|
|
|
|
case MessageContentType::PassportDataReceived:
|
2020-03-29 23:34:37 +02:00
|
|
|
case MessageContentType::Dice:
|
2020-10-29 20:25:58 +01:00
|
|
|
case MessageContentType::ProximityAlertTriggered:
|
2020-11-24 12:33:16 +01:00
|
|
|
case MessageContentType::GroupCall:
|
|
|
|
case MessageContentType::InviteToGroupCall:
|
2021-08-18 15:03:10 +02:00
|
|
|
case MessageContentType::ChatSetTheme:
|
2022-03-28 09:01:39 +02:00
|
|
|
case MessageContentType::WebViewDataSent:
|
|
|
|
case MessageContentType::WebViewDataReceived:
|
2022-07-01 14:28:22 +02:00
|
|
|
case MessageContentType::GiftPremium:
|
2022-12-09 12:13:37 +01:00
|
|
|
case MessageContentType::SuggestProfilePhoto:
|
2022-12-14 19:13:48 +01:00
|
|
|
case MessageContentType::WriteAccessAllowed:
|
2023-01-10 14:20:30 +01:00
|
|
|
case MessageContentType::RequestedDialog:
|
2023-02-22 10:24:43 +01:00
|
|
|
case MessageContentType::WebViewWriteAccessAllowed:
|
2023-04-10 13:12:35 +02:00
|
|
|
case MessageContentType::SetBackground:
|
2023-08-25 15:53:50 +02:00
|
|
|
case MessageContentType::WriteAccessAllowedByRequest:
|
2023-09-29 16:55:03 +02:00
|
|
|
case MessageContentType::GiftCode:
|
2023-09-29 23:32:39 +02:00
|
|
|
case MessageContentType::Giveaway:
|
2023-10-16 10:31:11 +02:00
|
|
|
case MessageContentType::GiveawayLaunch:
|
2018-09-28 22:57:34 +02:00
|
|
|
return string();
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return string();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-23 11:07:07 +02:00
|
|
|
bool update_message_content_extended_media(MessageContent *content,
|
|
|
|
telegram_api::object_ptr<telegram_api::MessageExtendedMedia> extended_media,
|
|
|
|
DialogId owner_dialog_id, Td *td) {
|
|
|
|
CHECK(content != nullptr);
|
|
|
|
CHECK(content->get_type() == MessageContentType::Invoice);
|
2022-09-23 11:52:54 +02:00
|
|
|
return static_cast<MessageInvoice *>(content)->input_invoice.update_extended_media(std::move(extended_media),
|
|
|
|
owner_dialog_id, td);
|
2022-09-23 11:07:07 +02:00
|
|
|
}
|
|
|
|
|
2022-09-24 21:17:17 +02:00
|
|
|
bool need_poll_message_content_extended_media(const MessageContent *content) {
|
|
|
|
CHECK(content != nullptr);
|
|
|
|
if (content->get_type() != MessageContentType::Invoice) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return static_cast<const MessageInvoice *>(content)->input_invoice.need_poll_extended_media();
|
|
|
|
}
|
|
|
|
|
2023-09-21 18:11:17 +02:00
|
|
|
void get_message_content_animated_emoji_click_sticker(const MessageContent *content, MessageFullId message_full_id,
|
2021-09-15 23:41:40 +02:00
|
|
|
Td *td, Promise<td_api::object_ptr<td_api::sticker>> &&promise) {
|
|
|
|
if (content->get_type() != MessageContentType::Text) {
|
|
|
|
return promise.set_error(Status::Error(400, "Message is not an animated emoji message"));
|
|
|
|
}
|
|
|
|
|
2021-10-04 15:08:51 +02:00
|
|
|
const auto &text = static_cast<const MessageText *>(content)->text;
|
|
|
|
if (!can_be_animated_emoji(text)) {
|
2021-09-16 22:22:34 +02:00
|
|
|
return promise.set_error(Status::Error(400, "Message is not an animated emoji message"));
|
2021-09-15 23:41:40 +02:00
|
|
|
}
|
2023-09-21 18:11:17 +02:00
|
|
|
td->stickers_manager_->get_animated_emoji_click_sticker(text.text, message_full_id, std::move(promise));
|
2021-09-15 23:41:40 +02:00
|
|
|
}
|
|
|
|
|
2023-09-21 18:11:17 +02:00
|
|
|
void on_message_content_animated_emoji_clicked(const MessageContent *content, MessageFullId message_full_id, Td *td,
|
2022-05-12 17:02:27 +02:00
|
|
|
string &&emoji, string &&data) {
|
2021-09-17 14:51:42 +02:00
|
|
|
if (content->get_type() != MessageContentType::Text) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-12 17:02:27 +02:00
|
|
|
remove_emoji_modifiers_in_place(emoji);
|
2021-09-17 14:51:42 +02:00
|
|
|
auto &text = static_cast<const MessageText *>(content)->text;
|
|
|
|
if (!text.entities.empty() || remove_emoji_modifiers(text.text) != emoji) {
|
|
|
|
return;
|
|
|
|
}
|
2023-09-21 18:11:17 +02:00
|
|
|
auto error = td->stickers_manager_->on_animated_emoji_message_clicked(std::move(emoji), message_full_id, data);
|
2021-09-17 14:51:42 +02:00
|
|
|
if (error.is_error()) {
|
|
|
|
LOG(WARNING) << "Failed to process animated emoji click with data \"" << data << "\": " << error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-25 18:47:37 +01:00
|
|
|
bool need_reget_message_content(const MessageContent *content) {
|
|
|
|
CHECK(content != nullptr);
|
|
|
|
switch (content->get_type()) {
|
|
|
|
case MessageContentType::Unsupported: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *m = static_cast<const MessageUnsupported *>(content);
|
|
|
|
return m->version != MessageUnsupported::CURRENT_VERSION;
|
2018-12-25 18:47:37 +01:00
|
|
|
}
|
2022-09-22 14:30:12 +02:00
|
|
|
case MessageContentType::Invoice: {
|
|
|
|
const auto *m = static_cast<const MessageInvoice *>(content);
|
2022-09-24 21:45:29 +02:00
|
|
|
return m->input_invoice.need_reget();
|
2022-09-22 14:30:12 +02:00
|
|
|
}
|
2018-12-25 18:47:37 +01:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-08 19:24:06 +01:00
|
|
|
bool need_delay_message_content_notification(const MessageContent *content, UserId my_user_id) {
|
|
|
|
switch (content->get_type()) {
|
|
|
|
case MessageContentType::ChatChangeTitle:
|
|
|
|
case MessageContentType::ChatChangePhoto:
|
|
|
|
case MessageContentType::ChatDeletePhoto:
|
|
|
|
case MessageContentType::ChatJoinedByLink:
|
|
|
|
return true;
|
|
|
|
case MessageContentType::ChatAddUsers: {
|
|
|
|
auto &added_user_ids = static_cast<const MessageChatAddUsers *>(content)->user_ids;
|
2019-10-22 01:12:58 +02:00
|
|
|
return !td::contains(added_user_ids, my_user_id);
|
2019-01-08 19:24:06 +01:00
|
|
|
}
|
|
|
|
case MessageContentType::ChatDeleteUser:
|
|
|
|
return static_cast<const MessageChatDeleteUser *>(content)->user_id != my_user_id;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-28 22:57:34 +02:00
|
|
|
void update_expired_message_content(unique_ptr<MessageContent> &content) {
|
|
|
|
switch (content->get_type()) {
|
|
|
|
case MessageContentType::Photo:
|
|
|
|
content = make_unique<MessageExpiredPhoto>();
|
|
|
|
break;
|
|
|
|
case MessageContentType::Video:
|
|
|
|
content = make_unique<MessageExpiredVideo>();
|
|
|
|
break;
|
|
|
|
case MessageContentType::Unsupported:
|
2020-04-21 00:39:44 +02:00
|
|
|
// can happen if message content file identifier is broken
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
|
|
|
case MessageContentType::ExpiredPhoto:
|
|
|
|
case MessageContentType::ExpiredVideo:
|
|
|
|
// can happen if message content has been reget from somewhere
|
|
|
|
break;
|
|
|
|
case MessageContentType::Animation:
|
|
|
|
case MessageContentType::Audio:
|
|
|
|
case MessageContentType::Document:
|
|
|
|
case MessageContentType::Sticker:
|
|
|
|
case MessageContentType::VideoNote:
|
|
|
|
case MessageContentType::VoiceNote:
|
|
|
|
// can happen if server will send a document with a wrong content
|
|
|
|
content = make_unique<MessageExpiredVideo>();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-19 15:06:48 +01:00
|
|
|
void update_failed_to_send_message_content(Td *td, unique_ptr<MessageContent> &content) {
|
2019-03-13 15:53:48 +01:00
|
|
|
// do not forget about failed to send message forwards
|
2019-02-19 15:06:48 +01:00
|
|
|
switch (content->get_type()) {
|
|
|
|
case MessageContentType::Poll: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *message_poll = static_cast<const MessagePoll *>(content.get());
|
2019-03-13 15:53:48 +01:00
|
|
|
if (PollManager::is_local_poll_id(message_poll->poll_id)) {
|
|
|
|
td->poll_manager_->stop_local_poll(message_poll->poll_id);
|
|
|
|
}
|
2019-02-19 15:06:48 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
// nothing to do
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-10 14:20:30 +01:00
|
|
|
void add_message_content_dependencies(Dependencies &dependencies, const MessageContent *message_content, bool is_bot) {
|
2018-09-28 22:57:34 +02:00
|
|
|
switch (message_content->get_type()) {
|
|
|
|
case MessageContentType::Text: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *content = static_cast<const MessageText *>(message_content);
|
2022-03-11 13:31:28 +01:00
|
|
|
dependencies.add(content->web_page_id);
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Animation:
|
|
|
|
break;
|
|
|
|
case MessageContentType::Audio:
|
|
|
|
break;
|
|
|
|
case MessageContentType::Contact: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *content = static_cast<const MessageContact *>(message_content);
|
2022-03-11 13:31:28 +01:00
|
|
|
dependencies.add(content->contact.get_user_id());
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Document:
|
|
|
|
break;
|
|
|
|
case MessageContentType::Game: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *content = static_cast<const MessageGame *>(message_content);
|
2022-03-11 13:31:28 +01:00
|
|
|
dependencies.add(content->game.get_bot_user_id());
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::Invoice:
|
|
|
|
break;
|
|
|
|
case MessageContentType::LiveLocation:
|
|
|
|
break;
|
|
|
|
case MessageContentType::Location:
|
|
|
|
break;
|
|
|
|
case MessageContentType::Photo:
|
|
|
|
break;
|
|
|
|
case MessageContentType::Sticker:
|
|
|
|
break;
|
|
|
|
case MessageContentType::Venue:
|
|
|
|
break;
|
|
|
|
case MessageContentType::Video:
|
|
|
|
break;
|
|
|
|
case MessageContentType::VideoNote:
|
|
|
|
break;
|
|
|
|
case MessageContentType::VoiceNote:
|
|
|
|
break;
|
|
|
|
case MessageContentType::ChatCreate: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *content = static_cast<const MessageChatCreate *>(message_content);
|
2022-03-11 13:31:28 +01:00
|
|
|
for (auto &participant_user_id : content->participant_user_ids) {
|
|
|
|
dependencies.add(participant_user_id);
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::ChatChangeTitle:
|
|
|
|
break;
|
|
|
|
case MessageContentType::ChatChangePhoto:
|
|
|
|
break;
|
|
|
|
case MessageContentType::ChatDeletePhoto:
|
|
|
|
break;
|
|
|
|
case MessageContentType::ChatDeleteHistory:
|
|
|
|
break;
|
|
|
|
case MessageContentType::ChatAddUsers: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *content = static_cast<const MessageChatAddUsers *>(message_content);
|
2022-03-11 13:31:28 +01:00
|
|
|
for (auto &user_id : content->user_ids) {
|
|
|
|
dependencies.add(user_id);
|
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::ChatJoinedByLink:
|
|
|
|
break;
|
|
|
|
case MessageContentType::ChatDeleteUser: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *content = static_cast<const MessageChatDeleteUser *>(message_content);
|
2022-03-11 13:31:28 +01:00
|
|
|
dependencies.add(content->user_id);
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::ChatMigrateTo: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *content = static_cast<const MessageChatMigrateTo *>(message_content);
|
2022-03-11 13:31:28 +01:00
|
|
|
dependencies.add(content->migrated_to_channel_id);
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::ChannelCreate:
|
|
|
|
break;
|
|
|
|
case MessageContentType::ChannelMigrateFrom: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *content = static_cast<const MessageChannelMigrateFrom *>(message_content);
|
2022-03-11 13:31:28 +01:00
|
|
|
dependencies.add(content->migrated_from_chat_id);
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageContentType::PinMessage:
|
|
|
|
break;
|
|
|
|
case MessageContentType::GameScore:
|
|
|
|
break;
|
|
|
|
case MessageContentType::ScreenshotTaken:
|
|
|
|
break;
|
2022-11-29 12:02:05 +01:00
|
|
|
case MessageContentType::ChatSetTtl: {
|
|
|
|
const auto *content = static_cast<const MessageChatSetTtl *>(message_content);
|
|
|
|
dependencies.add(content->from_user_id);
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
2022-11-29 12:02:05 +01:00
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::Unsupported:
|
|
|
|
break;
|
|
|
|
case MessageContentType::Call:
|
|
|
|
break;
|
2021-03-31 14:36:25 +02:00
|
|
|
case MessageContentType::PaymentSuccessful: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *content = static_cast<const MessagePaymentSuccessful *>(message_content);
|
2022-03-11 13:10:24 +01:00
|
|
|
dependencies.add_dialog_and_dependencies(content->invoice_dialog_id);
|
2018-09-28 22:57:34 +02:00
|
|
|
break;
|
2021-03-31 14:36:25 +02:00
|
|
|
}
|
2018-09-28 22:57:34 +02:00
|
|
|
case MessageContentType::ContactRegistered:
|
|
|
|
break;
|
|
|
|
case MessageContentType::ExpiredPhoto:
|
|
|
|
break;
|
|
|
|
case MessageContentType::ExpiredVideo:
|
|
|
|
break;
|
|
|
|
case MessageContentType::CustomServiceAction:
|
|
|
|
break;
|
|
|
|
case MessageContentType::WebsiteConnected:
|
|
|
|
break;
|
|
|
|
case MessageContentType::PassportDataSent:
|
|
|
|
break;
|
|
|
|
case MessageContentType::PassportDataReceived:
|
|
|
|
break;
|
2019-02-19 14:45:32 +01:00
|
|
|
case MessageContentType::Poll:
|
2020-01-15 00:44:24 +01:00
|
|
|
// no need to add poll dependencies, because they are forcely loaded with the poll
|
2019-02-19 14:45:32 +01:00
|
|
|
break;
|
2020-03-29 23:34:37 +02:00
|
|
|
case MessageContentType::Dice:
|
2020-03-14 17:56:39 +01:00
|
|
|
break;
|
2020-10-29 20:25:58 +01:00
|
|
|
case MessageContentType::ProximityAlertTriggered: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *content = static_cast<const MessageProximityAlertTriggered *>(message_content);
|
2022-03-11 13:10:24 +01:00
|
|
|
dependencies.add_message_sender_dependencies(content->traveler_dialog_id);
|
|
|
|
dependencies.add_message_sender_dependencies(content->watcher_dialog_id);
|
2020-10-19 19:44:09 +02:00
|
|
|
break;
|
2020-11-24 12:33:16 +01:00
|
|
|
}
|
|
|
|
case MessageContentType::GroupCall:
|
|
|
|
break;
|
|
|
|
case MessageContentType::InviteToGroupCall: {
|
2021-10-19 17:11:16 +02:00
|
|
|
const auto *content = static_cast<const MessageInviteToGroupCall *>(message_content);
|
2022-03-11 13:31:28 +01:00
|
|
|
for (auto &user_id : content->user_ids) {
|
|
|
|
dependencies.add(user_id);
|
|
|
|
}
|
2020-11-24 12:33:16 +01:00
|
|
|
break;
|
2020-10-19 19:44:09 +02:00
|
|
|
}
|
2021-08-18 15:03:10 +02:00
|
|
|
case MessageContentType::ChatSetTheme:
|
|
|
|
break;
|
2022-03-28 09:01:39 +02:00
|
|
|
case MessageContentType::WebViewDataSent:
|
|
|
|
break;
|
|
|
|
case MessageContentType::WebViewDataReceived:
|
|
|
|
break;
|
2022-07-01 14:28:22 +02:00
|
|
|
case MessageContentType::GiftPremium:
|
|
|
|
break;
|
2022-10-18 15:08:53 +02:00
|
|
|
case MessageContentType::TopicCreate:
|
|
|
|
break;
|
2022-10-18 21:16:03 +02:00
|
|
|
case MessageContentType::TopicEdit:
|
|
|
|
break;
|
2022-12-09 12:13:37 +01:00
|
|
|
case MessageContentType::SuggestProfilePhoto:
|
|
|
|
break;
|
2022-12-14 19:13:48 +01:00
|
|
|
case MessageContentType::WriteAccessAllowed:
|
|
|
|
break;
|
2023-01-10 14:20:30 +01:00
|
|
|
case MessageContentType::RequestedDialog: {
|
|
|
|
const auto *content = static_cast<const MessageRequestedDialog *>(message_content);
|
|
|
|
if (!is_bot) {
|
2023-01-11 18:03:43 +01:00
|
|
|
if (content->dialog_id.get_type() == DialogType::User) {
|
|
|
|
dependencies.add(content->dialog_id.get_user_id());
|
|
|
|
} else {
|
|
|
|
dependencies.add_dialog_and_dependencies(content->dialog_id);
|
|
|
|
}
|
2023-01-10 14:20:30 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2023-02-22 10:24:43 +01:00
|
|
|
case MessageContentType::WebViewWriteAccessAllowed:
|
|
|
|
break;
|
2023-04-10 13:12:35 +02:00
|
|
|
case MessageContentType::SetBackground:
|
|
|
|
break;
|
2023-06-12 18:23:58 +02:00
|
|
|
case MessageContentType::Story: {
|
|
|
|
const auto *content = static_cast<const MessageStory *>(message_content);
|
2023-07-10 14:36:38 +02:00
|
|
|
dependencies.add(content->story_full_id);
|
2023-06-12 18:23:58 +02:00
|
|
|
break;
|
|
|
|
}
|
2023-08-25 15:53:50 +02:00
|
|
|
case MessageContentType::WriteAccessAllowedByRequest:
|
|
|
|
break;
|
2023-09-29 16:55:03 +02:00
|
|
|
case MessageContentType::GiftCode: {
|
|
|
|
const auto *content = static_cast<const MessageGiftCode *>(message_content);
|
|
|
|
dependencies.add_message_sender_dependencies(content->creator_dialog_id);
|
|
|
|
break;
|
|
|
|
}
|
2023-09-29 23:32:39 +02:00
|
|
|
case MessageContentType::Giveaway: {
|
|
|
|
const auto *content = static_cast<const MessageGiveaway *>(message_content);
|
2023-10-12 16:05:03 +02:00
|
|
|
content->giveaway_parameters.add_dependencies(dependencies);
|
2023-09-29 23:32:39 +02:00
|
|
|
break;
|
|
|
|
}
|
2023-10-16 10:31:11 +02:00
|
|
|
case MessageContentType::GiveawayLaunch:
|
|
|
|
break;
|
2018-09-28 22:57:34 +02:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
add_formatted_text_dependencies(dependencies, get_message_content_text(message_content));
|
|
|
|
}
|
|
|
|
|
2022-10-27 18:03:58 +02:00
|
|
|
void update_forum_topic_info_by_service_message_content(Td *td, const MessageContent *content, DialogId dialog_id,
|
|
|
|
MessageId top_thread_message_id) {
|
|
|
|
if (!top_thread_message_id.is_valid()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (content->get_type()) {
|
|
|
|
case MessageContentType::TopicEdit:
|
|
|
|
return td->forum_topic_manager_->on_forum_topic_edited(
|
|
|
|
dialog_id, top_thread_message_id, static_cast<const MessageTopicEdit *>(content)->edited_data);
|
|
|
|
default:
|
|
|
|
// nothing to do
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-12 13:57:24 +01:00
|
|
|
void on_sent_message_content(Td *td, const MessageContent *content) {
|
|
|
|
switch (content->get_type()) {
|
|
|
|
case MessageContentType::Animation:
|
2022-09-04 20:35:11 +02:00
|
|
|
return td->animations_manager_->add_saved_animation_by_id(get_message_content_upload_file_id(content));
|
2018-12-12 13:57:24 +01:00
|
|
|
case MessageContentType::Sticker:
|
2022-09-04 20:35:11 +02:00
|
|
|
return td->stickers_manager_->add_recent_sticker_by_id(false, get_message_content_upload_file_id(content));
|
2018-12-12 13:57:24 +01:00
|
|
|
default:
|
|
|
|
// nothing to do
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-04 20:35:11 +02:00
|
|
|
void move_message_content_sticker_set_to_top(Td *td, const MessageContent *content) {
|
|
|
|
CHECK(content != nullptr);
|
|
|
|
if (content->get_type() == MessageContentType::Sticker) {
|
|
|
|
td->stickers_manager_->move_sticker_set_to_top_by_sticker_id(get_message_content_upload_file_id(content));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto text = get_message_content_text(content);
|
|
|
|
if (text == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
2022-10-03 00:26:32 +02:00
|
|
|
vector<CustomEmojiId> custom_emoji_ids;
|
2022-09-04 20:35:11 +02:00
|
|
|
for (auto &entity : text->entities) {
|
|
|
|
if (entity.type == MessageEntity::Type::CustomEmoji) {
|
2022-10-03 00:26:32 +02:00
|
|
|
custom_emoji_ids.push_back(entity.custom_emoji_id);
|
2022-09-04 20:35:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!custom_emoji_ids.empty()) {
|
|
|
|
td->stickers_manager_->move_sticker_set_to_top_by_custom_emoji_ids(custom_emoji_ids);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-19 00:52:56 +02:00
|
|
|
bool is_unsent_animated_emoji_click(Td *td, DialogId dialog_id, const DialogAction &action) {
|
2021-09-19 20:40:07 +02:00
|
|
|
auto emoji = action.get_watching_animations_emoji();
|
2021-09-19 00:52:56 +02:00
|
|
|
if (emoji.empty()) {
|
2021-09-23 16:16:59 +02:00
|
|
|
// not a WatchingAnimations action
|
2021-09-19 00:52:56 +02:00
|
|
|
return false;
|
|
|
|
}
|
2021-09-23 16:16:59 +02:00
|
|
|
return !td->stickers_manager_->is_sent_animated_emoji_click(dialog_id, remove_emoji_modifiers(emoji));
|
2021-09-19 00:52:56 +02:00
|
|
|
}
|
|
|
|
|
2022-04-11 15:01:30 +02:00
|
|
|
void init_stickers_manager(Td *td) {
|
|
|
|
td->stickers_manager_->init();
|
|
|
|
}
|
|
|
|
|
2020-01-27 01:25:23 +01:00
|
|
|
void on_dialog_used(TopDialogCategory category, DialogId dialog_id, int32 date) {
|
|
|
|
send_closure(G()->top_dialog_manager(), &TopDialogManager::on_dialog_used, category, dialog_id, date);
|
|
|
|
}
|
|
|
|
|
2020-01-27 01:34:23 +01:00
|
|
|
void update_used_hashtags(Td *td, const MessageContent *content) {
|
|
|
|
const FormattedText *text = get_message_content_text(content);
|
|
|
|
if (text == nullptr || text->text.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const unsigned char *ptr = Slice(text->text).ubegin();
|
|
|
|
const unsigned char *end = Slice(text->text).uend();
|
|
|
|
int32 utf16_pos = 0;
|
2022-08-19 15:19:58 +02:00
|
|
|
uint32 skipped_code = 0;
|
2020-01-27 01:34:23 +01:00
|
|
|
for (auto &entity : text->entities) {
|
|
|
|
if (entity.type != MessageEntity::Type::Hashtag) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
while (utf16_pos < entity.offset && ptr < end) {
|
|
|
|
utf16_pos += 1 + (ptr[0] >= 0xf0);
|
2022-08-19 15:37:44 +02:00
|
|
|
ptr = next_utf8_unsafe(ptr, &skipped_code);
|
2020-01-27 01:34:23 +01:00
|
|
|
}
|
|
|
|
CHECK(utf16_pos == entity.offset);
|
|
|
|
auto from = ptr;
|
|
|
|
|
|
|
|
while (utf16_pos < entity.offset + entity.length && ptr < end) {
|
|
|
|
utf16_pos += 1 + (ptr[0] >= 0xf0);
|
2022-08-19 15:37:44 +02:00
|
|
|
ptr = next_utf8_unsafe(ptr, &skipped_code);
|
2020-01-27 01:34:23 +01:00
|
|
|
}
|
|
|
|
CHECK(utf16_pos == entity.offset + entity.length);
|
|
|
|
auto to = ptr;
|
|
|
|
|
|
|
|
send_closure(td->hashtag_hints_, &HashtagHints::hashtag_used, Slice(from + 1, to).str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-21 18:11:17 +02:00
|
|
|
void recognize_message_content_speech(Td *td, const MessageContent *content, MessageFullId message_full_id,
|
2022-10-19 16:56:18 +02:00
|
|
|
Promise<Unit> &&promise) {
|
|
|
|
switch (content->get_type()) {
|
2022-10-20 20:31:00 +02:00
|
|
|
case MessageContentType::VideoNote:
|
2023-09-21 18:11:17 +02:00
|
|
|
return td->video_notes_manager_->recognize_speech(message_full_id, std::move(promise));
|
2022-10-19 16:56:18 +02:00
|
|
|
case MessageContentType::VoiceNote:
|
2023-09-21 18:11:17 +02:00
|
|
|
return td->voice_notes_manager_->recognize_speech(message_full_id, std::move(promise));
|
2022-10-19 16:56:18 +02:00
|
|
|
default:
|
|
|
|
return promise.set_error(Status::Error(400, "Invalid message specified"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-21 18:11:17 +02:00
|
|
|
void rate_message_content_speech_recognition(Td *td, const MessageContent *content, MessageFullId message_full_id,
|
2022-10-19 16:56:18 +02:00
|
|
|
bool is_good, Promise<Unit> &&promise) {
|
|
|
|
switch (content->get_type()) {
|
2022-10-20 20:31:00 +02:00
|
|
|
case MessageContentType::VideoNote:
|
2023-09-21 18:11:17 +02:00
|
|
|
return td->video_notes_manager_->rate_speech_recognition(message_full_id, is_good, std::move(promise));
|
2022-10-19 16:56:18 +02:00
|
|
|
case MessageContentType::VoiceNote:
|
2023-09-21 18:11:17 +02:00
|
|
|
return td->voice_notes_manager_->rate_speech_recognition(message_full_id, is_good, std::move(promise));
|
2022-10-19 16:56:18 +02:00
|
|
|
default:
|
|
|
|
return promise.set_error(Status::Error(400, "Invalid message specified"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-28 22:57:34 +02:00
|
|
|
} // namespace td
|