From 5cf7e8a02f39fcae2315f31237b91700b93c44d8 Mon Sep 17 00:00:00 2001 From: Siavash Sameni Date: Thu, 26 Mar 2026 23:17:03 +0400 Subject: [PATCH] Auto-join groups: /g and /gjoin auto-create if group doesn't exist MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Server: /join endpoint creates the group if it doesn't exist - CLI TUI: /g auto-joins before switching - Web: /g auto-joins before switching - No more "group not found" errors — just /g ops and go Co-Authored-By: Claude Opus 4.6 (1M context) --- warzone/crates/warzone-client/src/tui/app.rs | 2 ++ .../crates/warzone-server/src/routes/groups.rs | 15 ++++++++++++--- warzone/crates/warzone-server/src/routes/web.rs | 2 ++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/warzone/crates/warzone-client/src/tui/app.rs b/warzone/crates/warzone-client/src/tui/app.rs index 50d1cc8..f86371e 100644 --- a/warzone/crates/warzone-client/src/tui/app.rs +++ b/warzone/crates/warzone-client/src/tui/app.rs @@ -204,6 +204,8 @@ impl App { } if text.starts_with("/g ") { let name = text[3..].trim().to_string(); + // Auto-join + self.group_join(&name, client).await; self.add_message(ChatLine { sender: "system".into(), text: format!("Switched to group #{}", name), diff --git a/warzone/crates/warzone-server/src/routes/groups.rs b/warzone/crates/warzone-server/src/routes/groups.rs index 1288ebc..03123c9 100644 --- a/warzone/crates/warzone-server/src/routes/groups.rs +++ b/warzone/crates/warzone-server/src/routes/groups.rs @@ -102,16 +102,25 @@ async fn join_group( ) -> AppResult> { let fp = normalize_fp(&req.fingerprint); + // Auto-create if group doesn't exist let mut group = match load_group(&state.db.groups, &name) { Some(g) => g, - None => return Ok(Json(serde_json::json!({ "error": "group not found" }))), + None => { + let g = GroupInfo { + name: name.clone(), + creator: fp.clone(), + members: vec![], + }; + tracing::info!("Group '{}' auto-created by {}", name, fp); + g + } }; if !group.members.contains(&fp) { group.members.push(fp.clone()); - save_group(&state.db.groups, &group)?; - tracing::info!("{} joined group '{}'", fp, name); + tracing::info!("{} joined group '{}' ({} members)", fp, name, group.members.len()); } + save_group(&state.db.groups, &group)?; Ok(Json(serde_json::json!({ "ok": true, "members": group.members.len() }))) } diff --git a/warzone/crates/warzone-server/src/routes/web.rs b/warzone/crates/warzone-server/src/routes/web.rs index 3c0ffbf..fda177a 100644 --- a/warzone/crates/warzone-server/src/routes/web.rs +++ b/warzone/crates/warzone-server/src/routes/web.rs @@ -413,6 +413,8 @@ async function groupJoin(name) { } async function groupSwitch(name) { + // Auto-join + await groupJoin(name); const resp = await fetch(SERVER + '/v1/groups/' + name); const data = await resp.json(); if (data.error) { addSys('Error: ' + data.error); return; }