Cache chats to send stories.
This commit is contained in:
parent
82c702c16d
commit
cd7d960ba4
@ -9281,7 +9281,7 @@ void ContactsManager::get_created_public_dialogs(PublicDialogType type,
|
|||||||
return return_created_public_dialogs(std::move(promise), created_public_channels_[index]);
|
return return_created_public_dialogs(std::move(promise), created_public_channels_[index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (get_created_public_channels_queries_[index].empty() && G()->use_chat_info_database()) {
|
if (get_created_public_channels_queries_[index].empty() && G()->use_message_database()) {
|
||||||
auto pmc_key = PSTRING() << "public_channels" << index;
|
auto pmc_key = PSTRING() << "public_channels" << index;
|
||||||
auto str = G()->td_db()->get_binlog_pmc()->get(pmc_key);
|
auto str = G()->td_db()->get_binlog_pmc()->get(pmc_key);
|
||||||
if (!str.empty()) {
|
if (!str.empty()) {
|
||||||
@ -9316,7 +9316,8 @@ void ContactsManager::get_created_public_dialogs(PublicDialogType type,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (from_binlog) {
|
if (from_binlog) {
|
||||||
return return_created_public_dialogs(std::move(promise), created_public_channels_[index]);
|
return_created_public_dialogs(std::move(promise), created_public_channels_[index]);
|
||||||
|
promise = {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -9345,8 +9346,7 @@ void ContactsManager::finish_get_created_public_dialogs(PublicDialogType type, R
|
|||||||
auto promises = std::move(get_created_public_channels_queries_[index]);
|
auto promises = std::move(get_created_public_channels_queries_[index]);
|
||||||
reset_to_empty(get_created_public_channels_queries_[index]);
|
reset_to_empty(get_created_public_channels_queries_[index]);
|
||||||
if (result.is_error()) {
|
if (result.is_error()) {
|
||||||
fail_promises(promises, result.move_as_error());
|
return fail_promises(promises, result.move_as_error());
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CHECK(created_public_channels_inited_[index]);
|
CHECK(created_public_channels_inited_[index]);
|
||||||
@ -9417,7 +9417,7 @@ void ContactsManager::on_get_created_public_channels(PublicDialogType type,
|
|||||||
void ContactsManager::save_created_public_channels(PublicDialogType type) {
|
void ContactsManager::save_created_public_channels(PublicDialogType type) {
|
||||||
auto index = static_cast<int32>(type);
|
auto index = static_cast<int32>(type);
|
||||||
CHECK(created_public_channels_inited_[index]);
|
CHECK(created_public_channels_inited_[index]);
|
||||||
if (G()->use_chat_info_database()) {
|
if (G()->use_message_database()) {
|
||||||
G()->td_db()->get_binlog_pmc()->set(
|
G()->td_db()->get_binlog_pmc()->set(
|
||||||
PSTRING() << "public_channels" << index,
|
PSTRING() << "public_channels" << index,
|
||||||
implode(
|
implode(
|
||||||
@ -16003,6 +16003,10 @@ void ContactsManager::on_channel_status_changed(Channel *c, ChannelId channel_id
|
|||||||
CHECK(c->is_update_supergroup_sent);
|
CHECK(c->is_update_supergroup_sent);
|
||||||
bool have_channel_full = get_channel_full(channel_id) != nullptr;
|
bool have_channel_full = get_channel_full(channel_id) != nullptr;
|
||||||
|
|
||||||
|
if (old_status.can_post_stories() != new_status.can_post_stories()) {
|
||||||
|
td_->story_manager_->update_dialogs_to_send_stories(channel_id, new_status.can_post_stories());
|
||||||
|
}
|
||||||
|
|
||||||
bool need_reload_group_call = old_status.can_manage_calls() != new_status.can_manage_calls();
|
bool need_reload_group_call = old_status.can_manage_calls() != new_status.can_manage_calls();
|
||||||
if (old_status.can_manage_invite_links() && !new_status.can_manage_invite_links()) {
|
if (old_status.can_manage_invite_links() && !new_status.can_manage_invite_links()) {
|
||||||
auto channel_full = get_channel_full(channel_id, true, "on_channel_status_changed");
|
auto channel_full = get_channel_full(channel_id, true, "on_channel_status_changed");
|
||||||
|
@ -4588,9 +4588,46 @@ void StoryManager::return_dialogs_to_send_stories(Promise<td_api::object_ptr<td_
|
|||||||
|
|
||||||
void StoryManager::get_dialogs_to_send_stories(Promise<td_api::object_ptr<td_api::chats>> &&promise) {
|
void StoryManager::get_dialogs_to_send_stories(Promise<td_api::object_ptr<td_api::chats>> &&promise) {
|
||||||
if (channels_to_send_stories_inited_) {
|
if (channels_to_send_stories_inited_) {
|
||||||
return_dialogs_to_send_stories(std::move(promise), channels_to_send_stories_);
|
return return_dialogs_to_send_stories(std::move(promise), channels_to_send_stories_);
|
||||||
promise = {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (get_dialogs_to_send_stories_queries_.empty() && G()->use_message_database()) {
|
||||||
|
auto pmc_key = "channels_to_send_stories";
|
||||||
|
auto str = G()->td_db()->get_binlog_pmc()->get(pmc_key);
|
||||||
|
if (!str.empty()) {
|
||||||
|
auto r_channel_ids = transform(full_split(Slice(str), ','), [](Slice str) -> Result<ChannelId> {
|
||||||
|
TRY_RESULT(channel_id_int, to_integer_safe<int64>(str));
|
||||||
|
ChannelId channel_id(channel_id_int);
|
||||||
|
if (!channel_id.is_valid()) {
|
||||||
|
return Status::Error("Have invalid channel ID");
|
||||||
|
}
|
||||||
|
return channel_id;
|
||||||
|
});
|
||||||
|
if (std::any_of(r_channel_ids.begin(), r_channel_ids.end(),
|
||||||
|
[](auto &r_channel_id) { return r_channel_id.is_error(); })) {
|
||||||
|
LOG(ERROR) << "Can't parse " << str;
|
||||||
|
G()->td_db()->get_binlog_pmc()->erase(pmc_key);
|
||||||
|
} else {
|
||||||
|
Dependencies dependencies;
|
||||||
|
vector<ChannelId> channel_ids;
|
||||||
|
for (auto &r_channel_id : r_channel_ids) {
|
||||||
|
auto channel_id = r_channel_id.move_as_ok();
|
||||||
|
dependencies.add_dialog_and_dependencies(DialogId(channel_id));
|
||||||
|
channel_ids.push_back(channel_id);
|
||||||
|
}
|
||||||
|
if (!dependencies.resolve_force(td_, "get_dialogs_to_send_stories")) {
|
||||||
|
G()->td_db()->get_binlog_pmc()->erase(pmc_key);
|
||||||
|
} else {
|
||||||
|
channels_to_send_stories_ = std::move(channel_ids);
|
||||||
|
channels_to_send_stories_inited_ = true;
|
||||||
|
|
||||||
|
return_dialogs_to_send_stories(std::move(promise), channels_to_send_stories_);
|
||||||
|
promise = {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
reload_dialogs_to_send_stories(std::move(promise));
|
reload_dialogs_to_send_stories(std::move(promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4610,8 +4647,7 @@ void StoryManager::finish_get_dialogs_to_send_stories(Result<Unit> &&result) {
|
|||||||
auto promises = std::move(get_dialogs_to_send_stories_queries_);
|
auto promises = std::move(get_dialogs_to_send_stories_queries_);
|
||||||
reset_to_empty(get_dialogs_to_send_stories_queries_);
|
reset_to_empty(get_dialogs_to_send_stories_queries_);
|
||||||
if (result.is_error()) {
|
if (result.is_error()) {
|
||||||
fail_promises(promises, result.move_as_error());
|
return fail_promises(promises, result.move_as_error());
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CHECK(channels_to_send_stories_inited_);
|
CHECK(channels_to_send_stories_inited_);
|
||||||
@ -4620,6 +4656,23 @@ void StoryManager::finish_get_dialogs_to_send_stories(Result<Unit> &&result) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void StoryManager::update_dialogs_to_send_stories(ChannelId channel_id, bool can_send_stories) {
|
||||||
|
if (channels_to_send_stories_inited_) {
|
||||||
|
bool was_changed = false;
|
||||||
|
if (!can_send_stories) {
|
||||||
|
was_changed = td::remove(channels_to_send_stories_, channel_id);
|
||||||
|
} else {
|
||||||
|
if (!td::contains(channels_to_send_stories_, channel_id)) {
|
||||||
|
channels_to_send_stories_.push_back(channel_id);
|
||||||
|
was_changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (was_changed) {
|
||||||
|
save_channels_to_send_stories();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void StoryManager::on_get_dialogs_to_send_stories(vector<tl_object_ptr<telegram_api::Chat>> &&chats) {
|
void StoryManager::on_get_dialogs_to_send_stories(vector<tl_object_ptr<telegram_api::Chat>> &&chats) {
|
||||||
auto channel_ids = td_->contacts_manager_->get_channel_ids(std::move(chats), "on_get_dialogs_to_send_stories");
|
auto channel_ids = td_->contacts_manager_->get_channel_ids(std::move(chats), "on_get_dialogs_to_send_stories");
|
||||||
if (channels_to_send_stories_inited_ && channels_to_send_stories_ == channel_ids) {
|
if (channels_to_send_stories_inited_ && channels_to_send_stories_ == channel_ids) {
|
||||||
@ -4630,6 +4683,18 @@ void StoryManager::on_get_dialogs_to_send_stories(vector<tl_object_ptr<telegram_
|
|||||||
}
|
}
|
||||||
channels_to_send_stories_ = std::move(channel_ids);
|
channels_to_send_stories_ = std::move(channel_ids);
|
||||||
channels_to_send_stories_inited_ = true;
|
channels_to_send_stories_inited_ = true;
|
||||||
|
|
||||||
|
save_channels_to_send_stories();
|
||||||
|
}
|
||||||
|
|
||||||
|
void StoryManager::save_channels_to_send_stories() {
|
||||||
|
CHECK(channels_to_send_stories_inited_);
|
||||||
|
if (G()->use_message_database()) {
|
||||||
|
G()->td_db()->get_binlog_pmc()->set(
|
||||||
|
"channels_to_send_stories",
|
||||||
|
implode(transform(channels_to_send_stories_, [](auto channel_id) { return PSTRING() << channel_id.get(); }),
|
||||||
|
','));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void StoryManager::can_send_story(DialogId dialog_id,
|
void StoryManager::can_send_story(DialogId dialog_id,
|
||||||
|
@ -207,6 +207,8 @@ class StoryManager final : public Actor {
|
|||||||
|
|
||||||
void on_get_dialogs_to_send_stories(vector<tl_object_ptr<telegram_api::Chat>> &&chats);
|
void on_get_dialogs_to_send_stories(vector<tl_object_ptr<telegram_api::Chat>> &&chats);
|
||||||
|
|
||||||
|
void update_dialogs_to_send_stories(ChannelId channel_id, bool can_send_stories);
|
||||||
|
|
||||||
void can_send_story(DialogId dialog_id, Promise<td_api::object_ptr<td_api::CanSendStoryResult>> &&promise);
|
void can_send_story(DialogId dialog_id, Promise<td_api::object_ptr<td_api::CanSendStoryResult>> &&promise);
|
||||||
|
|
||||||
void send_story(DialogId dialog_id, td_api::object_ptr<td_api::InputStoryContent> &&input_story_content,
|
void send_story(DialogId dialog_id, td_api::object_ptr<td_api::InputStoryContent> &&input_story_content,
|
||||||
@ -466,6 +468,8 @@ class StoryManager final : public Actor {
|
|||||||
|
|
||||||
void finish_get_dialogs_to_send_stories(Result<Unit> &&result);
|
void finish_get_dialogs_to_send_stories(Result<Unit> &&result);
|
||||||
|
|
||||||
|
void save_channels_to_send_stories();
|
||||||
|
|
||||||
void on_get_dialog_pinned_stories(DialogId owner_dialog_id,
|
void on_get_dialog_pinned_stories(DialogId owner_dialog_id,
|
||||||
telegram_api::object_ptr<telegram_api::stories_stories> &&stories,
|
telegram_api::object_ptr<telegram_api::stories_stories> &&stories,
|
||||||
Promise<td_api::object_ptr<td_api::stories>> &&promise);
|
Promise<td_api::object_ptr<td_api::stories>> &&promise);
|
||||||
|
Loading…
Reference in New Issue
Block a user