Set the status for a session and publish bus events. Matches TS `SessionStatus.set(sessionID, status)`.
(&self, session_id: &str, status: SessionStatusInfo)
| 82 | /// Set the status for a session and publish bus events. |
| 83 | /// Matches TS `SessionStatus.set(sessionID, status)`. |
| 84 | pub async fn set(&self, session_id: &str, status: SessionStatusInfo) { |
| 85 | // Publish status event |
| 86 | if let Some(ref bus) = self.bus { |
| 87 | let event_data = serde_json::json!({ |
| 88 | "sessionID": session_id, |
| 89 | "status": status, |
| 90 | }); |
| 91 | bus.publish(&SESSION_STATUS_EVENT, event_data).await; |
| 92 | } |
| 93 | |
| 94 | let mut state = self.state.write().await; |
| 95 | match &status { |
| 96 | SessionStatusInfo::Idle => { |
| 97 | // Publish deprecated idle event |
| 98 | if let Some(ref bus) = self.bus { |
| 99 | let idle_data = serde_json::json!({ |
| 100 | "sessionID": session_id, |
| 101 | }); |
| 102 | bus.publish(&SESSION_IDLE_EVENT, idle_data).await; |
| 103 | } |
| 104 | state.remove(session_id); |
| 105 | } |
| 106 | _ => { |
| 107 | state.insert(session_id.to_string(), status); |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | /// Convenience: set status to idle. |
| 113 | pub async fn set_idle(&self, session_id: &str) { |
no test coverage detected