Add User.max_active_story_id_next_reload_time.

This commit is contained in:
levlam 2023-07-17 20:05:35 +03:00
parent a73a8dcca1
commit a023e80fb5
2 changed files with 20 additions and 1 deletions

View File

@ -4430,6 +4430,7 @@ void ContactsManager::User::store(StorerT &storer) const {
bool has_flags2 = true;
bool has_max_active_story_id = max_active_story_id.is_valid();
bool has_max_read_story_id = max_read_story_id.is_valid();
bool has_max_active_story_id_next_reload_time = max_active_story_id_next_reload_time > Time::now();
BEGIN_STORE_FLAGS();
STORE_FLAG(is_received);
STORE_FLAG(is_verified);
@ -4469,6 +4470,7 @@ void ContactsManager::User::store(StorerT &storer) const {
STORE_FLAG(has_stories);
STORE_FLAG(has_max_active_story_id);
STORE_FLAG(has_max_read_story_id);
STORE_FLAG(has_max_active_story_id_next_reload_time);
END_STORE_FLAGS();
}
store(first_name, storer);
@ -4510,6 +4512,9 @@ void ContactsManager::User::store(StorerT &storer) const {
if (has_max_read_story_id) {
store(max_read_story_id, storer);
}
if (has_max_active_story_id_next_reload_time) {
store_time(max_active_story_id_next_reload_time, storer);
}
}
template <class ParserT>
@ -4529,6 +4534,7 @@ void ContactsManager::User::parse(ParserT &parser) {
bool has_flags2 = parser.version() >= static_cast<int32>(Version::AddUserFlags2);
bool has_max_active_story_id = false;
bool has_max_read_story_id = false;
bool has_max_active_story_id_next_reload_time = false;
BEGIN_PARSE_FLAGS();
PARSE_FLAG(is_received);
PARSE_FLAG(is_verified);
@ -4568,6 +4574,7 @@ void ContactsManager::User::parse(ParserT &parser) {
PARSE_FLAG(has_stories);
PARSE_FLAG(has_max_active_story_id);
PARSE_FLAG(has_max_read_story_id);
PARSE_FLAG(has_max_active_story_id_next_reload_time);
END_PARSE_FLAGS();
}
parse(first_name, parser);
@ -4637,6 +4644,9 @@ void ContactsManager::User::parse(ParserT &parser) {
if (has_max_read_story_id) {
parse(max_read_story_id, parser);
}
if (has_max_active_story_id_next_reload_time) {
parse_time(max_active_story_id_next_reload_time, parser);
}
if (!check_utf8(first_name)) {
LOG(ERROR) << "Have invalid first name \"" << first_name << '"';
@ -13507,6 +13517,13 @@ void ContactsManager::on_update_user_has_stories(User *u, UserId user_id, bool h
u->max_active_story_id = max_active_story_id;
u->need_save_to_database = true;
}
auto max_active_story_id_next_reload_time = Time::now() + MAX_ACTIVE_STORY_ID_RELOAD_TIME;
if (max_active_story_id_next_reload_time >
u->max_active_story_id_next_reload_time + MAX_ACTIVE_STORY_ID_RELOAD_TIME / 5) {
LOG(DEBUG) << "Change max_active_story_id_next_reload_time of " << user_id;
u->max_active_story_id_next_reload_time = max_active_story_id_next_reload_time;
u->need_save_to_database = true;
}
if (!has_stories && !max_active_story_id.is_valid()) {
CHECK(max_read_story_id == StoryId());
if (u->max_read_story_id != StoryId()) {

View File

@ -759,6 +759,7 @@ class ContactsManager final : public Actor {
int32 was_online = 0;
int32 local_was_online = 0;
double max_active_story_id_next_reload_time = 0.0;
StoryId max_active_story_id;
StoryId max_read_story_id;
@ -1174,7 +1175,8 @@ class ContactsManager final : public Actor {
static constexpr size_t MAX_INVITE_LINK_TITLE_LENGTH = 32; // server side limit
static constexpr int32 MAX_GET_CHANNEL_PARTICIPANTS = 200; // server side limit
static constexpr int32 CHANNEL_PARTICIPANT_CACHE_TIME = 1800; // some reasonable limit
static constexpr int32 CHANNEL_PARTICIPANT_CACHE_TIME = 1800; // some reasonable limit
static constexpr int32 MAX_ACTIVE_STORY_ID_RELOAD_TIME = 3600; // some reasonable limit
// the True fields aren't set for manually created telegram_api::user objects, therefore the flags must be used
static constexpr int32 USER_FLAG_HAS_ACCESS_HASH = 1 << 0;