diff --git a/crates/openfang-channels/src/mastodon.rs b/crates/openfang-channels/src/mastodon.rs index 81be9f5c..22f3096e 100644 --- a/crates/openfang-channels/src/mastodon.rs +++ b/crates/openfang-channels/src/mastodon.rs @@ -456,10 +456,18 @@ impl ChannelAdapter for MastodonAdapter { let notifications: Vec = poll_resp.json().await.unwrap_or_default(); - for notif in ¬ifications { - if let Some(nid) = notif["id"].as_str() { + // Mastodon returns notifications newest-first. Record the first + // (highest) ID before processing so we never re-fetch these on + // the next poll. Updating inside the loop would leave us with + // the oldest ID, causing every previously seen notification to + // be re-delivered and re-processed. + if let Some(newest) = notifications.first() { + if let Some(nid) = newest["id"].as_str() { last_notification_id = Some(nid.to_string()); } + } + + for notif in ¬ifications { if let Some(msg) = parse_mastodon_notification(notif, &own_account_id) { if tx.send(msg).await.is_err() { return;