diff --git a/td/telegram/StoryManager.cpp b/td/telegram/StoryManager.cpp index 061bb54ac..a7332d1f0 100644 --- a/td/telegram/StoryManager.cpp +++ b/td/telegram/StoryManager.cpp @@ -1520,6 +1520,7 @@ void StoryManager::on_load_active_stories_from_server( story_list.state_ = std::move(stories->state_); save_story_list(story_list_id, story_list.state_, story_list.server_total_count_, story_list.server_has_more_); } + on_update_story_stealth_mode(std::move(stories->stealth_mode_)); break; } case telegram_api::stories_allStories::ID: { @@ -1603,6 +1604,8 @@ void StoryManager::on_load_active_stories_from_server( update_story_list_sent_total_count(story_list_id, story_list); lock.set_value(Unit()); + + on_update_story_stealth_mode(std::move(stories->stealth_mode_)); break; } default: @@ -3202,6 +3205,28 @@ bool StoryManager::on_update_read_stories(DialogId owner_dialog_id, StoryId max_ return false; } +td_api::object_ptr StoryManager::get_update_story_stealth_mode() const { + return stealth_mode_.get_update_story_stealth_mode_object(); +} + +void StoryManager::send_update_story_stealth_mode() const { + send_closure(G()->td(), &Td::send_update, get_update_story_stealth_mode()); +} + +void StoryManager::on_update_story_stealth_mode( + telegram_api::object_ptr &&stealth_mode) { + set_story_stealth_mode(StoryStealthMode(std::move(stealth_mode))); +} + +void StoryManager::set_story_stealth_mode(StoryStealthMode stealth_mode) { + if (stealth_mode == stealth_mode_) { + return; + } + + stealth_mode_ = stealth_mode; + send_update_story_stealth_mode(); +} + DialogId StoryManager::get_changelog_story_dialog_id() const { return DialogId(UserId(td_->option_manager_->get_option_integer( "stories_changelog_user_id", ContactsManager::get_service_notifications_user_id().get()))); @@ -3963,6 +3988,8 @@ void StoryManager::get_current_state(vector> updates.push_back(get_update_story_list_chat_count_object(story_list_id, story_list)); } } + + updates.push_back(get_update_story_stealth_mode()); } } diff --git a/td/telegram/StoryManager.h b/td/telegram/StoryManager.h index 95bc33c8c..32bc53e22 100644 --- a/td/telegram/StoryManager.h +++ b/td/telegram/StoryManager.h @@ -19,6 +19,7 @@ #include "td/telegram/StoryId.h" #include "td/telegram/StoryInteractionInfo.h" #include "td/telegram/StoryListId.h" +#include "td/telegram/StoryStealthMode.h" #include "td/telegram/td_api.h" #include "td/telegram/telegram_api.h" #include "td/telegram/UserId.h" @@ -261,6 +262,8 @@ class StoryManager final : public Actor { bool on_update_read_stories(DialogId owner_dialog_id, StoryId max_read_story_id); + void on_update_story_stealth_mode(telegram_api::object_ptr &&stealth_mode); + void on_dialog_active_stories_order_updated(DialogId owner_dialog_id, const char *source); Status can_get_story_viewers(StoryFullId story_full_id, const Story *story) const; @@ -506,6 +509,12 @@ class StoryManager final : public Actor { void on_synchronized_archive_all_stories(bool set_archive_all_stories, Result result); + td_api::object_ptr get_update_story_stealth_mode() const; + + void send_update_story_stealth_mode() const; + + void set_story_stealth_mode(StoryStealthMode stealth_mode); + void on_get_story_viewers(StoryId story_id, MessageViewer offset, Result> r_view_list, Promise> &&promise); @@ -560,6 +569,8 @@ class StoryManager final : public Actor { StoryList story_lists_[2]; + StoryStealthMode stealth_mode_; + uint32 send_story_count_ = 0; int64 max_story_global_id_ = 0; diff --git a/td/telegram/StoryStealthMode.cpp b/td/telegram/StoryStealthMode.cpp index fadb82066..fa278d9ad 100644 --- a/td/telegram/StoryStealthMode.cpp +++ b/td/telegram/StoryStealthMode.cpp @@ -29,9 +29,7 @@ bool StoryStealthMode::update() { return result; } -int32 StoryStealthMode::get_update_date() { - update(); - +int32 StoryStealthMode::get_update_date() const { if (active_until_date_ > 0) { if (cooldown_until_date_ > 0) { return min(active_until_date_, cooldown_until_date_); diff --git a/td/telegram/StoryStealthMode.h b/td/telegram/StoryStealthMode.h index c557903fd..67cf057c9 100644 --- a/td/telegram/StoryStealthMode.h +++ b/td/telegram/StoryStealthMode.h @@ -31,7 +31,7 @@ class StoryStealthMode { return active_until_date_ == 0 && cooldown_until_date_ == 0; } - int32 get_update_date(); + int32 get_update_date() const; bool update(); diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index 53dfba9b6..caef536ab 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -4311,6 +4311,11 @@ void UpdatesManager::on_update(tl_object_ptr up promise.set_value(Unit()); } +void UpdatesManager::on_update(tl_object_ptr update, Promise &&promise) { + td_->story_manager_->on_update_story_stealth_mode(std::move(update->stealth_mode_)); + promise.set_value(Unit()); +} + // unsupported updates void UpdatesManager::on_update(tl_object_ptr update, Promise &&promise) { @@ -4321,8 +4326,4 @@ void UpdatesManager::on_update(tl_object_ptr update promise.set_value(Unit()); } -void UpdatesManager::on_update(tl_object_ptr update, Promise &&promise) { - promise.set_value(Unit()); -} - } // namespace td diff --git a/td/telegram/UpdatesManager.h b/td/telegram/UpdatesManager.h index d4d1e8903..b54b4487e 100644 --- a/td/telegram/UpdatesManager.h +++ b/td/telegram/UpdatesManager.h @@ -624,13 +624,13 @@ class UpdatesManager final : public Actor { void on_update(tl_object_ptr update, Promise &&promise); + void on_update(tl_object_ptr update, Promise &&promise); + // unsupported updates void on_update(tl_object_ptr update, Promise &&promise); void on_update(tl_object_ptr update, Promise &&promise); - - void on_update(tl_object_ptr update, Promise &&promise); }; } // namespace td