refactor: wrap object field type with `Option` and change `shell()` method accordingly
This change allows to exactly know when a ChorusUser is authenticated or not
This commit is contained in:
parent
538781502c
commit
4920c91e52
|
@ -159,9 +159,10 @@ impl fmt::Display for Token {
|
||||||
pub struct ChorusUser {
|
pub struct ChorusUser {
|
||||||
pub belongs_to: Shared<Instance>,
|
pub belongs_to: Shared<Instance>,
|
||||||
pub token: String,
|
pub token: String,
|
||||||
|
pub mfa_token: Option<MfaToken>,
|
||||||
pub limits: Option<HashMap<LimitType, Limit>>,
|
pub limits: Option<HashMap<LimitType, Limit>>,
|
||||||
pub settings: Shared<UserSettings>,
|
pub settings: Shared<UserSettings>,
|
||||||
pub object: Shared<User>,
|
pub object: Option<Shared<User>>,
|
||||||
pub gateway: GatewayHandle,
|
pub gateway: GatewayHandle,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,12 +193,13 @@ impl ChorusUser {
|
||||||
token: String,
|
token: String,
|
||||||
limits: Option<HashMap<LimitType, Limit>>,
|
limits: Option<HashMap<LimitType, Limit>>,
|
||||||
settings: Shared<UserSettings>,
|
settings: Shared<UserSettings>,
|
||||||
object: Shared<User>,
|
object: Option<Shared<User>>,
|
||||||
gateway: GatewayHandle,
|
gateway: GatewayHandle,
|
||||||
) -> ChorusUser {
|
) -> ChorusUser {
|
||||||
ChorusUser {
|
ChorusUser {
|
||||||
belongs_to,
|
belongs_to,
|
||||||
token,
|
token,
|
||||||
|
mfa_token: None,
|
||||||
limits,
|
limits,
|
||||||
settings,
|
settings,
|
||||||
object,
|
object,
|
||||||
|
@ -212,12 +214,12 @@ impl ChorusUser {
|
||||||
/// first.
|
/// first.
|
||||||
pub(crate) async fn shell(instance: Shared<Instance>, token: String) -> ChorusUser {
|
pub(crate) async fn shell(instance: Shared<Instance>, token: String) -> ChorusUser {
|
||||||
let settings = Arc::new(RwLock::new(UserSettings::default()));
|
let settings = Arc::new(RwLock::new(UserSettings::default()));
|
||||||
let object = Arc::new(RwLock::new(User::default()));
|
|
||||||
let wss_url = instance.read().unwrap().urls.wss.clone();
|
let wss_url = instance.read().unwrap().urls.wss.clone();
|
||||||
// Dummy gateway object
|
// Dummy gateway object
|
||||||
let gateway = Gateway::spawn(wss_url).await.unwrap();
|
let gateway = Gateway::spawn(wss_url).await.unwrap();
|
||||||
ChorusUser {
|
ChorusUser {
|
||||||
token,
|
token,
|
||||||
|
mfa_token: None,
|
||||||
belongs_to: instance.clone(),
|
belongs_to: instance.clone(),
|
||||||
limits: instance
|
limits: instance
|
||||||
.read()
|
.read()
|
||||||
|
@ -226,7 +228,7 @@ impl ChorusUser {
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|info| info.ratelimits.clone()),
|
.map(|info| info.ratelimits.clone()),
|
||||||
settings,
|
settings,
|
||||||
object,
|
object: None,
|
||||||
gateway,
|
gateway,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue