Support archiving channel stories.

This commit is contained in:
levlam 2023-09-05 18:17:45 +03:00
parent 35a319db20
commit f2a821a07e
3 changed files with 59 additions and 2 deletions

View File

@ -5121,6 +5121,7 @@ void ContactsManager::Channel::store(StorerT &storer) const {
STORE_FLAG(has_max_active_story_id);
STORE_FLAG(has_max_read_story_id);
STORE_FLAG(has_max_active_story_id_next_reload_time);
STORE_FLAG(stories_hidden);
END_STORE_FLAGS();
}
@ -5218,6 +5219,7 @@ void ContactsManager::Channel::parse(ParserT &parser) {
PARSE_FLAG(has_max_active_story_id);
PARSE_FLAG(has_max_read_story_id);
PARSE_FLAG(has_max_active_story_id_next_reload_time);
PARSE_FLAG(stories_hidden);
END_PARSE_FLAGS();
}
@ -6005,6 +6007,14 @@ bool ContactsManager::get_user_stories_hidden(UserId user_id) const {
return u->stories_hidden;
}
bool ContactsManager::get_channel_stories_hidden(ChannelId channel_id) const {
auto c = get_channel(channel_id);
if (c == nullptr) {
return false;
}
return c->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) {
@ -12350,6 +12360,11 @@ void ContactsManager::update_channel(Channel *c, ChannelId channel_id, bool from
td_->messages_manager_->on_dialog_has_protected_content_updated(DialogId(channel_id));
c->is_noforwards_changed = false;
}
if (c->is_stories_hidden_changed) {
send_closure_later(td_->story_manager_actor_, &StoryManager::on_dialog_active_stories_order_updated,
DialogId(channel_id), "stories_hidden");
c->is_stories_hidden_changed = false;
}
if (!td_->auth_manager_->is_bot()) {
if (c->restriction_reasons.empty()) {
@ -16487,6 +16502,34 @@ void ContactsManager::on_update_channel_max_read_story_id(Channel *c, ChannelId
}
}
void ContactsManager::on_update_channel_stories_hidden(ChannelId channel_id, bool stories_hidden) {
if (!channel_id.is_valid()) {
LOG(ERROR) << "Receive invalid " << channel_id;
return;
}
Channel *c = get_channel_force(channel_id);
if (c != nullptr) {
on_update_channel_stories_hidden(c, channel_id, stories_hidden);
update_channel(c, channel_id);
} else {
LOG(INFO) << "Ignore update channel stories are archived about unknown " << channel_id;
}
}
void ContactsManager::on_update_channel_stories_hidden(Channel *c, ChannelId channel_id, bool stories_hidden) {
if (td_->auth_manager_->is_bot()) {
return;
}
if (c->stories_hidden != stories_hidden) {
LOG(DEBUG) << "Change stories are archived of " << channel_id << " to " << stories_hidden;
c->stories_hidden = stories_hidden;
c->is_stories_hidden_changed = true;
c->need_save_to_database = true;
}
}
void ContactsManager::on_update_channel_editable_username(ChannelId channel_id, string &&username) {
Channel *c = get_channel(channel_id);
CHECK(c != nullptr);
@ -19053,6 +19096,9 @@ void ContactsManager::on_chat_update(telegram_api::channel &channel, const char
on_update_channel_default_permissions(c, channel_id, RestrictedRights(channel.default_banned_rights_));
on_update_channel_has_location(c, channel_id, channel.has_geo_);
on_update_channel_noforwards(c, channel_id, channel.noforwards_);
if (!td_->auth_manager_->is_bot()) {
on_update_channel_stories_hidden(c, channel_id, channel.stories_hidden_);
}
bool need_update_participant_count = have_participant_count && participant_count != c->participant_count;
if (need_update_participant_count) {

View File

@ -128,6 +128,7 @@ class ContactsManager final : public Actor {
bool get_channel_has_protected_content(ChannelId channel_id) const;
bool get_user_stories_hidden(UserId user_id) const;
bool get_channel_stories_hidden(ChannelId channel_id) const;
string get_user_private_forward_name(UserId user_id);
bool get_user_voice_messages_forbidden(UserId user_id) const;
@ -215,6 +216,7 @@ class ContactsManager final : public Actor {
void on_update_channel_usernames(ChannelId channel_id, Usernames &&usernames);
void on_update_channel_story_ids(ChannelId channel_id, StoryId max_active_story_id, StoryId max_read_story_id);
void on_update_channel_max_read_story_id(ChannelId channel_id, StoryId max_read_story_id);
void on_update_channel_stories_hidden(ChannelId channel_id, bool stories_hidden);
void on_update_channel_description(ChannelId channel_id, string &&description);
void on_update_channel_sticker_set(ChannelId channel_id, StickerSetId sticker_set_id);
void on_update_channel_linked_channel_id(ChannelId channel_id, ChannelId group_channel_id);
@ -994,6 +996,7 @@ class ContactsManager final : public Actor {
bool can_be_deleted = false;
bool join_to_send = false;
bool join_request = false;
bool stories_hidden = false;
bool is_megagroup = false;
bool is_gigagroup = false;
@ -1009,6 +1012,7 @@ class ContactsManager final : public Actor {
bool is_photo_changed = true;
bool is_default_permissions_changed = true;
bool is_status_changed = true;
bool is_stories_hidden_changed = true;
bool is_has_location_changed = true;
bool is_noforwards_changed = true;
bool is_creator_changed = true;
@ -1500,6 +1504,7 @@ class ContactsManager final : public Actor {
RestrictedRights default_permissions);
static void on_update_channel_has_location(Channel *c, ChannelId channel_id, bool has_location);
static void on_update_channel_noforwards(Channel *c, ChannelId channel_id, bool noforwards);
void on_update_channel_stories_hidden(Channel *c, ChannelId channel_id, bool stories_hidden);
void on_update_channel_story_ids_impl(Channel *c, ChannelId channel_id, StoryId max_active_story_id,
StoryId max_read_story_id);
void on_update_channel_max_read_story_id(Channel *c, ChannelId channel_id, StoryId max_read_story_id);

View File

@ -3550,8 +3550,10 @@ void StoryManager::on_update_dialog_stories_hidden(DialogId owner_dialog_id, boo
case DialogType::User:
td_->contacts_manager_->on_update_user_stories_hidden(owner_dialog_id.get_user_id(), stories_hidden);
break;
case DialogType::Chat:
case DialogType::Channel:
td_->contacts_manager_->on_update_channel_stories_hidden(owner_dialog_id.get_channel_id(), stories_hidden);
break;
case DialogType::Chat:
case DialogType::SecretChat:
case DialogType::None:
default:
@ -3973,8 +3975,12 @@ StoryListId StoryManager::get_dialog_story_list_id(DialogId owner_dialog_id) con
return StoryListId::archive();
}
return StoryListId::main();
case DialogType::Chat:
case DialogType::Channel:
if (td_->contacts_manager_->get_channel_stories_hidden(owner_dialog_id.get_channel_id())) {
return StoryListId::archive();
}
return StoryListId::main();
case DialogType::Chat:
case DialogType::SecretChat:
case DialogType::None:
default: