story-kit: merge 261_story_bot_notifications_when_stories_move_between_stages

This commit is contained in:
Dave
2026-03-17 14:03:08 +00:00
parent a067091354
commit a4affca9be
4 changed files with 329 additions and 4 deletions

View File

@@ -86,7 +86,11 @@ pub struct BotContext {
/// Connect to the Matrix homeserver, join all configured rooms, and start
/// listening for messages. Runs the full Matrix sync loop — call from a
/// `tokio::spawn` task so it doesn't block the main thread.
pub async fn run_bot(config: BotConfig, project_root: PathBuf) -> Result<(), String> {
pub async fn run_bot(
config: BotConfig,
project_root: PathBuf,
watcher_rx: tokio::sync::broadcast::Receiver<crate::io::watcher::WatcherEvent>,
) -> Result<(), String> {
let store_path = project_root.join(".story_kit").join("matrix_store");
let client = Client::builder()
.homeserver_url(&config.homeserver)
@@ -181,6 +185,11 @@ pub async fn run_bot(config: BotConfig, project_root: PathBuf) -> Result<(), Str
target_room_ids
);
// Clone values needed by the notification listener before they are moved
// into BotContext.
let notif_room_ids = target_room_ids.clone();
let notif_project_root = project_root.clone();
let ctx = BotContext {
bot_user_id,
target_room_ids,
@@ -198,6 +207,15 @@ pub async fn run_bot(config: BotConfig, project_root: PathBuf) -> Result<(), Str
client.add_event_handler(on_room_message);
client.add_event_handler(on_to_device_verification_request);
// Spawn the stage-transition notification listener before entering the
// sync loop so it starts receiving watcher events immediately.
super::notifications::spawn_notification_listener(
client.clone(),
notif_room_ids,
watcher_rx,
notif_project_root,
);
slog!("[matrix-bot] Starting Matrix sync loop");
// This blocks until the connection is terminated or an error occurs.