More methods and an enum

This commit is contained in:
2024-06-25 23:26:29 -04:00
Unverified
parent d69c9e2316
commit bf3162c590

View File

@@ -1,16 +1,32 @@
use surrealdb::sql::Thing;
use tarpc::serde::{Deserialize, Serialize}; use tarpc::serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize)]
pub struct Record {
id: Thing,
}
#[tarpc::service] #[tarpc::service]
pub trait RealmChat { pub trait RealmChat {
async fn test(name: String) -> String; 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<Message, ErrorCode>;
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<Message, ErrorCode>; async fn get_message_from_guid(guid: String) -> Result<Message, ErrorCode>;
async fn get_messages_since(time: u64) -> Result<Vec<Message>, ErrorCode>;
async fn get_rooms() -> Result<Vec<Room>, ErrorCode>; async fn get_rooms() -> Result<Vec<Room>, ErrorCode>;
async fn get_room(roomid: String) -> Result<Room, ErrorCode>; async fn get_room(roomid: String) -> Result<Room, ErrorCode>;
async fn get_user(userid: String) -> Result<User, ErrorCode>; async fn get_user(userid: String) -> Result<User, ErrorCode>;
async fn get_joined_users() -> Result<Vec<User>, ErrorCode>; async fn get_joined_users() -> Result<Vec<User>, ErrorCode>;
async fn get_online_users() -> Result<Vec<User>, ErrorCode>; async fn get_online_users() -> Result<Vec<User>, ErrorCode>;
//TODO: Admin access only!
// async fn create_room() -> Result<Room, ErrorCode>;
} }
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
@@ -27,28 +43,61 @@ pub struct Message {
pub timestamp: u64, pub timestamp: u64,
pub user: User, pub user: User,
pub room: Room, pub room: Room,
pub text: Option<String>, pub data: MessageData,
pub attachments: Option<Vec<Attachment>>, }
pub reply_to_guid: Option<String>,
pub reaction_emoji: Option<String>, //TODO: Maybe have multipart messages
pub redact: bool, #[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)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct User { pub struct User {
pub userid: String, pub userid: String,
pub name: String, pub name: String,
pub online: bool,
//TODO //TODO
} }
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Room { pub struct Room {
pub roomid: String, pub roomid: String,
pub name: String,
//TODO //TODO
} }
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Attachment {
pub guid: String,
//TODO
}