Add class StoryList and activeStories.list.

This commit is contained in:
levlam 2023-06-28 16:09:44 +03:00
parent 98352f5571
commit f023646c6d
5 changed files with 52 additions and 6 deletions

View File

@ -4918,6 +4918,15 @@ inputStoryContentPhoto photo:InputFile added_sticker_file_ids:vector<int32> = In
inputStoryContentVideo video:InputFile added_sticker_file_ids:vector<int32> duration:double is_animation:Bool = InputStoryContent;
//@class StoryList @description Describes a list of stories
//@description The main list of stories, shown above the chat list
storyListMain = StoryList;
//@description The list of hidden stories, shown only in the Contacts section
storyListHidden = StoryList;
//@description Contains information about interactions with a story
//@view_count Number of times the story was viewed
//@recent_viewer_user_ids Identifiers of at most 3 recent viewers of the story
@ -4945,10 +4954,11 @@ stories total_count:int32 stories:vector<story> = Stories;
storyInfo story_id:int32 date:int32 = StoryInfo;
//@description Describes active stories sent by the same sender
//@list Identifier of the story list in which the stories are shown
//@story_sender_chat_id Identifier of the sender of the stories
//@max_read_story_id Identifier of the last read active story
//@stories Basic information about the stories; use getStory to get full information about the stories
activeStories story_sender_chat_id:int53 max_read_story_id:int32 stories:vector<storyInfo> = ActiveStories;
activeStories list:StoryList story_sender_chat_id:int53 max_read_story_id:int32 stories:vector<storyInfo> = ActiveStories;
//@description Contains a part of a file @data File bytes
@ -7268,7 +7278,7 @@ 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 posted by the chat are available on the main chat list @chat_id Identifier of the chat @are_hidden Pass true to make the story unavailable from the main chat list; pass false to make them available
//@description Toggles whether stories posted by the chat are available above chat lists @chat_id Identifier of the chat that posted stories @are_hidden Pass true to make the stories unavailable above the chat lists; pass false to make them available
toggleChatStoriesAreHidden chat_id:int53 are_hidden:Bool = Ok;
//@description Returns the list of active stories posted by the given chat. The stories are returned in a chronological order (i.e., in order of increasing story_id) @chat_id Chat identifier

View File

