src/bar_items/status.rs

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

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