Support Saved Messages topic draft.
This commit is contained in:
parent
21696de370
commit
6cfb50fd8f
@ -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<chatPosition> = Update;
|
||||
|
||||
|
@ -19217,6 +19217,14 @@ td_api::object_ptr<td_api::chat> MessagesManager::get_chat_object(DialogId dialo
|
||||
return get_chat_object(d);
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::draftMessage> 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<bool, int32> 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<td_api::updateChatDraftMessage>(
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -678,6 +678,8 @@ class MessagesManager final : public Actor {
|
||||
|
||||
td_api::object_ptr<td_api::chat> get_chat_object(DialogId dialog_id);
|
||||
|
||||
td_api::object_ptr<td_api::draftMessage> get_my_dialog_draft_message_object() const;
|
||||
|
||||
tl_object_ptr<td_api::messages> get_dialog_history(DialogId dialog_id, MessageId from_message_id, int32 offset,
|
||||
int32 limit, int left_tries, bool only_local,
|
||||
Promise<Unit> &&promise);
|
||||
|
@ -356,6 +356,12 @@ SavedMessagesManager::SavedMessagesTopic *SavedMessagesManager::add_topic(
|
||||
if (result == nullptr) {
|
||||
result = make_unique<SavedMessagesTopic>();
|
||||
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<int64>(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<td_api::savedMessagesTopic> 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<td_api::draftMessage> 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<td_api::savedMessagesTopic>(
|
||||
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<td_api::updateSavedMessagesTopic> 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));
|
||||
}
|
||||
|
||||
|
@ -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<Unit> &&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;
|
||||
|
Loading…
Reference in New Issue
Block a user