Add messageChatSetTtl.from_user_id.

This commit is contained in:
levlam 2022-11-29 14:02:05 +03:00
parent a26274a62b
commit 62e721fa6f
6 changed files with 51 additions and 17 deletions

View File

@ -2094,8 +2094,8 @@ messageScreenshotTaken = MessageContent;
//@description A theme in the chat has been changed @theme_name If non-empty, name of a new theme, set for the chat. Otherwise chat theme was reset to the default one
messageChatSetTheme theme_name:string = MessageContent;
//@description The TTL (Time To Live) setting for messages in the chat has been changed @ttl New message TTL
messageChatSetTtl ttl:int32 = MessageContent;
//@description The TTL (Time To Live) setting for messages in the chat has been changed @ttl New message TTL @from_user_id If not 0, a user identifier, which default setting was automatically applied
messageChatSetTtl ttl:int32 from_user_id:int53 = MessageContent;
//@description A forum topic has been created @name Name of the topic @icon Icon of the topic
messageForumTopicCreated name:string icon:forumTopicIcon = MessageContent;

View File

@ -450,9 +450,10 @@ class MessageScreenshotTaken final : public MessageContent {
class MessageChatSetTtl final : public MessageContent {
public:
int32 ttl;
UserId from_user_id;
MessageChatSetTtl() = default;
explicit MessageChatSetTtl(int32 ttl) : ttl(ttl) {
MessageChatSetTtl(int32 ttl, UserId from_user_id) : ttl(ttl), from_user_id(from_user_id) {
}
MessageContentType get_type() const final {
@ -1009,7 +1010,14 @@ static void store(const MessageContent *content, StorerT &storer) {
break;
case MessageContentType::ChatSetTtl: {
const auto *m = static_cast<const MessageChatSetTtl *>(content);
bool has_from_user_id = m->from_user_id.is_valid();
BEGIN_STORE_FLAGS();
STORE_FLAG(has_from_user_id);
END_STORE_FLAGS();
store(m->ttl, storer);
if (has_from_user_id) {
store(m->from_user_id, storer);
}
break;
}
case MessageContentType::Call: {
@ -1427,7 +1435,16 @@ static void parse(unique_ptr<MessageContent> &content, ParserT &parser) {
break;
case MessageContentType::ChatSetTtl: {
auto m = make_unique<MessageChatSetTtl>();
bool has_from_user_id = false;
if (parser.version() >= static_cast<int32>(Version::AddMessageChatSetTtlFlags)) {
BEGIN_PARSE_FLAGS();
PARSE_FLAG(has_from_user_id);
END_PARSE_FLAGS();
}
parse(m->ttl, parser);
if (has_from_user_id) {
parse(m->from_user_id, parser);
}
content = std::move(m);
break;
}
@ -1783,8 +1800,8 @@ unique_ptr<MessageContent> create_screenshot_taken_message_content() {
return make_unique<MessageScreenshotTaken>();
}
unique_ptr<MessageContent> create_chat_set_ttl_message_content(int32 ttl) {
return make_unique<MessageChatSetTtl>(ttl);
unique_ptr<MessageContent> create_chat_set_ttl_message_content(int32 ttl, UserId from_user_id) {
return make_unique<MessageChatSetTtl>(ttl, from_user_id);
}
static Result<InputMessageContent> create_input_message_content(
@ -3584,7 +3601,10 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo
const auto *old_ = static_cast<const MessageChatSetTtl *>(old_content);
const auto *new_ = static_cast<const MessageChatSetTtl *>(new_content);
if (old_->ttl != new_->ttl) {
LOG(ERROR) << "Ttl has changed from " << old_->ttl << " to " << new_->ttl;
LOG(ERROR) << "TTL has changed from " << old_->ttl << " to " << new_->ttl;
need_update = true;
}
if (old_->from_user_id != new_->from_user_id) {
need_update = true;
}
break;
@ -3592,10 +3612,11 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo
case MessageContentType::Call: {
const auto *old_ = static_cast<const MessageCall *>(old_content);
const auto *new_ = static_cast<const MessageCall *>(new_content);
if (old_->call_id != new_->call_id || old_->is_video != new_->is_video) {
if (old_->call_id != new_->call_id) {
is_content_changed = true;
}
if (old_->duration != new_->duration || old_->discard_reason != new_->discard_reason) {
if (old_->duration != new_->duration || old_->discard_reason != new_->discard_reason ||
old_->is_video != new_->is_video) {
need_update = true;
}
break;
@ -5129,11 +5150,12 @@ unique_ptr<MessageContent> get_action_message_content(Td *td, tl_object_ptr<tele
}
case telegram_api::messageActionSetMessagesTTL::ID: {
auto action = move_tl_object_as<telegram_api::messageActionSetMessagesTTL>(action_ptr);
if (action->period_ < 0) {
LOG(ERROR) << "Receive wrong TTL = " << action->period_;
UserId from_user_id(action->auto_setting_from_);
if (action->period_ < 0 || !(from_user_id == UserId() || from_user_id.is_valid())) {
LOG(ERROR) << "Receive invalid " << oneline(to_string(action));
break;
}
return make_unique<MessageChatSetTtl>(action->period_);
return make_unique<MessageChatSetTtl>(action->period_, from_user_id);
}
case telegram_api::messageActionGroupCallScheduled::ID: {
auto action = move_tl_object_as<telegram_api::messageActionGroupCallScheduled>(action_ptr);
@ -5361,7 +5383,8 @@ tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageCo
return make_tl_object<td_api::messageScreenshotTaken>();
case MessageContentType::ChatSetTtl: {
const auto *m = static_cast<const MessageChatSetTtl *>(content);
return make_tl_object<td_api::messageChatSetTtl>(m->ttl);
return make_tl_object<td_api::messageChatSetTtl>(
m->ttl, td->contacts_manager_->get_user_id_object(m->from_user_id, "MessageChatSetTtl"));
}
case MessageContentType::Call: {
const auto *m = static_cast<const MessageCall *>(content);
@ -6055,8 +6078,11 @@ void add_message_content_dependencies(Dependencies &dependencies, const MessageC
break;
case MessageContentType::ScreenshotTaken:
break;
case MessageContentType::ChatSetTtl:
case MessageContentType::ChatSetTtl: {
const auto *content = static_cast<const MessageChatSetTtl *>(message_content);
dependencies.add(content->from_user_id);
break;
}
case MessageContentType::Unsupported:
break;
case MessageContentType::Call:

View File

@ -98,7 +98,7 @@ unique_ptr<MessageContent> create_contact_registered_message_content();
unique_ptr<MessageContent> create_screenshot_taken_message_content();
unique_ptr<MessageContent> create_chat_set_ttl_message_content(int32 ttl);
unique_ptr<MessageContent> create_chat_set_ttl_message_content(int32 ttl, UserId from_user_id);
Result<InputMessageContent> get_input_message_content(
DialogId dialog_id, tl_object_ptr<td_api::InputMessageContent> &&input_message_content, Td *td, bool is_premium);

View File

@ -14527,7 +14527,7 @@ void MessagesManager::on_secret_chat_ttl_changed(SecretChatId secret_chat_id, Us
message_info.date = date;
message_info.random_id = random_id;
message_info.flags = MESSAGE_FLAG_HAS_FROM_ID;
message_info.content = create_chat_set_ttl_message_content(ttl);
message_info.content = create_chat_set_ttl_message_content(ttl, UserId());
Dialog *d = get_dialog_force(message_info.dialog_id, "on_secret_chat_ttl_changed");
if (d == nullptr && have_dialog_info_force(message_info.dialog_id)) {
@ -34564,7 +34564,7 @@ void MessagesManager::set_dialog_message_ttl(DialogId dialog_id, int32 ttl, Prom
} else {
bool need_update_dialog_pos = false;
Message *m = get_message_to_send(d, MessageId(), MessageId(), MessageSendOptions(),
create_chat_set_ttl_message_content(ttl), &need_update_dialog_pos);
create_chat_set_ttl_message_content(ttl, UserId()), &need_update_dialog_pos);
send_update_new_message(d, m);
if (need_update_dialog_pos) {

View File

@ -768,7 +768,6 @@ bool UpdatesManager::is_acceptable_message(const telegram_api::Message *message_
case telegram_api::messageActionContactSignUp::ID:
case telegram_api::messageActionGroupCall::ID:
case telegram_api::messageActionGroupCallScheduled::ID:
case telegram_api::messageActionSetMessagesTTL::ID:
case telegram_api::messageActionSetChatTheme::ID:
case telegram_api::messageActionChatJoinedByRequest::ID:
case telegram_api::messageActionWebViewDataSentMe::ID:
@ -838,6 +837,14 @@ bool UpdatesManager::is_acceptable_message(const telegram_api::Message *message_
}
break;
}
case telegram_api::messageActionSetMessagesTTL::ID: {
auto set_messages_ttl = static_cast<const telegram_api::messageActionSetMessagesTTL *>(action);
if (set_messages_ttl->auto_setting_from_ != 0 &&
!is_acceptable_user(UserId(set_messages_ttl->auto_setting_from_))) {
return false;
}
break;
}
default:
UNREACHABLE();
return false;

View File

@ -57,6 +57,7 @@ enum class Version : int32 {
AddStickerSetListFlags,
AddInputInvoiceFlags,
AddVideoNoteFlags,
AddMessageChatSetTtlFlags,
Next
};