diff --git a/ica-rs/src/data_struct/tailchat/status.rs b/ica-rs/src/data_struct/tailchat/status.rs index 8041faa..8bd0ad9 100644 --- a/ica-rs/src/data_struct/tailchat/status.rs +++ b/ica-rs/src/data_struct/tailchat/status.rs @@ -1,4 +1,7 @@ +use std::sync::Arc; + use serde::{Deserialize, Serialize}; +use tokio::sync::RwLock; use crate::data_struct::tailchat::UserId; @@ -29,3 +32,31 @@ pub struct UpdateDMConverse { #[serde(rename = "updatedAt")] pub updated_at: String, } + +pub type Writeable = Arc>; + +#[derive(Debug, Clone)] +pub struct BotStatus { + user_id: Writeable, +} + +impl BotStatus { + pub fn new(user_id: UserId) -> Self { + Self { + user_id: Arc::new(RwLock::new(user_id)), + } + } + + pub async fn get_user_id(&self) -> UserId { self.user_id.read().await.clone() } + + pub fn block_get_user_id(&self) -> UserId { + tokio::task::block_in_place(|| { + let rt = tokio::runtime::Runtime::new().unwrap(); + rt.block_on(self.get_user_id()) + }) + } + + pub async fn set_user_id(&self, user_id: UserId) { + self.user_id.write().await.clone_from(&user_id); + } +}