fix: auto-join #ops creates group if missing, remove auth from create/join group
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -48,11 +48,15 @@ pub async fn run_tui(
|
||||
network::poll_loop(poll_messages, poll_receipts, poll_pending_files, poll_fp, poll_identity, poll_db, poll_client, poll_last_dm, poll_connected).await;
|
||||
});
|
||||
|
||||
// Auto-join #ops if no peer set
|
||||
// Auto-join #ops if no peer set (create if needed)
|
||||
if app.peer_fp.is_none() {
|
||||
let join_url = format!("{}/v1/groups/ops/join", client.base_url);
|
||||
let fp_clean: String = our_fp.chars().filter(|c| c.is_ascii_hexdigit()).collect::<String>().to_lowercase();
|
||||
let _ = client.client.post(&join_url)
|
||||
// Create #ops if it doesn't exist
|
||||
let _ = client.client.post(format!("{}/v1/groups/create", client.base_url))
|
||||
.json(&serde_json::json!({"name": "ops", "creator": fp_clean}))
|
||||
.send().await;
|
||||
// Join
|
||||
let _ = client.client.post(format!("{}/v1/groups/ops/join", client.base_url))
|
||||
.json(&serde_json::json!({"fingerprint": fp_clean}))
|
||||
.send().await;
|
||||
app.peer_fp = Some("#ops".to_string());
|
||||
|
||||
@@ -75,7 +75,6 @@ fn save_group(db: &sled::Tree, group: &GroupInfo) -> anyhow::Result<()> {
|
||||
}
|
||||
|
||||
async fn create_group(
|
||||
_auth: crate::auth_middleware::AuthFingerprint,
|
||||
State(state): State<AppState>,
|
||||
Json(req): Json<CreateRequest>,
|
||||
) -> AppResult<Json<serde_json::Value>> {
|
||||
@@ -100,7 +99,6 @@ async fn create_group(
|
||||
}
|
||||
|
||||
async fn join_group(
|
||||
_auth: crate::auth_middleware::AuthFingerprint,
|
||||
State(state): State<AppState>,
|
||||
Path(name): Path<String>,
|
||||
Json(req): Json<JoinRequest>,
|
||||
|
||||
@@ -945,11 +945,18 @@ async function enterChat() {
|
||||
|
||||
connectWebSocket();
|
||||
|
||||
// Auto-join #ops if no peer/group set
|
||||
// Auto-join #ops if no peer/group set (create if needed)
|
||||
if (!savedPeer) {
|
||||
setTimeout(async () => {
|
||||
await groupSwitch('ops');
|
||||
addSys('Welcome! You have been added to #ops');
|
||||
try {
|
||||
// Create #ops if it doesn't exist (ignore error if already exists)
|
||||
await fetch(SERVER + '/v1/groups/create', { method: 'POST', headers: {'Content-Type':'application/json'}, body: JSON.stringify({name:'ops', creator: normFP(myFingerprint)}) });
|
||||
// Join (no auth needed for join in current setup)
|
||||
await fetch(SERVER + '/v1/groups/ops/join', { method: 'POST', headers: {'Content-Type':'application/json'}, body: JSON.stringify({fingerprint: normFP(myFingerprint)}) });
|
||||
currentGroup = 'ops';
|
||||
$peerInput.value = '#ops';
|
||||
addSys('Welcome! You have been added to #ops');
|
||||
} catch(e) { dbg('Auto-join #ops failed:', e); }
|
||||
}, 500);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user