Add and use can_have_input_media function.
GitOrigin-RevId: f40cb99154f6429f071dc9785f94a62322ef123e
This commit is contained in:
parent
4ec628fc78
commit
cde26abe1e
@ -1955,6 +1955,58 @@ Result<InputMessageContent> get_input_message_content(
|
||||
std::move(thumbnail), std::move(sticker_file_ids));
|
||||
}
|
||||
|
||||
bool can_have_input_media(const Td *td, const MessageContent *content) {
|
||||
switch (content->get_type()) {
|
||||
case MessageContentType::Game:
|
||||
return static_cast<const MessageGame *>(content)->game.has_input_media();
|
||||
case MessageContentType::Poll:
|
||||
return td->poll_manager_->has_input_media(static_cast<const MessagePoll *>(content)->poll_id);
|
||||
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:
|
||||
return false;
|
||||
case MessageContentType::Animation:
|
||||
case MessageContentType::Audio:
|
||||
case MessageContentType::Contact:
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
SecretInputMedia get_secret_input_media(const MessageContent *content, Td *td,
|
||||
tl_object_ptr<telegram_api::InputEncryptedFile> input_file,
|
||||
BufferSlice thumbnail, int32 layer) {
|
||||
@ -2015,9 +2067,11 @@ SecretInputMedia get_secret_input_media(const MessageContent *content, Td *td,
|
||||
auto m = static_cast<const MessageVoiceNote *>(content);
|
||||
return td->voice_notes_manager_->get_secret_input_media(m->file_id, std::move(input_file), m->caption.text);
|
||||
}
|
||||
case MessageContentType::LiveLocation:
|
||||
case MessageContentType::Call:
|
||||
case MessageContentType::Game:
|
||||
case MessageContentType::Invoice:
|
||||
case MessageContentType::LiveLocation:
|
||||
case MessageContentType::Poll:
|
||||
case MessageContentType::Unsupported:
|
||||
case MessageContentType::ChatCreate:
|
||||
case MessageContentType::ChatChangeTitle:
|
||||
@ -2042,7 +2096,6 @@ SecretInputMedia get_secret_input_media(const MessageContent *content, Td *td,
|
||||
case MessageContentType::WebsiteConnected:
|
||||
case MessageContentType::PassportDataSent:
|
||||
case MessageContentType::PassportDataReceived:
|
||||
case MessageContentType::Poll:
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
@ -2131,6 +2184,9 @@ static tl_object_ptr<telegram_api::inputMediaInvoice> get_input_media_invoice(co
|
||||
static tl_object_ptr<telegram_api::InputMedia> get_input_media_impl(
|
||||
const MessageContent *content, Td *td, tl_object_ptr<telegram_api::InputFile> input_file,
|
||||
tl_object_ptr<telegram_api::InputFile> input_thumbnail, int32 ttl) {
|
||||
if (!can_have_input_media(td, content)) {
|
||||
return nullptr;
|
||||
}
|
||||
switch (content->get_type()) {
|
||||
case MessageContentType::Animation: {
|
||||
auto m = static_cast<const MessageAnimation *>(content);
|
||||
@ -2150,9 +2206,6 @@ static tl_object_ptr<telegram_api::InputMedia> get_input_media_impl(
|
||||
}
|
||||
case MessageContentType::Game: {
|
||||
auto m = static_cast<const MessageGame *>(content);
|
||||
if (!m->game.has_input_media()) {
|
||||
return nullptr;
|
||||
}
|
||||
return m->game.get_input_media_game(td);
|
||||
}
|
||||
case MessageContentType::Invoice: {
|
||||
@ -2175,9 +2228,6 @@ static tl_object_ptr<telegram_api::InputMedia> get_input_media_impl(
|
||||
}
|
||||
case MessageContentType::Poll: {
|
||||
auto m = static_cast<const MessagePoll *>(content);
|
||||
if (!td->poll_manager_->has_input_media(m->poll_id)) {
|
||||
return nullptr;
|
||||
}
|
||||
return td->poll_manager_->get_input_media(m->poll_id);
|
||||
}
|
||||
case MessageContentType::Sticker: {
|
||||
@ -2738,15 +2788,6 @@ int32 get_message_content_live_location_period(const MessageContent *content) {
|
||||
}
|
||||
}
|
||||
|
||||
UserId get_message_content_game_bot_user_id(const MessageContent *content) {
|
||||
switch (content->get_type()) {
|
||||
case MessageContentType::Game:
|
||||
return static_cast<const MessageGame *>(content)->game.get_bot_user_id();
|
||||
default:
|
||||
return UserId();
|
||||
}
|
||||
}
|
||||
|
||||
bool get_message_content_poll_is_closed(const Td *td, const MessageContent *content) {
|
||||
switch (content->get_type()) {
|
||||
case MessageContentType::Poll:
|
||||
@ -4036,6 +4077,10 @@ unique_ptr<MessageContent> get_message_content(Td *td, FormattedText message,
|
||||
unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const MessageContent *content,
|
||||
MessageContentDupType type) {
|
||||
CHECK(content != nullptr);
|
||||
if (type != MessageContentDupType::Forward && type != MessageContentDupType::SendViaBot &&
|
||||
!can_have_input_media(td, content)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
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) {
|
||||
@ -4094,15 +4139,8 @@ unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const
|
||||
CHECK(result->file_id.is_valid());
|
||||
return std::move(result);
|
||||
}
|
||||
case MessageContentType::Game: {
|
||||
auto result = make_unique<MessageGame>(*static_cast<const MessageGame *>(content));
|
||||
if (type != MessageContentDupType::Forward && type != MessageContentDupType::SendViaBot &&
|
||||
!result->game.has_input_media()) {
|
||||
LOG(INFO) << "Can't send/copy game without bot_user_id";
|
||||
return nullptr;
|
||||
}
|
||||
return std::move(result);
|
||||
}
|
||||
case MessageContentType::Game:
|
||||
return make_unique<MessageGame>(*static_cast<const MessageGame *>(content));
|
||||
case MessageContentType::Invoice:
|
||||
return make_unique<MessageInvoice>(*static_cast<const MessageInvoice *>(content));
|
||||
case MessageContentType::LiveLocation:
|
||||
@ -4173,14 +4211,8 @@ unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const
|
||||
}
|
||||
return std::move(result);
|
||||
}
|
||||
case MessageContentType::Poll: {
|
||||
auto result = make_unique<MessagePoll>(*static_cast<const MessagePoll *>(content));
|
||||
if (type != MessageContentDupType::Forward && type != MessageContentDupType::SendViaBot &&
|
||||
!td->poll_manager_->has_input_media(result->poll_id)) {
|
||||
return nullptr;
|
||||
}
|
||||
return std::move(result);
|
||||
}
|
||||
case MessageContentType::Poll:
|
||||
return make_unique<MessagePoll>(*static_cast<const MessagePoll *>(content));
|
||||
case MessageContentType::Sticker: {
|
||||
auto result = make_unique<MessageSticker>(*static_cast<const MessageSticker *>(content));
|
||||
if (td->stickers_manager_->has_input_media(result->file_id, to_secret)) {
|
||||
@ -4909,6 +4941,7 @@ string get_message_content_search_text(const Td *td, const MessageContent *conte
|
||||
case MessageContentType::ChatSetTtl:
|
||||
case MessageContentType::Call:
|
||||
case MessageContentType::PaymentSuccessful:
|
||||
case MessageContentType::ContactRegistered:
|
||||
case MessageContentType::ExpiredPhoto:
|
||||
case MessageContentType::ExpiredVideo:
|
||||
case MessageContentType::CustomServiceAction:
|
||||
|
@ -142,6 +142,8 @@ unique_ptr<MessageContent> create_chat_set_ttl_message_content(int32 ttl);
|
||||
Result<InputMessageContent> get_input_message_content(
|
||||
DialogId dialog_id, tl_object_ptr<td_api::InputMessageContent> &&input_message_content, Td *td);
|
||||
|
||||
bool can_have_input_media(const Td *td, const MessageContent *content);
|
||||
|
||||
SecretInputMedia get_secret_input_media(const MessageContent *content, Td *td,
|
||||
tl_object_ptr<telegram_api::InputEncryptedFile> input_file,
|
||||
BufferSlice thumbnail, int32 layer);
|
||||
@ -180,8 +182,6 @@ UserId get_message_content_deleted_user_id(const MessageContent *content);
|
||||
|
||||
int32 get_message_content_live_location_period(const MessageContent *content);
|
||||
|
||||
UserId get_message_content_game_bot_user_id(const MessageContent *content);
|
||||
|
||||
bool get_message_content_poll_is_closed(const Td *td, const MessageContent *content);
|
||||
|
||||
bool get_message_content_poll_is_anonymous(const Td *td, const MessageContent *content);
|
||||
|
@ -17511,7 +17511,7 @@ Result<int32> MessagesManager::get_message_schedule_date(
|
||||
}
|
||||
}
|
||||
|
||||
tl_object_ptr<td_api::MessageSendingState> MessagesManager::get_message_sending_state_object(const Message *m) {
|
||||
tl_object_ptr<td_api::MessageSendingState> MessagesManager::get_message_sending_state_object(const Message *m) const {
|
||||
CHECK(m != nullptr);
|
||||
if (m->message_id.is_yet_unsent()) {
|
||||
return td_api::make_object<td_api::messageSendingStatePending>();
|
||||
@ -19416,7 +19416,7 @@ bool MessagesManager::can_edit_message(DialogId dialog_id, const Message *m, boo
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MessagesManager::can_resend_message(const Message *m) {
|
||||
bool MessagesManager::can_resend_message(const Message *m) const {
|
||||
if (m->send_error_code != 429 && m->send_error_message != "Message is too old to be re-sent automatically" &&
|
||||
m->send_error_message != "SCHEDULE_TOO_MUCH") {
|
||||
return false;
|
||||
@ -19431,8 +19431,7 @@ bool MessagesManager::can_resend_message(const Message *m) {
|
||||
auto content_type = m->content->get_type();
|
||||
if (m->via_bot_user_id.is_valid() || m->hide_via_bot) {
|
||||
// via bot message
|
||||
if (content_type == MessageContentType::Game &&
|
||||
!get_message_content_game_bot_user_id(m->content.get()).is_valid()) {
|
||||
if (!can_have_input_media(td_, m->content.get())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1533,7 +1533,7 @@ class MessagesManager : public Actor {
|
||||
Status can_send_message_content(DialogId dialog_id, const MessageContent *content,
|
||||
bool is_forward) const TD_WARN_UNUSED_RESULT;
|
||||
|
||||
static bool can_resend_message(const Message *m);
|
||||
bool can_resend_message(const Message *m) const;
|
||||
|
||||
bool can_edit_message(DialogId dialog_id, const Message *m, bool is_editing, bool only_reply_markup = false) const;
|
||||
|
||||
@ -1932,7 +1932,7 @@ class MessagesManager : public Actor {
|
||||
|
||||
static Result<int32> get_message_schedule_date(td_api::object_ptr<td_api::MessageSchedulingState> &&scheduling_state);
|
||||
|
||||
static tl_object_ptr<td_api::MessageSendingState> get_message_sending_state_object(const Message *m);
|
||||
tl_object_ptr<td_api::MessageSendingState> get_message_sending_state_object(const Message *m) const;
|
||||
|
||||
static tl_object_ptr<td_api::MessageSchedulingState> get_message_scheduling_state_object(int32 send_date);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user