Store max_active_story_id in User object.

This commit is contained in:
levlam 2023-07-07 18:06:14 +03:00
parent 288666c1fe
commit d40ea33796
3 changed files with 29 additions and 7 deletions

View File

@ -4428,6 +4428,7 @@ void ContactsManager::User::store(StorerT &storer) const {
bool has_emoji_status = !emoji_status.is_empty(); bool has_emoji_status = !emoji_status.is_empty();
bool has_usernames = !usernames.is_empty(); bool has_usernames = !usernames.is_empty();
bool has_flags2 = true; bool has_flags2 = true;
bool has_max_active_story_id = max_active_story_id.is_valid();
BEGIN_STORE_FLAGS(); BEGIN_STORE_FLAGS();
STORE_FLAG(is_received); STORE_FLAG(is_received);
STORE_FLAG(is_verified); STORE_FLAG(is_verified);
@ -4465,6 +4466,7 @@ void ContactsManager::User::store(StorerT &storer) const {
STORE_FLAG(is_close_friend); STORE_FLAG(is_close_friend);
STORE_FLAG(stories_hidden); STORE_FLAG(stories_hidden);
STORE_FLAG(has_stories); STORE_FLAG(has_stories);
STORE_FLAG(has_max_active_story_id);
END_STORE_FLAGS(); END_STORE_FLAGS();
} }
store(first_name, storer); store(first_name, storer);
@ -4500,6 +4502,9 @@ void ContactsManager::User::store(StorerT &storer) const {
if (has_usernames) { if (has_usernames) {
store(usernames, storer); store(usernames, storer);
} }
if (has_max_active_story_id) {
store(max_active_story_id, storer);
}
} }
template <class ParserT> template <class ParserT>
@ -4517,6 +4522,7 @@ void ContactsManager::User::parse(ParserT &parser) {
bool has_emoji_status; bool has_emoji_status;
bool has_usernames; bool has_usernames;
bool has_flags2 = parser.version() >= static_cast<int32>(Version::AddUserFlags2); bool has_flags2 = parser.version() >= static_cast<int32>(Version::AddUserFlags2);
bool has_max_active_story_id = false;
BEGIN_PARSE_FLAGS(); BEGIN_PARSE_FLAGS();
PARSE_FLAG(is_received); PARSE_FLAG(is_received);
PARSE_FLAG(is_verified); PARSE_FLAG(is_verified);
@ -4554,6 +4560,7 @@ void ContactsManager::User::parse(ParserT &parser) {
PARSE_FLAG(is_close_friend); PARSE_FLAG(is_close_friend);
PARSE_FLAG(stories_hidden); PARSE_FLAG(stories_hidden);
PARSE_FLAG(has_stories); PARSE_FLAG(has_stories);
PARSE_FLAG(has_max_active_story_id);
END_PARSE_FLAGS(); END_PARSE_FLAGS();
} }
parse(first_name, parser); parse(first_name, parser);
@ -4617,6 +4624,9 @@ void ContactsManager::User::parse(ParserT &parser) {
CHECK(!legacy_has_username); CHECK(!legacy_has_username);
parse(usernames, parser); parse(usernames, parser);
} }
if (has_max_active_story_id) {
parse(max_active_story_id, parser);
}
if (!check_utf8(first_name)) { if (!check_utf8(first_name)) {
LOG(ERROR) << "Have invalid first name \"" << first_name << '"'; LOG(ERROR) << "Have invalid first name \"" << first_name << '"';
@ -10366,7 +10376,7 @@ void ContactsManager::on_get_user(tl_object_ptr<telegram_api::User> &&user_ptr,
u->is_changed = true; u->is_changed = true;
} }
if (stories_available || stories_unavailable) { if (stories_available || stories_unavailable) {
on_update_user_has_stories(u, user_id, stories_available); on_update_user_has_stories(u, user_id, stories_available, StoryId(user->stories_max_id_));
} }
if (is_received) { if (is_received) {
on_update_user_stories_hidden(u, user_id, stories_hidden); on_update_user_stories_hidden(u, user_id, stories_hidden);
@ -13454,7 +13464,7 @@ void ContactsManager::on_update_user_emoji_status(User *u, UserId user_id, Emoji
} }
} }
void ContactsManager::on_update_user_has_stories(UserId user_id, bool has_stories) { void ContactsManager::on_update_user_has_stories(UserId user_id, bool has_stories, StoryId max_active_story_id) {
if (!user_id.is_valid()) { if (!user_id.is_valid()) {
LOG(ERROR) << "Receive invalid " << user_id; LOG(ERROR) << "Receive invalid " << user_id;
return; return;
@ -13462,19 +13472,24 @@ void ContactsManager::on_update_user_has_stories(UserId user_id, bool has_storie
User *u = get_user_force(user_id); User *u = get_user_force(user_id);
if (u != nullptr) { if (u != nullptr) {
on_update_user_has_stories(u, user_id, has_stories); on_update_user_has_stories(u, user_id, has_stories, max_active_story_id);
update_user(u, user_id); update_user(u, user_id);
} else { } else {
LOG(INFO) << "Ignore update user has stories about unknown " << user_id; LOG(INFO) << "Ignore update user has stories about unknown " << user_id;
} }
} }
void ContactsManager::on_update_user_has_stories(User *u, UserId user_id, bool has_stories) { void ContactsManager::on_update_user_has_stories(User *u, UserId user_id, bool has_stories,
StoryId max_active_story_id) {
if (u->has_stories != has_stories) { if (u->has_stories != has_stories) {
LOG(DEBUG) << "Change has stories of " << user_id << " to " << has_stories; LOG(DEBUG) << "Change has stories of " << user_id << " to " << has_stories;
u->has_stories = has_stories; u->has_stories = has_stories;
u->is_changed = true; u->is_changed = true;
} }
if (u->max_active_story_id != max_active_story_id) {
u->max_active_story_id = max_active_story_id;
u->need_save_to_database = true;
}
} }
void ContactsManager::on_update_user_stories_hidden(UserId user_id, bool stories_hidden) { void ContactsManager::on_update_user_stories_hidden(UserId user_id, bool stories_hidden) {

View File

@ -36,6 +36,7 @@
#include "td/telegram/RestrictionReason.h" #include "td/telegram/RestrictionReason.h"
#include "td/telegram/SecretChatId.h" #include "td/telegram/SecretChatId.h"
#include "td/telegram/StickerSetId.h" #include "td/telegram/StickerSetId.h"
#include "td/telegram/StoryId.h"
#include "td/telegram/SuggestedAction.h" #include "td/telegram/SuggestedAction.h"
#include "td/telegram/td_api.h" #include "td/telegram/td_api.h"
#include "td/telegram/telegram_api.h" #include "td/telegram/telegram_api.h"
@ -186,7 +187,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_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_phone_number(UserId user_id, string &&phone_number);
void on_update_user_emoji_status(UserId user_id, tl_object_ptr<telegram_api::EmojiStatus> &&emoji_status); void on_update_user_emoji_status(UserId user_id, tl_object_ptr<telegram_api::EmojiStatus> &&emoji_status);
void on_update_user_has_stories(UserId user_id, bool has_stories); void on_update_user_has_stories(UserId user_id, bool has_stories, StoryId max_active_story_id);
void on_update_user_stories_hidden(UserId user_id, bool stories_hidden); void on_update_user_stories_hidden(UserId user_id, bool stories_hidden);
void on_update_user_online(UserId user_id, tl_object_ptr<telegram_api::UserStatus> &&status); void on_update_user_online(UserId user_id, tl_object_ptr<telegram_api::UserStatus> &&status);
void on_update_user_local_was_online(UserId user_id, int32 local_was_online); void on_update_user_local_was_online(UserId user_id, int32 local_was_online);
@ -757,6 +758,8 @@ class ContactsManager final : public Actor {
int32 was_online = 0; int32 was_online = 0;
int32 local_was_online = 0; int32 local_was_online = 0;
StoryId max_active_story_id;
string language_code; string language_code;
FlatHashSet<int64> photo_ids; FlatHashSet<int64> photo_ids;
@ -1397,7 +1400,7 @@ class ContactsManager final : public Actor {
void on_update_user_photo(User *u, UserId user_id, tl_object_ptr<telegram_api::UserProfilePhoto> &&photo, void on_update_user_photo(User *u, UserId user_id, tl_object_ptr<telegram_api::UserProfilePhoto> &&photo,
const char *source); const char *source);
void on_update_user_emoji_status(User *u, UserId user_id, EmojiStatus emoji_status); void on_update_user_emoji_status(User *u, UserId user_id, EmojiStatus emoji_status);
void on_update_user_has_stories(User *u, UserId user_id, bool has_stories); void on_update_user_has_stories(User *u, UserId user_id, bool has_stories, StoryId max_active_story_id);
void on_update_user_stories_hidden(User *u, UserId user_id, bool stories_hidden); 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, void on_update_user_is_contact(User *u, UserId user_id, bool is_contact, bool is_mutual_contact,
bool is_close_friend); bool is_close_friend);

View File

@ -2339,7 +2339,11 @@ void StoryManager::on_update_active_stories(DialogId owner_dialog_id, StoryId ma
LOG(INFO) << "Update active stories in " << owner_dialog_id << " to " << story_ids << " with max read " LOG(INFO) << "Update active stories in " << owner_dialog_id << " to " << story_ids << " with max read "
<< max_read_story_id; << max_read_story_id;
if (owner_dialog_id.get_type() == DialogType::User) { if (owner_dialog_id.get_type() == DialogType::User) {
td_->contacts_manager_->on_update_user_has_stories(owner_dialog_id.get_user_id(), !story_ids.empty()); if (story_ids.empty()) {
td_->contacts_manager_->on_update_user_has_stories(owner_dialog_id.get_user_id(), false, StoryId());
} else {
td_->contacts_manager_->on_update_user_has_stories(owner_dialog_id.get_user_id(), true, story_ids.back());
}
} }
if (story_ids.empty()) { if (story_ids.empty()) {