Add Message.saved_messages_dialog_id.

This commit is contained in:
levlam 2024-01-12 15:38:12 +03:00
parent 2ff04387b8
commit 09e0add01f
2 changed files with 67 additions and 0 deletions

View File

@ -3903,6 +3903,7 @@ void MessagesManager::Message::store(StorerT &storer) const {
bool has_input_reply_to = !message_id.is_any_server() && input_reply_to.is_valid(); bool has_input_reply_to = !message_id.is_any_server() && input_reply_to.is_valid();
bool has_replied_message_info = !replied_message_info.is_empty(); bool has_replied_message_info = !replied_message_info.is_empty();
bool has_forward_info = forward_info != nullptr; bool has_forward_info = forward_info != nullptr;
bool has_saved_messages_dialog_id = saved_messages_dialog_id.is_valid();
BEGIN_STORE_FLAGS(); BEGIN_STORE_FLAGS();
STORE_FLAG(is_channel_post); STORE_FLAG(is_channel_post);
STORE_FLAG(is_outgoing); STORE_FLAG(is_outgoing);
@ -3984,6 +3985,7 @@ void MessagesManager::Message::store(StorerT &storer) const {
STORE_FLAG(has_input_reply_to); STORE_FLAG(has_input_reply_to);
STORE_FLAG(has_replied_message_info); STORE_FLAG(has_replied_message_info);
STORE_FLAG(has_forward_info); STORE_FLAG(has_forward_info);
STORE_FLAG(has_saved_messages_dialog_id);
END_STORE_FLAGS(); END_STORE_FLAGS();
} }
@ -4098,6 +4100,9 @@ void MessagesManager::Message::store(StorerT &storer) const {
if (has_replied_message_info) { if (has_replied_message_info) {
store(replied_message_info, storer); store(replied_message_info, storer);
} }
if (has_saved_messages_dialog_id) {
store(saved_messages_dialog_id, storer);
}
} }
// do not forget to resolve message dependencies // do not forget to resolve message dependencies
@ -4151,6 +4156,7 @@ void MessagesManager::Message::parse(ParserT &parser) {
bool has_input_reply_to = false; bool has_input_reply_to = false;
bool has_replied_message_info = false; bool has_replied_message_info = false;
bool has_forward_info = false; bool has_forward_info = false;
bool has_saved_messages_dialog_id = false;
BEGIN_PARSE_FLAGS(); BEGIN_PARSE_FLAGS();
PARSE_FLAG(is_channel_post); PARSE_FLAG(is_channel_post);
PARSE_FLAG(is_outgoing); PARSE_FLAG(is_outgoing);
@ -4232,6 +4238,7 @@ void MessagesManager::Message::parse(ParserT &parser) {
PARSE_FLAG(has_input_reply_to); PARSE_FLAG(has_input_reply_to);
PARSE_FLAG(has_replied_message_info); PARSE_FLAG(has_replied_message_info);
PARSE_FLAG(has_forward_info); PARSE_FLAG(has_forward_info);
PARSE_FLAG(has_saved_messages_dialog_id);
END_PARSE_FLAGS(); END_PARSE_FLAGS();
} }
@ -4410,6 +4417,9 @@ void MessagesManager::Message::parse(ParserT &parser) {
} else { } else {
replied_message_info = RepliedMessageInfo::legacy(legacy_reply_to_message_id, legacy_reply_in_dialog_id); replied_message_info = RepliedMessageInfo::legacy(legacy_reply_to_message_id, legacy_reply_in_dialog_id);
} }
if (has_saved_messages_dialog_id) {
parse(saved_messages_dialog_id, parser);
}
CHECK(content != nullptr); CHECK(content != nullptr);
is_content_secret |= is_content_secret |=
@ -12735,6 +12745,23 @@ void MessagesManager::finish_add_secret_message(unique_ptr<PendingSecretMessage>
pending_secret_message->success_promise.set_value(Unit()); // TODO: set after message is saved pending_secret_message->success_promise.set_value(Unit()); // TODO: set after message is saved
} }
DialogId MessagesManager::get_saved_messages_dialog_id(DialogId my_dialog_id, const Message *m) {
if (m->forward_info != nullptr) {
auto last_dialog_id = m->forward_info->get_last_dialog_id();
if (last_dialog_id.is_valid()) {
return last_dialog_id;
}
auto from_dialog_id = m->forward_info->get_origin().get_sender();
if (from_dialog_id.is_valid()) {
return my_dialog_id;
}
if (m->forward_info->get_origin().is_sender_hidden()) {
return DialogId(static_cast<int64>(2666000));
}
}
return my_dialog_id;
}
MessagesManager::MessageInfo MessagesManager::parse_telegram_api_message( MessagesManager::MessageInfo MessagesManager::parse_telegram_api_message(
tl_object_ptr<telegram_api::Message> message_ptr, bool is_scheduled, const char *source) const { tl_object_ptr<telegram_api::Message> message_ptr, bool is_scheduled, const char *source) const {
LOG(DEBUG) << "Receive from " << source << " " << to_string(message_ptr); LOG(DEBUG) << "Receive from " << source << " " << to_string(message_ptr);
@ -12810,6 +12837,9 @@ MessagesManager::MessageInfo MessagesManager::parse_telegram_api_message(
message_info.reply_markup = std::move(message->reply_markup_); message_info.reply_markup = std::move(message->reply_markup_);
message_info.restriction_reasons = get_restriction_reasons(std::move(message->restriction_reason_)); message_info.restriction_reasons = get_restriction_reasons(std::move(message->restriction_reason_));
message_info.author_signature = std::move(message->post_author_); message_info.author_signature = std::move(message->post_author_);
if (message->saved_peer_id_ != nullptr) {
message_info.saved_messages_dialog_id = DialogId(message->saved_peer_id_);
}
break; break;
} }
case telegram_api::messageService::ID: { case telegram_api::messageService::ID: {
@ -12838,6 +12868,9 @@ MessagesManager::MessageInfo MessagesManager::parse_telegram_api_message(
message_info.reply_header.replied_message_info_); message_info.reply_header.replied_message_info_);
message_info.reply_header.replied_message_info_ = RepliedMessageInfo(); message_info.reply_header.replied_message_info_ = RepliedMessageInfo();
message_info.reply_header.story_full_id_ = StoryFullId(); message_info.reply_header.story_full_id_ = StoryFullId();
if (message_info.dialog_id == td_->dialog_manager_->get_my_dialog_id()) {
message_info.saved_messages_dialog_id = message_info.dialog_id;
}
break; break;
} }
default: default:
@ -13090,6 +13123,7 @@ std::pair<DialogId, unique_ptr<MessagesManager::Message>> MessagesManager::creat
message->reply_to_story_full_id = reply_to_story_full_id; message->reply_to_story_full_id = reply_to_story_full_id;
message->restriction_reasons = std::move(message_info.restriction_reasons); message->restriction_reasons = std::move(message_info.restriction_reasons);
message->author_signature = std::move(message_info.author_signature); message->author_signature = std::move(message_info.author_signature);
message->saved_messages_dialog_id = message_info.saved_messages_dialog_id;
message->is_outgoing = is_outgoing; message->is_outgoing = is_outgoing;
message->is_channel_post = is_channel_post; message->is_channel_post = is_channel_post;
message->contains_mention = message->contains_mention =
@ -13139,6 +13173,19 @@ std::pair<DialogId, unique_ptr<MessagesManager::Message>> MessagesManager::creat
message->had_forward_info = true; message->had_forward_info = true;
} }
if (dialog_id == my_dialog_id) {
if (!message->saved_messages_dialog_id.is_valid()) {
LOG(ERROR) << "Receive no saved messages topic for " << message_id << " in " << dialog_id;
message->saved_messages_dialog_id = get_saved_messages_dialog_id(dialog_id, message.get());
}
} else {
if (message->saved_messages_dialog_id.is_valid()) {
LOG(ERROR) << "Receive saved messages topic " << message_info.saved_messages_dialog_id << " for " << message_id
<< " in " << dialog_id;
message->saved_messages_dialog_id = DialogId();
}
}
Dependencies dependencies; Dependencies dependencies;
add_message_dependencies(dependencies, message.get()); add_message_dependencies(dependencies, message.get());
for (auto dependent_dialog_id : dependencies.get_dialog_ids()) { for (auto dependent_dialog_id : dependencies.get_dialog_ids()) {
@ -21352,6 +21399,9 @@ unique_ptr<MessagesManager::Message> MessagesManager::parse_message(Dialog *d, M
if (m->is_pinned && is_scheduled) { if (m->is_pinned && is_scheduled) {
m->is_pinned = false; m->is_pinned = false;
} }
if (dialog_id == td_->dialog_manager_->get_my_dialog_id() && !m->saved_messages_dialog_id.is_valid()) {
m->saved_messages_dialog_id = get_saved_messages_dialog_id(dialog_id, m);
}
LOG(INFO) << "Loaded " << m->message_id << " in " << dialog_id << " of size " << value.size() << " from database"; LOG(INFO) << "Loaded " << m->message_id << " in " << dialog_id << " of size " << value.size() << " from database";
return message; return message;
@ -22535,6 +22585,9 @@ unique_ptr<MessagesManager::Message> MessagesManager::create_message_to_send(
} }
m->is_content_secret = is_secret_message_content(m->ttl, m->content->get_type()); m->is_content_secret = is_secret_message_content(m->ttl, m->content->get_type());
} }
if (dialog_id == DialogId(my_id)) {
m->saved_messages_dialog_id = get_saved_messages_dialog_id(dialog_id, m);
}
return message; return message;
} }
@ -22879,6 +22932,7 @@ void MessagesManager::add_message_dependencies(Dependencies &dependencies, const
auto is_bot = td_->auth_manager_->is_bot(); auto is_bot = td_->auth_manager_->is_bot();
dependencies.add(m->sender_user_id); dependencies.add(m->sender_user_id);
dependencies.add_dialog_and_dependencies(m->sender_dialog_id); dependencies.add_dialog_and_dependencies(m->sender_dialog_id);
dependencies.add_dialog_and_dependencies(m->saved_messages_dialog_id);
m->replied_message_info.add_dependencies(dependencies, is_bot); m->replied_message_info.add_dependencies(dependencies, is_bot);
dependencies.add_dialog_and_dependencies(m->reply_to_story_full_id.get_dialog_id()); dependencies.add_dialog_and_dependencies(m->reply_to_story_full_id.get_dialog_id());
dependencies.add_dialog_and_dependencies(m->real_forward_from_dialog_id); dependencies.add_dialog_and_dependencies(m->real_forward_from_dialog_id);
@ -26620,6 +26674,9 @@ Result<MessageId> MessagesManager::add_local_message(
} }
m->is_content_secret = is_secret_message_content(m->ttl, m->content->get_type()); m->is_content_secret = is_secret_message_content(m->ttl, m->content->get_type());
m->send_emoji = std::move(message_content.emoji); m->send_emoji = std::move(message_content.emoji);
if (dialog_id == DialogId(my_id)) {
m->saved_messages_dialog_id = get_saved_messages_dialog_id(dialog_id, m);
}
bool need_update = true; bool need_update = true;
bool need_update_dialog_pos = false; bool need_update_dialog_pos = false;
@ -33071,6 +33128,12 @@ bool MessagesManager::update_message(Dialog *d, Message *old_message, unique_ptr
<< new_message->had_forward_info; << new_message->had_forward_info;
old_message->had_forward_info = new_message->had_forward_info; old_message->had_forward_info = new_message->had_forward_info;
} }
if (old_message->saved_messages_dialog_id != new_message->saved_messages_dialog_id) {
LOG(ERROR) << "Saved messages topic for " << message_id << " in " << dialog_id << " changed from "
<< old_message->saved_messages_dialog_id << " to " << new_message->saved_messages_dialog_id;
old_message->saved_messages_dialog_id = new_message->saved_messages_dialog_id;
need_send_update = true;
}
if (old_message->notification_id != new_message->notification_id) { if (old_message->notification_id != new_message->notification_id) {
CHECK(!is_scheduled); CHECK(!is_scheduled);
if (old_message->notification_id.is_valid()) { if (old_message->notification_id.is_valid()) {

View File

@ -948,6 +948,7 @@ class MessagesManager final : public Actor {
MessageId message_id; MessageId message_id;
UserId sender_user_id; UserId sender_user_id;
DialogId sender_dialog_id; DialogId sender_dialog_id;
DialogId saved_messages_dialog_id;
int32 date = 0; int32 date = 0;
int32 ttl_period = 0; int32 ttl_period = 0;
int32 ttl = 0; int32 ttl = 0;
@ -985,6 +986,7 @@ class MessagesManager final : public Actor {
MessageId message_id; MessageId message_id;
UserId sender_user_id; UserId sender_user_id;
DialogId sender_dialog_id; DialogId sender_dialog_id;
DialogId saved_messages_dialog_id;
int32 date = 0; int32 date = 0;
int32 edit_date = 0; int32 edit_date = 0;
int32 send_date = 0; int32 send_date = 0;
@ -1609,6 +1611,8 @@ class MessagesManager final : public Actor {
void finish_delete_secret_chat_history(DialogId dialog_id, bool remove_from_dialog_list, MessageId last_message_id, void finish_delete_secret_chat_history(DialogId dialog_id, bool remove_from_dialog_list, MessageId last_message_id,
Promise<Unit> promise); Promise<Unit> promise);
static DialogId get_saved_messages_dialog_id(DialogId my_dialog_id, const Message *m);
MessageInfo parse_telegram_api_message(tl_object_ptr<telegram_api::Message> message_ptr, bool is_scheduled, MessageInfo parse_telegram_api_message(tl_object_ptr<telegram_api::Message> message_ptr, bool is_scheduled,
const char *source) const; const char *source) const;