From bf3162c5902e9e1517c395aa909c1c4cd7656de0 Mon Sep 17 00:00:00 2001 From: Joshua Higgins Date: Tue, 25 Jun 2024 23:26:29 -0400 Subject: [PATCH] More methods and an enum --- server/src/types.rs | 71 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 60 insertions(+), 11 deletions(-) diff --git a/server/src/types.rs b/server/src/types.rs index 3ae4d42..a197024 100644 --- a/server/src/types.rs +++ b/server/src/types.rs @@ -1,16 +1,32 @@ +use surrealdb::sql::Thing; use tarpc::serde::{Deserialize, Serialize}; +#[derive(Debug, Deserialize)] +pub struct Record { + id: Thing, +} + #[tarpc::service] pub trait RealmChat { async fn test(name: String) -> String; - async fn send_message(message: Message) -> ErrorCode; + + //TODO: Any user authorized as themselves + async fn send_message(message: Message) -> Result; + async fn start_typing() -> ErrorCode; + async fn stop_typing() -> ErrorCode; + async fn keep_typing() -> ErrorCode; //NOTE: If a keep alive hasn't been received in 5 seconds, stop typing + //NOTE: Any user can call, if they are in the server async fn get_message_from_guid(guid: String) -> Result; + async fn get_messages_since(time: u64) -> Result, ErrorCode>; async fn get_rooms() -> Result, ErrorCode>; async fn get_room(roomid: String) -> Result; async fn get_user(userid: String) -> Result; async fn get_joined_users() -> Result, ErrorCode>; async fn get_online_users() -> Result, ErrorCode>; + + //TODO: Admin access only! + // async fn create_room() -> Result; } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -27,28 +43,61 @@ pub struct Message { pub timestamp: u64, pub user: User, pub room: Room, - pub text: Option, - pub attachments: Option>, - pub reply_to_guid: Option, - pub reaction_emoji: Option, - pub redact: bool, + pub data: MessageData, +} + +//TODO: Maybe have multipart messages +#[derive(Debug, Clone, Serialize, Deserialize)] +pub enum MessageData { + Text(String), + Attachment(Attachment), + Reply(Reply), + Edit(Edit), //NOTE: Have to be the owner of the referencing_guid + Reaction(Reaction), + Redaction(Redaction), + TypingIndicator(bool), //isTyping +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Attachment { + //TODO +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Reply { + pub referencing_guid: String, + pub text: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Edit { + pub referencing_guid: String, + pub text: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Reaction { + pub referencing_guid: String, + pub emoji: String +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Redaction { + pub referencing_guid: String, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct User { pub userid: String, pub name: String, + pub online: bool, //TODO } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Room { pub roomid: String, + pub name: String, //TODO } -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct Attachment { - pub guid: String, - //TODO -} \ No newline at end of file