Preload chat to which belongs the replied meessage from a draft.

This commit is contained in:
levlam 2023-11-01 21:32:09 +03:00
parent 36ce823dcc
commit 37637bf9ed
6 changed files with 72 additions and 7 deletions

View File

@ -1013,6 +1013,10 @@ void DialogFilterManager::on_load_dialog_filter_dialogs(DialogFilterId dialog_fi
promise.set_value(Unit());
}
void DialogFilterManager::load_input_dialog(const InputDialogId &input_dialog_id, Promise<Unit> &&promise) {
td_->create_handler<GetDialogsQuery>(std::move(promise))->send({input_dialog_id});
}
void DialogFilterManager::delete_dialogs_from_filter(const DialogFilter *dialog_filter, vector<DialogId> &&dialog_ids,
const char *source) {
if (dialog_ids.empty()) {

View File

@ -120,6 +120,8 @@ class DialogFilterManager final : public Actor {
void load_dialog_filter_dialogs(DialogFilterId dialog_filter_id, vector<InputDialogId> &&input_dialog_ids,
Promise<Unit> &&promise);
void load_input_dialog(const InputDialogId &input_dialog_id, Promise<Unit> &&promise);
void set_dialog_filter_has_my_invite_links(DialogFilterId dialog_filter_id, bool has_my_invite_links);
void get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const;

View File

@ -15,6 +15,25 @@
namespace td {
InputDialogId::InputDialogId(const telegram_api::object_ptr<telegram_api::InputUser> &input_user) {
CHECK(input_user != nullptr);
switch (input_user->get_id()) {
case telegram_api::inputUser::ID: {
auto user = static_cast<const telegram_api::inputUser *>(input_user.get());
UserId user_id(user->user_id_);
if (user_id.is_valid()) {
dialog_id = DialogId(user_id);
access_hash = user->access_hash_;
return;
}
break;
}
default:
break;
}
LOG(ERROR) << "Receive " << to_string(input_user);
}
InputDialogId::InputDialogId(const tl_object_ptr<telegram_api::InputPeer> &input_peer) {
CHECK(input_peer != nullptr);
switch (input_peer->get_id()) {

View File

@ -25,6 +25,8 @@ class InputDialogId {
explicit constexpr InputDialogId(DialogId dialog_id) : dialog_id(dialog_id) {
}
explicit InputDialogId(const telegram_api::object_ptr<telegram_api::InputUser> &input_user);
explicit InputDialogId(const tl_object_ptr<telegram_api::InputPeer> &input_peer);
static vector<InputDialogId> get_input_dialog_ids(const vector<tl_object_ptr<telegram_api::InputPeer>> &input_peers,

View File

@ -31401,20 +31401,25 @@ void MessagesManager::fail_edit_message_media(MessageFullId message_full_id, Sta
}
void MessagesManager::on_update_dialog_draft_message(DialogId dialog_id, MessageId top_thread_message_id,
tl_object_ptr<telegram_api::DraftMessage> &&draft_message) {
tl_object_ptr<telegram_api::DraftMessage> &&draft_message,
bool force) {
if (G()->close_flag()) {
return;
}
if (!dialog_id.is_valid()) {
LOG(ERROR) << "Receive update chat draft in invalid " << dialog_id;
LOG(ERROR) << "Receive update of draft message in invalid " << dialog_id;
return;
}
if (td_->auth_manager_->is_bot()) {
LOG(ERROR) << "Receive update chat draft in " << dialog_id;
if (draft_message != nullptr) {
LOG(ERROR) << "Receive update of draft message in " << dialog_id;
}
return;
}
auto draft = get_draft_message(td_, std::move(draft_message));
auto d = get_dialog_force(dialog_id, "on_update_dialog_draft_message");
if (d == nullptr) {
LOG(INFO) << "Ignore update chat draft in unknown " << dialog_id;
if (draft != nullptr) {
if (draft_message != nullptr && draft_message->get_id() != telegram_api::draftMessageEmpty::ID) {
if (!have_input_peer(dialog_id, AccessRights::Read)) {
LOG(ERROR) << "Have no read access to " << dialog_id << " to repair chat draft message";
} else {
@ -31427,7 +31432,40 @@ void MessagesManager::on_update_dialog_draft_message(DialogId dialog_id, Message
// TODO update thread message draft
return;
}
update_dialog_draft_message(d, std::move(draft), true, true);
if (!force && draft_message != nullptr && draft_message->get_id() == telegram_api::draftMessage::ID) {
auto *input_reply_to = static_cast<const telegram_api::draftMessage *>(draft_message.get())->reply_to_.get();
if (input_reply_to != nullptr) {
InputDialogId input_dialog_id;
switch (input_reply_to->get_id()) {
case telegram_api::inputReplyToStory::ID: {
auto reply_to = static_cast<const telegram_api::inputReplyToStory *>(input_reply_to);
input_dialog_id = InputDialogId(reply_to->user_id_);
break;
}
case telegram_api::inputReplyToMessage::ID: {
auto reply_to = static_cast<const telegram_api::inputReplyToMessage *>(input_reply_to);
if (reply_to->reply_to_peer_id_ != nullptr) {
input_dialog_id = InputDialogId(reply_to->reply_to_peer_id_);
}
break;
}
default:
UNREACHABLE();
}
auto reply_in_dialog_id = input_dialog_id.get_dialog_id();
if (reply_in_dialog_id.is_valid() && !have_dialog_force(reply_in_dialog_id, "on_update_dialog_draft_message")) {
td_->dialog_filter_manager_->load_input_dialog(
input_dialog_id, [actor_id = actor_id(this), dialog_id, top_thread_message_id,
draft_message = std::move(draft_message)](Unit) mutable {
send_closure(actor_id, &MessagesManager::on_update_dialog_draft_message, dialog_id, top_thread_message_id,
std::move(draft_message), true);
});
return;
}
}
}
update_dialog_draft_message(d, get_draft_message(td_, std::move(draft_message)), true, true);
}
bool MessagesManager::update_dialog_draft_message(Dialog *d, unique_ptr<DraftMessage> &&draft_message, bool from_update,

View File

@ -268,7 +268,7 @@ class MessagesManager final : public Actor {
bool on_update_message_id(int64 random_id, MessageId new_message_id, const char *source);
void on_update_dialog_draft_message(DialogId dialog_id, MessageId top_thread_message_id,
tl_object_ptr<telegram_api::DraftMessage> &&draft_message);
tl_object_ptr<telegram_api::DraftMessage> &&draft_message, bool force = false);
void on_update_dialog_is_pinned(FolderId folder_id, DialogId dialog_id, bool is_pinned);