Add Unsigned::age_ts function

This commit is contained in:
Erik Johnston committed 2026-06-22 11:11:53 +01:00
1 parent 32b0eafdb3
commit a1cd8f3a53
2 files changed
+9 -1

No files matched your search

+1 -1
View File
@@ -477,7 +477,7 @@ fn serialize_event_value(
// us it *should* be an integer, but it is possible for it to be out of i64
// range. In that case, just omit `age` rather than erroring.
let unsigned = unsigned_mut(&mut d);
if let Some(age_ts) = unsigned.get(unsigned_field::AGE_TS).and_then(Value::as_i64) {
if let Some(age_ts) = event.unsigned().age_ts()?.and_then(|n| n.as_i64()) {
unsigned.insert(
unsigned_field::AGE.to_owned(),
Value::Number(Number::from(time_now_ms - age_ts)),
+8
View File
@@ -291,6 +291,14 @@ impl Unsigned {
}
}
impl Unsigned {
/// Get the `age_ts` field, which is used to generate the `age` field when
/// serializing an event.
pub fn age_ts(&self) -> PyResult<Option<Number>> {
Ok(self.py_read()?.persisted_fields.age_ts.clone())
}
}
fn room_state_to_py<'py>(
py: Python<'py>,
state: &[serde_json::Value],