From eb92b86ce4ac26112e5fbcbcc9165f06a8e596aa Mon Sep 17 00:00:00 2001 From: Nathan Musoke Date: Thu, 25 Jan 2018 17:52:41 +1300 Subject: [PATCH] Store device_id in session The device_id is needed by the client, but otherwise inaccessible (unless provided to the server by the client). This is analogous to how the user_id is currently stored for guests, but will probably be more often used. The device_id is needed to implement e2e encryption. --- src/lib.rs | 6 +++--- src/session.rs | 10 +++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index fba1b29b..41b2eb16 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -114,7 +114,7 @@ where }, ) .map(move |response| { - let session = Session::new(response.access_token, response.user_id); + let session = Session::new(response.access_token, response.user_id, response.device_id); *data.session.borrow_mut() = Some(session.clone()); session @@ -142,7 +142,7 @@ where }, ) .map(move |response| { - let session = Session::new(response.access_token, response.user_id); + let session = Session::new(response.access_token, response.user_id, response.device_id); *data.session.borrow_mut() = Some(session.clone()); session @@ -179,7 +179,7 @@ where }, ) .map(move |response| { - let session = Session::new(response.access_token, response.user_id); + let session = Session::new(response.access_token, response.user_id, response.device_id); *data.session.borrow_mut() = Some(session.clone()); session diff --git a/src/session.rs b/src/session.rs index 388567d4..07314d26 100644 --- a/src/session.rs +++ b/src/session.rs @@ -7,14 +7,17 @@ pub struct Session { access_token: String, /// The user the access token was issued for. user_id: UserId, + /// The ID of the client device + device_id: String, } impl Session { /// Create a new user session from an access token and a user ID. - pub fn new(access_token: String, user_id: UserId) -> Self { + pub fn new(access_token: String, user_id: UserId, device_id: String) -> Self { Session { access_token, user_id, + device_id, } } @@ -27,4 +30,9 @@ impl Session { pub fn user_id(&self) -> &UserId { &self.user_id } + + /// Get ID of the device the session belongs to. + pub fn device_id(&self) -> &str { + &self.device_id + } }