From 5a07286d2d04f744ec5affa8aeca2ae5237728f7 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Tue, 4 Jun 2024 00:22:36 +0800 Subject: [PATCH] gogogo --- ica-rs/src/ica/events.rs | 4 ++-- ica-rs/src/tailchat.rs | 11 ++++++----- ica-rs/src/tailchat/events.rs | 32 ++++++++++++++++++++------------ news.md | 12 ++++++++++++ 4 files changed, 40 insertions(+), 19 deletions(-) diff --git a/ica-rs/src/ica/events.rs b/ica-rs/src/ica/events.rs index 51b34a0..6c2e8fb 100644 --- a/ica-rs/src/ica/events.rs +++ b/ica-rs/src/ica/events.rs @@ -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 = 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); } } diff --git a/ica-rs/src/tailchat.rs b/ica-rs/src/tailchat.rs index 403681a..1c1335b 100644 --- a/ica-rs/src/tailchat.rs +++ b/ica-rs/src/tailchat.rs @@ -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"); diff --git a/ica-rs/src/tailchat/events.rs b/ica-rs/src/tailchat/events.rs index c56f850..e0b1aa0 100644 --- a/ica-rs/src/tailchat/events.rs +++ b/ica-rs/src/tailchat/events.rs @@ -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()); + } + } + _ => (), + } } diff --git a/news.md b/news.md index 9ef1f01..b31d0cb 100644 --- a/news.md +++ b/news.md @@ -1,5 +1,17 @@ # 更新日志 +## 0.6.5 + +怎么就突然 0.6.5 了 +我也不造啊 + +- 反正支持了 tailchat 的信息接受 +- 但是需要你在对面服务端打开 `DISABLE_MESSAGEPACK` 环境变量 +- 能用就行 + +- 现在 `update_online_data` 不会再以 INFO 级别显示了 +- `update_all_room` 同上 + ## 0.6.2 - 添加 API