Commit e289083eeb

e289083eeb35f944bc554e27e761e96fb46cdf85

parent: 924a7fdec1

Unsigned

Darafei Praliaskouski <me@komzpa.net> · 2026-07-31 09:51 UTC
committer: <strk@kbt.io>

fix: restore newest Matrix room history

Layout: unified · split

src/room/mod.rs +12 −13
@@ -142,12 +142,12 @@ const HISTORY_PAGE_TAGS: [&str; 2] =
142142const RESTORED_HISTORY_BATCH_SIZE: u16 = 25;
143143const INTERACTIVE_HISTORY_BATCH_SIZE: u16 = 25;
144144
145fn restored_prev_batch(prev_batch: Option<String>) -> Option<PrevBatch> {
146 // A restored SDK room does not always have a sync pagination token in its
147 // store. Matrix permits a backward /messages request without `from`, which
148 // starts at the newest visible event. Keep that request representable so a
149 // freshly restored room can still populate its WeeChat buffer.
150 Some(PrevBatch::Backwards(prev_batch))
145fn restored_prev_batch(_prev_batch: Option<String>) -> Option<PrevBatch> {
146 // The SDK does not replay the stored sync timeline when a room is restored.
147 // Its last_prev_batch token points before that timeline, so using it here
148 // skips the newest messages entirely. Start at the current room end; the
149 // response's end token will drive older backward pagination afterwards.
150 Some(PrevBatch::Backwards(None))
151151}
152152
153153fn has_history_page(prev_batch: &Option<PrevBatch>) -> bool {
@@ -2872,10 +2872,10 @@ mod tests {
28722872 }
28732873
28742874 #[test]
2875 fn restored_rooms_fetch_history_backwards_from_prev_batch() {
2875 fn restored_rooms_fetch_newest_history_before_older_pages() {
28762876 assert_eq!(
28772877 restored_prev_batch(Some("token".to_owned())),
2878 Some(PrevBatch::Backwards(Some("token".to_owned())))
2878 Some(PrevBatch::Backwards(None))
28792879 );
28802880 }
28812881
@@ -2996,8 +2996,8 @@ mod tests {
29962996
29972997 #[test]
29982998 fn reply_event_details_extract_sender_and_body() {
2999 let event: AnySyncTimelineEvent = serde_json::from_value(
3000 serde_json::json!({
2999 let event: AnySyncTimelineEvent =
3000 serde_json::from_value(serde_json::json!({
30013001 "type": "m.room.message",
30023002 "event_id": "$original:example.org",
30033003 "sender": "@alice:example.org",
@@ -3007,9 +3007,8 @@ mod tests {
30073007 "body": "original message"
30083008 },
30093009 "unsigned": {}
3010 }),
3011 )
3012 .expect("valid Matrix event");
3010 }))
3011 .expect("valid Matrix event");
30133012
30143013 assert_eq!(
30153014 reply_event_details(event),