Skip to content

Commit

Permalink
refactor: wrap object field type with Option and change shell() m…
Browse files Browse the repository at this point in the history
…ethod accordingly

This change allows to exactly know when a ChorusUser is authenticated or not
  • Loading branch information
xystrive committed Jul 4, 2024
1 parent 5387815 commit 4920c91
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,10 @@ impl fmt::Display for Token {
pub struct ChorusUser {
pub belongs_to: Shared<Instance>,
pub token: String,
pub mfa_token: Option<MfaToken>,
pub limits: Option<HashMap<LimitType, Limit>>,
pub settings: Shared<UserSettings>,
pub object: Shared<User>,
pub object: Option<Shared<User>>,
pub gateway: GatewayHandle,
}

Expand Down Expand Up @@ -192,12 +193,13 @@ impl ChorusUser {
token: String,
limits: Option<HashMap<LimitType, Limit>>,
settings: Shared<UserSettings>,
object: Shared<User>,
object: Option<Shared<User>>,
gateway: GatewayHandle,
) -> ChorusUser {
ChorusUser {
belongs_to,
token,
mfa_token: None,
limits,
settings,
object,
Expand All @@ -212,12 +214,12 @@ impl ChorusUser {
/// first.
pub(crate) async fn shell(instance: Shared<Instance>, token: String) -> ChorusUser {
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();
// Dummy gateway object
let gateway = Gateway::spawn(wss_url).await.unwrap();
ChorusUser {
token,
mfa_token: None,
belongs_to: instance.clone(),
limits: instance
.read()
Expand All @@ -226,7 +228,7 @@ impl ChorusUser {
.as_ref()
.map(|info| info.ratelimits.clone()),
settings,
object,
object: None,
gateway,
}
}
Expand Down

0 comments on commit 4920c91

Please sign in to comment.