usernames now work on the frontend and display the correct username
Some checks failed
Release / release (ubuntu-22.04) (push) Has been cancelled
Release / release (windows-latest) (push) Has been cancelled

This commit is contained in:
2026-04-17 04:59:19 -04:00
parent c3c31dea47
commit 57d9841cfb
2 changed files with 17 additions and 15 deletions

View File

@@ -60,6 +60,7 @@ pub async fn send_message(
"CREATE message SET "CREATE message SET
room = type::record('room', $room_id), room = type::record('room', $room_id),
author = $auth, author = $auth,
author_username = $auth.username,
body = $body, body = $body,
created = time::now()", created = time::now()",
) )
@@ -81,7 +82,7 @@ pub async fn get_messages(
) -> Result<Vec<Message>, String> { ) -> Result<Vec<Message>, String> {
let result: Vec<Message> = state let result: Vec<Message> = state
.db .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)) .bind(("room_id", room_id))
.await .await
.map_err(into_err)? .map_err(into_err)?
@@ -121,7 +122,7 @@ pub async fn subscribe_room(
let db = state.db.clone(); let db = state.db.clone();
let mut stream = db 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)) .bind(("room_id", room_id))
.await .await
.map_err(into_err)? .map_err(into_err)?

View File

@@ -42,6 +42,7 @@ DEFINE TABLE message SCHEMAFULL
FOR delete WHERE author = $auth; FOR delete WHERE author = $auth;
DEFINE FIELD room ON message TYPE record<room>; DEFINE FIELD room ON message TYPE record<room>;
DEFINE FIELD author ON message TYPE record<user>; DEFINE FIELD author ON message TYPE record<user>;
DEFINE FIELD author_username ON message TYPE option<string>;
DEFINE FIELD body ON message TYPE string; DEFINE FIELD body ON message TYPE string;
DEFINE FIELD created ON message TYPE datetime DEFAULT time::now(); DEFINE FIELD created ON message TYPE datetime DEFAULT time::now();