Commit 86598bb257

86598bb257041c770bd5176e3c741954f7276a58

parent: 86cbd7ae64

Unsigned

Darafei Praliaskouski <me@komzpa.net> · 2026-06-23 18:43 UTC
committer: <strk@kbt.io>

fix: fetch history for empty room buffers

Layout: unified · split

src/lib.rs +16 −2
@@ -167,12 +167,21 @@ impl SignalCallback for Servers {
167167 fn callback(
168168 &mut self,
169169 _: &Weechat,
170 _signal_name: &str,
170 signal_name: &str,
171171 data: Option<SignalData>,
172172 ) -> ReturnCode {
173173 if let Some(SignalData::Buffer(buffer)) = data {
174174 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 }
176185 }
177186 }
178187 ReturnCode::Ok
@@ -191,6 +200,8 @@ struct Matrix {
191200 #[allow(dead_code)]
192201 typing_notice_signal: SignalHook,
193202 #[allow(dead_code)]
203 history_fetch_signal: SignalHook,
204 #[allow(dead_code)]
194205 completions: Completions,
195206 debug_buffer: RefCell<Option<BufferHandle>>,
196207}
@@ -266,6 +277,8 @@ impl Plugin for Matrix {
266277
267278 let typing = SignalHook::new("input_text_changed", servers.clone())
268279 .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");
269282
270283 let plugin = Matrix {
271284 global_runtime,
@@ -276,6 +289,7 @@ impl Plugin for Matrix {
276289 completions,
277290 debug_buffer: RefCell::new(None),
278291 typing_notice_signal: typing,
292 history_fetch_signal: history_fetch,
279293 };
280294
281295 Weechat::spawn(async move {
src/room/mod.rs +11
@@ -924,6 +924,17 @@ impl MatrixRoom {
924924 Weechat::bar_item_update("matrix_modes");
925925 }
926926
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
927938 async fn handle_outgoing_message(
928939 &self,
929940 transaction_id: &TransactionId,