use lazy_static::lazy_static;
use serde_json::json;
use crate::core::mongo;
lazy_static! {
pub static ref CHAT_MESSAGE_DB: &'static str = "chat_message_db";
pub static ref CHAT_MESSAGE_COL: &'static str = "t_chat_messages";
}
use crate::core::error2::Result;
pub async fn save_chat_message(client: &mongo::MongoClient, msg: &str) -> Result<String> {
let now = chrono::Utc::now().timestamp_millis();
log::info!("save_chat_message: msg={}, now={}", msg, now);
client
.insert_one(
*CHAT_MESSAGE_DB,
*CHAT_MESSAGE_COL,
json!({"msg": msg, "time": now}),
)
.await
}