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; |
| 14 | mod matrix; |
14 | mod matrix; |
| 15 | mod me; |
15 | mod me; |
| 16 | mod media; |
16 | mod media; |
| |
17 | mod names; |
| 17 | mod page_up; |
18 | mod page_up; |
| 18 | mod part; |
19 | mod part; |
| 19 | mod redact; |
20 | mod redact; |
| @@ -27,6 +28,7 @@ use keys::KeysCommand; |
| 27 | use matrix::MatrixCommand; |
28 | use matrix::MatrixCommand; |
| 28 | use me::MeCommand; |
29 | use me::MeCommand; |
| 29 | use media::MediaCommand; |
30 | use media::MediaCommand; |
| |
31 | use names::NamesCommand; |
| 30 | use page_up::PageUpCommand; |
32 | use page_up::PageUpCommand; |
| 31 | use part::PartCommand; |
33 | use part::PartCommand; |
| 32 | use redact::RedactCommand; |
34 | use redact::RedactCommand; |
| @@ -44,6 +46,7 @@ pub struct Commands { |
| 44 | _me: CommandRun, |
46 | _me: CommandRun, |
| 45 | _upload: CommandRun, |
47 | _upload: CommandRun, |
| 46 | _part: CommandRun, |
48 | _part: CommandRun, |
| |
49 | _names: CommandRun, |
| 47 | } |
50 | } |
| 48 | |
51 | |
| 49 | impl Commands { |
52 | impl Commands { |
| @@ -63,6 +66,7 @@ impl Commands { |
| 63 | _me: MeCommand::create(servers)?, |
66 | _me: MeCommand::create(servers)?, |
| 64 | _upload: UploadCommand::create(servers)?, |
67 | _upload: UploadCommand::create(servers)?, |
| 65 | _part: PartCommand::create(servers)?, |
68 | _part: PartCommand::create(servers)?, |
| |
69 | _names: NamesCommand::create(servers)?, |
| 66 | }) |
70 | }) |
| 67 | } |
71 | } |
| 68 | } |
72 | } |
src/commands/names.rs
added
+47
| @@ -0,0 +1,47 @@ |
| |
1 | use std::borrow::Cow; |
| |
2 | |
| |
3 | use weechat::{ |
| |
4 | buffer::Buffer, |
| |
5 | hooks::{CommandRun, CommandRunCallback}, |
| |
6 | ReturnCode, Weechat, |
| |
7 | }; |
| |
8 | |
| |
9 | use crate::Servers; |
| |
10 | |
| |
11 | pub struct NamesCommand { |
| |
12 | servers: Servers, |
| |
13 | } |
| |
14 | |
| |
15 | impl 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 | |
| |
26 | impl 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 { |
| 259 | self.last_active.insert(user_id.to_owned(), timestamp); |
259 | self.last_active.insert(user_id.to_owned(), timestamp); |
| 260 | } |
260 | } |
| 261 | |
261 | |
| |
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 | |
| 262 | fn should_smart_filter( |
272 | fn should_smart_filter( |
| 263 | &self, |
273 | &self, |
| 264 | user_id: &UserId, |
274 | user_id: &UserId, |
src/room/mod.rs
+4
| @@ -455,6 +455,10 @@ impl MatrixRoom { |
| 455 | &self.room_id |
455 | &self.room_id |
| 456 | } |
456 | } |
| 457 | |
457 | |
| |
458 | pub fn names(&self) -> Vec<String> { |
| |
459 | self.members.names() |
| |
460 | } |
| |
461 | |
| 458 | pub fn buffer_handle(&self) -> BufferHandle { |
462 | pub fn buffer_handle(&self) -> BufferHandle { |
| 459 | self.buffer.buffer_handle() |
463 | self.buffer.buffer_handle() |
| 460 | } |
464 | } |