@ -5908,6 +5908,14 @@ bool ContactsManager::get_channel_has_protected_content(ChannelId channel_id) co
return c->noforwards;
}
bool ContactsManager::get_user_stories_hidden(UserId user_id) const {
auto u = get_user(user_id);
if (u == nullptr) {
return false;
}
return u->stories_hidden;
}
string ContactsManager::get_user_private_forward_name(UserId user_id) {
auto user_full = get_user_full_force(user_id);
if (user_full != nullptr) {
@ -10541,7 +10549,8 @@ void ContactsManager::on_save_user_to_database(UserId user_id, bool success) {
<< u->is_deleted << ' ' << u->is_bot << ' ' << u->need_save_to_database << ' '
<< u->is_changed << ' ' << u->is_status_changed << ' ' << u->is_name_changed << ' '
<< u->is_username_changed << ' ' << u->is_photo_changed << ' '
<< u->is_is_contact_changed << ' ' << u->is_is_deleted_changed << ' ' << u->log_event_id;
<< u->is_is_contact_changed << ' ' << u->is_is_deleted_changed << ' '
<< u->is_stories_hidden_changed << ' ' << u->log_event_id;
CHECK(load_user_from_database_queries_.count(user_id) == 0);
u->is_being_saved = false;
@ -11932,6 +11941,10 @@ void ContactsManager::update_user(User *u, UserId user_id, bool from_binlog, boo
user_online_timeout_.cancel_timeout(user_id.get());
}
}
if (u->is_stories_hidden_changed) {
td_->story_manager_->on_dialog_stories_hidden_updated(DialogId(user_id));
u->is_stories_hidden_changed = false;
}
if (!td_->auth_manager_->is_bot()) {
if (u->restriction_reasons.empty()) {
restricted_user_ids_.erase(user_id);
@ -13459,6 +13472,7 @@ void ContactsManager::on_update_user_stories_hidden(User *u, UserId user_id, boo
if (u->stories_hidden != stories_hidden) {
LOG(DEBUG) << "Change stories are archived of " << user_id << " to " << stories_hidden;
u->stories_hidden = stories_hidden;
u->is_stories_hidden_changed = true;
u->need_save_to_database = true;
}
}

View File

@ -127,6 +127,8 @@ class ContactsManager final : public Actor {
bool get_chat_has_protected_content(ChatId chat_id) const;
bool get_channel_has_protected_content(ChannelId channel_id) const;
bool get_user_stories_hidden(UserId user_id) const;
string get_user_private_forward_name(UserId user_id);
bool get_user_voice_messages_forbidden(UserId user_id) const;
@ -797,6 +799,7 @@ class ContactsManager final : public Actor {
bool is_phone_number_changed = true;
bool is_is_contact_changed = true;
bool is_is_deleted_changed = true;
bool is_stories_hidden_changed = true;
bool is_full_info_changed = false;
bool is_changed = true; // have new changes that need to be sent to the client and database
bool need_save_to_database = true; // have new changes that need only to be saved to the database

View File

@ -946,7 +946,7 @@ void StoryManager::get_dialog_expiring_stories(DialogId owner_dialog_id,
return promise.set_error(Status::Error(400, "Can't access the story sender"));
}
if (owner_dialog_id.get_type() != DialogType::User) {
return promise.set_value(td_api::make_object<td_api::activeStories>(owner_dialog_id.get(), 0, Auto()));
return promise.set_value(get_active_stories_object(owner_dialog_id));
}
auto active_stories = get_active_stories(owner_dialog_id);
@ -1453,9 +1453,20 @@ td_api::object_ptr<td_api::activeStories> StoryManager::get_active_stories_objec
}
}
}
bool stories_hidden = false;
if (owner_dialog_id.get_type() == DialogType::User) {
stories_hidden = td_->contacts_manager_->get_user_stories_hidden(owner_dialog_id.get_user_id());
}
td_api::object_ptr<td_api::StoryList> list;
if (stories_hidden) {
list = td_api::make_object<td_api::storyListHidden>();
} else {
list = td_api::make_object<td_api::storyListMain>();
}
return td_api::make_object<td_api::activeStories>(
td_->messages_manager_->get_chat_id_object(owner_dialog_id, "get_active_stories_object"), max_read_story_id.get(),
std::move(stories));
std::move(list), td_->messages_manager_->get_chat_id_object(owner_dialog_id, "get_active_stories_object"),
max_read_story_id.get(), std::move(stories));
}
vector<FileId> StoryManager::get_story_file_ids(const Story *story) const {
@ -1916,6 +1927,12 @@ bool StoryManager::on_update_read_stories(DialogId owner_dialog_id, StoryId max_
return false;
}
void StoryManager::on_dialog_stories_hidden_updated(DialogId owner_dialog_id) {
if (active_stories_.count(owner_dialog_id)) {
send_update_active_stories(owner_dialog_id);
}
}
void StoryManager::on_get_story_views(const vector<StoryId> &story_ids,
telegram_api::object_ptr<telegram_api::stories_storyViews> &&story_views) {
schedule_interaction_info_update();

View File

@ -151,6 +151,8 @@ class StoryManager final : public Actor {
bool on_update_read_stories(DialogId owner_dialog_id, StoryId max_read_story_id);
void on_dialog_stories_hidden_updated(DialogId owner_dialog_id);
Status can_get_story_viewers(StoryFullId story_full_id, const Story *story) const;
void on_get_story_views(const vector<StoryId> &story_ids,