matrix: widen sync event window backwards — sender precedes type marker

This commit is contained in:
pierre committed 2026-09-02 02:22:38 +03:00
1 parent a6d4e29589
commit 77f3150af4
1 file changed
+4 -1
+4 -1
View File
@@ -121,8 +121,11 @@ pub fn sync(alloc: std.mem.Allocator, io: Io, token: []const u8, since: []const
var i: usize = 0; var i: usize = 0;
while (std.mem.indexOfPos(u8, resp, i, "\"m.room.message\"")) |pos| { while (std.mem.indexOfPos(u8, resp, i, "\"m.room.message\"")) |pos| {
defer i = pos + 15; defer i = pos + 15;
// Event layout: sender (and event_id) come BEFORE the type marker,
// body comes after it in content — window spans both sides.
const win_start = pos -| 600;
const win_end = @min(resp.len, pos + 1500); const win_end = @min(resp.len, pos + 1500);
const win = resp[pos..win_end]; const win = resp[win_start..win_end];
const sender = letta.jsonStr(alloc, win, 0, "sender") orelse continue; const sender = letta.jsonStr(alloc, win, 0, "sender") orelse continue;
const body = letta.jsonStr(alloc, win, 0, "body") orelse { const body = letta.jsonStr(alloc, win, 0, "body") orelse {
alloc.free(sender.val); alloc.free(sender.val);