src/bar_items/status.rs
54 lines · 1398 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 if !room.contains_only_verified_devices() {
33 signs.push(
34 server
35 .config()
36 .borrow()
37 .look()
38 .encryption_warning_sign(),
39 );
40 }
41 }
42
43 if room.is_public() {
44 signs.push(server.config().borrow().look().public_room_sign());
45 }
46
47 if room.is_busy() {
48 signs.push(server.config().borrow().look().busy_sign());
49 }
50 }
51
52 signs.join("")
53 }
54}