⚡️ 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() {
|
if homeserver_url.is_some() && username.is_some() && password.is_some() {
|
||||||
let client = Client::spawn(homeserver_url.unwrap()).await;
|
let client = Client::spawn(homeserver_url.unwrap()).await;
|
||||||
|
|
||||||
// TODO: Handle error case.
|
if let Err(err) = client.init().await {
|
||||||
let _ = client.init().await;
|
error!("Following error occureds during client init: {}", err);
|
||||||
|
}
|
||||||
|
|
||||||
match client
|
match client
|
||||||
.login(LoginStyle::Password(username.unwrap(), password.unwrap()))
|
.login(LoginStyle::Password(username.unwrap(), password.unwrap()))
|
||||||
|
@@ -367,16 +367,19 @@ impl Client {
|
|||||||
self.sync_handle = tokio::spawn({
|
self.sync_handle = tokio::spawn({
|
||||||
async move {
|
async move {
|
||||||
// Sync once so we receive the client state and old messages
|
// 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) {
|
debug!("User connected to the homeserver, start syncing");
|
||||||
// warn!("Unable to notify that the Matrix client is now synchronized ({err})");
|
|
||||||
// }
|
|
||||||
|
|
||||||
loop {
|
|
||||||
let settings = SyncSettings::default();
|
|
||||||
let _ = client.sync(settings).await;
|
let _ = client.sync(settings).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user