Add can_be_local_message_content.

This commit is contained in:
levlam 2024-06-22 11:05:35 +03:00
parent 741272ad8f
commit 3a50bc6332
3 changed files with 81 additions and 8 deletions

View File

@ -320,6 +320,83 @@ bool can_be_secret_message_content(MessageContentType content_type) {
}
}
bool can_be_local_message_content(MessageContentType content_type) {
switch (content_type) {
case MessageContentType::Animation:
case MessageContentType::Audio:
case MessageContentType::Contact:
case MessageContentType::Document:
case MessageContentType::Location:
case MessageContentType::Photo:
case MessageContentType::Sticker:
case MessageContentType::Text:
case MessageContentType::Venue:
case MessageContentType::Video:
case MessageContentType::VideoNote:
case MessageContentType::VoiceNote:
case MessageContentType::Story:
return true;
case MessageContentType::Game:
case MessageContentType::Invoice:
case MessageContentType::LiveLocation:
case MessageContentType::Unsupported:
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:
case MessageContentType::Dice:
case MessageContentType::ProximityAlertTriggered:
case MessageContentType::GroupCall:
case MessageContentType::InviteToGroupCall:
case MessageContentType::ChatSetTheme:
case MessageContentType::WebViewDataSent:
case MessageContentType::WebViewDataReceived:
case MessageContentType::GiftPremium:
case MessageContentType::TopicCreate:
case MessageContentType::TopicEdit:
case MessageContentType::SuggestProfilePhoto:
case MessageContentType::WriteAccessAllowed:
case MessageContentType::RequestedDialog:
case MessageContentType::WebViewWriteAccessAllowed:
case MessageContentType::SetBackground:
case MessageContentType::WriteAccessAllowedByRequest:
case MessageContentType::GiftCode:
case MessageContentType::Giveaway:
case MessageContentType::GiveawayLaunch:
case MessageContentType::GiveawayResults:
case MessageContentType::GiveawayWinners:
case MessageContentType::ExpiredVideoNote:
case MessageContentType::ExpiredVoiceNote:
case MessageContentType::BoostApply:
case MessageContentType::DialogShared:
return false;
default:
UNREACHABLE();
return false;
}
}
bool is_service_message_content(MessageContentType content_type) {
switch (content_type) {
case MessageContentType::Animation:

View File

@ -94,6 +94,8 @@ bool is_homogenous_media_group_content(MessageContentType content_type);
bool can_be_secret_message_content(MessageContentType content_type);
bool can_be_local_message_content(MessageContentType content_type);
bool is_service_message_content(MessageContentType content_type);
bool is_editable_message_content(MessageContentType content_type);

View File

@ -26908,14 +26908,8 @@ Result<MessageId> MessagesManager::add_local_message(
TRY_RESULT(d, check_dialog_access(dialog_id, true, AccessRights::Read, "add_local_message"));
TRY_RESULT(message_content, process_input_message_content(dialog_id, std::move(input_message_content), false));
if (message_content.content->get_type() == MessageContentType::Poll) {
return Status::Error(400, "Can't add local poll message");
}
if (message_content.content->get_type() == MessageContentType::Game) {
return Status::Error(400, "Can't add local game message");
}
if (message_content.content->get_type() == MessageContentType::Dice) {
return Status::Error(400, "Can't add local dice message");
if (!can_be_local_message_content(message_content.content->get_type())) {
return Status::Error(400, "Can't add a local message with the specified content");
}
bool is_channel_post = td_->dialog_manager_->is_broadcast_channel(dialog_id);