Move checks for Game message content in dup_message_content.
GitOrigin-RevId: e9d5ad1216c5178b4990b4f17bc5c808cd70cb6f
This commit is contained in:
parent
ebaea15679
commit
7ffd9ad7c9
@ -4091,15 +4091,22 @@ unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const
|
|||||||
CHECK(result->file_id.is_valid());
|
CHECK(result->file_id.is_valid());
|
||||||
return std::move(result);
|
return std::move(result);
|
||||||
}
|
}
|
||||||
case MessageContentType::Game:
|
case MessageContentType::Game: {
|
||||||
return make_unique<MessageGame>(*static_cast<const MessageGame *>(content));
|
auto result = make_unique<MessageGame>(*static_cast<const MessageGame *>(content));
|
||||||
|
if (type != MessageContentDupType::Forward && type != MessageContentDupType::SendViaBot &&
|
||||||
|
!result->game.get_bot_user_id().is_valid()) {
|
||||||
|
LOG(INFO) << "Can't send/copy game without bot_user_id";
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return std::move(result);
|
||||||
|
}
|
||||||
case MessageContentType::Invoice:
|
case MessageContentType::Invoice:
|
||||||
return make_unique<MessageInvoice>(*static_cast<const MessageInvoice *>(content));
|
return make_unique<MessageInvoice>(*static_cast<const MessageInvoice *>(content));
|
||||||
case MessageContentType::LiveLocation:
|
case MessageContentType::LiveLocation:
|
||||||
if (to_secret || type != MessageContentDupType::Send) {
|
if (!to_secret && (type == MessageContentDupType::Send || type == MessageContentDupType::SendViaBot)) {
|
||||||
return make_unique<MessageLocation>(Location(static_cast<const MessageLiveLocation *>(content)->location));
|
|
||||||
} else {
|
|
||||||
return make_unique<MessageLiveLocation>(*static_cast<const MessageLiveLocation *>(content));
|
return make_unique<MessageLiveLocation>(*static_cast<const MessageLiveLocation *>(content));
|
||||||
|
} else {
|
||||||
|
return make_unique<MessageLocation>(Location(static_cast<const MessageLiveLocation *>(content)->location));
|
||||||
}
|
}
|
||||||
case MessageContentType::Location:
|
case MessageContentType::Location:
|
||||||
return make_unique<MessageLocation>(*static_cast<const MessageLocation *>(content));
|
return make_unique<MessageLocation>(*static_cast<const MessageLocation *>(content));
|
||||||
@ -5088,6 +5095,7 @@ void add_message_content_dependencies(Dependencies &dependencies, const MessageC
|
|||||||
case MessageContentType::PassportDataReceived:
|
case MessageContentType::PassportDataReceived:
|
||||||
break;
|
break;
|
||||||
case MessageContentType::Poll:
|
case MessageContentType::Poll:
|
||||||
|
// no need to add poll dependencies, because they are forcely loaded with the poll
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
|
@ -178,10 +178,10 @@ vector<UserId> get_message_content_added_user_ids(const MessageContent *content)
|
|||||||
|
|
||||||
UserId get_message_content_deleted_user_id(const MessageContent *content);
|
UserId get_message_content_deleted_user_id(const MessageContent *content);
|
||||||
|
|
||||||
UserId get_message_content_game_bot_user_id(const MessageContent *content);
|
|
||||||
|
|
||||||
int32 get_message_content_live_location_period(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_closed(const Td *td, const MessageContent *content);
|
||||||
|
|
||||||
bool get_message_content_poll_is_anonymous(const Td *td, const MessageContent *content);
|
bool get_message_content_poll_is_anonymous(const Td *td, const MessageContent *content);
|
||||||
@ -221,7 +221,7 @@ unique_ptr<MessageContent> get_message_content(Td *td, FormattedText message_tex
|
|||||||
DialogId owner_dialog_id, bool is_content_read, UserId via_bot_user_id,
|
DialogId owner_dialog_id, bool is_content_read, UserId via_bot_user_id,
|
||||||
int32 *ttl);
|
int32 *ttl);
|
||||||
|
|
||||||
enum class MessageContentDupType : int32 { Send, Forward, Copy, CopyWithoutCaption };
|
enum class MessageContentDupType : int32 { Send, SendViaBot, Forward, Copy, CopyWithoutCaption };
|
||||||
|
|
||||||
unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const MessageContent *content,
|
unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const MessageContent *content,
|
||||||
MessageContentDupType type);
|
MessageContentDupType type);
|
||||||
|
@ -17767,8 +17767,8 @@ Status MessagesManager::can_send_message(DialogId dialog_id) const {
|
|||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
Status MessagesManager::can_send_message_content(DialogId dialog_id, const MessageContent *content, bool is_forward,
|
Status MessagesManager::can_send_message_content(DialogId dialog_id, const MessageContent *content,
|
||||||
bool is_via_bot) const {
|
bool is_forward) const {
|
||||||
auto dialog_type = dialog_id.get_type();
|
auto dialog_type = dialog_id.get_type();
|
||||||
int32 secret_chat_layer = std::numeric_limits<int32>::max();
|
int32 secret_chat_layer = std::numeric_limits<int32>::max();
|
||||||
if (dialog_type == DialogType::SecretChat) {
|
if (dialog_type == DialogType::SecretChat) {
|
||||||
@ -17786,7 +17786,7 @@ Status MessagesManager::can_send_message_content(DialogId dialog_id, const Messa
|
|||||||
auto content_type = content->get_type();
|
auto content_type = content->get_type();
|
||||||
switch (dialog_type) {
|
switch (dialog_type) {
|
||||||
case DialogType::User:
|
case DialogType::User:
|
||||||
if (content_type == MessageContentType::Poll && !is_forward && !td_->auth_manager_->is_bot() && !is_via_bot &&
|
if (content_type == MessageContentType::Poll && !is_forward && !td_->auth_manager_->is_bot() &&
|
||||||
!td_->contacts_manager_->is_user_bot(dialog_id.get_user_id()) && dialog_id != get_my_dialog_id()) {
|
!td_->contacts_manager_->is_user_bot(dialog_id.get_user_id()) && dialog_id != get_my_dialog_id()) {
|
||||||
return Status::Error(400, "Polls can't be sent to the private chat");
|
return Status::Error(400, "Polls can't be sent to the private chat");
|
||||||
}
|
}
|
||||||
@ -17846,9 +17846,6 @@ Status MessagesManager::can_send_message_content(DialogId dialog_id, const Messa
|
|||||||
if (!can_send_games) {
|
if (!can_send_games) {
|
||||||
return Status::Error(400, "Not enough rights to send games to the chat");
|
return Status::Error(400, "Not enough rights to send games to the chat");
|
||||||
}
|
}
|
||||||
if (!is_forward && !is_via_bot && !get_message_content_game_bot_user_id(content).is_valid()) {
|
|
||||||
return Status::Error(400, "Games can't be copied");
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case MessageContentType::Invoice:
|
case MessageContentType::Invoice:
|
||||||
if (!is_forward) {
|
if (!is_forward) {
|
||||||
@ -19168,12 +19165,12 @@ Result<MessageId> MessagesManager::send_inline_query_result_message(DialogId dia
|
|||||||
}
|
}
|
||||||
|
|
||||||
TRY_STATUS(can_use_send_message_options(send_message_options, content->message_content, 0));
|
TRY_STATUS(can_use_send_message_options(send_message_options, content->message_content, 0));
|
||||||
TRY_STATUS(can_send_message_content(dialog_id, content->message_content.get(), false, true));
|
TRY_STATUS(can_send_message_content(dialog_id, content->message_content.get(), false));
|
||||||
|
|
||||||
bool need_update_dialog_pos = false;
|
bool need_update_dialog_pos = false;
|
||||||
Message *m = get_message_to_send(
|
Message *m = get_message_to_send(
|
||||||
d, get_reply_to_message_id(d, reply_to_message_id), send_message_options,
|
d, get_reply_to_message_id(d, reply_to_message_id), send_message_options,
|
||||||
dup_message_content(td_, dialog_id, content->message_content.get(), MessageContentDupType::Send),
|
dup_message_content(td_, dialog_id, content->message_content.get(), MessageContentDupType::SendViaBot),
|
||||||
&need_update_dialog_pos, nullptr, true);
|
&need_update_dialog_pos, nullptr, true);
|
||||||
m->hide_via_bot = hide_via_bot;
|
m->hide_via_bot = hide_via_bot;
|
||||||
if (!hide_via_bot) {
|
if (!hide_via_bot) {
|
||||||
@ -20678,17 +20675,13 @@ Result<vector<MessageId>> MessagesManager::forward_messages(DialogId to_dialog_i
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto content_type = content->get_type();
|
|
||||||
bool is_game = content_type == MessageContentType::Game;
|
|
||||||
if (need_copy) {
|
if (need_copy) {
|
||||||
if (is_game && !get_message_content_game_bot_user_id(content.get()).is_valid()) {
|
|
||||||
LOG(INFO) << "Can't copy game from " << message_id;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
copied_messages.push_back({std::move(content), forwarded_message->disable_web_page_preview, i});
|
copied_messages.push_back({std::move(content), forwarded_message->disable_web_page_preview, i});
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto content_type = content->get_type();
|
||||||
|
bool is_game = content_type == MessageContentType::Game;
|
||||||
unique_ptr<MessageForwardInfo> forward_info;
|
unique_ptr<MessageForwardInfo> forward_info;
|
||||||
if (!is_game && content_type != MessageContentType::Audio) {
|
if (!is_game && content_type != MessageContentType::Audio) {
|
||||||
DialogId saved_from_dialog_id;
|
DialogId saved_from_dialog_id;
|
||||||
@ -20903,13 +20896,6 @@ Result<vector<MessageId>> MessagesManager::resend_messages(DialogId dialog_id, v
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (content->get_type() == MessageContentType::Game &&
|
|
||||||
!get_message_content_game_bot_user_id(content.get()).is_valid()) {
|
|
||||||
// must not happen
|
|
||||||
LOG(ERROR) << "Can't resend game from " << m->message_id;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
new_contents[i] = std::move(content);
|
new_contents[i] = std::move(content);
|
||||||
|
|
||||||
if (m->media_album_id != 0) {
|
if (m->media_album_id != 0) {
|
||||||
@ -29337,7 +29323,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
|
|||||||
add_message_dependencies(dependencies, dialog_id, m.get());
|
add_message_dependencies(dependencies, dialog_id, m.get());
|
||||||
resolve_dependencies_force(dependencies);
|
resolve_dependencies_force(dependencies);
|
||||||
|
|
||||||
m->content = dup_message_content(td_, dialog_id, m->content.get(), MessageContentDupType::Send);
|
m->content = dup_message_content(td_, dialog_id, m->content.get(), MessageContentDupType::SendViaBot);
|
||||||
|
|
||||||
auto result_message = continue_send_message(dialog_id, std::move(m), event.id_);
|
auto result_message = continue_send_message(dialog_id, std::move(m), event.id_);
|
||||||
if (result_message != nullptr) {
|
if (result_message != nullptr) {
|
||||||
|
@ -1530,8 +1530,8 @@ class MessagesManager : public Actor {
|
|||||||
|
|
||||||
Status can_send_message(DialogId dialog_id) const TD_WARN_UNUSED_RESULT;
|
Status can_send_message(DialogId dialog_id) const TD_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
Status can_send_message_content(DialogId dialog_id, const MessageContent *content, bool is_forward,
|
Status can_send_message_content(DialogId dialog_id, const MessageContent *content,
|
||||||
bool is_via_bot = false) const TD_WARN_UNUSED_RESULT;
|
bool is_forward) const TD_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
static bool can_resend_message(const Message *m);
|
static bool can_resend_message(const Message *m);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user