This commit is contained in:
shenjack 2024-06-04 00:22:36 +08:00
parent 0858085df7
commit 5a07286d2d
Signed by: shenjack
GPG Key ID: 7B1134A979775551
4 changed files with 40 additions and 19 deletions

View File

@ -14,7 +14,7 @@ pub async fn get_online_data(payload: Payload, _client: Client) {
if let Payload::Text(values) = payload {
if let Some(value) = values.first() {
let online_data = OnlineData::new_from_json(value);
info!("update_online_data {}", format!("{:?}", online_data).cyan());
event!(Level::DEBUG, "update_online_data {}", format!("{:?}", online_data).cyan());
MainStatus::global_ica_status_mut().update_online_status(online_data);
}
}
@ -80,7 +80,7 @@ pub async fn update_all_room(payload: Payload, _client: Client) {
if let Some(value) = values.first() {
if let Some(raw_rooms) = value.as_array() {
let rooms: Vec<Room> = raw_rooms.iter().map(Room::new_from_json).collect();
info!("update_all_room {}", rooms.len());
event!(Level::DEBUG, "update_all_room {}", rooms.len());
MainStatus::global_ica_status_mut().update_rooms(rooms);
}
}

View File

@ -62,21 +62,22 @@ pub async fn start_tailchat(
.auth(json!({"token": status.jwt.clone()}))
.transport_type(TransportType::Websocket)
.on_any(wrap_any_callback!(events::any_event))
.on("chat.message.sendMessage", wrap_callback!(events::on_message))
.on("notify:chat.message.add", wrap_callback!(events::on_message))
.on("notify:chat.message.delete", wrap_callback!(events::on_msg_delete))
// .on("notify:chat.message.update", wrap_callback!(events::on_message))
// .on("notify:chat.message.addReaction", wrap_callback!(events::on_msg_update))
.connect()
.await
.unwrap();
event!(Level::INFO, "tailchat connected");
// sleep for 1 sec
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
// sleep for 500ms to wait for the connection to be established
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
socket.emit("chat.converse.findAndJoinRoom", json!([])).await.unwrap();
event!(Level::INFO, "tailchat joined room");
// notify:chat.message.delete
// notify:chat.message.add
stop_reciver.await.ok();
event!(Level::INFO, "socketio client stopping");

View File

@ -1,21 +1,23 @@
use colored::Colorize;
use rust_socketio::asynchronous::Client;
use rust_socketio::{Event, Payload};
use serde_json::json;
use tracing::info;
use crate::data_struct::tailchat::messages::ReciveMessage;
/// 所有
pub async fn any_event(event: Event, payload: Payload, _client: Client) {
let handled = [
// 真正处理过的
"chat.message.sendMessage",
// "notify:chat.message.add",
"notify:chat.message.add",
"notify:chat.message.delete",
// 也许以后会用到
"notify:chat.message.update",
"notify:chat.message.addReaction",
"notify:chat.message.removeReaction",
// 忽略的
"notify:chat.inbox.append", // 被 @ 之类的事件
];
println!("event: {:?}", event);
println!("payload: {:?}", payload);
match &event {
Event::Custom(event_name) => {
if handled.contains(&event_name.as_str()) {
@ -54,18 +56,24 @@ pub async fn any_event(event: Event, payload: Payload, _client: Client) {
}
}
pub async fn on_message(payload: Payload, client: Client) {
pub async fn on_message(payload: Payload, _client: Client) {
match payload {
Payload::Text(values) => {
if let Some(value) = values.first() {
info!("收到消息 {}", value.to_string().yellow());
let message: ReciveMessage = serde_json::from_value(value.clone()).unwrap();
info!("收到消息 {:?}", message);
}
}
_ => (),
}
}
pub async fn on_connect(payload: Payload, client: Client) {
let _ = client.emit("chat.converse.findAndJoinRoom", json! {[]}).await;
info!("连接成功 {:?}", payload);
pub async fn on_msg_delete(payload: Payload, _client: Client) {
match payload {
Payload::Text(values) => {
if let Some(value) = values.first() {
info!("删除消息 {}", value.to_string().red());
}
}
_ => (),
}
}

12
news.md
View File

@ -1,5 +1,17 @@
# 更新日志
## 0.6.5
怎么就突然 0.6.5 了
我也不造啊
- 反正支持了 tailchat 的信息接受
- 但是需要你在对面服务端打开 `DISABLE_MESSAGEPACK` 环境变量
- 能用就行
- 现在 `update_online_data` 不会再以 INFO 级别显示了
- `update_all_room` 同上
## 0.6.2
- 添加 API