Launcher: BlueMap view with player side panel, map actions, guild invitations
This commit is contained in:
10 files changed
+342
-7
No files matched your search
@@ -1190,3 +1190,51 @@ pub async fn like_user_post(state: State<'_, AppState>, post_id: i64) -> Res<boo
|
||||
let body: serde_json::Value = resp.json().await.map_err(err)?;
|
||||
Ok(body["liked"].as_bool().unwrap_or(false))
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Map actions and guild invitations
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
async fn ok_or_panel_error(resp: reqwest::Response, fallback: &str) -> Res<serde_json::Value> {
|
||||
if resp.status().is_success() {
|
||||
return Ok(resp.json().await.unwrap_or(serde_json::Value::Null));
|
||||
}
|
||||
let body: serde_json::Value = resp.json().await.unwrap_or_default();
|
||||
Err(body["error"].as_str().or(body["message"].as_str()).unwrap_or(fallback).to_string())
|
||||
}
|
||||
|
||||
/// From the map: ask a player to teleport to, or send them a message in game.
|
||||
#[tauri::command]
|
||||
pub async fn map_action(state: State<'_, AppState>, server_id: i64, action: String, target_uuid: String, text: Option<String>) -> Res<()> {
|
||||
let req = account_api(&state, reqwest::Method::POST, &format!("/servers/{server_id}/map/actions")).await?;
|
||||
let resp = req
|
||||
.json(&serde_json::json!({ "action": action, "target_uuid": target_uuid, "text": text.unwrap_or_default() }))
|
||||
.send()
|
||||
.await
|
||||
.map_err(err)?;
|
||||
ok_or_panel_error(resp, "unable to do that right now").await.map(|_| ())
|
||||
}
|
||||
|
||||
/// Invite a player to a guild you lead or officiate.
|
||||
#[tauri::command]
|
||||
pub async fn guild_send_invite(state: State<'_, AppState>, guild_id: String, target_uuid: String) -> Res<serde_json::Value> {
|
||||
let req = account_api(&state, reqwest::Method::POST, &format!("/guilds/{guild_id}/invites")).await?;
|
||||
let resp = req.json(&serde_json::json!({ "uuid": target_uuid })).send().await.map_err(err)?;
|
||||
ok_or_panel_error(resp, "unable to send the invitation").await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn my_guild_invites(state: State<'_, AppState>) -> Res<serde_json::Value> {
|
||||
let req = account_api(&state, reqwest::Method::GET, "/guilds/invites").await?;
|
||||
let resp = req.send().await.map_err(err)?;
|
||||
ok_or_panel_error(resp, "unable to load invitations").await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn respond_guild_invite(state: State<'_, AppState>, invite_id: i64, accept: bool) -> Res<serde_json::Value> {
|
||||
let path = format!("/guilds/invites/{invite_id}/{}", if accept { "accept" } else { "decline" });
|
||||
let req = account_api(&state, reqwest::Method::POST, &path).await?;
|
||||
let resp = req.send().await.map_err(err)?;
|
||||
ok_or_panel_error(resp, "unable to answer the invitation").await
|
||||
}
|
||||
@@ -58,6 +58,10 @@ pub fn run() {
|
||||
commands::request_password_reset,
|
||||
commands::discord_connection,
|
||||
commands::discord_info,
|
||||
commands::map_action,
|
||||
commands::guild_send_invite,
|
||||
commands::my_guild_invites,
|
||||
commands::respond_guild_invite,
|
||||
commands::discord_link_start,
|
||||
commands::discord_unlink,
|
||||
commands::register_panel,
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
"csp": "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' https: http: data: blob:; media-src 'self' https: http: blob:; font-src 'self' data:; connect-src 'self' ipc: http://ipc.localhost"
|
||||
"csp": "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' https: http: data: blob:; media-src 'self' https: http: blob:; font-src 'self' data:; frame-src https: http:; connect-src 'self' ipc: http://ipc.localhost"
|
||||
}
|
||||
},
|
||||
"bundle": {
|
||||
|
||||
Reference in new issue
Block a user