Commit 86598bb257
Unsigned
Layout: unified · split
src/lib.rs +16 −2
| @@ -167,12 +167,21 @@ impl SignalCallback for Servers { | ||
| 167 | 167 | fn callback( |
| 168 | 168 | &mut self, |
| 169 | 169 | _: &Weechat, |
| 170 | _signal_name: &str, | |
| 170 | signal_name: &str, | |
| 171 | 171 | data: Option<SignalData>, |
| 172 | 172 | ) -> ReturnCode { |
| 173 | 173 | if let Some(SignalData::Buffer(buffer)) = data { |
| 174 | 174 | if let Some(room) = self.find_room(&buffer) { |
| 175 | room.update_typing_notice(); | |
| 175 | match signal_name { | |
| 176 | "buffer_switch" => { | |
| 177 | Weechat::spawn(async move { | |
| 178 | room.get_messages_if_empty().await | |
| 179 | }) | |
| 180 | .detach(); | |
| 181 | } | |
| 182 | "input_text_changed" => room.update_typing_notice(), | |
| 183 | _ => (), | |
| 184 | } | |
| 176 | 185 | } |
| 177 | 186 | } |
| 178 | 187 | ReturnCode::Ok |
| @@ -191,6 +200,8 @@ struct Matrix { | ||
| 191 | 200 | #[allow(dead_code)] |
| 192 | 201 | typing_notice_signal: SignalHook, |
| 193 | 202 | #[allow(dead_code)] |
| 203 | history_fetch_signal: SignalHook, | |
| 204 | #[allow(dead_code)] | |
| 194 | 205 | completions: Completions, |
| 195 | 206 | debug_buffer: RefCell<Option<BufferHandle>>, |
| 196 | 207 | } |
| @@ -266,6 +277,8 @@ impl Plugin for Matrix { | ||
| 266 | 277 | |
| 267 | 278 | let typing = SignalHook::new("input_text_changed", servers.clone()) |
| 268 | 279 | .expect("Can't create signal hook for the typing notice cb"); |
| 280 | let history_fetch = SignalHook::new("buffer_switch", servers.clone()) | |
| 281 | .expect("Can't create signal hook for the history fetch cb"); | |
| 269 | 282 | |
| 270 | 283 | let plugin = Matrix { |
| 271 | 284 | global_runtime, |
| @@ -276,6 +289,7 @@ impl Plugin for Matrix { | ||
| 276 | 289 | completions, |
| 277 | 290 | debug_buffer: RefCell::new(None), |
| 278 | 291 | typing_notice_signal: typing, |
| 292 | history_fetch_signal: history_fetch, | |
| 279 | 293 | }; |
| 280 | 294 | |
| 281 | 295 | Weechat::spawn(async move { |
src/room/mod.rs +11
| @@ -924,6 +924,17 @@ impl MatrixRoom { | ||
| 924 | 924 | Weechat::bar_item_update("matrix_modes"); |
| 925 | 925 | } |
| 926 | 926 | |
| 927 | pub async fn get_messages_if_empty(&self) { | |
| 928 | let buffer_handle = self.buffer_handle(); | |
| 929 | let Ok(buffer) = buffer_handle.upgrade() else { | |
| 930 | return; | |
| 931 | }; | |
| 932 | ||
| 933 | if buffer.num_lines() == 0 { | |
| 934 | self.get_messages().await; | |
| 935 | } | |
| 936 | } | |
| 937 | ||
| 927 | 938 | async fn handle_outgoing_message( |
| 928 | 939 | &self, |
| 929 | 940 | transaction_id: &TransactionId, |