lib

Core libraries for Radroots
git clone https://radroots.dev/git/lib.git
Log | Files | Refs | README | LICENSE

model.rs (6039B)


      1 use alloc::string::String;
      2 use alloc::vec::Vec;
      3 use serde::{Deserialize, Serialize};
      4 
      5 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
      6 pub struct RadrootsSimplexAppProfile {
      7     pub profile_id: String,
      8     pub display_name: String,
      9     pub created_at_unix: i64,
     10 }
     11 
     12 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
     13 pub struct RadrootsSimplexAppContact {
     14     pub contact_id: String,
     15     pub profile_id: String,
     16     pub display_name: String,
     17     pub lifecycle: String,
     18     pub created_at_unix: i64,
     19 }
     20 
     21 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
     22 pub struct RadrootsSimplexAppConnection {
     23     pub connection_id: String,
     24     pub profile_id: String,
     25     pub contact_id: Option<String>,
     26     pub state: String,
     27     pub agent_connection_id: Option<String>,
     28     pub created_at_unix: i64,
     29 }
     30 
     31 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
     32 pub struct RadrootsSimplexAppQueueEndpoint {
     33     pub queue_endpoint_id: String,
     34     pub connection_id: String,
     35     pub role: String,
     36     pub server: String,
     37     pub sender_id: Vec<u8>,
     38     pub status: String,
     39     pub created_at_unix: i64,
     40 }
     41 
     42 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
     43 pub struct RadrootsSimplexAppConversation {
     44     pub conversation_id: String,
     45     pub profile_id: String,
     46     pub contact_id: Option<String>,
     47     pub created_at_unix: i64,
     48 }
     49 
     50 #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
     51 #[serde(rename_all = "snake_case")]
     52 pub enum RadrootsSimplexAppChatDirection {
     53     Inbound,
     54     Outbound,
     55     System,
     56 }
     57 
     58 impl RadrootsSimplexAppChatDirection {
     59     pub fn as_str(self) -> &'static str {
     60         match self {
     61             Self::Inbound => "inbound",
     62             Self::Outbound => "outbound",
     63             Self::System => "system",
     64         }
     65     }
     66 
     67     pub fn parse(value: &str) -> Result<Self, String> {
     68         match value {
     69             "inbound" => Ok(Self::Inbound),
     70             "outbound" => Ok(Self::Outbound),
     71             "system" => Ok(Self::System),
     72             other => Err(alloc::format!("unknown chat direction `{other}`")),
     73         }
     74     }
     75 }
     76 
     77 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
     78 pub struct RadrootsSimplexAppChatItem {
     79     pub chat_item_id: String,
     80     pub conversation_id: String,
     81     pub logical_order: i64,
     82     pub direction: RadrootsSimplexAppChatDirection,
     83     pub chat_msg_id: Option<String>,
     84     pub body: String,
     85     pub delivery_status: String,
     86     pub created_at_unix: i64,
     87 }
     88 
     89 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
     90 pub struct RadrootsSimplexAppInboundMessageLogEntry {
     91     pub inbound_id: String,
     92     pub connection_id: String,
     93     pub broker_message_id_hash: Vec<u8>,
     94     pub inbound_sequence: Option<i64>,
     95     pub message_hash: Vec<u8>,
     96     pub runtime_ack_handle: String,
     97     pub ack_status: String,
     98     pub app_record_kind: String,
     99     pub app_record_id: String,
    100     pub received_at_unix: i64,
    101 }
    102 
    103 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
    104 pub struct RadrootsSimplexAppInboundChildEvent {
    105     pub child_event_id: String,
    106     pub inbound_id: String,
    107     pub child_ordinal: u32,
    108     pub app_record_kind: String,
    109     pub app_record_id: String,
    110     pub event_kind: String,
    111     pub chat_msg_id: Option<String>,
    112     pub received_at_unix: i64,
    113 }
    114 
    115 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
    116 pub struct RadrootsSimplexAppOutboxMessage {
    117     pub outbox_id: String,
    118     pub chat_item_id: String,
    119     pub connection_id: String,
    120     pub conversation_id: Option<String>,
    121     pub chat_msg_id: String,
    122     pub body: String,
    123     pub status: String,
    124     pub runtime_message_id: Option<i64>,
    125     pub retry_after_unix: Option<i64>,
    126     pub created_at_unix: i64,
    127 }
    128 
    129 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
    130 pub struct RadrootsSimplexAppOutboundTextRequest {
    131     pub connection_id: String,
    132     pub conversation_id: String,
    133     pub body: String,
    134     pub created_at_unix: i64,
    135 }
    136 
    137 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
    138 pub struct RadrootsSimplexAppOutboundTextDraft {
    139     pub chat_item: RadrootsSimplexAppChatItem,
    140     pub outbox_message: RadrootsSimplexAppOutboxMessage,
    141 }
    142 
    143 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
    144 pub struct RadrootsSimplexAppInboundTextRequest {
    145     pub connection_id: String,
    146     pub conversation_id: String,
    147     pub broker_message_id_hash: Vec<u8>,
    148     pub inbound_sequence: Option<i64>,
    149     pub message_hash: Vec<u8>,
    150     pub runtime_ack_handle: String,
    151     pub child_ordinal: u32,
    152     pub chat_msg_id: Option<String>,
    153     pub body: String,
    154     pub received_at_unix: i64,
    155 }
    156 
    157 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
    158 pub struct RadrootsSimplexAppInboundUnsupportedEventRequest {
    159     pub connection_id: String,
    160     pub broker_message_id_hash: Vec<u8>,
    161     pub inbound_sequence: Option<i64>,
    162     pub message_hash: Vec<u8>,
    163     pub runtime_ack_handle: String,
    164     pub child_ordinal: u32,
    165     pub event_kind: String,
    166     pub payload_json: String,
    167     pub received_at_unix: i64,
    168 }
    169 
    170 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
    171 pub struct RadrootsSimplexAppInboundCommit {
    172     pub inbound: RadrootsSimplexAppInboundMessageLogEntry,
    173     pub child_event: RadrootsSimplexAppInboundChildEvent,
    174     pub chat_item: Option<RadrootsSimplexAppChatItem>,
    175     pub unsupported_event: Option<RadrootsSimplexAppUnsupportedProtocolEvent>,
    176     pub duplicate: bool,
    177 }
    178 
    179 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
    180 pub struct RadrootsSimplexAppUnsupportedProtocolEvent {
    181     pub event_id: String,
    182     pub connection_id: Option<String>,
    183     pub event_kind: String,
    184     pub payload_json: String,
    185     pub status: String,
    186     pub received_at_unix: i64,
    187 }
    188 
    189 #[derive(Debug, Clone, PartialEq, Eq)]
    190 pub struct RadrootsSimplexAppDiagnostics {
    191     pub encrypted: bool,
    192     pub cipher: String,
    193     pub schema_version: u32,
    194     pub migration_count: usize,
    195     pub foreign_keys_enabled: bool,
    196     pub wal_enabled: bool,
    197     pub key_source: String,
    198     pub key_slot_digest: String,
    199 }