⚡️ Use of the token returned by the first sync with the homeserver
This commit is contained in:
@@ -212,8 +212,9 @@ pub async fn login(
|
||||
if homeserver_url.is_some() && username.is_some() && password.is_some() {
|
||||
let client = Client::spawn(homeserver_url.unwrap()).await;
|
||||
|
||||
// TODO: Handle error case.
|
||||
let _ = client.init().await;
|
||||
if let Err(err) = client.init().await {
|
||||
error!("Following error occureds during client init: {}", err);
|
||||
}
|
||||
|
||||
match client
|
||||
.login(LoginStyle::Password(username.unwrap(), password.unwrap()))
|
||||
|
@@ -367,16 +367,19 @@ impl Client {
|
||||
self.sync_handle = tokio::spawn({
|
||||
async move {
|
||||
// Sync once so we receive the client state and old messages
|
||||
let _ = client.sync_once(SyncSettings::default()).await;
|
||||
let sync_token_option = match client.sync_once(SyncSettings::default()).await {
|
||||
Ok(sync_response) => Some(sync_response.next_batch),
|
||||
Err(err) => {
|
||||
error!("Error during sync one: {}", err);
|
||||
None
|
||||
}
|
||||
};
|
||||
|
||||
debug!("User connected to the homeserver");
|
||||
if let Some(sync_token) = sync_token_option {
|
||||
let settings = SyncSettings::default().token(sync_token);
|
||||
|
||||
// if let Err(err) = synchronized_tx.send(true) {
|
||||
// warn!("Unable to notify that the Matrix client is now synchronized ({err})");
|
||||
// }
|
||||
debug!("User connected to the homeserver, start syncing");
|
||||
|
||||
loop {
|
||||
let settings = SyncSettings::default();
|
||||
let _ = client.sync(settings).await;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user