Add user.has_active_stories.

This commit is contained in:
levlam 2023-06-12 15:04:49 +03:00
parent 20901b6ac5
commit ed4d6df307
3 changed files with 39 additions and 6 deletions

View File

@ -713,12 +713,13 @@ usernames active_usernames:vector<string> disabled_usernames:vector<string> edit
//@restriction_reason If non-empty, it contains a human-readable description of the reason why access to this user must be restricted
//@is_scam True, if many users reported this user as a scam
//@is_fake True, if many users reported this user as a fake account
//@has_active_stories True, if the user has non-expired stories available to the current user
//@stories_are_archived True, if stories of the user aren't available on the main chat list
//@have_access If false, the user is inaccessible, and the only information known about the user is inside this class. Identifier of the user can't be passed to any method
//@type Type of the user
//@language_code IETF language tag of the user's language; only available to bots
//@added_to_attachment_menu True, if the user added the current bot to attachment menu; only available to bots
user id:int53 first_name:string last_name:string usernames:usernames phone_number:string status:UserStatus profile_photo:profilePhoto emoji_status:emojiStatus is_contact:Bool is_mutual_contact:Bool is_close_friend:Bool is_verified:Bool is_premium:Bool is_support:Bool restriction_reason:string is_scam:Bool is_fake:Bool stories_are_archived:Bool have_access:Bool type:UserType language_code:string added_to_attachment_menu:Bool = User;
user id:int53 first_name:string last_name:string usernames:usernames phone_number:string status:UserStatus profile_photo:profilePhoto emoji_status:emojiStatus is_contact:Bool is_mutual_contact:Bool is_close_friend:Bool is_verified:Bool is_premium:Bool is_support:Bool restriction_reason:string is_scam:Bool is_fake:Bool has_active_stories:Bool stories_are_archived:Bool have_access:Bool type:UserType language_code:string added_to_attachment_menu:Bool = User;
//@description Contains information about a bot

View File

@ -4463,6 +4463,7 @@ void ContactsManager::User::store(StorerT &storer) const {
BEGIN_STORE_FLAGS();
STORE_FLAG(is_close_friend);
STORE_FLAG(stories_hidden);
STORE_FLAG(has_stories);
END_STORE_FLAGS();
}
store(first_name, storer);
@ -4551,6 +4552,7 @@ void ContactsManager::User::parse(ParserT &parser) {
BEGIN_PARSE_FLAGS();
PARSE_FLAG(is_close_friend);
PARSE_FLAG(stories_hidden);
PARSE_FLAG(has_stories);
END_PARSE_FLAGS();
}
parse(first_name, parser);
@ -10286,6 +10288,8 @@ void ContactsManager::on_get_user(tl_object_ptr<telegram_api::User> &&user_ptr,
bool has_bot_info_version = (flags & USER_FLAG_HAS_BOT_INFO_VERSION) != 0;
bool need_apply_min_photo = (flags & USER_FLAG_NEED_APPLY_MIN_PHOTO) != 0;
bool is_fake = (flags & USER_FLAG_IS_FAKE) != 0;
bool stories_available = user->stories_max_id_ > 0;
bool stories_unavailable = user->stories_unavailable_;
bool stories_hidden = user->stories_hidden_;
LOG_IF(ERROR, !can_join_groups && !is_bot)
@ -10352,6 +10356,9 @@ void ContactsManager::on_get_user(tl_object_ptr<telegram_api::User> &&user_ptr,
u->attach_menu_enabled = attach_menu_enabled;
u->is_changed = true;
}
if (stories_available || stories_unavailable) {
on_update_user_has_stories(u, user_id, stories_available);
}
if (is_received) {
on_update_user_stories_hidden(u, user_id, stories_hidden);
}
@ -13405,6 +13412,29 @@ 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) {
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_has_stories(u, user_id, has_stories);
update_user(u, user_id);
} else {
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) {
if (u->has_stories != has_stories) {
LOG(DEBUG) << "Change has stories of " << user_id << " to " << has_stories;
u->has_stories = has_stories;
u->is_changed = true;
}
}
void ContactsManager::on_update_user_stories_hidden(UserId user_id, bool stories_hidden) {
if (!user_id.is_valid()) {
LOG(ERROR) << "Receive invalid " << user_id;
@ -13422,8 +13452,7 @@ void ContactsManager::on_update_user_stories_hidden(UserId user_id, bool stories
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;
LOG(DEBUG) << "Change stories are archived of " << user_id << " to " << stories_hidden;
u->stories_hidden = stories_hidden;
u->is_changed = true;
}
@ -18739,7 +18768,7 @@ td_api::object_ptr<td_api::updateUser> ContactsManager::get_update_unknown_user_
auto have_access = user_id == get_my_id() || user_messages_.count(user_id) != 0;
return td_api::make_object<td_api::updateUser>(td_api::make_object<td_api::user>(
user_id.get(), "", "", nullptr, "", td_api::make_object<td_api::userStatusEmpty>(), nullptr, nullptr, false,
false, false, false, false, false, "", false, false, false, have_access,
false, false, false, false, false, "", false, false, false, false, have_access,
td_api::make_object<td_api::userTypeUnknown>(), "", false));
}
@ -18773,11 +18802,11 @@ tl_object_ptr<td_api::user> ContactsManager::get_user_object(UserId user_id, con
auto emoji_status = u->last_sent_emoji_status.is_valid() ? u->emoji_status.get_emoji_status_object() : nullptr;
auto have_access = user_id == get_my_id() || have_input_peer_user(u, user_id, AccessRights::Know);
return make_tl_object<td_api::user>(
return td_api::make_object<td_api::user>(
user_id.get(), u->first_name, u->last_name, u->usernames.get_usernames_object(), u->phone_number,
get_user_status_object(user_id, u), get_profile_photo_object(td_->file_manager_.get(), u->photo),
std::move(emoji_status), u->is_contact, u->is_mutual_contact, u->is_close_friend, u->is_verified, u->is_premium,
u->is_support, get_restriction_reason_description(u->restriction_reasons), u->is_scam, u->is_fake,
u->is_support, get_restriction_reason_description(u->restriction_reasons), u->is_scam, u->is_fake, u->has_stories,
u->stories_hidden, have_access, std::move(type), u->language_code, u->attach_menu_enabled);
}

View File

@ -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<telegram_api::EmojiStatus> &&emoji_status);
void on_update_user_has_stories(UserId user_id, bool has_stories);
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_local_was_online(UserId user_id, int32 local_was_online);
@ -782,6 +783,7 @@ class ContactsManager final : public Actor {
bool need_apply_min_photo = false;
bool can_be_added_to_attach_menu = false;
bool attach_menu_enabled = false;
bool has_stories = false;
bool stories_hidden = false;
bool is_photo_inited = false;
@ -1388,6 +1390,7 @@ class ContactsManager final : public Actor {
void on_update_user_photo(User *u, UserId user_id, tl_object_ptr<telegram_api::UserProfilePhoto> &&photo,
const char *source);
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_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);