hive-matrix-mcp: sync with sliding sync when the server has it, classic /sync otherwise
This commit is contained in:
parent
24c5c02942
commit
c41429e473
1 changed files with 198 additions and 15 deletions
|
|
@ -42,7 +42,7 @@ use tokio::time::Instant;
|
|||
use hive_matrix_mcp::accounts::{AccountCfg, Registry};
|
||||
use hive_matrix_mcp::client::PermanentBringUpError;
|
||||
use hive_matrix_mcp::credential::Token;
|
||||
use hive_matrix_mcp::{accounts, client, credential, mcp, paths, timeline, wake};
|
||||
use hive_matrix_mcp::{accounts, client, credential, mcp, paths, sliding, timeline, wake};
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(name = "hive-matrix-daemon", about = "matrix-sdk client + MCP daemon")]
|
||||
|
|
@ -781,22 +781,35 @@ fn account_sync_loop(client: &Client, tag: Option<String>) -> SyncLoop {
|
|||
// each sweep (see the sweep fns) so re-invites / new messages re-push.
|
||||
let invite_notified = Arc::new(tokio::sync::Mutex::new(std::collections::HashSet::new()));
|
||||
let unread_notified = Arc::new(tokio::sync::Mutex::new(std::collections::HashSet::new()));
|
||||
// Both loops run this after each response.
|
||||
let sweep = move || {
|
||||
let client = cb_client.clone();
|
||||
let invite_notified = invite_notified.clone();
|
||||
let unread_notified = unread_notified.clone();
|
||||
let tag = tag.clone();
|
||||
async move {
|
||||
timeline::sweep_invites(&client, &invite_notified, tag.as_deref()).await;
|
||||
timeline::sweep_unread(&client, &unread_notified, tag.as_deref()).await;
|
||||
}
|
||||
};
|
||||
Box::pin(async move {
|
||||
if sliding::wanted(&sync_client).await {
|
||||
tracing::info!("syncing with sliding sync");
|
||||
match sliding::run(&sync_client, &sweep).await {
|
||||
Ok(()) => return Ok(()),
|
||||
Err(e) => tracing::warn!(error = %e, "sliding sync gave up, falling back to /sync"),
|
||||
}
|
||||
} else {
|
||||
tracing::info!("syncing with classic /sync");
|
||||
}
|
||||
sync_client
|
||||
.sync_with_callback(
|
||||
SyncSettings::default().filter(sync_filter()),
|
||||
move |_response| {
|
||||
let client = cb_client.clone();
|
||||
let invite_notified = invite_notified.clone();
|
||||
let unread_notified = unread_notified.clone();
|
||||
let tag = tag.clone();
|
||||
async move {
|
||||
timeline::sweep_invites(&client, &invite_notified, tag.as_deref()).await;
|
||||
timeline::sweep_unread(&client, &unread_notified, tag.as_deref()).await;
|
||||
matrix_sdk::LoopCtrl::Continue
|
||||
}
|
||||
},
|
||||
)
|
||||
.sync_with_callback(SyncSettings::default().filter(sync_filter()), |_response| {
|
||||
let sweep = sweep();
|
||||
async move {
|
||||
sweep.await;
|
||||
matrix_sdk::LoopCtrl::Continue
|
||||
}
|
||||
})
|
||||
.await
|
||||
.context("matrix-sdk sync loop exited")?;
|
||||
Ok(())
|
||||
|
|
|
|||
Loading…
Reference in a new issue