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 {
167 fn callback( 167 fn callback(
168 &mut self, 168 &mut self,
169 _: &Weechat, 169 _: &Weechat,
170 _signal_name: &str, 170 signal_name: &str,
171 data: Option<SignalData>, 171 data: Option<SignalData>,
172 ) -> ReturnCode { 172 ) -> ReturnCode {
173 if let Some(SignalData::Buffer(buffer)) = data { 173 if let Some(SignalData::Buffer(buffer)) = data {
174 if let Some(room) = self.find_room(&buffer) { 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 ReturnCode::Ok 187 ReturnCode::Ok
@@ -191,6 +200,8 @@ struct Matrix {
191 #[allow(dead_code)] 200 #[allow(dead_code)]
192 typing_notice_signal: SignalHook, 201 typing_notice_signal: SignalHook,
193 #[allow(dead_code)] 202 #[allow(dead_code)]
203 history_fetch_signal: SignalHook,
204 #[allow(dead_code)]
194 completions: Completions, 205 completions: Completions,
195 debug_buffer: RefCell<Option<BufferHandle>>, 206 debug_buffer: RefCell<Option<BufferHandle>>,
196} 207}
@@ -266,6 +277,8 @@ impl Plugin for Matrix {
266 277
267 let typing = SignalHook::new("input_text_changed", servers.clone()) 278 let typing = SignalHook::new("input_text_changed", servers.clone())
268 .expect("Can't create signal hook for the typing notice cb"); 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 let plugin = Matrix { 283 let plugin = Matrix {
271 global_runtime, 284 global_runtime,
@@ -276,6 +289,7 @@ impl Plugin for Matrix {
276 completions, 289 completions,
277 debug_buffer: RefCell::new(None), 290 debug_buffer: RefCell::new(None),
278 typing_notice_signal: typing, 291 typing_notice_signal: typing,
292 history_fetch_signal: history_fetch,
279 }; 293 };
280 294
281 Weechat::spawn(async move { 295 Weechat::spawn(async move {
src/room/mod.rs +11
@@ -924,6 +924,17 @@ impl MatrixRoom {
924 Weechat::bar_item_update("matrix_modes"); 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 async fn handle_outgoing_message( 938 async fn handle_outgoing_message(
928 &self, 939 &self,
929 transaction_id: &TransactionId, 940 transaction_id: &TransactionId,