Hide video and voice message drafts when the message is sent.

This commit is contained in:
levlam 2024-01-31 02:58:17 +03:00
parent 2f1de10541
commit 0e16c0af02
3 changed files with 34 additions and 1 deletions

View File

@ -362,6 +362,21 @@ DraftMessage::DraftMessage() = default;
DraftMessage::~DraftMessage() = default;
bool DraftMessage::need_clear_local(MessageContentType content_type) const {
if (!is_local()) {
return false;
}
switch (local_content_->get_type()) {
case DraftMessageContentType::VideoNote:
return content_type == MessageContentType::VideoNote;
case DraftMessageContentType::VoiceNote:
return content_type == MessageContentType::VoiceNote;
default:
UNREACHABLE();
return false;
}
}
bool DraftMessage::need_update_to(const DraftMessage &other, bool from_update) const {
if (is_local()) {
return !from_update || other.is_local();

View File

@ -9,6 +9,7 @@
#include "td/telegram/DialogId.h"
#include "td/telegram/InputMessageText.h"
#include "td/telegram/logevent/LogEvent.h"
#include "td/telegram/MessageContentType.h"
#include "td/telegram/MessageId.h"
#include "td/telegram/MessageInputReplyTo.h"
#include "td/telegram/td_api.h"
@ -65,6 +66,8 @@ class DraftMessage {
return local_content_ != nullptr;
}
bool need_clear_local(MessageContentType content_type) const;
bool need_update_to(const DraftMessage &other, bool from_update) const;
void add_dependencies(Dependencies &dependencies) const;

View File

@ -12120,6 +12120,7 @@ void MessagesManager::ttl_read_history(Dialog *d, bool is_outgoing, MessageId fr
void MessagesManager::ttl_read_history_impl(DialogId dialog_id, bool is_outgoing, MessageId from_message_id,
MessageId till_message_id, double view_date) {
CHECK(dialog_id.get_type() == DialogType::SecretChat);
CHECK(!from_message_id.is_scheduled());
CHECK(!till_message_id.is_scheduled());
@ -30180,9 +30181,23 @@ bool MessagesManager::update_dialog_draft_message(Dialog *d, unique_ptr<DraftMes
}
void MessagesManager::clear_dialog_draft_by_sent_message(Dialog *d, const Message *m, bool need_update_dialog_pos) {
if (!m->clear_draft || td_->auth_manager_->is_bot()) {
if (td_->auth_manager_->is_bot()) {
return;
}
if (!m->clear_draft) {
const DraftMessage *draft_message = nullptr;
if (m->initial_top_thread_message_id.is_valid()) {
auto top_m = get_message_force(d, m->initial_top_thread_message_id, "clear_dialog_draft_by_sent_message");
if (top_m != nullptr) {
draft_message = top_m->thread_draft_message.get();
}
} else {
draft_message = d->draft_message.get();
}
if (draft_message == nullptr || !draft_message->need_clear_local(m->content->get_type())) {
return;
}
}
if (m->initial_top_thread_message_id.is_valid()) {
set_dialog_draft_message(d->dialog_id, m->initial_top_thread_message_id, nullptr).ignore();
} else {