src/bar_items/status.rs

014dde15f4d66b4515a736d8d3bdaf1f64598040
weechat-matrix-rs/src/bar_items/status.rs history · blame · raw

40 lines · 909 bytes

 1use weechat::{
 2    buffer::Buffer,
 3    hooks::{BarItem, BarItemCallback},
 4    Weechat,
 5};
 6
 7use crate::{BufferOwner, Servers};
 8
 9pub(super) struct Status {
10    servers: Servers,
11}
12
13impl Status {
14    pub(super) fn create(servers: Servers) -> Result<BarItem, ()> {
15        let status = Status { servers };
16        BarItem::new("buffer_modes", status)
17    }
18}
19
20impl BarItemCallback for Status {
21    fn callback(&mut self, _: &Weechat, buffer: &Buffer) -> String {
22        let mut signs = Vec::new();
23
24        if let BufferOwner::Room(server, room) =
25            self.servers.buffer_owner(buffer)
26        {
27            if room.is_encrypted() {
28                signs.push(
29                    server.config().borrow().look().encrypted_room_sign(),
30                );
31            }
32
33            if room.is_busy() {
34                signs.push("⏳".to_owned());
35            }
36        }
37
38        signs.join("")
39    }
40}