refactor: 统一 current_timestamp 函数到 bus::message 模块

- bus/message.rs: current_timestamp 改为 pub(crate) 导出
- cli_chat.rs: 删除本地定义,改用 crate:🚌:message::current_timestamp()
- feishu.rs: 改用 crate:🚌:message::current_timestamp()
- storage/mod.rs: 删除本地定义,改用 crate:🚌:message::current_timestamp()
This commit is contained in:
xiaoxixi 2026-04-26 17:24:44 +08:00
parent 72c888a41f
commit 75281952d0
4 changed files with 10 additions and 27 deletions

View File

@ -251,7 +251,7 @@ pub struct ControlMessage {
// Helpers // Helpers
// ============================================================================ // ============================================================================
fn current_timestamp() -> i64 { pub(crate) fn current_timestamp() -> i64 {
std::time::SystemTime::now() std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH) .duration_since(std::time::UNIX_EPOCH)
.unwrap() .unwrap()

View File

@ -117,7 +117,7 @@ impl CliChatChannel {
sender_id: "cli".to_string(), sender_id: "cli".to_string(),
chat_id: session_id.clone(), chat_id: session_id.clone(),
content, content,
timestamp: current_timestamp(), timestamp: crate::bus::message::current_timestamp(),
media: Vec::new(), media: Vec::new(),
metadata: Default::default(), metadata: Default::default(),
forwarded_metadata: Default::default(), forwarded_metadata: Default::default(),
@ -397,10 +397,3 @@ impl Channel for CliChatChannel {
Ok(()) Ok(())
} }
} }
fn current_timestamp() -> i64 {
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_millis() as i64
}

View File

@ -1107,10 +1107,7 @@ impl FeishuChannel {
sender_id: parsed.open_id.clone(), sender_id: parsed.open_id.clone(),
chat_id: parsed.chat_id.clone(), chat_id: parsed.chat_id.clone(),
content: parsed.content.clone(), content: parsed.content.clone(),
timestamp: std::time::SystemTime::now() timestamp: crate::bus::message::current_timestamp(),
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_millis() as i64,
media: parsed.media.map(|m| vec![m]).unwrap_or_default(), media: parsed.media.map(|m| vec![m]).unwrap_or_default(),
metadata: std::collections::HashMap::new(), metadata: std::collections::HashMap::new(),
forwarded_metadata, forwarded_metadata,

View File

@ -113,7 +113,7 @@ impl SessionStore {
} }
pub fn create_cli_session(&self, title: Option<&str>) -> Result<SessionRecord, StorageError> { pub fn create_cli_session(&self, title: Option<&str>) -> Result<SessionRecord, StorageError> {
let now = current_timestamp(); let now = crate::bus::message::current_timestamp();
let id = uuid::Uuid::new_v4().to_string(); let id = uuid::Uuid::new_v4().to_string();
let title = title let title = title
.map(str::trim) .map(str::trim)
@ -146,7 +146,7 @@ impl SessionStore {
return Ok(record); return Ok(record);
} }
let now = current_timestamp(); let now = crate::bus::message::current_timestamp();
let title = format!("{}:{}", channel_name, chat_id); let title = format!("{}:{}", channel_name, chat_id);
let conn = self.conn.lock().expect("session db mutex poisoned"); let conn = self.conn.lock().expect("session db mutex poisoned");
conn.execute( conn.execute(
@ -213,7 +213,7 @@ impl SessionStore {
} }
pub fn rename_session(&self, session_id: &str, title: &str) -> Result<(), StorageError> { pub fn rename_session(&self, session_id: &str, title: &str) -> Result<(), StorageError> {
let now = current_timestamp(); let now = crate::bus::message::current_timestamp();
let conn = self.conn.lock().expect("session db mutex poisoned"); let conn = self.conn.lock().expect("session db mutex poisoned");
conn.execute( conn.execute(
"UPDATE sessions SET title = ?2, updated_at = ?3 WHERE id = ?1 AND deleted_at IS NULL", "UPDATE sessions SET title = ?2, updated_at = ?3 WHERE id = ?1 AND deleted_at IS NULL",
@ -223,7 +223,7 @@ impl SessionStore {
} }
pub fn archive_session(&self, session_id: &str) -> Result<(), StorageError> { pub fn archive_session(&self, session_id: &str) -> Result<(), StorageError> {
let now = current_timestamp(); let now = crate::bus::message::current_timestamp();
let conn = self.conn.lock().expect("session db mutex poisoned"); let conn = self.conn.lock().expect("session db mutex poisoned");
conn.execute( conn.execute(
"UPDATE sessions SET archived_at = ?2, updated_at = ?2 WHERE id = ?1 AND deleted_at IS NULL", "UPDATE sessions SET archived_at = ?2, updated_at = ?2 WHERE id = ?1 AND deleted_at IS NULL",
@ -240,7 +240,7 @@ impl SessionStore {
} }
pub fn clear_messages(&self, session_id: &str) -> Result<(), StorageError> { pub fn clear_messages(&self, session_id: &str) -> Result<(), StorageError> {
let now = current_timestamp(); let now = crate::bus::message::current_timestamp();
let conn = self.conn.lock().expect("session db mutex poisoned"); let conn = self.conn.lock().expect("session db mutex poisoned");
conn.execute("DELETE FROM messages WHERE session_id = ?1", params![session_id])?; conn.execute("DELETE FROM messages WHERE session_id = ?1", params![session_id])?;
conn.execute( conn.execute(
@ -255,7 +255,7 @@ impl SessionStore {
} }
pub fn reset_session(&self, session_id: &str) -> Result<(), StorageError> { pub fn reset_session(&self, session_id: &str) -> Result<(), StorageError> {
let now = current_timestamp(); let now = crate::bus::message::current_timestamp();
let conn = self.conn.lock().expect("session db mutex poisoned"); let conn = self.conn.lock().expect("session db mutex poisoned");
let tx = conn.unchecked_transaction()?; let tx = conn.unchecked_transaction()?;
@ -314,7 +314,7 @@ impl SessionStore {
], ],
)?; )?;
let now = current_timestamp(); let now = crate::bus::message::current_timestamp();
tx.execute( tx.execute(
" "
UPDATE sessions UPDATE sessions
@ -467,13 +467,6 @@ fn load_messages_after(
Ok(messages) Ok(messages)
} }
fn current_timestamp() -> i64 {
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.expect("system clock before unix epoch")
.as_millis() as i64
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;