diff --git a/CMakeLists.txt b/CMakeLists.txt index 0088248b..1e2d9c67 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -420,6 +420,7 @@ set(TDLIB_SOURCE td/telegram/Location.cpp td/telegram/Logging.cpp td/telegram/MessageContent.cpp + td/telegram/MessageContentType.cpp td/telegram/MessageEntity.cpp td/telegram/MessageId.cpp td/telegram/MessagesDb.cpp @@ -582,6 +583,7 @@ set(TDLIB_SOURCE td/telegram/logevent/SecretChatEvent.h td/telegram/Logging.h td/telegram/MessageContent.h + td/telegram/MessageContentType.h td/telegram/MessageEntity.h td/telegram/MessageId.h td/telegram/MessagesDb.h diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index 0d71ff8d..330eb25e 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -643,98 +643,6 @@ class MessagePoll : public MessageContent { } }; -StringBuilder &operator<<(StringBuilder &string_builder, MessageContentType content_type) { - switch (content_type) { - case MessageContentType::None: - return string_builder << "None"; - case MessageContentType::Animation: - return string_builder << "Animation"; - case MessageContentType::Audio: - return string_builder << "Audio"; - case MessageContentType::Document: - return string_builder << "Document"; - case MessageContentType::ExpiredPhoto: - return string_builder << "ExpiredPhoto"; - case MessageContentType::Photo: - return string_builder << "Photo"; - case MessageContentType::ExpiredVideo: - return string_builder << "ExpiredVideo"; - case MessageContentType::Video: - return string_builder << "Video"; - case MessageContentType::VideoNote: - return string_builder << "VideoNote"; - case MessageContentType::VoiceNote: - return string_builder << "VoiceNote"; - case MessageContentType::Contact: - return string_builder << "Contact"; - case MessageContentType::LiveLocation: - return string_builder << "LiveLocation"; - case MessageContentType::Location: - return string_builder << "Location"; - case MessageContentType::Venue: - return string_builder << "Venue"; - case MessageContentType::Game: - return string_builder << "Game"; - case MessageContentType::Invoice: - return string_builder << "Invoice"; - case MessageContentType::Sticker: - return string_builder << "Sticker"; - case MessageContentType::Text: - return string_builder << "Text"; - case MessageContentType::Unsupported: - return string_builder << "Unsupported"; - case MessageContentType::ChatCreate: - return string_builder << "ChatCreate"; - case MessageContentType::ChatChangeTitle: - return string_builder << "ChatChangeTitle"; - case MessageContentType::ChatChangePhoto: - return string_builder << "ChatChangePhoto"; - case MessageContentType::ChatDeletePhoto: - return string_builder << "ChatDeletePhoto"; - case MessageContentType::ChatDeleteHistory: - return string_builder << "ChatDeleteHistory"; - case MessageContentType::ChatAddUsers: - return string_builder << "ChatAddUsers"; - case MessageContentType::ChatJoinedByLink: - return string_builder << "ChatJoinedByLink"; - case MessageContentType::ChatDeleteUser: - return string_builder << "ChatDeleteUser"; - case MessageContentType::ChatMigrateTo: - return string_builder << "ChatMigrateTo"; - case MessageContentType::ChannelCreate: - return string_builder << "ChannelCreate"; - case MessageContentType::ChannelMigrateFrom: - return string_builder << "ChannelMigrateFrom"; - case MessageContentType::PinMessage: - return string_builder << "PinMessage"; - case MessageContentType::GameScore: - return string_builder << "GameScore"; - case MessageContentType::ScreenshotTaken: - return string_builder << "ScreenshotTaken"; - case MessageContentType::ChatSetTtl: - return string_builder << "ChatSetTtl"; - case MessageContentType::Call: - return string_builder << "Call"; - case MessageContentType::PaymentSuccessful: - return string_builder << "PaymentSuccessful"; - case MessageContentType::ContactRegistered: - return string_builder << "ContactRegistered"; - case MessageContentType::CustomServiceAction: - return string_builder << "CustomServiceAction"; - case MessageContentType::WebsiteConnected: - return string_builder << "WebsiteConnected"; - case MessageContentType::PassportDataSent: - return string_builder << "PassportDataSent"; - case MessageContentType::PassportDataReceived: - return string_builder << "PassportDataReceived"; - case MessageContentType::Poll: - return string_builder << "Poll"; - default: - UNREACHABLE(); - return string_builder; - } -} - template static void store(const MessageContent *content, StorerT &storer) { CHECK(content != nullptr); @@ -2399,57 +2307,6 @@ void delete_message_content_thumbnail(MessageContent *content, Td *td) { } } -bool is_allowed_media_group_content(MessageContentType content_type) { - switch (content_type) { - case MessageContentType::Photo: - case MessageContentType::Video: - case MessageContentType::ExpiredPhoto: - case MessageContentType::ExpiredVideo: - return true; - case MessageContentType::Animation: - case MessageContentType::Audio: - case MessageContentType::Contact: - case MessageContentType::Document: - case MessageContentType::Game: - case MessageContentType::Invoice: - case MessageContentType::LiveLocation: - case MessageContentType::Location: - case MessageContentType::Sticker: - case MessageContentType::Text: - 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: - case MessageContentType::ContactRegistered: - case MessageContentType::CustomServiceAction: - case MessageContentType::WebsiteConnected: - case MessageContentType::PassportDataSent: - case MessageContentType::PassportDataReceived: - case MessageContentType::Poll: - return false; - default: - UNREACHABLE(); - return false; - } -} - bool can_forward_message_content(const MessageContent *content) { auto content_type = content->get_type(); if (content_type == MessageContentType::Text) { @@ -2465,162 +2322,6 @@ bool can_forward_message_content(const MessageContent *content) { content_type != MessageContentType::ExpiredPhoto && content_type != MessageContentType::ExpiredVideo; } -bool is_secret_message_content(int32 ttl, MessageContentType content_type) { - if (ttl <= 0 || ttl > 60) { - return false; - } - switch (content_type) { - case MessageContentType::Animation: - case MessageContentType::Audio: - case MessageContentType::Photo: - case MessageContentType::Video: - case MessageContentType::VideoNote: - case MessageContentType::VoiceNote: - return true; - case MessageContentType::Contact: - case MessageContentType::Document: - case MessageContentType::Game: - case MessageContentType::Invoice: - case MessageContentType::LiveLocation: - case MessageContentType::Location: - case MessageContentType::Sticker: - case MessageContentType::Text: - case MessageContentType::Unsupported: - case MessageContentType::Venue: - case MessageContentType::ExpiredPhoto: - case MessageContentType::ExpiredVideo: - 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::CustomServiceAction: - case MessageContentType::WebsiteConnected: - case MessageContentType::PassportDataSent: - case MessageContentType::PassportDataReceived: - case MessageContentType::Poll: - return false; - default: - UNREACHABLE(); - return false; - } -} - -bool is_service_message_content(MessageContentType content_type) { - switch (content_type) { - case MessageContentType::Animation: - case MessageContentType::Audio: - case MessageContentType::Contact: - case MessageContentType::Document: - case MessageContentType::Game: - case MessageContentType::Invoice: - case MessageContentType::LiveLocation: - case MessageContentType::Location: - case MessageContentType::Photo: - case MessageContentType::Sticker: - case MessageContentType::Text: - case MessageContentType::Unsupported: - case MessageContentType::Venue: - case MessageContentType::Video: - case MessageContentType::VideoNote: - case MessageContentType::VoiceNote: - case MessageContentType::ExpiredPhoto: - case MessageContentType::ExpiredVideo: - case MessageContentType::Poll: - return false; - 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::CustomServiceAction: - case MessageContentType::WebsiteConnected: - case MessageContentType::PassportDataSent: - case MessageContentType::PassportDataReceived: - return true; - default: - UNREACHABLE(); - return false; - } -} - -bool can_have_message_content_caption(MessageContentType content_type) { - switch (content_type) { - case MessageContentType::Animation: - case MessageContentType::Audio: - case MessageContentType::Document: - case MessageContentType::Photo: - case MessageContentType::Video: - case MessageContentType::VoiceNote: - return true; - case MessageContentType::Contact: - case MessageContentType::Game: - case MessageContentType::Invoice: - case MessageContentType::LiveLocation: - case MessageContentType::Location: - case MessageContentType::Sticker: - case MessageContentType::Text: - case MessageContentType::Unsupported: - case MessageContentType::Venue: - case MessageContentType::VideoNote: - 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: - case MessageContentType::Poll: - return false; - default: - UNREACHABLE(); - return false; - } -} - bool update_opened_message_content(MessageContent *content) { switch (content->get_type()) { case MessageContentType::VideoNote: { diff --git a/td/telegram/MessageContent.h b/td/telegram/MessageContent.h index 8e450a90..87b40875 100644 --- a/td/telegram/MessageContent.h +++ b/td/telegram/MessageContent.h @@ -11,6 +11,7 @@ #include "td/telegram/files/FileId.h" #include "td/telegram/FullMessageId.h" #include "td/telegram/logevent/LogEvent.h" +#include "td/telegram/MessageContentType.h" #include "td/telegram/MessageEntity.h" #include "td/telegram/MessageId.h" #include "td/telegram/Photo.h" @@ -29,7 +30,6 @@ #include "td/utils/buffer.h" #include "td/utils/common.h" #include "td/utils/Status.h" -#include "td/utils/StringBuilder.h" #include @@ -41,53 +41,6 @@ class Td; class MultiPromiseActor; -enum class MessageContentType : int32 { - None = -1, - Text, - Animation, - Audio, - Document, - Photo, - Sticker, - Video, - VoiceNote, - Contact, - Location, - Venue, - ChatCreate, - ChatChangeTitle, - ChatChangePhoto, - ChatDeletePhoto, - ChatDeleteHistory, - ChatAddUsers, - ChatJoinedByLink, - ChatDeleteUser, - ChatMigrateTo, - ChannelCreate, - ChannelMigrateFrom, - PinMessage, - Game, - GameScore, - ScreenshotTaken, - ChatSetTtl, - Unsupported, - Call, - Invoice, - PaymentSuccessful, - VideoNote, - ContactRegistered, - ExpiredPhoto, - ExpiredVideo, - LiveLocation, - CustomServiceAction, - WebsiteConnected, - PassportDataSent, - PassportDataReceived, - Poll -}; - -StringBuilder &operator<<(StringBuilder &string_builder, MessageContentType content_type); - // Do not forget to update merge_message_contents when one of the inheritors of this class changes class MessageContent { public: @@ -162,16 +115,8 @@ tl_object_ptr get_input_media(const MessageContent *co void delete_message_content_thumbnail(MessageContent *content, Td *td); -bool is_allowed_media_group_content(MessageContentType content_type); - bool can_forward_message_content(const MessageContent *content); -bool is_secret_message_content(int32 ttl, MessageContentType content_type); - -bool is_service_message_content(MessageContentType content_type); - -bool can_have_message_content_caption(MessageContentType content_type); - bool update_opened_message_content(MessageContent *content); int32 get_message_content_index_mask(const MessageContent *content, const Td *td, bool is_secret, bool is_outgoing); diff --git a/td/telegram/MessageContentType.cpp b/td/telegram/MessageContentType.cpp new file mode 100644 index 00000000..8d58addb --- /dev/null +++ b/td/telegram/MessageContentType.cpp @@ -0,0 +1,310 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2020 +// +// 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/MessageContentType.h" + +namespace td { + +StringBuilder &operator<<(StringBuilder &string_builder, MessageContentType content_type) { + switch (content_type) { + case MessageContentType::None: + return string_builder << "None"; + case MessageContentType::Animation: + return string_builder << "Animation"; + case MessageContentType::Audio: + return string_builder << "Audio"; + case MessageContentType::Document: + return string_builder << "Document"; + case MessageContentType::ExpiredPhoto: + return string_builder << "ExpiredPhoto"; + case MessageContentType::Photo: + return string_builder << "Photo"; + case MessageContentType::ExpiredVideo: + return string_builder << "ExpiredVideo"; + case MessageContentType::Video: + return string_builder << "Video"; + case MessageContentType::VideoNote: + return string_builder << "VideoNote"; + case MessageContentType::VoiceNote: + return string_builder << "VoiceNote"; + case MessageContentType::Contact: + return string_builder << "Contact"; + case MessageContentType::LiveLocation: + return string_builder << "LiveLocation"; + case MessageContentType::Location: + return string_builder << "Location"; + case MessageContentType::Venue: + return string_builder << "Venue"; + case MessageContentType::Game: + return string_builder << "Game"; + case MessageContentType::Invoice: + return string_builder << "Invoice"; + case MessageContentType::Sticker: + return string_builder << "Sticker"; + case MessageContentType::Text: + return string_builder << "Text"; + case MessageContentType::Unsupported: + return string_builder << "Unsupported"; + case MessageContentType::ChatCreate: + return string_builder << "ChatCreate"; + case MessageContentType::ChatChangeTitle: + return string_builder << "ChatChangeTitle"; + case MessageContentType::ChatChangePhoto: + return string_builder << "ChatChangePhoto"; + case MessageContentType::ChatDeletePhoto: + return string_builder << "ChatDeletePhoto"; + case MessageContentType::ChatDeleteHistory: + return string_builder << "ChatDeleteHistory"; + case MessageContentType::ChatAddUsers: + return string_builder << "ChatAddUsers"; + case MessageContentType::ChatJoinedByLink: + return string_builder << "ChatJoinedByLink"; + case MessageContentType::ChatDeleteUser: + return string_builder << "ChatDeleteUser"; + case MessageContentType::ChatMigrateTo: + return string_builder << "ChatMigrateTo"; + case MessageContentType::ChannelCreate: + return string_builder << "ChannelCreate"; + case MessageContentType::ChannelMigrateFrom: + return string_builder << "ChannelMigrateFrom"; + case MessageContentType::PinMessage: + return string_builder << "PinMessage"; + case MessageContentType::GameScore: + return string_builder << "GameScore"; + case MessageContentType::ScreenshotTaken: + return string_builder << "ScreenshotTaken"; + case MessageContentType::ChatSetTtl: + return string_builder << "ChatSetTtl"; + case MessageContentType::Call: + return string_builder << "Call"; + case MessageContentType::PaymentSuccessful: + return string_builder << "PaymentSuccessful"; + case MessageContentType::ContactRegistered: + return string_builder << "ContactRegistered"; + case MessageContentType::CustomServiceAction: + return string_builder << "CustomServiceAction"; + case MessageContentType::WebsiteConnected: + return string_builder << "WebsiteConnected"; + case MessageContentType::PassportDataSent: + return string_builder << "PassportDataSent"; + case MessageContentType::PassportDataReceived: + return string_builder << "PassportDataReceived"; + case MessageContentType::Poll: + return string_builder << "Poll"; + default: + UNREACHABLE(); + return string_builder; + } +} + +bool is_allowed_media_group_content(MessageContentType content_type) { + switch (content_type) { + case MessageContentType::Photo: + case MessageContentType::Video: + case MessageContentType::ExpiredPhoto: + case MessageContentType::ExpiredVideo: + return true; + case MessageContentType::Animation: + case MessageContentType::Audio: + case MessageContentType::Contact: + case MessageContentType::Document: + case MessageContentType::Game: + case MessageContentType::Invoice: + case MessageContentType::LiveLocation: + case MessageContentType::Location: + case MessageContentType::Sticker: + case MessageContentType::Text: + 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: + case MessageContentType::ContactRegistered: + case MessageContentType::CustomServiceAction: + case MessageContentType::WebsiteConnected: + case MessageContentType::PassportDataSent: + case MessageContentType::PassportDataReceived: + case MessageContentType::Poll: + return false; + default: + UNREACHABLE(); + return false; + } +} + +bool is_secret_message_content(int32 ttl, MessageContentType content_type) { + if (ttl <= 0 || ttl > 60) { + return false; + } + switch (content_type) { + case MessageContentType::Animation: + case MessageContentType::Audio: + case MessageContentType::Photo: + case MessageContentType::Video: + case MessageContentType::VideoNote: + case MessageContentType::VoiceNote: + return true; + case MessageContentType::Contact: + case MessageContentType::Document: + case MessageContentType::Game: + case MessageContentType::Invoice: + case MessageContentType::LiveLocation: + case MessageContentType::Location: + case MessageContentType::Sticker: + case MessageContentType::Text: + case MessageContentType::Unsupported: + case MessageContentType::Venue: + case MessageContentType::ExpiredPhoto: + case MessageContentType::ExpiredVideo: + 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::CustomServiceAction: + case MessageContentType::WebsiteConnected: + case MessageContentType::PassportDataSent: + case MessageContentType::PassportDataReceived: + case MessageContentType::Poll: + return false; + default: + UNREACHABLE(); + return false; + } +} + +bool is_service_message_content(MessageContentType content_type) { + switch (content_type) { + case MessageContentType::Animation: + case MessageContentType::Audio: + case MessageContentType::Contact: + case MessageContentType::Document: + case MessageContentType::Game: + case MessageContentType::Invoice: + case MessageContentType::LiveLocation: + case MessageContentType::Location: + case MessageContentType::Photo: + case MessageContentType::Sticker: + case MessageContentType::Text: + case MessageContentType::Unsupported: + case MessageContentType::Venue: + case MessageContentType::Video: + case MessageContentType::VideoNote: + case MessageContentType::VoiceNote: + case MessageContentType::ExpiredPhoto: + case MessageContentType::ExpiredVideo: + case MessageContentType::Poll: + return false; + 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::CustomServiceAction: + case MessageContentType::WebsiteConnected: + case MessageContentType::PassportDataSent: + case MessageContentType::PassportDataReceived: + return true; + default: + UNREACHABLE(); + return false; + } +} + +bool can_have_message_content_caption(MessageContentType content_type) { + switch (content_type) { + case MessageContentType::Animation: + case MessageContentType::Audio: + case MessageContentType::Document: + case MessageContentType::Photo: + case MessageContentType::Video: + case MessageContentType::VoiceNote: + return true; + case MessageContentType::Contact: + case MessageContentType::Game: + case MessageContentType::Invoice: + case MessageContentType::LiveLocation: + case MessageContentType::Location: + case MessageContentType::Sticker: + case MessageContentType::Text: + case MessageContentType::Unsupported: + case MessageContentType::Venue: + case MessageContentType::VideoNote: + 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: + case MessageContentType::Poll: + return false; + default: + UNREACHABLE(); + return false; + } +} + +} // namespace td diff --git a/td/telegram/MessageContentType.h b/td/telegram/MessageContentType.h new file mode 100644 index 00000000..240b58b9 --- /dev/null +++ b/td/telegram/MessageContentType.h @@ -0,0 +1,69 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2020 +// +// 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) +// +#pragma once + +#include "td/utils/common.h" +#include "td/utils/StringBuilder.h" + +namespace td { + +enum class MessageContentType : int32 { + None = -1, + Text, + Animation, + Audio, + Document, + Photo, + Sticker, + Video, + VoiceNote, + Contact, + Location, + Venue, + ChatCreate, + ChatChangeTitle, + ChatChangePhoto, + ChatDeletePhoto, + ChatDeleteHistory, + ChatAddUsers, + ChatJoinedByLink, + ChatDeleteUser, + ChatMigrateTo, + ChannelCreate, + ChannelMigrateFrom, + PinMessage, + Game, + GameScore, + ScreenshotTaken, + ChatSetTtl, + Unsupported, + Call, + Invoice, + PaymentSuccessful, + VideoNote, + ContactRegistered, + ExpiredPhoto, + ExpiredVideo, + LiveLocation, + CustomServiceAction, + WebsiteConnected, + PassportDataSent, + PassportDataReceived, + Poll +}; + +StringBuilder &operator<<(StringBuilder &string_builder, MessageContentType content_type); + +bool is_allowed_media_group_content(MessageContentType content_type); + +bool is_secret_message_content(int32 ttl, MessageContentType content_type); + +bool is_service_message_content(MessageContentType content_type); + +bool can_have_message_content_caption(MessageContentType content_type); + +} // namespace td diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 3220080c..64953ea4 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -25,6 +25,7 @@ #include "td/telegram/FullMessageId.h" #include "td/telegram/Global.h" #include "td/telegram/MessageContent.h" +#include "td/telegram/MessageContentType.h" #include "td/telegram/MessageEntity.h" #include "td/telegram/MessageId.h" #include "td/telegram/MessagesDb.h"