Skip to content

Commit

Permalink
Cherry-pick from #379 (#380)
Browse files Browse the repository at this point in the history
* cherry-pick: Remove unnecessary clones (fixes #50) (#326) (#376)

* Remove unnecessary clones (fixes #50) (#326)

* Remove unnecessary clones

Removes unnecessary clones by:
  1) Removing the clone() call
  2) Borrowing the value instead
  3) Defering the clone() call on the item that needs to be cloned and
     not the whole containing datastructure

* Fixed lint and formatting issues

---------

Co-authored-by: Sathishkumar <satlead@gmail.com>

* Remove unnecessary clones (fixes #50) (#326)

* Remove unnecessary clones

Removes unnecessary clones by:
  1) Removing the clone() call
  2) Borrowing the value instead
  3) Defering the clone() call on the item that needs to be cloned and
     not the whole containing datastructure

* Fixed lint and formatting issues

---------

Co-authored-by: Sathishkumar <satlead@gmail.com>

---------

Co-authored-by: Stefan Bossbaly <Sbossb@gmail.com>

* fix: Context update (#379)

* fix: Context Update not working for extensions

* fix: for updating context token if available on boot

---------

Co-authored-by: Stefan Bossbaly <Sbossb@gmail.com>
  • Loading branch information
satlead and StefanBossbaly authored Jan 12, 2024
1 parent 3fa01fd commit 8f61691
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
27 changes: 25 additions & 2 deletions core/main/src/processor/main_context_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ use ripple_sdk::{
distributor::distributor_sync::{SyncAndMonitorModule, SyncAndMonitorRequest},
firebolt::fb_capabilities::{CapEvent, FireboltCap},
manifest::device_manifest::PrivacySettingsStorageType,
session::AccountSessionRequest,
session::{AccountSessionRequest, AccountSessionResponse},
},
async_trait::async_trait,
extn::{
client::extn_processor::{
DefaultExtnStreamer, ExtnEventProcessor, ExtnStreamProcessor, ExtnStreamer,
},
extn_client_message::ExtnMessage,
extn_client_message::{ExtnMessage, ExtnResponse},
},
log::{debug, error, info},
tokio::{
Expand Down Expand Up @@ -77,6 +77,9 @@ impl MainContextProcessor {
}
}

///
/// Method which gets called on bootstrap for a presence of account session
///
async fn check_account_session_token(state: &PlatformState) -> bool {
let mut token_available = false;
let mut event = CapEvent::OnUnavailable;
Expand All @@ -90,6 +93,26 @@ impl MainContextProcessor {
state.session_state.insert_account_session(session);
MetricsState::update_account_session(state).await;
event = CapEvent::OnAvailable;
let state_c = state.clone();
// update ripple context for token asynchronously
tokio::spawn(async move {
if let Ok(response) = state_c
.get_client()
.send_extn_request(AccountSessionRequest::GetAccessToken)
.await
{
if let Some(ExtnResponse::AccountSession(
AccountSessionResponse::AccountSessionToken(token),
)) = response.payload.extract::<ExtnResponse>()
{
state_c.get_client().get_extn_client().context_update(
ripple_sdk::api::context::RippleContextUpdateRequest::Token(token),
)
} else {
error!("couldnt update the session response")
}
}
});
token_available = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/sdk/src/extn/client/extn_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ impl ExtnClient {
let senders = self.get_other_senders();

for sender in senders {
let send_res = sender.send(c_message.clone());
let send_res = sender.try_send(c_message.clone());
trace!("Send to other client result: {:?}", send_res);
}
}
Expand Down

0 comments on commit 8f61691

Please sign in to comment.