gitdataai/libs/transport/event/message.rs

123 lines
3.2 KiB
Rust

use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use models::{MessageId, RoomId, RoomThreadId, Seq, UserId, Uuid};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum MessageEventType {
New,
Edited,
Revoked,
StreamChunk,
StreamDone,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum MessageEvent {
New(MessageNewService),
Edited(MessageEditedService),
Revoked(MessageRevokedService),
StreamChunk(MessageStreamChunkService),
StreamDone(MessageStreamDoneService),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MessageNewService {
pub id: MessageId,
pub seq: Seq,
pub room: RoomId,
pub sender_type: String,
pub sender_id: Option<UserId>,
pub display_name: Option<String>,
pub thread: Option<RoomThreadId>,
pub in_reply_to: Option<MessageId>,
pub content: String,
pub content_type: String,
pub thinking_content: Option<String>,
pub thinking_is_chunked: bool,
pub send_at: DateTime<Utc>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reactions: Option<Vec<super::reaction::ReactionGroup>>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MessageEditedService {
pub id: MessageId,
pub seq: Seq,
pub room: RoomId,
pub sender_id: Option<UserId>,
pub content: String,
pub edited_at: DateTime<Utc>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MessageRevokedService {
pub id: MessageId,
pub seq: Seq,
pub room: RoomId,
pub revoked_at: DateTime<Utc>,
pub revoked_by: Option<UserId>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MessageStreamStartService {
pub message_id: MessageId,
pub room: RoomId,
/// SSE endpoint the client should open to receive full chunk content.
pub sse_url: String,
pub display_name: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MessageStreamChunkService {
pub message_id: MessageId,
pub room: RoomId,
pub seq: u64,
pub content: String,
pub chunk_type: Option<String>,
pub display_name: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MessageStreamDoneService {
pub message_id: MessageId,
pub room: RoomId,
pub content: String,
pub thinking_content: Option<String>,
pub display_name: Option<String>,
pub error: Option<String>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct MessageSendClient {
pub room: RoomId,
pub content: String,
pub content_type: Option<String>,
pub thread: Option<RoomThreadId>,
pub in_reply_to: Option<MessageId>,
#[serde(default)]
pub attachment_ids: Vec<Uuid>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct MessageEditClient {
pub room: RoomId,
pub message_id: MessageId,
pub content: String,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct MessageRevokeClient {
pub room: RoomId,
pub message_id: MessageId,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MessageListService {
pub room: RoomId,
pub messages: Vec<MessageNewService>,
pub total: i64,
}