diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index e0e810de5..eba0dc009 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -7202,6 +7202,9 @@ toggleStoryIsPinned story_id:int32 is_pinned:Bool = Ok; //@description Deletes a previously sent story @story_id Identifier of the story to delete deleteStory story_id:int32 = Ok; +//@description Toggles whether stories of the user are available on the main chat list @user_id Identifier of the user @are_archived Pass true to make the story unavailable on the main chat list; pass false to make them available +toggleUserStoriesAreArchived user_id:int53 are_archived:Bool = Ok; + //@description Returns the list of pinned stories of a given user. The stories are returned in a reverse chronological order (i.e., in order of decreasing story_id). //-For optimal performance, the number of returned stories is chosen by TDLib //@user_id User identifier diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index b49d0f9d9..f349388df 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -10348,11 +10348,13 @@ void ContactsManager::on_get_user(tl_object_ptr &&user_ptr, LOG(DEBUG) << "Info has changed for " << user_id; u->is_changed = true; } - if (is_received && (attach_menu_enabled != u->attach_menu_enabled || stories_hidden != u->stories_hidden)) { + if (is_received && attach_menu_enabled != u->attach_menu_enabled) { u->attach_menu_enabled = attach_menu_enabled; - u->stories_hidden = stories_hidden; u->is_changed = true; } + if (is_received) { + on_update_user_stories_hidden(u, user_id, stories_hidden); + } if (is_premium != u->is_premium) { u->is_premium = is_premium; u->is_changed = true; @@ -13403,6 +13405,30 @@ void ContactsManager::on_update_user_emoji_status(User *u, UserId user_id, Emoji } } +void ContactsManager::on_update_user_stories_hidden(UserId user_id, bool stories_hidden) { + if (!user_id.is_valid()) { + LOG(ERROR) << "Receive invalid " << user_id; + return; + } + + User *u = get_user_force(user_id); + if (u != nullptr) { + on_update_user_stories_hidden(u, user_id, stories_hidden); + update_user(u, user_id); + } else { + LOG(INFO) << "Ignore update user stories are archived about unknown " << user_id; + } +} + +void ContactsManager::on_update_user_stories_hidden(User *u, UserId user_id, bool stories_hidden) { + if (u->stories_hidden != stories_hidden) { + LOG(DEBUG) << "Change stories are archived of " << user_id << " from " << u->stories_hidden << " to " + << stories_hidden; + u->stories_hidden = stories_hidden; + u->is_changed = true; + } +} + void ContactsManager::on_update_user_is_contact(User *u, UserId user_id, bool is_contact, bool is_mutual_contact, bool is_close_friend) { UserId my_id = get_my_id(); diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index f2f73ea4b..99b83d6b6 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -184,6 +184,7 @@ class ContactsManager final : public Actor { void on_update_user_name(UserId user_id, string &&first_name, string &&last_name, Usernames &&usernames); void on_update_user_phone_number(UserId user_id, string &&phone_number); void on_update_user_emoji_status(UserId user_id, tl_object_ptr &&emoji_status); + void on_update_user_stories_hidden(UserId user_id, bool stories_hidden); void on_update_user_online(UserId user_id, tl_object_ptr &&status); void on_update_user_local_was_online(UserId user_id, int32 local_was_online); void on_update_user_is_blocked(UserId user_id, bool is_blocked); @@ -1387,6 +1388,7 @@ class ContactsManager final : public Actor { void on_update_user_photo(User *u, UserId user_id, tl_object_ptr &&photo, const char *source); void on_update_user_emoji_status(User *u, UserId user_id, EmojiStatus emoji_status); + void on_update_user_stories_hidden(User *u, UserId user_id, bool stories_hidden); void on_update_user_is_contact(User *u, UserId user_id, bool is_contact, bool is_mutual_contact, bool is_close_friend); void on_update_user_online(User *u, UserId user_id, tl_object_ptr &&status); diff --git a/td/telegram/StoryManager.cpp b/td/telegram/StoryManager.cpp index 5503c35ec..69253d6b3 100644 --- a/td/telegram/StoryManager.cpp +++ b/td/telegram/StoryManager.cpp @@ -31,6 +31,45 @@ namespace td { +class ToggleStoriesHiddenQuery final : public Td::ResultHandler { + Promise promise_; + UserId user_id_; + bool are_hidden_ = false; + + public: + explicit ToggleStoriesHiddenQuery(Promise &&promise) : promise_(std::move(promise)) { + } + + void send(UserId user_id, bool are_hidden) { + user_id_ = user_id; + are_hidden_ = are_hidden; + auto r_input_user = td_->contacts_manager_->get_input_user(user_id_); + if (r_input_user.is_error()) { + return on_error(r_input_user.move_as_error()); + } + send_query(G()->net_query_creator().create( + telegram_api::contacts_toggleStoriesHidden(r_input_user.move_as_ok(), are_hidden))); + } + + void on_result(BufferSlice packet) final { + auto result_ptr = fetch_result(packet); + if (result_ptr.is_error()) { + return on_error(result_ptr.move_as_error()); + } + + auto result = result_ptr.move_as_ok(); + LOG(DEBUG) << "Receive result for ToggleStoriesHiddenQuery: " << result; + if (result) { + td_->contacts_manager_->on_update_user_stories_hidden(user_id_, are_hidden_); + } + promise_.set_value(Unit()); + } + + void on_error(Status status) final { + promise_.set_error(std::move(status)); + } +}; + class GetStoriesByIDQuery final : public Td::ResultHandler { Promise promise_; UserId user_id_; @@ -402,6 +441,20 @@ StoryManager::Story *StoryManager::get_story_editable(StoryFullId story_full_id) return stories_.get_pointer(story_full_id); } +void StoryManager::toggle_dialog_stories_hidden(DialogId dialog_id, bool are_hidden, Promise &&promise) { + if (!td_->messages_manager_->have_dialog_info_force(dialog_id)) { + return promise.set_error(Status::Error(400, "Story sender not found")); + } + if (!td_->messages_manager_->have_input_peer(dialog_id, AccessRights::Read)) { + return promise.set_error(Status::Error(400, "Can't access the story sender")); + } + if (dialog_id.get_type() != DialogType::User) { + return promise.set_error(Status::Error(400, "Can't archive sender stories")); + } + + td_->create_handler(std::move(promise))->send(dialog_id.get_user_id(), are_hidden); +} + void StoryManager::get_dialog_pinned_stories(DialogId owner_dialog_id, StoryId from_story_id, int32 limit, Promise> &&promise) { if (limit <= 0) { diff --git a/td/telegram/StoryManager.h b/td/telegram/StoryManager.h index 0538b852d..a15a61f8e 100644 --- a/td/telegram/StoryManager.h +++ b/td/telegram/StoryManager.h @@ -92,6 +92,8 @@ class StoryManager final : public Actor { void delete_story(StoryId story_id, Promise &&promise); + void toggle_dialog_stories_hidden(DialogId dialog_id, bool are_hidden, Promise &&promise); + void get_dialog_pinned_stories(DialogId owner_dialog_id, StoryId from_story_id, int32 limit, Promise> &&promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index bb43ba575..2c40a64d0 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -5652,6 +5652,13 @@ void Td::on_request(uint64 id, const td_api::deleteStory &request) { story_manager_->delete_story(StoryId(request.story_id_), std::move(promise)); } +void Td::on_request(uint64 id, const td_api::toggleUserStoriesAreArchived &request) { + CHECK_IS_USER(); + CREATE_OK_REQUEST_PROMISE(); + story_manager_->toggle_dialog_stories_hidden(DialogId(UserId(request.user_id_)), request.are_archived_, + std::move(promise)); +} + void Td::on_request(uint64 id, const td_api::getForumTopicDefaultIcons &request) { CREATE_REQUEST_PROMISE(); stickers_manager_->get_default_topic_icons(false, std::move(promise)); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 89c08ce73..e78baf14a 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -796,6 +796,8 @@ class Td final : public Actor { void on_request(uint64 id, const td_api::deleteStory &request); + void on_request(uint64 id, const td_api::toggleUserStoriesAreArchived &request); + void on_request(uint64 id, const td_api::getForumTopicDefaultIcons &request); void on_request(uint64 id, td_api::createForumTopic &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 4bef2d2da..5fff35203 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -3998,6 +3998,11 @@ class CliClient final : public Actor { StoryId story_id; get_args(args, story_id); send_request(td_api::make_object(story_id)); + } else if (op == "tusaa") { + UserId user_id; + bool are_archived; + get_args(args, user_id, are_archived); + send_request(td_api::make_object(user_id, are_archived)); } else if (op == "gups") { UserId user_id; StoryId from_story_id;