From 3109ac4c2291df9fdba1df56f225030864039d4e Mon Sep 17 00:00:00 2001 From: MDietermann Date: Wed, 12 Aug 2026 17:21:44 +0200 Subject: [PATCH] feat: add message Tauri commands --- src-tauri/src/commands/message.rs | 49 +++++++++++++++++++++++++++++++ src-tauri/src/commands/mod.rs | 1 + src-tauri/src/lib.rs | 2 ++ 3 files changed, 52 insertions(+) create mode 100644 src-tauri/src/commands/message.rs diff --git a/src-tauri/src/commands/message.rs b/src-tauri/src/commands/message.rs new file mode 100644 index 0000000..abe54c6 --- /dev/null +++ b/src-tauri/src/commands/message.rs @@ -0,0 +1,49 @@ +use crate::models::Message; +use crate::state::{AppState, BASE_URL}; + +#[tauri::command] +pub async fn list_messages( + state: tauri::State<'_, AppState>, + conversation_id: String, +) -> Result, String> { + state + .client + .get(format!("{}/conversations/{}/messages", BASE_URL, conversation_id)) + .send() + .await + .map_err(|e| e.to_string())? + .json() + .await + .map_err(|e| e.to_string()) +} + +#[tauri::command] +pub async fn send_message( + state: tauri::State<'_, AppState>, + conversation_id: String, + content: String, +) -> Result { + let user_id = state + .user_id + .lock() + .unwrap() + .clone() + .ok_or_else(|| "Not logged in".to_string())?; + + let body = serde_json::json!({ + "conversation_id": conversation_id, + "user_id": user_id, + "content": content, + }); + + state + .client + .post(format!("{}/messages", BASE_URL)) + .json(&body) + .send() + .await + .map_err(|e| e.to_string())? + .json() + .await + .map_err(|e| e.to_string()) +} diff --git a/src-tauri/src/commands/mod.rs b/src-tauri/src/commands/mod.rs index 4856d1a..f9226bd 100644 --- a/src-tauri/src/commands/mod.rs +++ b/src-tauri/src/commands/mod.rs @@ -1,3 +1,4 @@ pub mod conversation; +pub mod message; pub mod user; pub mod workspace; diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index bbee861..a93c6e3 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -12,6 +12,8 @@ pub fn run() { commands::user::login, commands::workspace::list_workspaces, commands::conversation::list_conversations, + commands::message::list_messages, + commands::message::send_message, ]) .run(tauri::generate_context!()) .expect("error while running tauri application");