2024-06-04 23:48:01 +08:00
|
|
|
use crate::data_struct::tailchat::messages::SendingMessage;
|
|
|
|
// use crate::data_struct::tailchat::{ConverseId, GroupId, MessageId, UserId};
|
2024-03-30 18:30:43 +08:00
|
|
|
|
2024-06-04 23:48:01 +08:00
|
|
|
use rust_socketio::asynchronous::Client;
|
|
|
|
|
|
|
|
use colored::Colorize;
|
2024-06-10 16:05:24 +08:00
|
|
|
use serde_json::{json, Value};
|
|
|
|
use tracing::{debug, info, warn};
|
2024-06-04 23:48:01 +08:00
|
|
|
|
|
|
|
pub async fn send_message(client: &Client, message: &SendingMessage) -> bool {
|
2024-06-15 00:35:21 +08:00
|
|
|
if message.contain_file() {
|
|
|
|
// 处理文件
|
|
|
|
}
|
2024-06-04 23:48:01 +08:00
|
|
|
let value: Value = message.as_value();
|
|
|
|
match client.emit("chat.message.sendMessage", value).await {
|
|
|
|
Ok(_) => {
|
|
|
|
debug!("send_message {}", format!("{:#?}", message).cyan());
|
|
|
|
true
|
|
|
|
}
|
|
|
|
Err(e) => {
|
2024-06-15 01:34:03 +08:00
|
|
|
warn!("send_message failed:{}", format!("{:#?}", e).red());
|
2024-06-04 23:48:01 +08:00
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-06-10 16:05:24 +08:00
|
|
|
|
|
|
|
pub async fn emit_join_room(client: &Client) -> bool {
|
|
|
|
match client.emit("chat.converse.findAndJoinRoom", json!([])).await {
|
|
|
|
Ok(_) => {
|
|
|
|
info!("emiting join room");
|
|
|
|
true
|
|
|
|
}
|
|
|
|
Err(e) => {
|
|
|
|
warn!("emit_join_room faild:{}", format!("{:#?}", e).red());
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|