Process server-provided birthday today dismissed suggestions.

This commit is contained in:
levlam 2024-04-26 15:00:21 +03:00
parent 79c05c4878
commit 02d8cef6c5
5 changed files with 22 additions and 3 deletions

View File

@ -64,7 +64,7 @@ bool TD_TL_writer::is_full_constructor_generated(const tl::tl_combinator *t, boo
t->name == "langPackString" || t->name == "langPackStringPluralized" || t->name == "langPackStringDeleted" || t->name == "langPackString" || t->name == "langPackStringPluralized" || t->name == "langPackStringDeleted" ||
t->name == "peerUser" || t->name == "peerChat" || t->name == "updateServiceNotification" || t->name == "peerUser" || t->name == "peerChat" || t->name == "updateServiceNotification" ||
t->name == "updateNewMessage" || t->name == "updateChannelTooLong" || t->name == "messages.stickerSet" || t->name == "updateNewMessage" || t->name == "updateChannelTooLong" || t->name == "messages.stickerSet" ||
t->name == "updates.differenceSlice"; t->name == "updates.differenceSlice" || t->name == "contacts.contactBirthdays";
} }
int TD_TL_writer::get_storer_type(const tl::tl_combinator *t, const std::string &storer_name) const { int TD_TL_writer::get_storer_type(const tl::tl_combinator *t, const std::string &storer_name) const {

View File

@ -1482,6 +1482,7 @@ void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &c
string animation_search_provider; string animation_search_provider;
string animation_search_emojis; string animation_search_emojis;
vector<SuggestedAction> suggested_actions; vector<SuggestedAction> suggested_actions;
vector<string> dismissed_suggestions;
bool can_archive_and_mute_new_chats_from_unknown_users = false; bool can_archive_and_mute_new_chats_from_unknown_users = false;
int32 chat_read_mark_expire_period = 0; int32 chat_read_mark_expire_period = 0;
int32 chat_read_mark_size_threshold = 0; int32 chat_read_mark_size_threshold = 0;
@ -1675,12 +1676,16 @@ void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &c
} }
continue; continue;
} }
if (key == "pending_suggestions") { if (key == "pending_suggestions" || key == "dismissed_suggestions") {
if (value->get_id() == telegram_api::jsonArray::ID) { if (value->get_id() == telegram_api::jsonArray::ID) {
auto actions = std::move(static_cast<telegram_api::jsonArray *>(value)->value_); auto actions = std::move(static_cast<telegram_api::jsonArray *>(value)->value_);
auto otherwise_relogin_days = G()->get_option_integer("otherwise_relogin_days"); auto otherwise_relogin_days = G()->get_option_integer("otherwise_relogin_days");
for (auto &action : actions) { for (auto &action : actions) {
auto action_str = get_json_value_string(std::move(action), key); auto action_str = get_json_value_string(std::move(action), key);
if (key == "dismissed_suggestions") {
dismissed_suggestions.push_back(action_str);
continue;
}
SuggestedAction suggested_action(action_str); SuggestedAction suggested_action(action_str);
if (!suggested_action.is_empty()) { if (!suggested_action.is_empty()) {
if (otherwise_relogin_days > 0 && if (otherwise_relogin_days > 0 &&
@ -2165,6 +2170,11 @@ void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &c
if (dialog_filter_update_period > 0) { if (dialog_filter_update_period > 0) {
options.set_option_integer("chat_folder_new_chats_update_period", dialog_filter_update_period); options.set_option_integer("chat_folder_new_chats_update_period", dialog_filter_update_period);
} }
if (td::contains(dismissed_suggestions, "BIRTHDAY_CONTACTS_TODAY")) {
options.set_option_boolean("dismiss_birthday_contact_today", true);
} else {
options.set_option_empty("dismiss_birthday_contact_today");
}
if (!is_premium_available) { if (!is_premium_available) {
premium_bot_username.clear(); // just in case premium_bot_username.clear(); // just in case

View File

@ -103,7 +103,7 @@ class ConfigManager final : public NetQueryCallback {
private: private:
struct AppConfig { struct AppConfig {
static constexpr int32 CURRENT_VERSION = 42; static constexpr int32 CURRENT_VERSION = 43;
int32 version_ = 0; int32 version_ = 0;
int32 hash_ = 0; int32 hash_ = 0;
telegram_api::object_ptr<telegram_api::JSONValue> config_; telegram_api::object_ptr<telegram_api::JSONValue> config_;

View File

@ -386,6 +386,7 @@ bool OptionManager::is_internal_option(Slice name) {
"dialogs_pinned_limit_premium", "dialogs_pinned_limit_premium",
"dice_emojis", "dice_emojis",
"dice_success_values", "dice_success_values",
"dismiss_birthday_contact_today",
"edit_time_limit", "edit_time_limit",
"emoji_sounds", "emoji_sounds",
"fragment_prefixes", "fragment_prefixes",
@ -519,6 +520,9 @@ void OptionManager::on_option_updated(Slice name) {
if (name == "disable_top_chats") { if (name == "disable_top_chats") {
send_closure(td_->top_dialog_manager_actor_, &TopDialogManager::update_is_enabled, !get_option_boolean(name)); send_closure(td_->top_dialog_manager_actor_, &TopDialogManager::update_is_enabled, !get_option_boolean(name));
} }
if (name == "dismiss_birthday_contact_today") {
send_closure(td_->user_manager_actor_, &UserManager::reload_contact_birthdates, true);
}
break; break;
case 'e': case 'e':
if (name == "emoji_sounds") { if (name == "emoji_sounds") {

View File

@ -6500,6 +6500,11 @@ std::pair<int32, vector<UserId>> UserManager::search_contacts(const string &quer
} }
void UserManager::reload_contact_birthdates(bool force) { void UserManager::reload_contact_birthdates(bool force) {
if (td_->option_manager_->get_option_boolean("dismiss_birthday_contact_today")) {
contact_birthdates_.is_being_synced_ = true;
return on_get_contact_birthdates(
telegram_api::make_object<telegram_api::contacts_contactBirthdays>(Auto(), Auto()));
}
if (!G()->close_flag() && !td_->auth_manager_->is_bot() && !contact_birthdates_.is_being_synced_ && if (!G()->close_flag() && !td_->auth_manager_->is_bot() && !contact_birthdates_.is_being_synced_ &&
(contact_birthdates_.next_sync_time_ < Time::now() || force)) { (contact_birthdates_.next_sync_time_ < Time::now() || force)) {
contact_birthdates_.is_being_synced_ = true; contact_birthdates_.is_being_synced_ = true;