p2p_chat/ui/runner/actions/commands/
info.rs

1//! This module contains command handlers for displaying application information and help.
2use anyhow::Result;
3use base64::prelude::BASE64_STANDARD;
4use base64::Engine;
5
6use super::super::context::CommandContext;
7
8/// Displays the user's identity information.
9///
10/// This includes the Peer ID and the E2E public key.
11///
12/// # Arguments
13///
14/// * `context` - The `CommandContext` providing access to the user's identity.
15pub async fn show_info(context: &CommandContext) -> Result<()> {
16    let output = format!(
17        "Your Identity:\n  Peer ID: {}\n  E2E Public Key: {}",
18        context.node().identity.peer_id,
19        BASE64_STANDARD.encode(context.node().identity.hpke_public_key())
20    );
21    context.emit_chat(output);
22    Ok(())
23}
24
25/// Displays a message about mailbox discovery status.
26///
27/// # Arguments
28///
29/// * `context` - The `CommandContext` for emitting chat messages.
30pub async fn show_check_message(context: &CommandContext) -> Result<()> {
31    context.emit_chat("✅ Mailbox discovery runs automatically every few seconds.");
32    Ok(())
33}
34
35/// Displays available commands and their usage.
36///
37/// # Arguments
38///
39/// * `context` - The `CommandContext` for emitting chat messages.
40pub async fn show_help(context: &CommandContext) -> Result<()> {
41    let help_text = "Available commands:\n  friend <peer_id> <e2e_key> [nickname] - Add a friend and optionally assign a nickname\n  friends                     - List all friends\n  send <peer_id_or_nickname> <message>    - Send a message\n  history <peer_id_or_nickname> [count] - Show message history (default: 20, max: 1000)\n  peers                       - Show connected peers\n  info                        - Show your identity\n  check                       - Check for new messages in mailboxes\n  help                        - Show this help\n  exit                        - Exit the application";
42    context.emit_chat(help_text);
43    Ok(())
44}