feat: implement chat-cli /members to list group members (#209)

This commit is contained in:
Mojtaba Chenani
2026-08-19 16:06:06 +02:00
committed by GitHub
parent ee2572a141
commit 74265e6ed7
2 changed files with 34 additions and 1 deletions
+3 -1
View File
@@ -70,7 +70,8 @@ and copies it to the clipboard.
required; addresses can follow (e.g. Pax's) to invite people at creation.
2. Saro types `/add <raya's address>` to invite Raya; the invite stays pending
until the group commits it.
3. Once the invite commits, everyone can chat.
3. `/members` lists the roster — Raya shows `(pending)` until the commit lands,
then appears without it. Once committed, both can chat.
### Optional: KeyPackage registry
@@ -115,6 +116,7 @@ The registry is a throwaway testnet helper; v0.3 replaces it with a
| `/dm <address>` | Start a direct (1:1) chat |
| `/new <name> [address...]` | Create a named group chat (optionally inviting members) |
| `/add <address>` | Add someone to the active group |
| `/members` | List members of the active conversation |
| `/chats` | List all established chats |
| `/switch <user>` | Switch active chat |
| `/delete <user>` | Delete a chat session |
+31
View File
@@ -325,6 +325,7 @@ where
self.add_system_message("/dm <address> - Start a direct (1:1) chat");
self.add_system_message("/new <name> [address...] - Create a group chat");
self.add_system_message("/add <address> - Add someone to the active group");
self.add_system_message("/members - List members of the active conversation");
self.add_system_message("/nickname <name> - Name the active chat");
self.add_system_message("/chats - List all chats");
self.add_system_message("/switch <name|id> - Switch active chat");
@@ -436,6 +437,36 @@ where
self.status = "Invite pending — the group will commit it shortly.".to_string();
Ok(Some("Invite pending".to_string()))
}
"/members" => {
let chat_id = self
.state
.active_chat
.clone()
.ok_or_else(|| anyhow::anyhow!("No active conversation."))?;
let members = self
.client
.group_members(&chat_id)
.map_err(|e| anyhow::anyhow!("{e:?}"))?;
let my_addr = self.client.addr().to_string();
self.add_system_message(&format!("── Members ({}) ──", members.len()));
for m in &members {
let id = m
.account
.as_ref()
.map(|a| a.as_str())
.unwrap_or_else(|| m.local_identity.as_str());
let short = &id[..16.min(id.len())];
let mut tags = String::new();
if m.account.as_ref().map(|a| a.as_str()) == Some(my_addr.as_str()) {
tags.push_str(" (you)");
}
if m.pending {
tags.push_str(" (pending)");
}
self.add_system_message(&format!("{short}{tags}"));
}
Ok(Some(format!("{} member(s)", members.len())))
}
"/nickname" => {
if args.is_empty() {
return Ok(Some("Usage: /nickname <name>".to_string()));