diff --git a/src/matrix.zig b/src/matrix.zig index d0a954f..becf4a1 100644 --- a/src/matrix.zig +++ b/src/matrix.zig @@ -121,8 +121,11 @@ pub fn sync(alloc: std.mem.Allocator, io: Io, token: []const u8, since: []const var i: usize = 0; while (std.mem.indexOfPos(u8, resp, i, "\"m.room.message\"")) |pos| { 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 = resp[pos..win_end]; + const win = resp[win_start..win_end]; const sender = letta.jsonStr(alloc, win, 0, "sender") orelse continue; const body = letta.jsonStr(alloc, win, 0, "body") orelse { alloc.free(sender.val);