Auto-join groups: /g and /gjoin auto-create if group doesn't exist
- Server: /join endpoint creates the group if it doesn't exist - CLI TUI: /g <name> auto-joins before switching - Web: /g <name> auto-joins before switching - No more "group not found" errors — just /g ops and go Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -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),
|
||||
|
||||
@@ -102,16 +102,25 @@ async fn join_group(
|
||||
) -> AppResult<Json<serde_json::Value>> {
|
||||
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() })))
|
||||
}
|
||||
|
||||
@@ -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; }
|
||||
|
||||
Reference in New Issue
Block a user