Add suggestedActionSetPassword.
This commit is contained in:
parent
4084b30a52
commit
f5c65b83ee
@ -3482,6 +3482,9 @@ suggestedActionSeeTicksHint = 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
|
||||
suggestedActionSetPassword authorization_delay:int32 = SuggestedAction;
|
||||
|
||||
|
||||
//@description Contains a counter @count Count
|
||||
count count:int32 = Count;
|
||||
|
@ -783,6 +783,9 @@ void AuthManager::on_get_authorization(tl_object_ptr<telegram_api::auth_Authoriz
|
||||
if ((auth->flags_ & telegram_api::auth_authorization::TMP_SESSIONS_MASK) != 0) {
|
||||
G()->shared_config().set_option_integer("session_count", auth->tmp_sessions_);
|
||||
}
|
||||
if (auth->setup_password_required_ && auth->otherwise_relogin_days_ > 0) {
|
||||
G()->shared_config().set_option_integer("otherwise_relogin_days", auth->otherwise_relogin_days_);
|
||||
}
|
||||
td_->messages_manager_->on_authorization_success();
|
||||
td_->notification_manager_->init();
|
||||
td_->stickers_manager_->init();
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
#include "td/telegram/ChannelId.h"
|
||||
#include "td/telegram/ConfigManager.h"
|
||||
#include "td/telegram/ConfigShared.h"
|
||||
#include "td/telegram/ContactsManager.h"
|
||||
#include "td/telegram/Global.h"
|
||||
#include "td/telegram/Td.h"
|
||||
@ -70,6 +71,12 @@ SuggestedAction::SuggestedAction(const td_api::object_ptr<td_api::SuggestedActio
|
||||
}
|
||||
break;
|
||||
}
|
||||
case td_api::suggestedActionSetPassword::ID: {
|
||||
auto action = static_cast<const td_api::suggestedActionSetPassword *>(suggested_action.get());
|
||||
type_ = Type::SetPassword;
|
||||
otherwise_relogin_days_ = action->authorization_delay_;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
@ -106,6 +113,8 @@ td_api::object_ptr<td_api::SuggestedAction> SuggestedAction::get_suggested_actio
|
||||
return td_api::make_object<td_api::suggestedActionSeeTicksHint>();
|
||||
case Type::ConvertToGigagroup:
|
||||
return td_api::make_object<td_api::suggestedActionConvertToBroadcastGroup>(dialog_id_.get_channel_id().get());
|
||||
case Type::SetPassword:
|
||||
return td_api::make_object<td_api::suggestedActionSetPassword>(otherwise_relogin_days_);
|
||||
default:
|
||||
UNREACHABLE();
|
||||
return nullptr;
|
||||
@ -166,6 +175,18 @@ void dismiss_suggested_action(SuggestedAction action, Promise<Unit> &&promise) {
|
||||
case SuggestedAction::Type::ConvertToGigagroup:
|
||||
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) {
|
||||
return promise.set_error(Status::Error(400, "Invalid authorization_delay specified"));
|
||||
}
|
||||
auto days = narrow_cast<int32>(G()->shared_config().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));
|
||||
G()->shared_config().set_option_empty("otherwise_relogin_days");
|
||||
}
|
||||
return promise.set_value(Unit());
|
||||
}
|
||||
default:
|
||||
UNREACHABLE();
|
||||
return;
|
||||
|
@ -23,16 +23,19 @@ struct SuggestedAction {
|
||||
CheckPhoneNumber,
|
||||
SeeTicksHint,
|
||||
ConvertToGigagroup,
|
||||
CheckPassword
|
||||
CheckPassword,
|
||||
SetPassword
|
||||
};
|
||||
Type type_ = Type::Empty;
|
||||
DialogId dialog_id_;
|
||||
int32 otherwise_relogin_days_ = 0;
|
||||
|
||||
void init(Type type);
|
||||
|
||||
SuggestedAction() = default;
|
||||
|
||||
explicit SuggestedAction(Type type, DialogId dialog_id = DialogId()) : type_(type), dialog_id_(dialog_id) {
|
||||
explicit SuggestedAction(Type type, DialogId dialog_id = DialogId(), int32 otherwise_relogin_days = 0)
|
||||
: type_(type), dialog_id_(dialog_id), otherwise_relogin_days_(otherwise_relogin_days) {
|
||||
}
|
||||
|
||||
explicit SuggestedAction(Slice action_str);
|
||||
|
@ -3280,7 +3280,7 @@ bool Td::is_internal_config_option(Slice name) {
|
||||
case 'n':
|
||||
return name == "notification_cloud_delay_ms" || name == "notification_default_delay_ms";
|
||||
case 'o':
|
||||
return name == "online_update_period_ms" || name == "online_cloud_timeout_ms";
|
||||
return name == "online_update_period_ms" || name == "online_cloud_timeout_ms" || name == "otherwise_relogin_days";
|
||||
case 'r':
|
||||
return name == "revoke_pm_inbox" || name == "revoke_time_limit" || name == "revoke_pm_time_limit" ||
|
||||
name == "rating_e_decay" || name == "recent_stickers_limit";
|
||||
@ -3323,6 +3323,13 @@ void Td::on_config_option_updated(const string &name) {
|
||||
stickers_manager_->on_update_disable_animated_emojis();
|
||||
} else if (name == "my_id") {
|
||||
G()->set_my_id(G()->shared_config().get_option_integer(name));
|
||||
} else if (name == "otherwise_relogin_days") {
|
||||
auto days = narrow_cast<int32>(G()->shared_config().get_option_integer(name));
|
||||
if (days > 0) {
|
||||
vector<SuggestedAction> added_actions{SuggestedAction{SuggestedAction::Type::SetPassword, DialogId(), days}};
|
||||
send_closure(G()->td(), &Td::send_update, get_update_suggested_actions_object(added_actions, {}));
|
||||
}
|
||||
return;
|
||||
} else if (name == "session_count") {
|
||||
G()->net_query_dispatcher().update_session_count();
|
||||
} else if (name == "use_pfs") {
|
||||
|
@ -1407,6 +1407,9 @@ class CliClient final : public Actor {
|
||||
if (begins_with(action, "giga")) {
|
||||
return td_api::make_object<td_api::suggestedActionConvertToBroadcastGroup>(as_supergroup_id(action.substr(4)));
|
||||
}
|
||||
if (begins_with(action, "spass")) {
|
||||
return td_api::make_object<td_api::suggestedActionSetPassword>(to_integer<int32>(action.substr(5)));
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user