diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 96aa09515..c1d70b359 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -1908,7 +1908,8 @@ savedMessagesTopicTypeSavedFromChat chat_id:int53 = SavedMessagesTopicType; //@is_pinned True, if the topic is pinned //@order A parameter used to determine order of the topic in the topic list. Topics must be sorted by the order in descending order //@last_message Last message in the topic; may be null if none or unknown -savedMessagesTopic id:int53 type:SavedMessagesTopicType is_pinned:Bool order:int64 last_message:message = SavedMessagesTopic; +//@draft_message A draft of a message in the topic; may be null if none +savedMessagesTopic id:int53 type:SavedMessagesTopicType is_pinned:Bool order:int64 last_message:message draft_message:draftMessage = SavedMessagesTopic; //@description Describes a forum topic icon @color Color of the topic icon in RGB format @custom_emoji_id Unique identifier of the custom emoji shown on the topic icon; 0 if none @@ -6434,7 +6435,7 @@ updateChatAvailableReactions chat_id:int53 available_reactions:ChatAvailableReac //@description A chat draft has changed. Be aware that the update may come in the currently opened chat but with old content of the draft. If the user has changed the content of the draft, this update mustn't be applied //@chat_id Chat identifier -//@draft_message The new draft message; may be null +//@draft_message The new draft message; may be null if none //@positions The new chat positions in the chat lists updateChatDraftMessage chat_id:int53 draft_message:draftMessage positions:vector = Update; diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index c0061ae99..c47c4217c 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -19217,6 +19217,14 @@ td_api::object_ptr MessagesManager::get_chat_object(DialogId dialo return get_chat_object(d); } +td_api::object_ptr MessagesManager::get_my_dialog_draft_message_object() const { + const Dialog *d = get_dialog(td_->dialog_manager_->get_my_dialog_id()); + if (d == nullptr) { + return nullptr; + } + return get_draft_message_object(td_, d->draft_message); +} + std::pair MessagesManager::get_dialog_mute_until(DialogId dialog_id, const Dialog *d) const { CHECK(!td_->auth_manager_->is_bot()); if (d == nullptr || !d->notification_settings.is_synchronized) { @@ -28492,6 +28500,11 @@ void MessagesManager::send_update_chat_draft_message(const Dialog *d) { td_api::make_object( get_chat_id_object(d->dialog_id, "updateChatDraftMessage"), get_draft_message_object(td_, d->draft_message), get_chat_positions_object(d))); + + if (d->dialog_id == td_->dialog_manager_->get_my_dialog_id()) { + td_->saved_messages_manager_->on_topic_draft_message_updated( + SavedMessagesTopicId(d->dialog_id), d->draft_message == nullptr ? 0 : d->draft_message->get_date()); + } } } diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 3ac4c4e1c..c8acb56ba 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -678,6 +678,8 @@ class MessagesManager final : public Actor { td_api::object_ptr get_chat_object(DialogId dialog_id); + td_api::object_ptr get_my_dialog_draft_message_object() const; + tl_object_ptr get_dialog_history(DialogId dialog_id, MessageId from_message_id, int32 offset, int32 limit, int left_tries, bool only_local, Promise &&promise); diff --git a/td/telegram/SavedMessagesManager.cpp b/td/telegram/SavedMessagesManager.cpp index a3b779534..88aa19e84 100644 --- a/td/telegram/SavedMessagesManager.cpp +++ b/td/telegram/SavedMessagesManager.cpp @@ -356,6 +356,12 @@ SavedMessagesManager::SavedMessagesTopic *SavedMessagesManager::add_topic( if (result == nullptr) { result = make_unique(); result->saved_messages_topic_id_ = saved_messages_topic_id; + if (saved_messages_topic_id == SavedMessagesTopicId(td_->dialog_manager_->get_my_dialog_id())) { + auto draft_message_object = td_->messages_manager_->get_my_dialog_draft_message_object(); + if (draft_message_object != nullptr) { + result->draft_message_date_ = draft_message_object->date_; + } + } send_update_saved_messages_topic(result.get()); } return result.get(); @@ -405,6 +411,19 @@ void SavedMessagesManager::on_topic_message_deleted(SavedMessagesTopicId saved_m get_saved_messages_topic_history(saved_messages_topic_id, MessageId(), 0, 1, Auto()); } +void SavedMessagesManager::on_topic_draft_message_updated(SavedMessagesTopicId saved_messages_topic_id, + int32 draft_message_date) { + auto *topic = get_topic(saved_messages_topic_id); + if (topic == nullptr) { + return; + } + + topic->draft_message_date_ = draft_message_date; + topic->is_changed_ = true; + + on_topic_changed(topic); +} + int64 SavedMessagesManager::get_topic_order(int32 message_date, MessageId message_id) { return (static_cast(message_date) << 31) + message_id.get_prev_server_message_id().get_server_message_id().get(); @@ -434,6 +453,12 @@ void SavedMessagesManager::on_topic_changed(SavedMessagesTopic *topic) { } else { topic->private_order_ = 0; } + if (topic->draft_message_date_ != 0) { + int64 draft_order = get_topic_order(topic->draft_message_date_, MessageId()); + if (topic->private_order_ < draft_order) { + topic->private_order_ = draft_order; + } + } if (topic->private_order_ != 0) { bool is_inserted = topic_list_.ordered_topics_.insert({topic->private_order_, topic->saved_messages_topic_id_}).second; @@ -655,10 +680,14 @@ td_api::object_ptr SavedMessagesManager::get_saved_m last_message_object = td_->messages_manager_->get_message_object( {td_->dialog_manager_->get_my_dialog_id(), topic->last_message_id_}, "get_saved_messages_topic_object"); } + td_api::object_ptr draft_message_object; + if (topic->draft_message_date_ != 0) { + draft_message_object = td_->messages_manager_->get_my_dialog_draft_message_object(); + } return td_api::make_object( topic->saved_messages_topic_id_.get_unique_id(), topic->saved_messages_topic_id_.get_saved_messages_topic_type_object(td_), topic->pinned_order_ != 0, - get_topic_public_order(topic), std::move(last_message_object)); + get_topic_public_order(topic), std::move(last_message_object), std::move(draft_message_object)); } td_api::object_ptr SavedMessagesManager::get_update_saved_messages_topic_object( @@ -670,7 +699,7 @@ void SavedMessagesManager::send_update_saved_messages_topic(const SavedMessagesT CHECK(topic != nullptr); LOG(INFO) << "Send update about " << topic->saved_messages_topic_id_ << " with order " << get_topic_public_order(topic) << " and last " << topic->last_message_id_ << " sent at " - << topic->last_message_date_; + << topic->last_message_date_ << " with draft at " << topic->draft_message_date_; send_closure(G()->td(), &Td::send_update, get_update_saved_messages_topic_object(topic)); } diff --git a/td/telegram/SavedMessagesManager.h b/td/telegram/SavedMessagesManager.h index f399359a2..f661b5ecc 100644 --- a/td/telegram/SavedMessagesManager.h +++ b/td/telegram/SavedMessagesManager.h @@ -39,6 +39,8 @@ class SavedMessagesManager final : public Actor { void on_topic_message_deleted(SavedMessagesTopicId saved_messages_topic_id, MessageId message_id); + void on_topic_draft_message_updated(SavedMessagesTopicId saved_messages_topic_id, int32 draft_message_date); + void load_saved_messages_topics(int32 limit, Promise &&promsie); void on_get_saved_messages_topics(bool is_pinned, int32 limit, @@ -75,6 +77,7 @@ class SavedMessagesManager final : public Actor { SavedMessagesTopicId saved_messages_topic_id_; MessageId last_message_id_; int32 last_message_date_ = 0; + int32 draft_message_date_ = 0; int64 pinned_order_ = 0; int64 private_order_ = 0; bool is_changed_ = false;