v0.0.37: TUI call state UI, missed calls, inline keyboards in web

FC-P2-T4: TUI call state machine
- CallInfo struct + CallPhase enum (Calling/Ringing/Active)
- Header shows call indicator: yellow "Calling...", magenta "Incoming", green timer
- /call sets Calling, /accept sets Active, /reject+/hangup clears
- Incoming signals show contextual messages (Offer→prompt, Answer→connected, etc.)

FC-P2-T5: Missed call display in TUI
- WS Text frames parsed for missed_call + bot_message JSON
- Missed calls: "📞 Missed call from X at HH:MM" + terminal bell
- Bot messages rendered as @botname: text

FC-P8-T5: Inline keyboard buttons in web
- CSS styled keyboard buttons (.kbd-btn)
- Bot messages with reply_markup render clickable button rows
- Click sends callback_data back to bot as bot_message
- Works in both WS text handler and handleIncomingMessage fallback

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Siavash Sameni
2026-03-29 16:44:14 +04:00
parent 3429f518b1
commit a368ab24d2
8 changed files with 288 additions and 38 deletions

View File

@@ -496,14 +496,75 @@ fn process_wire_message(
payload: _,
target: _,
} => {
let type_str = format!("{:?}", signal_type);
messages.lock().unwrap().push(ChatLine {
sender: { cache_eth_lookup(&sender_fingerprint, client, eth_cache); display_sender(&sender_fingerprint, eth_cache) },
text: format!("\u{1f4de} Call signal: {}", type_str),
is_system: false,
is_self: false,
message_id: None, timestamp: Local::now(),
});
use warzone_protocol::message::CallSignalType;
let sender_short = { cache_eth_lookup(&sender_fingerprint, client, eth_cache); display_sender(&sender_fingerprint, eth_cache) };
match signal_type {
CallSignalType::Offer => {
messages.lock().unwrap().push(ChatLine {
sender: "system".into(),
text: format!("\u{1f4de} Incoming call from {} \u{2014} /accept or /reject", sender_short),
is_system: true,
is_self: false,
message_id: None, timestamp: Local::now(),
});
// Terminal bell for incoming call
print!("\x07");
}
CallSignalType::Answer => {
messages.lock().unwrap().push(ChatLine {
sender: "system".into(),
text: format!("\u{2713} {} accepted the call", sender_short),
is_system: true,
is_self: false,
message_id: None, timestamp: Local::now(),
});
}
CallSignalType::Hangup => {
messages.lock().unwrap().push(ChatLine {
sender: "system".into(),
text: "Call ended".into(),
is_system: true,
is_self: false,
message_id: None, timestamp: Local::now(),
});
}
CallSignalType::Reject => {
messages.lock().unwrap().push(ChatLine {
sender: "system".into(),
text: format!("{} rejected the call", sender_short),
is_system: true,
is_self: false,
message_id: None, timestamp: Local::now(),
});
}
CallSignalType::Ringing => {
messages.lock().unwrap().push(ChatLine {
sender: "system".into(),
text: "Ringing...".into(),
is_system: true,
is_self: false,
message_id: None, timestamp: Local::now(),
});
}
CallSignalType::Busy => {
messages.lock().unwrap().push(ChatLine {
sender: "system".into(),
text: format!("{} is busy", sender_short),
is_system: true,
is_self: false,
message_id: None, timestamp: Local::now(),
});
}
_ => {
messages.lock().unwrap().push(ChatLine {
sender: sender_short,
text: format!("\u{1f4de} Call signal: {:?}", signal_type),
is_system: false,
is_self: false,
message_id: None, timestamp: Local::now(),
});
}
}
}
}
}
@@ -545,8 +606,44 @@ pub async fn poll_loop(
let (_, mut read) = ws_stream.split();
while let Some(Ok(msg)) = read.next().await {
if let tokio_tungstenite::tungstenite::Message::Binary(data) = msg {
process_incoming(&data, &identity, &db, &messages, &receipts, &pending_files, &our_fp, &client, &eth_cache, &last_dm_peer);
match msg {
tokio_tungstenite::tungstenite::Message::Binary(data) => {
process_incoming(&data, &identity, &db, &messages, &receipts, &pending_files, &our_fp, &client, &eth_cache, &last_dm_peer);
}
tokio_tungstenite::tungstenite::Message::Text(text) => {
if let Ok(json) = serde_json::from_str::<serde_json::Value>(&text) {
if json.get("type").and_then(|v| v.as_str()) == Some("missed_call") {
let data = json.get("data").cloned().unwrap_or_default();
let caller = data.get("caller_fp").and_then(|v| v.as_str()).unwrap_or("unknown");
let ts = data.get("timestamp").and_then(|v| v.as_i64()).unwrap_or(0);
let when = chrono::DateTime::from_timestamp(ts, 0)
.map(|dt| dt.with_timezone(&Local).format("%H:%M").to_string())
.unwrap_or_else(|| "?".to_string());
messages.lock().unwrap().push(ChatLine {
sender: "system".into(),
text: format!("\u{1f4de} Missed call from {} at {}", &caller[..caller.len().min(12)], when),
is_system: true,
is_self: false,
message_id: None,
timestamp: Local::now(),
});
print!("\x07");
} else if json.get("type").and_then(|v| v.as_str()) == Some("bot_message") {
let from = json.get("from_name").or(json.get("from")).and_then(|v| v.as_str()).unwrap_or("bot");
let text_content = json.get("text").and_then(|v| v.as_str()).unwrap_or("");
messages.lock().unwrap().push(ChatLine {
sender: format!("@{}", from),
text: text_content.to_string(),
is_system: false,
is_self: false,
message_id: None,
timestamp: Local::now(),
});
print!("\x07");
}
}
}
_ => {}
}
}