Merge commit '7cde6f0adb890300355663f904155570197f8b9d'
This commit is contained in:
commit
23af91ce0d
@ -4511,6 +4511,7 @@ void MessagesManager::Message::store(StorerT &storer) const {
|
|||||||
bool has_reply_in_dialog_id = is_reply && reply_in_dialog_id.is_valid();
|
bool has_reply_in_dialog_id = is_reply && reply_in_dialog_id.is_valid();
|
||||||
bool has_top_thread_message_id = top_thread_message_id.is_valid();
|
bool has_top_thread_message_id = top_thread_message_id.is_valid();
|
||||||
bool has_thread_draft_message = thread_draft_message != nullptr;
|
bool has_thread_draft_message = thread_draft_message != nullptr;
|
||||||
|
bool has_local_thread_message_ids = !local_thread_message_ids.empty();
|
||||||
BEGIN_STORE_FLAGS();
|
BEGIN_STORE_FLAGS();
|
||||||
STORE_FLAG(is_channel_post);
|
STORE_FLAG(is_channel_post);
|
||||||
STORE_FLAG(is_outgoing);
|
STORE_FLAG(is_outgoing);
|
||||||
@ -4565,6 +4566,7 @@ void MessagesManager::Message::store(StorerT &storer) const {
|
|||||||
STORE_FLAG(has_reply_in_dialog_id);
|
STORE_FLAG(has_reply_in_dialog_id);
|
||||||
STORE_FLAG(has_top_thread_message_id);
|
STORE_FLAG(has_top_thread_message_id);
|
||||||
STORE_FLAG(has_thread_draft_message);
|
STORE_FLAG(has_thread_draft_message);
|
||||||
|
STORE_FLAG(has_local_thread_message_ids);
|
||||||
END_STORE_FLAGS();
|
END_STORE_FLAGS();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4661,6 +4663,9 @@ void MessagesManager::Message::store(StorerT &storer) const {
|
|||||||
if (has_thread_draft_message) {
|
if (has_thread_draft_message) {
|
||||||
store(thread_draft_message, storer);
|
store(thread_draft_message, storer);
|
||||||
}
|
}
|
||||||
|
if (has_local_thread_message_ids) {
|
||||||
|
store(local_thread_message_ids, storer);
|
||||||
|
}
|
||||||
store_message_content(content.get(), storer);
|
store_message_content(content.get(), storer);
|
||||||
if (has_reply_markup) {
|
if (has_reply_markup) {
|
||||||
store(reply_markup, storer);
|
store(reply_markup, storer);
|
||||||
@ -4700,6 +4705,7 @@ void MessagesManager::Message::parse(ParserT &parser) {
|
|||||||
bool has_reply_in_dialog_id = false;
|
bool has_reply_in_dialog_id = false;
|
||||||
bool has_top_thread_message_id = false;
|
bool has_top_thread_message_id = false;
|
||||||
bool has_thread_draft_message = false;
|
bool has_thread_draft_message = false;
|
||||||
|
bool has_local_thread_message_ids = 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);
|
||||||
@ -4754,6 +4760,7 @@ void MessagesManager::Message::parse(ParserT &parser) {
|
|||||||
PARSE_FLAG(has_reply_in_dialog_id);
|
PARSE_FLAG(has_reply_in_dialog_id);
|
||||||
PARSE_FLAG(has_top_thread_message_id);
|
PARSE_FLAG(has_top_thread_message_id);
|
||||||
PARSE_FLAG(has_thread_draft_message);
|
PARSE_FLAG(has_thread_draft_message);
|
||||||
|
PARSE_FLAG(has_local_thread_message_ids);
|
||||||
END_PARSE_FLAGS();
|
END_PARSE_FLAGS();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4856,6 +4863,9 @@ void MessagesManager::Message::parse(ParserT &parser) {
|
|||||||
if (has_thread_draft_message) {
|
if (has_thread_draft_message) {
|
||||||
parse(thread_draft_message, parser);
|
parse(thread_draft_message, parser);
|
||||||
}
|
}
|
||||||
|
if (has_local_thread_message_ids) {
|
||||||
|
parse(local_thread_message_ids, parser);
|
||||||
|
}
|
||||||
parse_message_content(content, parser);
|
parse_message_content(content, parser);
|
||||||
if (has_reply_markup) {
|
if (has_reply_markup) {
|
||||||
parse(reply_markup, parser);
|
parse(reply_markup, parser);
|
||||||
@ -6206,6 +6216,7 @@ void MessagesManager::on_update_service_notification(tl_object_ptr<telegram_api:
|
|||||||
if (m != nullptr && need_update) {
|
if (m != nullptr && need_update) {
|
||||||
send_update_new_message(d, m);
|
send_update_new_message(d, m);
|
||||||
}
|
}
|
||||||
|
register_new_local_message_id(d, m);
|
||||||
|
|
||||||
if (need_update_dialog_pos) {
|
if (need_update_dialog_pos) {
|
||||||
send_update_chat_last_message(d, "on_update_service_notification");
|
send_update_chat_last_message(d, "on_update_service_notification");
|
||||||
@ -14415,6 +14426,16 @@ unique_ptr<MessagesManager::Message> MessagesManager::do_delete_message(Dialog *
|
|||||||
void MessagesManager::on_message_deleted(Dialog *d, Message *m, bool is_permanently_deleted, const char *source) {
|
void MessagesManager::on_message_deleted(Dialog *d, Message *m, bool is_permanently_deleted, const char *source) {
|
||||||
// also called for unloaded messages
|
// also called for unloaded messages
|
||||||
|
|
||||||
|
if (m->message_id.is_yet_unsent() && m->top_thread_message_id.is_valid()) {
|
||||||
|
auto it = d->yet_unsent_thread_message_ids.find(m->top_thread_message_id);
|
||||||
|
CHECK(it != d->yet_unsent_thread_message_ids.end());
|
||||||
|
auto is_deleted = it->second.erase(m->message_id) > 0;
|
||||||
|
CHECK(is_deleted);
|
||||||
|
if (it->second.empty()) {
|
||||||
|
d->yet_unsent_thread_message_ids.erase(it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cancel_send_deleted_message(d->dialog_id, m, is_permanently_deleted);
|
cancel_send_deleted_message(d->dialog_id, m, is_permanently_deleted);
|
||||||
|
|
||||||
CHECK(m->message_id.is_valid());
|
CHECK(m->message_id.is_valid());
|
||||||
@ -25307,6 +25328,7 @@ Result<MessageId> MessagesManager::add_local_message(
|
|||||||
auto result =
|
auto result =
|
||||||
add_message_to_dialog(d, std::move(m), true, &need_update, &need_update_dialog_pos, "add local message");
|
add_message_to_dialog(d, std::move(m), true, &need_update, &need_update_dialog_pos, "add local message");
|
||||||
LOG_CHECK(result != nullptr) << message_id << " " << debug_add_message_to_dialog_fail_reason_;
|
LOG_CHECK(result != nullptr) << message_id << " " << debug_add_message_to_dialog_fail_reason_;
|
||||||
|
register_new_local_message_id(d, result);
|
||||||
|
|
||||||
if (is_message_auto_read(dialog_id, result->is_outgoing)) {
|
if (is_message_auto_read(dialog_id, result->is_outgoing)) {
|
||||||
if (result->is_outgoing) {
|
if (result->is_outgoing) {
|
||||||
@ -27626,6 +27648,7 @@ void MessagesManager::fail_send_message(FullMessageId full_message_id, int error
|
|||||||
// add_message_to_dialog will not update counts, because need_update == false
|
// add_message_to_dialog will not update counts, because need_update == false
|
||||||
update_message_count_by_index(d, +1, m);
|
update_message_count_by_index(d, +1, m);
|
||||||
}
|
}
|
||||||
|
register_new_local_message_id(d, m);
|
||||||
|
|
||||||
LOG(INFO) << "Send updateMessageSendFailed for " << full_message_id;
|
LOG(INFO) << "Send updateMessageSendFailed for " << full_message_id;
|
||||||
if (!td_->auth_manager_->is_bot()) {
|
if (!td_->auth_manager_->is_bot()) {
|
||||||
@ -30975,6 +30998,11 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m->message_id.is_yet_unsent() && m->top_thread_message_id.is_valid()) {
|
||||||
|
auto is_inserted = d->yet_unsent_thread_message_ids[m->top_thread_message_id].insert(m->message_id).second;
|
||||||
|
CHECK(is_inserted);
|
||||||
|
}
|
||||||
|
|
||||||
switch (dialog_id.get_type()) {
|
switch (dialog_id.get_type()) {
|
||||||
case DialogType::User:
|
case DialogType::User:
|
||||||
case DialogType::Chat:
|
case DialogType::Chat:
|
||||||
@ -31137,6 +31165,30 @@ MessagesManager::Message *MessagesManager::add_scheduled_message_to_dialog(Dialo
|
|||||||
return result_message;
|
return result_message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MessagesManager::register_new_local_message_id(Dialog *d, const Message *m) {
|
||||||
|
if (m == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (m->message_id.is_scheduled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
CHECK(m->message_id.is_local());
|
||||||
|
if (m->top_thread_message_id.is_valid() && m->top_thread_message_id != m->message_id) {
|
||||||
|
Message *top_m = get_message_force(d, m->top_thread_message_id, "register_new_local_message_id");
|
||||||
|
if (top_m != nullptr && top_m->top_thread_message_id == top_m->message_id) {
|
||||||
|
auto it = std::lower_bound(top_m->local_thread_message_ids.begin(), top_m->local_thread_message_ids.end(),
|
||||||
|
m->message_id);
|
||||||
|
if (it == top_m->local_thread_message_ids.end() || *it != m->message_id) {
|
||||||
|
top_m->local_thread_message_ids.insert(it, m->message_id);
|
||||||
|
if (top_m->local_thread_message_ids.size() >= 1000) {
|
||||||
|
top_m->local_thread_message_ids.erase(top_m->local_thread_message_ids.begin());
|
||||||
|
}
|
||||||
|
on_message_changed(d, top_m, false, "register_new_local_message_id");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MessagesManager::on_message_changed(const Dialog *d, const Message *m, bool need_send_update, const char *source) {
|
void MessagesManager::on_message_changed(const Dialog *d, const Message *m, bool need_send_update, const char *source) {
|
||||||
CHECK(d != nullptr);
|
CHECK(d != nullptr);
|
||||||
CHECK(m != nullptr);
|
CHECK(m != nullptr);
|
||||||
@ -31315,6 +31367,20 @@ void MessagesManager::delete_message_from_database(Dialog *d, MessageId message_
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m != nullptr && !m->message_id.is_scheduled() && m->message_id.is_local() &&
|
||||||
|
m->top_thread_message_id.is_valid() && m->top_thread_message_id != m->message_id) {
|
||||||
|
// must not load the message from the database
|
||||||
|
Message *top_m = get_message(d, m->top_thread_message_id);
|
||||||
|
if (top_m != nullptr && top_m->top_thread_message_id == top_m->message_id) {
|
||||||
|
auto it = std::lower_bound(top_m->local_thread_message_ids.begin(), top_m->local_thread_message_ids.end(),
|
||||||
|
m->message_id);
|
||||||
|
if (it != top_m->local_thread_message_ids.end() && *it == m->message_id) {
|
||||||
|
top_m->local_thread_message_ids.erase(it);
|
||||||
|
on_message_changed(d, top_m, false, "delete_message_from_database");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (is_permanently_deleted) {
|
if (is_permanently_deleted) {
|
||||||
if (message_id.is_scheduled() && message_id.is_scheduled_server()) {
|
if (message_id.is_scheduled() && message_id.is_scheduled_server()) {
|
||||||
d->deleted_scheduled_server_message_ids.insert(message_id.get_scheduled_server_message_id());
|
d->deleted_scheduled_server_message_ids.insert(message_id.get_scheduled_server_message_id());
|
||||||
|
@ -1035,6 +1035,7 @@ class MessagesManager : public Actor {
|
|||||||
int64 reply_to_random_id = 0; // for send_message
|
int64 reply_to_random_id = 0; // for send_message
|
||||||
DialogId reply_in_dialog_id;
|
DialogId reply_in_dialog_id;
|
||||||
MessageId top_thread_message_id;
|
MessageId top_thread_message_id;
|
||||||
|
vector<MessageId> local_thread_message_ids;
|
||||||
|
|
||||||
UserId via_bot_user_id;
|
UserId via_bot_user_id;
|
||||||
|
|
||||||
@ -1250,6 +1251,9 @@ class MessagesManager : public Actor {
|
|||||||
// application start, used to guarantee that all assigned message identifiers
|
// application start, used to guarantee that all assigned message identifiers
|
||||||
// are different
|
// are different
|
||||||
|
|
||||||
|
std::unordered_map<MessageId, std::set<MessageId>, MessageIdHash>
|
||||||
|
yet_unsent_thread_message_ids; // top_thread_message_id -> yet unsent message IDs
|
||||||
|
|
||||||
std::unordered_map<ScheduledServerMessageId, int32, ScheduledServerMessageIdHash> scheduled_message_date;
|
std::unordered_map<ScheduledServerMessageId, int32, ScheduledServerMessageIdHash> scheduled_message_date;
|
||||||
|
|
||||||
std::unordered_map<MessageId, MessageId, MessageIdHash> yet_unsent_message_id_to_persistent_message_id;
|
std::unordered_map<MessageId, MessageId, MessageIdHash> yet_unsent_message_id_to_persistent_message_id;
|
||||||
@ -2053,6 +2057,8 @@ class MessagesManager : public Actor {
|
|||||||
Message *add_scheduled_message_to_dialog(Dialog *d, unique_ptr<Message> message, bool from_update, bool *need_update,
|
Message *add_scheduled_message_to_dialog(Dialog *d, unique_ptr<Message> message, bool from_update, bool *need_update,
|
||||||
const char *source);
|
const char *source);
|
||||||
|
|
||||||
|
void register_new_local_message_id(Dialog *d, const Message *m);
|
||||||
|
|
||||||
void on_message_changed(const Dialog *d, const Message *m, bool need_send_update, const char *source);
|
void on_message_changed(const Dialog *d, const Message *m, bool need_send_update, const char *source);
|
||||||
|
|
||||||
bool need_delete_file(FullMessageId full_message_id, FileId file_id) const;
|
bool need_delete_file(FullMessageId full_message_id, FileId file_id) const;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user