Add user.has_unread_active_stories.
This commit is contained in:
parent
d40ea33796
commit
f589137af4
@ -716,11 +716,12 @@ usernames active_usernames:vector<string> disabled_usernames:vector<string> edit
|
||||
//@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
|
||||
//@has_unread_active_stories True, if the user has unread non-expired stories available to the current user
|
||||
//@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 has_active_stories: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 has_unread_active_stories:Bool have_access:Bool type:UserType language_code:string added_to_attachment_menu:Bool = User;
|
||||
|
||||
|
||||
//@description Contains information about a bot
|
||||
|
@ -4429,6 +4429,7 @@ void ContactsManager::User::store(StorerT &storer) const {
|
||||
bool has_usernames = !usernames.is_empty();
|
||||
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();
|
||||
BEGIN_STORE_FLAGS();
|
||||
STORE_FLAG(is_received);
|
||||
STORE_FLAG(is_verified);
|
||||
@ -4467,6 +4468,7 @@ void ContactsManager::User::store(StorerT &storer) const {
|
||||
STORE_FLAG(stories_hidden);
|
||||
STORE_FLAG(has_stories);
|
||||
STORE_FLAG(has_max_active_story_id);
|
||||
STORE_FLAG(has_max_read_story_id);
|
||||
END_STORE_FLAGS();
|
||||
}
|
||||
store(first_name, storer);
|
||||
@ -4505,6 +4507,9 @@ void ContactsManager::User::store(StorerT &storer) const {
|
||||
if (has_max_active_story_id) {
|
||||
store(max_active_story_id, storer);
|
||||
}
|
||||
if (has_max_read_story_id) {
|
||||
store(max_read_story_id, storer);
|
||||
}
|
||||
}
|
||||
|
||||
template <class ParserT>
|
||||
@ -4523,6 +4528,7 @@ void ContactsManager::User::parse(ParserT &parser) {
|
||||
bool has_usernames;
|
||||
bool has_flags2 = parser.version() >= static_cast<int32>(Version::AddUserFlags2);
|
||||
bool has_max_active_story_id = false;
|
||||
bool has_max_read_story_id = false;
|
||||
BEGIN_PARSE_FLAGS();
|
||||
PARSE_FLAG(is_received);
|
||||
PARSE_FLAG(is_verified);
|
||||
@ -4561,6 +4567,7 @@ void ContactsManager::User::parse(ParserT &parser) {
|
||||
PARSE_FLAG(stories_hidden);
|
||||
PARSE_FLAG(has_stories);
|
||||
PARSE_FLAG(has_max_active_story_id);
|
||||
PARSE_FLAG(has_max_read_story_id);
|
||||
END_PARSE_FLAGS();
|
||||
}
|
||||
parse(first_name, parser);
|
||||
@ -4627,6 +4634,9 @@ void ContactsManager::User::parse(ParserT &parser) {
|
||||
if (has_max_active_story_id) {
|
||||
parse(max_active_story_id, parser);
|
||||
}
|
||||
if (has_max_read_story_id) {
|
||||
parse(max_read_story_id, parser);
|
||||
}
|
||||
|
||||
if (!check_utf8(first_name)) {
|
||||
LOG(ERROR) << "Have invalid first name \"" << first_name << '"';
|
||||
@ -10376,7 +10386,7 @@ void ContactsManager::on_get_user(tl_object_ptr<telegram_api::User> &&user_ptr,
|
||||
u->is_changed = true;
|
||||
}
|
||||
if (stories_available || stories_unavailable) {
|
||||
on_update_user_has_stories(u, user_id, stories_available, StoryId(user->stories_max_id_));
|
||||
on_update_user_has_stories(u, user_id, stories_available, StoryId(user->stories_max_id_), StoryId());
|
||||
}
|
||||
if (is_received) {
|
||||
on_update_user_stories_hidden(u, user_id, stories_hidden);
|
||||
@ -13464,7 +13474,8 @@ 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, StoryId max_active_story_id) {
|
||||
void ContactsManager::on_update_user_has_stories(UserId user_id, bool has_stories, StoryId max_active_story_id,
|
||||
StoryId max_read_story_id) {
|
||||
if (!user_id.is_valid()) {
|
||||
LOG(ERROR) << "Receive invalid " << user_id;
|
||||
return;
|
||||
@ -13472,15 +13483,16 @@ void ContactsManager::on_update_user_has_stories(UserId user_id, bool has_storie
|
||||
|
||||
User *u = get_user_force(user_id);
|
||||
if (u != nullptr) {
|
||||
on_update_user_has_stories(u, user_id, has_stories, max_active_story_id);
|
||||
on_update_user_has_stories(u, user_id, has_stories, max_active_story_id, max_read_story_id);
|
||||
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,
|
||||
StoryId max_active_story_id) {
|
||||
void ContactsManager::on_update_user_has_stories(User *u, UserId user_id, bool has_stories, StoryId max_active_story_id,
|
||||
StoryId max_read_story_id) {
|
||||
auto has_unread_stories = get_has_unread_stories(u);
|
||||
if (u->has_stories != has_stories) {
|
||||
LOG(DEBUG) << "Change has stories of " << user_id << " to " << has_stories;
|
||||
u->has_stories = has_stories;
|
||||
@ -13490,6 +13502,19 @@ 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;
|
||||
}
|
||||
if (!has_stories && !max_active_story_id.is_valid()) {
|
||||
CHECK(max_read_story_id == StoryId());
|
||||
if (u->max_read_story_id != StoryId()) {
|
||||
u->max_read_story_id = StoryId();
|
||||
u->need_save_to_database = true;
|
||||
}
|
||||
} else if (max_read_story_id.get() > u->max_read_story_id.get()) {
|
||||
u->max_read_story_id = max_read_story_id;
|
||||
u->need_save_to_database = true;
|
||||
}
|
||||
if (has_unread_stories != get_has_unread_stories(u)) {
|
||||
u->is_changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
void ContactsManager::on_update_user_stories_hidden(UserId user_id, bool stories_hidden) {
|
||||
@ -18831,6 +18856,10 @@ td_api::object_ptr<td_api::UserStatus> ContactsManager::get_user_status_object(U
|
||||
}
|
||||
}
|
||||
|
||||
bool ContactsManager::get_has_unread_stories(const User *u) {
|
||||
return u->has_stories && u->max_active_story_id.get() > u->max_read_story_id.get();
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::updateUser> ContactsManager::get_update_user_object(UserId user_id, const User *u) const {
|
||||
if (u == nullptr) {
|
||||
return get_update_unknown_user_object(user_id);
|
||||
@ -18842,7 +18871,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));
|
||||
}
|
||||
|
||||
@ -18882,7 +18911,7 @@ tl_object_ptr<td_api::user> ContactsManager::get_user_object(UserId user_id, con
|
||||
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->has_stories,
|
||||
have_access, std::move(type), u->language_code, u->attach_menu_enabled);
|
||||
get_has_unread_stories(u), have_access, std::move(type), u->language_code, u->attach_menu_enabled);
|
||||
}
|
||||
|
||||
vector<int64> ContactsManager::get_user_ids_object(const vector<UserId> &user_ids, const char *source) const {
|
||||
|
@ -187,7 +187,8 @@ 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, StoryId max_active_story_id);
|
||||
void on_update_user_has_stories(UserId user_id, bool has_stories, StoryId max_active_story_id,
|
||||
StoryId max_read_story_id);
|
||||
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);
|
||||
@ -759,6 +760,7 @@ class ContactsManager final : public Actor {
|
||||
int32 local_was_online = 0;
|
||||
|
||||
StoryId max_active_story_id;
|
||||
StoryId max_read_story_id;
|
||||
|
||||
string language_code;
|
||||
|
||||
@ -1400,7 +1402,8 @@ 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, StoryId max_active_story_id);
|
||||
void on_update_user_has_stories(User *u, UserId user_id, bool has_stories, StoryId max_active_story_id,
|
||||
StoryId max_read_story_id);
|
||||
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);
|
||||
@ -1736,6 +1739,8 @@ class ContactsManager final : public Actor {
|
||||
|
||||
void on_dismiss_suggested_action(SuggestedAction action, Result<Unit> &&result);
|
||||
|
||||
static bool get_has_unread_stories(const User *u);
|
||||
|
||||
td_api::object_ptr<td_api::updateUser> get_update_user_object(UserId user_id, const User *u) const;
|
||||
|
||||
td_api::object_ptr<td_api::updateUser> get_update_unknown_user_object(UserId user_id) const;
|
||||
|
@ -2340,9 +2340,10 @@ void StoryManager::on_update_active_stories(DialogId owner_dialog_id, StoryId ma
|
||||
<< max_read_story_id;
|
||||
if (owner_dialog_id.get_type() == DialogType::User) {
|
||||
if (story_ids.empty()) {
|
||||
td_->contacts_manager_->on_update_user_has_stories(owner_dialog_id.get_user_id(), false, StoryId());
|
||||
td_->contacts_manager_->on_update_user_has_stories(owner_dialog_id.get_user_id(), false, StoryId(), StoryId());
|
||||
} else {
|
||||
td_->contacts_manager_->on_update_user_has_stories(owner_dialog_id.get_user_id(), true, story_ids.back());
|
||||
td_->contacts_manager_->on_update_user_has_stories(owner_dialog_id.get_user_id(), true, story_ids.back(),
|
||||
max_read_story_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user