WIP sync thread implementation
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
use crate::broadcast_messages::{BroadcastMessage, BroadcastSender};
|
||||
use crate::matrix_connection::matrix_client::MatrixClient;
|
||||
use futures_util::StreamExt;
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct MatrixSyncTaskID(uuid::Uuid);
|
||||
@@ -29,6 +30,14 @@ async fn sync_thread_task(id: MatrixSyncTaskID, client: MatrixClient, tx: Broadc
|
||||
|
||||
log::info!("Sync thread {id:?} started for user {:?}", client.email);
|
||||
|
||||
log::info!("Perform initial synchronization...");
|
||||
if let Err(e) = client.perform_initial_sync().await {
|
||||
log::error!("Failed to perform initial Matrix synchronization! {e:?}");
|
||||
return;
|
||||
}
|
||||
|
||||
let mut sync_stream = client.sync_stream().await;
|
||||
|
||||
loop {
|
||||
tokio::select! {
|
||||
// Message from tokio broadcast
|
||||
@@ -40,13 +49,25 @@ async fn sync_thread_task(id: MatrixSyncTaskID, client: MatrixClient, tx: Broadc
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("Failed to receive a message from broadcast! {e}");
|
||||
return;
|
||||
break;
|
||||
}
|
||||
Ok(_) => {}
|
||||
}
|
||||
}
|
||||
|
||||
evt = sync_stream.next() => {
|
||||
let Some(evt)= evt else {
|
||||
log::error!("No more Matrix event to process, stopping now...");
|
||||
break;
|
||||
};
|
||||
|
||||
println!("Sync thread {id:?} event: {:?}", evt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log::info!("Sync thread {id:?} terminated!");
|
||||
if let Err(e) = tx.send(BroadcastMessage::SyncThreadStopped(id)) {
|
||||
log::warn!("Failed to notify that synchronization thread has been interrupted! {e}")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user