Watch
0
0
Fork
You've already forked hyperhive
0

hive-matrix-mcp: sync with sliding sync when the server has it, classic /sync otherwise

This commit is contained in:
damocles 2026-11-09 14:43:32 +01:00 • committed by mara
commit c41429e473

View file

@ -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(())