Make Session fields public.

This commit is contained in:
Jimmy Cuadra 2019-02-08 13:43:15 -08:00
parent c50f043c51
commit fa798d7a04
3 changed files with 28 additions and 8 deletions

View File

@ -30,6 +30,10 @@ version = "0.3.1"
optional = true
version = "0.2.2"
[dependencies.serde]
version = "1.0.87"
features = ["derive"]
[dev-dependencies]
ruma-events = "0.11.0"
tokio = "0.1"

View File

@ -114,7 +114,11 @@ where
},
)
.map(move |response| {
let session = Session::new(response.access_token, response.user_id, response.device_id);
let session = Session {
access_token: response.access_token,
device_id: response.device_id,
user_id: response.user_id,
};
*data.session.lock().unwrap() = Some(session.clone());
session
@ -142,7 +146,11 @@ where
},
)
.map(move |response| {
let session = Session::new(response.access_token, response.user_id, response.device_id);
let session = Session {
access_token: response.access_token,
device_id: response.device_id,
user_id: response.user_id,
};
*data.session.lock().unwrap() = Some(session.clone());
session
@ -179,7 +187,11 @@ where
},
)
.map(move |response| {
let session = Session::new(response.access_token, response.user_id, response.device_id);
let session = Session {
access_token: response.access_token,
device_id: response.device_id,
user_id: response.user_id,
};
*data.session.lock().unwrap() = Some(session.clone());
session
@ -252,7 +264,7 @@ where
if E::METADATA.requires_authentication {
if let Some(ref session) = *data1.session.lock().unwrap() {
url.query_pairs_mut()
.append_pair("access_token", session.access_token());
.append_pair("access_token", &session.access_token);
} else {
return Err(Error::AuthenticationRequired);
}

View File

@ -1,18 +1,19 @@
use ruma_identifiers::UserId;
/// A user session, containing an access token and information about the associated user account.
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
#[derive(Clone, Debug, serde::Deserialize, Eq, Hash, PartialEq, serde::Serialize)]
pub struct Session {
/// The access token used for this session.
access_token: String,
pub access_token: String,
/// The user the access token was issued for.
user_id: UserId,
pub user_id: UserId,
/// The ID of the client device
device_id: String,
pub device_id: String,
}
impl Session {
/// Create a new user session from an access token and a user ID.
#[deprecated]
pub fn new(access_token: String, user_id: UserId, device_id: String) -> Self {
Session {
access_token,
@ -22,16 +23,19 @@ impl Session {
}
/// Get the access token associated with this session.
#[deprecated]
pub fn access_token(&self) -> &str {
&self.access_token
}
/// Get the ID of the user the session belongs to.
#[deprecated]
pub fn user_id(&self) -> &UserId {
&self.user_id
}
/// Get ID of the device the session belongs to.
#[deprecated]
pub fn device_id(&self) -> &str {
&self.device_id
}