Commit 9377b55ad6

9377b55ad62be7d02e66befc1531ee8657f47db0

parent: 82ea03837d

Unsigned

Darafei Praliaskouski <me@komzpa.net> · 2026-06-30 13:02 UTC
committer: <strk@kbt.io>

feat: add Matrix names command

Layout: unified · split

src/commands/mod.rs +4
@@ -14,6 +14,7 @@ mod keys;
1414mod matrix;
1515mod me;
1616mod media;
17mod names;
1718mod page_up;
1819mod part;
1920mod redact;
@@ -27,6 +28,7 @@ use keys::KeysCommand;
2728use matrix::MatrixCommand;
2829use me::MeCommand;
2930use media::MediaCommand;
31use names::NamesCommand;
3032use page_up::PageUpCommand;
3133use part::PartCommand;
3234use redact::RedactCommand;
@@ -44,6 +46,7 @@ pub struct Commands {
4446 _me: CommandRun,
4547 _upload: CommandRun,
4648 _part: CommandRun,
49 _names: CommandRun,
4750}
4851
4952impl Commands {
@@ -63,6 +66,7 @@ impl Commands {
6366 _me: MeCommand::create(servers)?,
6467 _upload: UploadCommand::create(servers)?,
6568 _part: PartCommand::create(servers)?,
69 _names: NamesCommand::create(servers)?,
6670 })
6771 }
6872}
src/commands/names.rs added +47
@@ -0,0 +1,47 @@
1use std::borrow::Cow;
2
3use weechat::{
4 buffer::Buffer,
5 hooks::{CommandRun, CommandRunCallback},
6 ReturnCode, Weechat,
7};
8
9use crate::Servers;
10
11pub struct NamesCommand {
12 servers: Servers,
13}
14
15impl NamesCommand {
16 pub fn create(servers: &Servers) -> Result<CommandRun, ()> {
17 CommandRun::new(
18 "2000|/names",
19 NamesCommand {
20 servers: servers.clone(),
21 },
22 )
23 }
24}
25
26impl CommandRunCallback for NamesCommand {
27 fn callback(
28 &mut self,
29 _: &Weechat,
30 buffer: &Buffer,
31 _: Cow<str>,
32 ) -> ReturnCode {
33 if let Some(room) = self.servers.find_room(buffer) {
34 let names = room.names();
35 let message = if names.is_empty() {
36 "No Matrix room members are known yet.".to_owned()
37 } else {
38 format!("Matrix room members: {}", names.join(", "))
39 };
40
41 buffer.print(&message);
42 ReturnCode::OkEat
43 } else {
44 ReturnCode::Ok
45 }
46 }
47}
src/room/members.rs +10
@@ -259,6 +259,16 @@ impl Members {
259259 self.last_active.insert(user_id.to_owned(), timestamp);
260260 }
261261
262 pub fn names(&self) -> Vec<String> {
263 let mut names: Vec<_> = self
264 .nicks
265 .iter()
266 .map(|entry| entry.value().clone())
267 .collect();
268 names.sort_unstable();
269 names
270 }
271
262272 fn should_smart_filter(
263273 &self,
264274 user_id: &UserId,
src/room/mod.rs +4
@@ -455,6 +455,10 @@ impl MatrixRoom {
455455 &self.room_id
456456 }
457457
458 pub fn names(&self) -> Vec<String> {
459 self.members.names()
460 }
461
458462 pub fn buffer_handle(&self) -> BufferHandle {
459463 self.buffer.buffer_handle()
460464 }