gitdataai/libs/transport/handler/inbound/mod.rs
ZhenYi deb25614ba refactor(transport): split handler inbound and types into sub-modules
Extract MessageHandler methods into inbound/{message,room,reaction,misc,msg}
and type definitions into types/{in_message,out_event}.
2026-05-11 17:05:17 +08:00

118 lines
6.5 KiB
Rust

use crate::error::AppTransportError;
use crate::handler::session::TransportSession;
use crate::handler::types::{WsInMessage, WsOutEvent};
mod misc;
mod msg;
mod message;
mod reaction;
mod room;
pub struct MessageHandler;
impl MessageHandler {
pub async fn handle(
session: &TransportSession,
msg: WsInMessage,
) -> Result<Option<WsOutEvent>, AppTransportError> {
match msg {
WsInMessage::Ping => msg::ping().await,
WsInMessage::Subscribe { room } => msg::subscribe(session, room).await,
WsInMessage::Unsubscribe { room } => msg::unsubscribe(session, room).await,
WsInMessage::TypingStart { room } => msg::typing_start(session, room).await,
WsInMessage::TypingStop { room } => msg::typing_stop(session, room).await,
WsInMessage::ReadReceipt { room, last_read_seq } => {
msg::read_receipt(session, room, last_read_seq).await
}
WsInMessage::MessageList { room, before_seq, after_seq, limit } => {
message::message_list(session, room, before_seq, after_seq, limit).await
}
WsInMessage::MessageCreate { room, content, content_type, thread, in_reply_to } => {
message::message_create(session, room, content, content_type, thread, in_reply_to).await
}
WsInMessage::MessageUpdate { message, content } => {
message::message_update(session, message, content).await
}
WsInMessage::MessageRevoke { message } => {
message::message_revoke(session, message).await
}
WsInMessage::RoomGet { room } => room::room_get(session, room).await,
WsInMessage::RoomCreate { project, room_name, public, category } => {
room::room_create(session, project, room_name, public, category).await
}
WsInMessage::RoomUpdate { room, room_name, public, category } => {
room::room_update(session, room, room_name, public, category).await
}
WsInMessage::RoomDelete { room } => room::room_delete(session, room).await,
WsInMessage::CategoryCreate { project, name, position } => {
room::category_create(session, project, name, position).await
}
WsInMessage::CategoryUpdate { id, name, position } => {
room::category_update(session, id, name, position).await
}
WsInMessage::CategoryDelete { id } => room::category_delete(session, id).await,
WsInMessage::AccessGrant { room, user } => room::access_grant(session, room, user).await,
WsInMessage::AccessRevoke { room, user } => room::access_revoke(session, room, user).await,
WsInMessage::ReactionAdd { room, message, emoji } => {
reaction::reaction_add(session, room, message, emoji).await
}
WsInMessage::ReactionRemove { room, message, emoji } => {
reaction::reaction_remove(session, room, message, emoji).await
}
WsInMessage::ThreadCreate { room, parent } => {
reaction::thread_create(session, room, parent).await
}
WsInMessage::ThreadResolve { thread_id } => reaction::thread_resolve(thread_id).await,
WsInMessage::ThreadArchive { thread_id } => reaction::thread_archive(thread_id).await,
WsInMessage::PinAdd { message, .. } => reaction::pin_add(session, message).await,
WsInMessage::PinRemove { message, .. } => reaction::pin_remove(session, message).await,
WsInMessage::DraftSave { room, content } => {
reaction::draft_save(session, room, content).await
}
WsInMessage::DraftClear { room } => reaction::draft_clear(session, room).await,
WsInMessage::NotificationMarkRead { id } => {
misc::notification_mark_read(session, id).await
}
WsInMessage::NotificationMarkAllRead { .. } => {
misc::notification_mark_all_read(session).await
}
WsInMessage::NotificationArchive { id } => {
misc::notification_archive(session, id).await
}
WsInMessage::Search { q, room, start_time, end_time, sender_id, content_type, limit, offset } => {
misc::search(session, q, room, start_time, end_time, sender_id, content_type, limit, offset).await
}
WsInMessage::PresenceUpdate { status } => {
misc::presence_update(session, status).await
}
WsInMessage::CustomStatusUpdate { emoji, text, expires_at } => {
misc::custom_status_update(session, emoji, text, expires_at).await
}
WsInMessage::InviteCreate { .. } => misc::invite_create().await,
WsInMessage::InviteAccept { .. } => misc::invite_accept().await,
WsInMessage::InviteRevoke { .. } => misc::invite_revoke().await,
WsInMessage::BanCreate { .. } => misc::ban_create().await,
WsInMessage::BanRemove { .. } => misc::ban_remove().await,
WsInMessage::VoiceJoin { room } => misc::voice_join(room).await,
WsInMessage::VoiceLeave { room } => misc::voice_leave(room).await,
WsInMessage::VoiceMute { room, muted } => misc::voice_mute(room, muted).await,
WsInMessage::VoiceDeaf { room, deafened } => misc::voice_deaf(room, deafened).await,
WsInMessage::ScreenShare { room, start } => misc::screen_share(room, start).await,
WsInMessage::AiList { room } => misc::ai_list(session, room).await,
WsInMessage::AiUpsert { room, model, version, system_prompt, temperature, max_tokens, stream } => {
misc::ai_upsert(session, room, model, version, system_prompt, temperature, max_tokens, stream).await
}
WsInMessage::AiDelete { room, agent_id } => {
misc::ai_delete(session, room, agent_id).await
}
WsInMessage::AiStop { room } => misc::ai_stop(session, room).await,
WsInMessage::UserSummary { username } => misc::user_summary(session, username).await,
WsInMessage::StateSetReadSeq { room, last_read_seq } => {
misc::state_set_read_seq(session, room, last_read_seq).await
}
WsInMessage::StateUpdateDnd { room, do_not_disturb, dnd_start_hour, dnd_end_hour } => {
misc::state_update_dnd(session, room, do_not_disturb, dnd_start_hour, dnd_end_hour).await
}
}
}
}