src/bar_items/status.rs

0e0a16c77efc019eea79a30eb91f69e5e30d1fbe
weechat-matrix-rs/src/bar_items/status.rs history · blame · raw

46 lines · 1104 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_public() {
34                signs.push(
35                    server.config().borrow().look().public_room_sign(),
36                );
37            }
38
39            if room.is_busy() {
40                signs.push(server.config().borrow().look().busy_sign());
41            }
42        }
43
44        signs.join("")
45    }
46}