Add td_api::updateSavedMessagesTopicCount.
This commit is contained in:
parent
d243739d67
commit
071d232908
@ -6510,6 +6510,9 @@ updateChatOnlineMemberCount chat_id:int53 online_member_count:int32 = Update;
|
|||||||
//@topic New data about the topic
|
//@topic New data about the topic
|
||||||
updateSavedMessagesTopic topic:savedMessagesTopic = Update;
|
updateSavedMessagesTopic topic:savedMessagesTopic = Update;
|
||||||
|
|
||||||
|
//@description Number of Saved Messages topics has changed @topic_count Approximate total number of Saved Messages topics
|
||||||
|
updateSavedMessagesTopicCount topic_count:int32 = Update;
|
||||||
|
|
||||||
//@description Basic information about a topic in a forum chat was changed @chat_id Chat identifier @info New information about the topic
|
//@description Basic information about a topic in a forum chat was changed @chat_id Chat identifier @info New information about the topic
|
||||||
updateForumTopicInfo chat_id:int53 info:forumTopicInfo = Update;
|
updateForumTopicInfo chat_id:int53 info:forumTopicInfo = Update;
|
||||||
|
|
||||||
|
@ -473,6 +473,8 @@ void SavedMessagesManager::on_topic_changed(SavedMessagesTopic *topic, const cha
|
|||||||
<< source;
|
<< source;
|
||||||
|
|
||||||
send_update_saved_messages_topic(topic, source);
|
send_update_saved_messages_topic(topic, source);
|
||||||
|
|
||||||
|
update_saved_messages_topic_sent_total_count(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SavedMessagesManager::load_saved_messages_topics(int32 limit, Promise<Unit> &&promise) {
|
void SavedMessagesManager::load_saved_messages_topics(int32 limit, Promise<Unit> &&promise) {
|
||||||
@ -648,6 +650,17 @@ void SavedMessagesManager::on_get_saved_messages_topics(
|
|||||||
on_topic_changed(topic, "on_get_saved_messages_topics");
|
on_topic_changed(topic, "on_get_saved_messages_topics");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!is_pinned) {
|
||||||
|
topic_list_.server_total_count_ = total_count;
|
||||||
|
|
||||||
|
topic_list_.offset_date_ = last_message_date;
|
||||||
|
topic_list_.offset_dialog_id_ = last_dialog_id;
|
||||||
|
topic_list_.offset_message_id_ = last_message_id;
|
||||||
|
} else if (topic_list_.server_total_count_ <= total_count) {
|
||||||
|
topic_list_.server_total_count_ = total_count + 1;
|
||||||
|
}
|
||||||
|
update_saved_messages_topic_sent_total_count("on_get_saved_messages_topics");
|
||||||
|
|
||||||
if (is_pinned) {
|
if (is_pinned) {
|
||||||
if (!topic_list_.are_pinned_saved_messages_topics_inited_ && total_count < limit) {
|
if (!topic_list_.are_pinned_saved_messages_topics_inited_ && total_count < limit) {
|
||||||
get_saved_dialogs(limit - total_count, std::move(promise));
|
get_saved_dialogs(limit - total_count, std::move(promise));
|
||||||
@ -658,22 +671,18 @@ void SavedMessagesManager::on_get_saved_messages_topics(
|
|||||||
set_last_topic_date({MIN_PINNED_TOPIC_ORDER - 1, SavedMessagesTopicId()});
|
set_last_topic_date({MIN_PINNED_TOPIC_ORDER - 1, SavedMessagesTopicId()});
|
||||||
} else if (is_last) {
|
} else if (is_last) {
|
||||||
set_last_topic_date(MAX_TOPIC_DATE);
|
set_last_topic_date(MAX_TOPIC_DATE);
|
||||||
|
|
||||||
|
if (dialogs.empty()) {
|
||||||
|
return promise.set_error(Status::Error(404, "Not Found"));
|
||||||
|
}
|
||||||
} else if (last_message_date > 0) {
|
} else if (last_message_date > 0) {
|
||||||
set_last_topic_date({get_topic_order(last_message_date, last_message_id), SavedMessagesTopicId(last_dialog_id)});
|
set_last_topic_date({get_topic_order(last_message_date, last_message_id), SavedMessagesTopicId(last_dialog_id)});
|
||||||
} else {
|
} else {
|
||||||
LOG(ERROR) << "Receive no suitable topics";
|
LOG(ERROR) << "Receive no suitable topics";
|
||||||
set_last_topic_date(MAX_TOPIC_DATE);
|
set_last_topic_date(MAX_TOPIC_DATE);
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_pinned) {
|
|
||||||
topic_list_.offset_date_ = last_message_date;
|
|
||||||
topic_list_.offset_dialog_id_ = last_dialog_id;
|
|
||||||
topic_list_.offset_message_id_ = last_message_id;
|
|
||||||
|
|
||||||
if (is_last && dialogs.empty()) {
|
|
||||||
return promise.set_error(Status::Error(404, "Not Found"));
|
return promise.set_error(Status::Error(404, "Not Found"));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
promise.set_value(Unit());
|
promise.set_value(Unit());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -714,6 +723,32 @@ int64 SavedMessagesManager::get_next_pinned_saved_messages_topic_order() {
|
|||||||
return current_pinned_saved_messages_topic_order_;
|
return current_pinned_saved_messages_topic_order_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
td_api::object_ptr<td_api::updateSavedMessagesTopicCount>
|
||||||
|
SavedMessagesManager::get_update_saved_messages_topic_count_object() const {
|
||||||
|
CHECK(topic_list_.sent_total_count_ != -1);
|
||||||
|
return td_api::make_object<td_api::updateSavedMessagesTopicCount>(topic_list_.sent_total_count_);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SavedMessagesManager::update_saved_messages_topic_sent_total_count(const char *source) {
|
||||||
|
if (td_->auth_manager_->is_bot()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (topic_list_.server_total_count_ == -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
LOG(INFO) << "Update Saved Messages topic sent total count from " << source;
|
||||||
|
auto new_total_count = static_cast<int32>(topic_list_.ordered_topics_.size());
|
||||||
|
if (topic_list_.last_topic_date_ != MAX_TOPIC_DATE) {
|
||||||
|
new_total_count = max(new_total_count, topic_list_.server_total_count_);
|
||||||
|
} else if (topic_list_.server_total_count_ != new_total_count) {
|
||||||
|
topic_list_.server_total_count_ = new_total_count;
|
||||||
|
}
|
||||||
|
if (topic_list_.sent_total_count_ != new_total_count) {
|
||||||
|
topic_list_.sent_total_count_ = new_total_count;
|
||||||
|
send_closure(G()->td(), &Td::send_update, get_update_saved_messages_topic_count_object());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool SavedMessagesManager::set_pinned_saved_messages_topics(vector<SavedMessagesTopicId> saved_messages_topic_ids) {
|
bool SavedMessagesManager::set_pinned_saved_messages_topics(vector<SavedMessagesTopicId> saved_messages_topic_ids) {
|
||||||
if (topic_list_.pinned_saved_messages_topic_ids_ == saved_messages_topic_ids) {
|
if (topic_list_.pinned_saved_messages_topic_ids_ == saved_messages_topic_ids) {
|
||||||
return false;
|
return false;
|
||||||
@ -989,6 +1024,10 @@ void SavedMessagesManager::get_current_state(vector<td_api::object_ptr<td_api::U
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (topic_list_.sent_total_count_ != -1) {
|
||||||
|
updates.push_back(get_update_saved_messages_topic_count_object());
|
||||||
|
}
|
||||||
|
|
||||||
for (const auto &it : saved_messages_topics_) {
|
for (const auto &it : saved_messages_topics_) {
|
||||||
const auto *topic = it.second.get();
|
const auto *topic = it.second.get();
|
||||||
updates.push_back(get_update_saved_messages_topic_object(topic));
|
updates.push_back(get_update_saved_messages_topic_object(topic));
|
||||||
|
@ -110,6 +110,10 @@ class SavedMessagesManager final : public Actor {
|
|||||||
return order_ == other.order_ && topic_id_ == other.topic_id_;
|
return order_ == other.order_ && topic_id_ == other.topic_id_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool operator!=(const TopicDate &other) const {
|
||||||
|
return !(*this == other);
|
||||||
|
}
|
||||||
|
|
||||||
SavedMessagesTopicId get_topic_id() const {
|
SavedMessagesTopicId get_topic_id() const {
|
||||||
return topic_id_;
|
return topic_id_;
|
||||||
}
|
}
|
||||||
@ -119,6 +123,9 @@ class SavedMessagesManager final : public Actor {
|
|||||||
static const TopicDate MAX_TOPIC_DATE;
|
static const TopicDate MAX_TOPIC_DATE;
|
||||||
|
|
||||||
struct TopicList {
|
struct TopicList {
|
||||||
|
int32 server_total_count_ = -1;
|
||||||
|
int32 sent_total_count_ = -1;
|
||||||
|
|
||||||
vector<SavedMessagesTopicId> pinned_saved_messages_topic_ids_;
|
vector<SavedMessagesTopicId> pinned_saved_messages_topic_ids_;
|
||||||
bool are_pinned_saved_messages_topics_inited_ = false;
|
bool are_pinned_saved_messages_topics_inited_ = false;
|
||||||
|
|
||||||
@ -179,6 +186,10 @@ class SavedMessagesManager final : public Actor {
|
|||||||
|
|
||||||
void send_update_saved_messages_topic(const SavedMessagesTopic *topic, const char *source) const;
|
void send_update_saved_messages_topic(const SavedMessagesTopic *topic, const char *source) const;
|
||||||
|
|
||||||
|
td_api::object_ptr<td_api::updateSavedMessagesTopicCount> get_update_saved_messages_topic_count_object() const;
|
||||||
|
|
||||||
|
void update_saved_messages_topic_sent_total_count(const char *source);
|
||||||
|
|
||||||
Td *td_;
|
Td *td_;
|
||||||
ActorShared<> parent_;
|
ActorShared<> parent_;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user