From 57d9841cfbc8c85da3e048b326b52eaf16855b42 Mon Sep 17 00:00:00 2001 From: qdust41 Date: Fri, 17 Apr 2026 04:59:19 -0400 Subject: [PATCH] usernames now work on the frontend and display the correct username --- src-tauri/src/commands/chat.rs | 13 +++++++------ surreal/schema.surql | 19 ++++++++++--------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src-tauri/src/commands/chat.rs b/src-tauri/src/commands/chat.rs index 1a240d6..3256c5c 100644 --- a/src-tauri/src/commands/chat.rs +++ b/src-tauri/src/commands/chat.rs @@ -58,10 +58,11 @@ pub async fn send_message( .db .query( "CREATE message SET - room = type::record('room', $room_id), - author = $auth, - body = $body, - created = time::now()", + room = type::record('room', $room_id), + author = $auth, + author_username = $auth.username, + body = $body, + created = time::now()", ) .bind(("room_id", room_id)) .bind(("body", body)) @@ -81,7 +82,7 @@ pub async fn get_messages( ) -> Result, String> { let result: Vec = state .db - .query("SELECT *, author.username AS author_username FROM message WHERE room = type::record('room', $room_id) ORDER BY created ASC") + .query("SELECT * FROM message WHERE room = type::record('room', $room_id) ORDER BY created ASC") .bind(("room_id", room_id)) .await .map_err(into_err)? @@ -121,7 +122,7 @@ pub async fn subscribe_room( let db = state.db.clone(); let mut stream = db - .query("LIVE SELECT *, author.username AS author_username FROM message WHERE room = type::record('room', $room_id)") + .query("LIVE SELECT * FROM message WHERE room = type::record('room', $room_id)") .bind(("room_id", room_id)) .await .map_err(into_err)? diff --git a/surreal/schema.surql b/surreal/schema.surql index f8164e5..1bce90f 100644 --- a/surreal/schema.surql +++ b/surreal/schema.surql @@ -20,11 +20,11 @@ DEFINE TABLE user SCHEMAFULL FOR update WHERE id = $auth FOR create NONE FOR delete NONE; -DEFINE FIELD username ON user TYPE string; -DEFINE FIELD email ON user TYPE string; -DEFINE FIELD password ON user TYPE string; -DEFINE FIELD avatar ON user TYPE option; -DEFINE FIELD created ON user TYPE datetime DEFAULT time::now(); +DEFINE FIELD username ON user TYPE string; +DEFINE FIELD email ON user TYPE string; +DEFINE FIELD password ON user TYPE string; +DEFINE FIELD avatar ON user TYPE option; +DEFINE FIELD created ON user TYPE datetime DEFAULT time::now(); DEFINE INDEX email_idx ON user FIELDS email UNIQUE; DEFINE TABLE room SCHEMAFULL @@ -40,10 +40,11 @@ DEFINE TABLE message SCHEMAFULL FOR create WHERE author = $auth FOR update WHERE author = $auth FOR delete WHERE author = $auth; -DEFINE FIELD room ON message TYPE record; -DEFINE FIELD author ON message TYPE record; -DEFINE FIELD body ON message TYPE string; -DEFINE FIELD created ON message TYPE datetime DEFAULT time::now(); +DEFINE FIELD room ON message TYPE record; +DEFINE FIELD author ON message TYPE record; +DEFINE FIELD author_username ON message TYPE option; +DEFINE FIELD body ON message TYPE string; +DEFINE FIELD created ON message TYPE datetime DEFAULT time::now(); DEFINE TABLE contact SCHEMAFULL PERMISSIONS