Set age dynamically #504

This commit is contained in:
Matthew Scheffel 2024-07-16 21:19:03 -03:00
parent c29197b3f4
commit 5182a7e38f
No known key found for this signature in database
GPG key ID: 29D74EE3B1DA9FE3

View file

@ -116,7 +116,11 @@ impl PduEvent {
.map_or_else(|| Ok(BTreeMap::new()), |u| serde_json::from_str(u.get()))
.map_err(|_| Error::bad_database("Invalid unsigned in pdu event"))?;
unsigned.insert("age".to_owned(), to_raw_value(&1).unwrap());
let now: u64 = MilliSecondsSinceUnixEpoch::now().get().into();
let then: u64 = self.origin_server_ts.into();
let this_age: u64 = now - then;
unsigned.insert("age".to_owned(), to_raw_value(&this_age).unwrap());
self.unsigned = Some(to_raw_value(&unsigned).expect("unsigned is valid"));
Ok(())