Commit 7183c3cd50

7183c3cd5042e5d0586cdbb1832ce9b12b976bf7

parent: 56f61c8ae6

Unsigned

Darafei Praliaskouski <me@komzpa.net> · 2026-06-23 16:39 UTC
committer: <strk@kbt.io>

feat: configure nick prefix colors

Layout: unified · split

README.md +8
@@ -207,6 +207,14 @@ The plugin keeps Matrix state and encryption data in
207If the cache grows or causes too much disk I/O, disconnect WeeChat and remove 207If the cache grows or causes too much disk I/O, disconnect WeeChat and remove
208only the `-cache` directory. Do not remove the main server directory unless you 208only the `-cache` directory. Do not remove the main server directory unless you
209want to reset stored Matrix state. 209want to reset stored Matrix state.
210Nick prefix colors for Matrix power levels can be changed with:
211
212 /set matrix-rust.color.nick_prefix_admin lightgreen
213 /set matrix-rust.color.nick_prefix_moderator lightmagenta
214 /set matrix-rust.color.nick_prefix_power yellow
215
216Existing nicklist entries may need a member update or plugin restart before the new colors are visible.
217
210 218
211# Helpful Commands 219# Helpful Commands
212 220
src/config.rs +24
@@ -138,6 +138,30 @@ config!(
138 }, 138 },
139 }, 139 },
140 140
141 Section color {
142 nick_prefix_admin: Color {
143 // Description.
144 "Color for the admin nick prefix (&)",
145 // Default value.
146 "lightgreen",
147 },
148
149 nick_prefix_moderator: Color {
150 // Description.
151 "Color for the moderator nick prefix (@)",
152 // Default value.
153 "lightmagenta",
154 },
155
156 nick_prefix_power: Color {
157 // Description.
158 "Color for the nick prefix (+) used by users with a non-default \
159 power level below moderator",
160 // Default value.
161 "yellow",
162 },
163 },
164
141 Section network { 165 Section network {
142 debug_buffer: bool { 166 debug_buffer: bool {
143 // Description 167 // Description
src/room/members.rs +37 −9
@@ -1,4 +1,4 @@
1use std::rc::Rc; 1use std::{cell::RefCell, rc::Rc};
2 2
3use dashmap::DashMap; 3use dashmap::DashMap;
4use tokio::runtime::Handle; 4use tokio::runtime::Handle;
@@ -24,7 +24,9 @@ use weechat::{
24 Prefix, Weechat, 24 Prefix, Weechat,
25}; 25};
26 26
27use crate::{render::render_membership, room::buffer::RoomBuffer}; 27use crate::{
28 config::Config, render::render_membership, room::buffer::RoomBuffer,
29};
28 30
29#[derive(Clone)] 31#[derive(Clone)]
30pub struct Members { 32pub struct Members {
@@ -33,6 +35,7 @@ pub struct Members {
33 ambiguity_map: Rc<DashMap<OwnedUserId, bool>>, 35 ambiguity_map: Rc<DashMap<OwnedUserId, bool>>,
34 nicks: Rc<DashMap<OwnedUserId, String>>, 36 nicks: Rc<DashMap<OwnedUserId, String>>,
35 last_active: Rc<DashMap<OwnedUserId, MilliSecondsSinceUnixEpoch>>, 37 last_active: Rc<DashMap<OwnedUserId, MilliSecondsSinceUnixEpoch>>,
38 config: Rc<RefCell<Config>>,
36 buffer: RoomBuffer, 39 buffer: RoomBuffer,
37} 40}
38 41
@@ -40,6 +43,7 @@ pub struct Members {
40pub struct WeechatRoomMember { 43pub struct WeechatRoomMember {
41 inner: RoomMember, 44 inner: RoomMember,
42 color: Rc<String>, 45 color: Rc<String>,
46 prefix_color: Rc<String>,
43 ambiguous_nick: Rc<bool>, 47 ambiguous_nick: Rc<bool>,
44} 48}
45 49
@@ -50,13 +54,19 @@ impl PartialEq for WeechatRoomMember {
50} 54}
51 55
52impl Members { 56impl Members {
53 pub fn new(room: Room, runtime: Handle, buffer: RoomBuffer) -> Self { 57 pub fn new(
58 room: Room,
59 runtime: Handle,
60 config: Rc<RefCell<Config>>,
61 buffer: RoomBuffer,
62 ) -> Self {
54 Self { 63 Self {
55 room, 64 room,
56 runtime, 65 runtime,
57 nicks: DashMap::new().into(), 66 nicks: DashMap::new().into(),
58 ambiguity_map: DashMap::new().into(), 67 ambiguity_map: DashMap::new().into(),
59 last_active: DashMap::new().into(), 68 last_active: DashMap::new().into(),
69 config,
60 buffer, 70 buffer,
61 } 71 }
62 } 72 }
@@ -222,6 +232,10 @@ impl Members {
222 .expect("Fetching the room member from the store panicked") 232 .expect("Fetching the room member from the store panicked")
223 { 233 {
224 Ok(m) => m.map(|m| WeechatRoomMember { 234 Ok(m) => m.map(|m| WeechatRoomMember {
235 prefix_color: Rc::new(Self::prefix_color_for_power_level(
236 &self.config.borrow(),
237 m.normalized_power_level(),
238 )),
225 color: Rc::new(color), 239 color: Rc::new(color),
226 ambiguous_nick: Rc::new( 240 ambiguous_nick: Rc::new(
227 self.ambiguity_map 241 self.ambiguity_map
@@ -242,6 +256,25 @@ impl Members {
242 } 256 }
243 } 257 }
244 258
259 fn prefix_color_for_power_level(
260 config: &Config,
261 power_level: UserPowerLevel,
262 ) -> String {
263 let color = config.color();
264
265 match power_level {
266 UserPowerLevel::Infinite => color.nick_prefix_admin(),
267 p if p >= Int::from(100) => color.nick_prefix_admin(),
268 p if p >= Int::from(50) => color.nick_prefix_moderator(),
269 p if p > Int::from(0) => color.nick_prefix_power(),
270 _ => "default".to_owned(),
271 }
272 }
273
274 fn room(&self) -> &Room {
275 &self.room
276 }
277
245 pub fn mark_active( 278 pub fn mark_active(
246 &self, 279 &self,
247 user_id: &UserId, 280 user_id: &UserId,
@@ -437,12 +470,7 @@ impl WeechatRoomMember {
437 } 470 }
438 471
439 fn prefix_color(&self) -> &str { 472 fn prefix_color(&self) -> &str {
440 match self.prefix() { 473 &self.prefix_color
441 "&" => "lightgreen",
442 "@" => "lightmagenta",
443 "+" => "yellow",
444 _ => "default",
445 }
446 } 474 }
447 475
448 pub fn nick_colored(&self) -> String { 476 pub fn nick_colored(&self) -> String {
src/room/mod.rs +6 −2
@@ -241,8 +241,12 @@ impl RoomHandle {
241 own_user_id: &UserId, 241 own_user_id: &UserId,
242 ) -> Self { 242 ) -> Self {
243 let buffer = RoomBuffer::new(room.clone(), runtime.clone()); 243 let buffer = RoomBuffer::new(room.clone(), runtime.clone());
244 let members = 244 let members = Members::new(
245 Members::new(room.clone(), runtime.clone(), buffer.clone()); 245 room.clone(),
246 runtime.clone(),
247 config.clone(),
248 buffer.clone(),
249 );
246 250
247 let own_nick = runtime 251 let own_nick = runtime
248 .block_on(room.get_member_no_sync(own_user_id)) 252 .block_on(room.get_member_no_sync(own_user_id))