Skip to content

Commit

Permalink
add metadata to client stuct
Browse files Browse the repository at this point in the history
  • Loading branch information
NorbertBodziony committed Aug 2, 2023
1 parent b9465fa commit 0beca6c
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion sdk/bindings/InitializeResponse.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export interface InitializeResponse { responseId: string, sessionId: string, createdNew: boolean, publicKeys: Array<string>, }
export interface InitializeResponse { responseId: string, sessionId: string, createdNew: boolean, publicKeys: Array<string>, metadata?: string, }
7 changes: 1 addition & 6 deletions server/bindings/InitializeResponse.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export interface InitializeResponse {
responseId: string
sessionId: string
createdNew: boolean
publicKeys: Array<string>
}
export interface InitializeResponse { responseId: string, sessionId: string, createdNew: boolean, publicKeys: Array<string>, metadata?: string, }
4 changes: 4 additions & 0 deletions server/src/app/app_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ pub async fn app_handler(
client_id: None,
device: None,
connected_public_keys: Vec::new(),
metadata: None,
},
network: init_data.network,
version: init_data.version,
Expand Down Expand Up @@ -135,6 +136,7 @@ pub async fn app_handler(
client_id: None,
device: None,
connected_public_keys: Vec::new(),
metadata: None,
},
network: init_data.network,
version: init_data.version,
Expand All @@ -150,13 +152,15 @@ pub async fn app_handler(
let mut sessions = sessions.write().await;
let created_session = sessions.get_mut(&session_id).expect("safe unwrap");
let public_keys = created_session.client_state.connected_public_keys.clone();
let metadata = created_session.client_state.metadata.clone();

match created_session
.send_to_app(ServerToApp::InitializeResponse(InitializeResponse {
response_id: init_data.response_id,
session_id: session_id.clone(),
created_new: created_new,
public_keys: public_keys,
metadata: metadata,
}))
.await
{
Expand Down
1 change: 1 addition & 0 deletions server/src/client/client_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ pub async fn client_handler(
session.update_status(SessionStatus::ClientConnected);
session.client_state.device = connect_request.device.clone();
session.client_state.connected_public_keys = connect_request.public_keys.clone();
session.client_state.metadata = connect_request.metadata.clone();
session.client_state.client_id = Some(connect_request.client_id.clone());
// Setup notification
match &connect_request.notification {
Expand Down
1 change: 1 addition & 0 deletions server/src/client/connect_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub async fn connect_session(
session.update_status(SessionStatus::ClientConnected);
session.client_state.device = request.device.clone();
session.client_state.connected_public_keys = request.public_keys.clone();
session.client_state.metadata = request.metadata.clone();
session.client_state.client_id = Some(request.client_id.clone());
// notification
if let Some(notification) = request.notification.clone() {
Expand Down
1 change: 1 addition & 0 deletions server/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ impl DisconnectUser for Sessions {
client_id: None,
connected_public_keys: vec![],
device: None,
metadata: None,
};
session.notification = None;
session.pending_requests.clear();
Expand Down
3 changes: 3 additions & 0 deletions server/src/structs/app_messages/initialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@ pub struct InitializeResponse {
pub created_new: bool, // if the session was created new or if it was restored
#[serde(rename = "publicKeys")]
pub public_keys: Vec<String>, // if session was restored, this is the list of public keys that were restored
#[serde(rename = "metadata")]
#[ts(optional)]
pub metadata: Option<String>, // if session was restored, this is the metadata that was restored
}
2 changes: 1 addition & 1 deletion server/src/structs/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,5 @@ pub struct ClientState {
pub client_id: Option<ClientId>,
pub device: Option<Device>,
pub connected_public_keys: Vec<String>,
// TODO add metadata
pub metadata: Option<String>,
}

0 comments on commit 0beca6c

Please sign in to comment.