Support audio-only and document-only albums.
GitOrigin-RevId: 96283716a84613e8e9dd1cb9bfb4d69097cefcc7
This commit is contained in:
parent
af6fe68c00
commit
d159ab4f52
@ -104,15 +104,15 @@ StringBuilder &operator<<(StringBuilder &string_builder, MessageContentType cont
|
||||
|
||||
bool is_allowed_media_group_content(MessageContentType content_type) {
|
||||
switch (content_type) {
|
||||
case MessageContentType::Audio:
|
||||
case MessageContentType::Document:
|
||||
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:
|
||||
@ -154,6 +154,10 @@ bool is_allowed_media_group_content(MessageContentType content_type) {
|
||||
}
|
||||
}
|
||||
|
||||
bool is_homogenous_media_group_content(MessageContentType content_type) {
|
||||
return content_type == MessageContentType::Audio || content_type == MessageContentType::Document;
|
||||
}
|
||||
|
||||
bool is_secret_message_content(int32 ttl, MessageContentType content_type) {
|
||||
if (ttl <= 0 || ttl > 60) {
|
||||
return false;
|
||||
|
@ -61,6 +61,8 @@ StringBuilder &operator<<(StringBuilder &string_builder, MessageContentType cont
|
||||
|
||||
bool is_allowed_media_group_content(MessageContentType content_type);
|
||||
|
||||
bool is_homogenous_media_group_content(MessageContentType content_type);
|
||||
|
||||
bool is_secret_message_content(int32 ttl, MessageContentType content_type);
|
||||
|
||||
bool is_service_message_content(MessageContentType content_type);
|
||||
|
@ -22653,15 +22653,25 @@ Result<vector<MessageId>> MessagesManager::send_message_group(
|
||||
TRY_RESULT(message_send_options, process_message_send_options(dialog_id, std::move(options)));
|
||||
|
||||
vector<std::pair<unique_ptr<MessageContent>, int32>> message_contents;
|
||||
std::unordered_set<MessageContentType> message_content_types;
|
||||
for (auto &input_message_content : input_message_contents) {
|
||||
TRY_RESULT(message_content, process_input_message_content(dialog_id, std::move(input_message_content)));
|
||||
TRY_STATUS(can_use_message_send_options(message_send_options, message_content));
|
||||
if (!is_allowed_media_group_content(message_content.content->get_type())) {
|
||||
auto message_content_type = message_content.content->get_type();
|
||||
if (!is_allowed_media_group_content(message_content_type)) {
|
||||
return Status::Error(5, "Invalid message content type");
|
||||
}
|
||||
message_content_types.insert(message_content_type);
|
||||
|
||||
message_contents.emplace_back(std::move(message_content.content), message_content.ttl);
|
||||
}
|
||||
if (message_content_types.size() > 1) {
|
||||
for (auto message_content_type : message_content_types) {
|
||||
if (is_homogenous_media_group_content(message_content_type)) {
|
||||
return Status::Error(400, PSLICE() << message_content_type << " can't be mixed with other media types");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
reply_to_message_id = get_reply_to_message_id(d, top_thread_message_id, reply_to_message_id);
|
||||
TRY_STATUS(can_use_top_thread_message_id(d, top_thread_message_id, reply_to_message_id));
|
||||
@ -24039,10 +24049,6 @@ void MessagesManager::edit_message_media(FullMessageId full_message_id,
|
||||
old_message_content_type != MessageContentType::Photo && old_message_content_type != MessageContentType::Video) {
|
||||
return promise.set_error(Status::Error(5, "There is no media in the message to edit"));
|
||||
}
|
||||
if (m->media_album_id != 0 && new_message_content_type != td_api::inputMessagePhoto::ID &&
|
||||
new_message_content_type != td_api::inputMessageVideo::ID) {
|
||||
return promise.set_error(Status::Error(5, "Message can be edit only to Photo or Video"));
|
||||
}
|
||||
if (m->ttl > 0) {
|
||||
return promise.set_error(Status::Error(5, "Can't edit media in self-destructing message"));
|
||||
}
|
||||
@ -24056,6 +24062,19 @@ void MessagesManager::edit_message_media(FullMessageId full_message_id,
|
||||
return promise.set_error(Status::Error(5, "Can't enable self-destruction for media"));
|
||||
}
|
||||
|
||||
if (m->media_album_id != 0) {
|
||||
auto new_content_type = content.content->get_type();
|
||||
if (old_message_content_type != new_content_type) {
|
||||
if (!is_allowed_media_group_content(new_content_type)) {
|
||||
return promise.set_error(Status::Error(5, "Message content type can't be used in an album"));
|
||||
}
|
||||
if (is_homogenous_media_group_content(old_message_content_type) ||
|
||||
is_homogenous_media_group_content(new_content_type)) {
|
||||
return promise.set_error(Status::Error(5, "Can't change media type in the album"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto r_new_reply_markup = get_reply_markup(std::move(reply_markup), td_->auth_manager_->is_bot(), true, false,
|
||||
has_message_sender_user_id(dialog_id, m));
|
||||
if (r_new_reply_markup.is_error()) {
|
||||
|
Loading…
Reference in New Issue
Block a user