fix: Store to-device messages before syncs can read their count

This commit is contained in:
Erwan Leboucher authored and Ellis Git committed 2026-11-05 15:17:36 +00:00
1 parent fb389cb6f9
commit 8c720e5427
2 files changed
+14 -11

No files matched your search

@@ -0,0 +1 @@
Fix to-device messages, including room keys, sometimes being lost before delivery. Contributed by @eleboucher.
+13 -11
View File
@@ -216,17 +216,19 @@ impl super::Service {
event_type: &str,
content: serde_json::Value,
) {
let count = self.services.globals.next_count().unwrap();
let key = (target_user_id, target_device_id, count);
self.db.todeviceid_events.put(
key,
Json(json!({
"type": event_type,
"sender": sender,
"content": content,
})),
);
let event = Json(json!({
"type": event_type,
"sender": sender,
"content": content,
}));
self.services
.globals
.next_count_with(|count| {
self.db
.todeviceid_events
.put((target_user_id, target_device_id, count), event);
})
.unwrap();
self.services.sync.wake(target_user_id).await;
}