| @@ -7,6 +7,7 @@ mod debug; |
| 7 | mod render; |
7 | mod render; |
| 8 | mod room; |
8 | mod room; |
| 9 | mod server; |
9 | mod server; |
| |
10 | mod bar_items; |
| 10 | |
11 | |
| 11 | use std::{ |
12 | use std::{ |
| 12 | cell::{Ref, RefCell, RefMut}, |
13 | cell::{Ref, RefCell, RefMut}, |
| @@ -16,13 +17,14 @@ use std::{ |
| 16 | |
17 | |
| 17 | use weechat::{ |
18 | use weechat::{ |
| 18 | buffer::{Buffer, BufferHandle}, |
19 | buffer::{Buffer, BufferHandle}, |
| 19 | hooks::{BarItem, BarItemCallback, SignalCallback, SignalData, SignalHook}, |
20 | hooks::{SignalCallback, SignalData, SignalHook}, |
| 20 | plugin, Args, Plugin, ReturnCode, Weechat, |
21 | plugin, Args, Plugin, ReturnCode, Weechat, |
| 21 | }; |
22 | }; |
| 22 | |
23 | |
| 23 | use crate::{ |
24 | use crate::{ |
| 24 | commands::Commands, config::ConfigHandle, room::RoomHandle, |
25 | commands::Commands, config::ConfigHandle, room::RoomHandle, |
| 25 | server::MatrixServer, |
26 | server::MatrixServer, |
| |
27 | bar_items::BarItems, |
| 26 | }; |
28 | }; |
| 27 | |
29 | |
| 28 | const PLUGIN_NAME: &str = "matrix"; |
30 | const PLUGIN_NAME: &str = "matrix"; |
| @@ -117,7 +119,7 @@ struct Matrix { |
| 117 | #[used] |
119 | #[used] |
| 118 | config: ConfigHandle, |
120 | config: ConfigHandle, |
| 119 | #[used] |
121 | #[used] |
| 120 | status_bar: BarItem, |
122 | bar_items: BarItems, |
| 121 | #[used] |
123 | #[used] |
| 122 | typing_notice_signal: SignalHook, |
124 | typing_notice_signal: SignalHook, |
| 123 | debug_buffer: RefCell<Option<BufferHandle>>, |
125 | debug_buffer: RefCell<Option<BufferHandle>>, |
| @@ -159,38 +161,6 @@ impl Matrix { |
| 159 | } |
161 | } |
| 160 | } |
162 | } |
| 161 | |
163 | |
| 162 | impl BarItemCallback for Servers { |
| |
| 163 | fn callback(&mut self, _: &Weechat, buffer: &Buffer) -> String { |
| |
| 164 | let servers = self.borrow(); |
| |
| 165 | |
| |
| 166 | let mut signs = Vec::new(); |
| |
| 167 | |
| |
| 168 | for server in servers.values() { |
| |
| 169 | let server = server.inner(); |
| |
| 170 | |
| |
| 171 | for room in server.rooms().values() { |
| |
| 172 | if let Ok(b) = room.buffer_handle().upgrade() { |
| |
| 173 | if buffer == &b { |
| |
| 174 | if room.is_encrypted() { |
| |
| 175 | signs.push( |
| |
| 176 | server.config().look().encrypted_room_sign(), |
| |
| 177 | ); |
| |
| 178 | } |
| |
| 179 | |
| |
| 180 | if room.is_busy() { |
| |
| 181 | signs.push("⏳".to_owned()); |
| |
| 182 | } |
| |
| 183 | |
| |
| 184 | break; |
| |
| 185 | } |
| |
| 186 | } |
| |
| 187 | } |
| |
| 188 | } |
| |
| 189 | |
| |
| 190 | signs.join("") |
| |
| 191 | } |
| |
| 192 | } |
| |
| 193 | |
| |
| 194 | impl Plugin for Matrix { |
164 | impl Plugin for Matrix { |
| 195 | fn init(_: &Weechat, _args: Args) -> Result<Self, ()> { |
165 | fn init(_: &Weechat, _args: Args) -> Result<Self, ()> { |
| 196 | let servers = Servers::new(); |
166 | let servers = Servers::new(); |
| @@ -198,7 +168,7 @@ impl Plugin for Matrix { |
| 198 | let commands = Commands::hook_all(&servers, &config)?; |
168 | let commands = Commands::hook_all(&servers, &config)?; |
| 199 | |
169 | |
| 200 | // TODO move the bar creation into a separate file. |
170 | // TODO move the bar creation into a separate file. |
| 201 | let status_bar = BarItem::new("matrix_modes", servers.clone())?; |
171 | let bar_items = BarItems::hook_all(servers.clone())?; |
| 202 | |
172 | |
| 203 | tracing_subscriber::fmt() |
173 | tracing_subscriber::fmt() |
| 204 | .with_writer(debug::Debug) |
174 | .with_writer(debug::Debug) |
| @@ -226,7 +196,7 @@ impl Plugin for Matrix { |
| 226 | servers: servers.clone(), |
196 | servers: servers.clone(), |
| 227 | commands, |
197 | commands, |
| 228 | config, |
198 | config, |
| 229 | status_bar, |
199 | bar_items, |
| 230 | debug_buffer: RefCell::new(None), |
200 | debug_buffer: RefCell::new(None), |
| 231 | typing_notice_signal: typing, |
201 | typing_notice_signal: typing, |
| 232 | }; |
202 | }; |