Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(notif): mark connection live during ping (#2217)
Sean Aye01796366d02b
diff --git a/rust/cloud-storage/connection_gateway/src/api/connection/messages.rs b/rust/cloud-storage/connection_gateway/src/api/connection/messages.rsindex 47b886d2d8..11404e09c3 100644--- a/rust/cloud-storage/connection_gateway/src/api/connection/messages.rs+++ b/rust/cloud-storage/connection_gateway/src/api/connection/messages.rs@@ -9,7 +9,9 @@ use crate::{};use anyhow::{Context, Result};use axum::extract::ws::{Message, WebSocket};+use cowlike::CowLike;use futures::{StreamExt, stream::SplitStream};+use macro_user_id::user_id::MacroUserIdStr;use std::error::Error;use tokio::sync::mpsc::Sender;use tungstenite::error::{Error as TungsteniteError, ProtocolError};@@ -79,6 +81,15 @@ pub async fn handle_message(// Handle incoming ping messagesif text_message.trim() == PING_MESSAGE {+ // Refresh last-online timestamp so long-lived connections don't appear offline+ if let Ok(user_id) =+ MacroUserIdStr::parse_from_str(&connection_context.user_context.user_id)+ {+ connection_context+ .api_context+ .last_online_worker+ .record_online(user_id.into_owned());+ }sender.send(OutgoingMessage::Pong).await?;return Ok(());}diff --git a/rust/cloud-storage/last_online_tracker/src/inbound.rs b/rust/cloud-storage/last_online_tracker/src/inbound.rsindex 0e34611404..cf064b94c4 100644--- a/rust/cloud-storage/last_online_tracker/src/inbound.rs+++ b/rust/cloud-storage/last_online_tracker/src/inbound.rs@@ -26,6 +26,7 @@ impl Drop for RecordOnDrop {}impl LastOnlineWorker {+ /// Create a new [LastOnlineWorker] that processes last-online updates in the background.pub fn new<T: SystemTime, R: LastOnlineRepo>(service: LastOnlineService<T, R>) -> Self {let (tx, mut rx) = tokio::sync::mpsc::channel(100);@@ -38,7 +39,7 @@ impl LastOnlineWorker {LastOnlineWorker { tx, handle }}- /// returns a guard which records the users online time during creation and also during drop+ /// Returns a guard which records the users online time during creation and also during drop.pub fn new_guard(&self, user: MacroUserIdStr<'static>) -> RecordOnDrop {let tx = self.tx.clone();if let Err(e) = tx.try_send(user.clone()) {@@ -47,4 +48,14 @@ impl LastOnlineWorker {RecordOnDrop { val: user, tx }}++ /// Record that a user is currently online without creating a guard.+ ///+ /// Use this to refresh the last-online timestamp during long-lived connections+ /// (e.g. on each WebSocket ping/pong) so the user is not falsely reported as offline.+ pub fn record_online(&self, user: MacroUserIdStr<'static>) {+ if let Err(e) = self.tx.try_send(user) {+ tracing::error!("{e:?}");+ }+ }}