Support standalone SetPassword suggested action.
This commit is contained in:
parent
91ab399946
commit
2d7608459e
@ -4816,7 +4816,8 @@ suggestedActionViewChecksHint = SuggestedAction;
|
||||
//@description Suggests the user to convert specified supergroup to a broadcast group @supergroup_id Supergroup identifier
|
||||
suggestedActionConvertToBroadcastGroup supergroup_id:int53 = SuggestedAction;
|
||||
|
||||
//@description Suggests the user to set a 2-step verification password to be able to log in again @authorization_delay The number of days to pass between consecutive authorizations if the user declines to set password
|
||||
//@description Suggests the user to set a 2-step verification password to be able to log in again
|
||||
//@authorization_delay The number of days to pass between consecutive authorizations if the user declines to set password; if 0, then the user is advised to set the password for security reasons
|
||||
suggestedActionSetPassword authorization_delay:int32 = SuggestedAction;
|
||||
|
||||
|
||||
|
@ -1463,8 +1463,6 @@ void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &c
|
||||
CHECK(config != nullptr);
|
||||
LOG(INFO) << "Receive app config " << to_string(config);
|
||||
|
||||
const bool archive_and_mute = G()->get_option_boolean("archive_and_mute_new_chats_from_unknown_users");
|
||||
|
||||
string autologin_token;
|
||||
vector<string> autologin_domains;
|
||||
vector<string> url_auth_domains;
|
||||
@ -1664,6 +1662,8 @@ void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &c
|
||||
if (key == "pending_suggestions") {
|
||||
if (value->get_id() == telegram_api::jsonArray::ID) {
|
||||
auto actions = std::move(static_cast<telegram_api::jsonArray *>(value)->value_);
|
||||
const bool archive_and_mute = G()->get_option_boolean("archive_and_mute_new_chats_from_unknown_users");
|
||||
auto otherwise_relogin_days = G()->get_option_integer("otherwise_relogin_days");
|
||||
for (auto &action : actions) {
|
||||
auto action_str = get_json_value_string(std::move(action), key);
|
||||
SuggestedAction suggested_action(action_str);
|
||||
@ -1671,6 +1671,9 @@ void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &c
|
||||
if (archive_and_mute &&
|
||||
suggested_action == SuggestedAction{SuggestedAction::Type::EnableArchiveAndMuteNewChats}) {
|
||||
LOG(INFO) << "Skip EnableArchiveAndMuteNewChats suggested action";
|
||||
} else if (otherwise_relogin_days > 0 &&
|
||||
suggested_action == SuggestedAction{SuggestedAction::Type::SetPassword}) {
|
||||
LOG(INFO) << "Skip SetPassword suggested action";
|
||||
} else {
|
||||
suggested_actions.push_back(suggested_action);
|
||||
}
|
||||
@ -2025,7 +2028,7 @@ void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &c
|
||||
|
||||
void ConfigManager::get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const {
|
||||
if (!suggested_actions_.empty()) {
|
||||
updates.push_back(get_update_suggested_actions_object(suggested_actions_, {}));
|
||||
updates.push_back(get_update_suggested_actions_object(suggested_actions_, {}, "get_current_state"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -303,7 +303,7 @@ td_api::object_ptr<td_api::Update> OptionManager::get_internal_option_update(Sli
|
||||
auto days = narrow_cast<int32>(get_option_integer(name));
|
||||
if (days > 0) {
|
||||
vector<SuggestedAction> added_actions{SuggestedAction{SuggestedAction::Type::SetPassword, DialogId(), days}};
|
||||
return get_update_suggested_actions_object(added_actions, {});
|
||||
return get_update_suggested_actions_object(added_actions, {}, "get_internal_option_update");
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
|
@ -821,6 +821,7 @@ void PasswordManager::do_get_state(Promise<PasswordState> promise) {
|
||||
dismiss_suggested_action(SuggestedAction{SuggestedAction::Type::SetPassword, DialogId(), days},
|
||||
Promise<Unit>());
|
||||
}
|
||||
dismiss_suggested_action(SuggestedAction{SuggestedAction::Type::SetPassword}, Promise<Unit>());
|
||||
} else {
|
||||
state.has_password = false;
|
||||
send_closure(actor_id, &PasswordManager::drop_cached_secret);
|
||||
|
@ -35,6 +35,8 @@ SuggestedAction::SuggestedAction(Slice action_str) {
|
||||
init(Type::CheckPhoneNumber);
|
||||
} else if (action_str == Slice("NEWCOMER_TICKS")) {
|
||||
init(Type::ViewChecksHint);
|
||||
} else if (action_str == Slice("SETUP_PASSWORD")) {
|
||||
init(Type::SetPassword);
|
||||
}
|
||||
}
|
||||
|
||||
@ -95,6 +97,8 @@ string SuggestedAction::get_suggested_action_str() const {
|
||||
return "NEWCOMER_TICKS";
|
||||
case Type::ConvertToGigagroup:
|
||||
return "CONVERT_GIGAGROUP";
|
||||
case Type::SetPassword:
|
||||
return "SETUP_PASSWORD";
|
||||
default:
|
||||
return string();
|
||||
}
|
||||
@ -123,7 +127,8 @@ td_api::object_ptr<td_api::SuggestedAction> SuggestedAction::get_suggested_actio
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::updateSuggestedActions> get_update_suggested_actions_object(
|
||||
const vector<SuggestedAction> &added_actions, const vector<SuggestedAction> &removed_actions) {
|
||||
const vector<SuggestedAction> &added_actions, const vector<SuggestedAction> &removed_actions, const char *source) {
|
||||
LOG(INFO) << "Get updateSuggestedActions from " << source;
|
||||
auto get_object = [](const SuggestedAction &action) {
|
||||
return action.get_suggested_action_object();
|
||||
};
|
||||
@ -154,12 +159,14 @@ void update_suggested_actions(vector<SuggestedAction> &suggested_actions,
|
||||
}
|
||||
CHECK(!added_actions.empty() || !removed_actions.empty());
|
||||
suggested_actions = std::move(new_suggested_actions);
|
||||
send_closure(G()->td(), &Td::send_update, get_update_suggested_actions_object(added_actions, removed_actions));
|
||||
send_closure(G()->td(), &Td::send_update,
|
||||
get_update_suggested_actions_object(added_actions, removed_actions, "update_suggested_actions"));
|
||||
}
|
||||
|
||||
void remove_suggested_action(vector<SuggestedAction> &suggested_actions, SuggestedAction suggested_action) {
|
||||
if (td::remove(suggested_actions, suggested_action)) {
|
||||
send_closure(G()->td(), &Td::send_update, get_update_suggested_actions_object({}, {suggested_action}));
|
||||
send_closure(G()->td(), &Td::send_update,
|
||||
get_update_suggested_actions_object({}, {suggested_action}, "remove_suggested_action"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -177,13 +184,18 @@ void dismiss_suggested_action(SuggestedAction action, Promise<Unit> &&promise) {
|
||||
return send_closure_later(G()->contacts_manager(), &ContactsManager::dismiss_dialog_suggested_action,
|
||||
std::move(action), std::move(promise));
|
||||
case SuggestedAction::Type::SetPassword: {
|
||||
if (action.otherwise_relogin_days_ <= 0) {
|
||||
if (action.otherwise_relogin_days_ < 0) {
|
||||
return promise.set_error(Status::Error(400, "Invalid authorization_delay specified"));
|
||||
}
|
||||
if (action.otherwise_relogin_days_ == 0) {
|
||||
return send_closure_later(G()->config_manager(), &ConfigManager::dismiss_suggested_action, std::move(action),
|
||||
std::move(promise));
|
||||
}
|
||||
auto days = narrow_cast<int32>(G()->get_option_integer("otherwise_relogin_days"));
|
||||
if (days == action.otherwise_relogin_days_) {
|
||||
vector<SuggestedAction> removed_actions{SuggestedAction{SuggestedAction::Type::SetPassword, DialogId(), days}};
|
||||
send_closure(G()->td(), &Td::send_update, get_update_suggested_actions_object({}, removed_actions));
|
||||
send_closure(G()->td(), &Td::send_update,
|
||||
get_update_suggested_actions_object({}, removed_actions, "dismiss_suggested_action"));
|
||||
G()->set_option_empty("otherwise_relogin_days");
|
||||
}
|
||||
return promise.set_value(Unit());
|
||||
|
@ -67,7 +67,7 @@ inline bool operator<(const SuggestedAction &lhs, const SuggestedAction &rhs) {
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::updateSuggestedActions> get_update_suggested_actions_object(
|
||||
const vector<SuggestedAction> &added_actions, const vector<SuggestedAction> &removed_actions);
|
||||
const vector<SuggestedAction> &added_actions, const vector<SuggestedAction> &removed_actions, const char *source);
|
||||
|
||||
void update_suggested_actions(vector<SuggestedAction> &suggested_actions,
|
||||
vector<SuggestedAction> &&new_suggested_actions);
|
||||
|
Loading…
Reference in New Issue
Block a user