fix(event_sender): undo of custom time event creation and entering

previously only the tracking would be undone after entering .NEW@TIME
This commit is contained in:
xeruf 2025-01-15 22:06:34 +01:00
parent 4769c12336
commit a1347def62

View file

@ -39,30 +39,29 @@ impl EventSender {
// TODO this direly needs testing // TODO this direly needs testing
pub(crate) fn submit(&self, event_builder: EventBuilder) -> Result<Event> { pub(crate) fn submit(&self, event_builder: EventBuilder) -> Result<Event> {
let min = Timestamp::now().sub(UNDO_DELAY); let event = event_builder.sign_with_keys(&self.keys)?;
let time = event.created_at;
{ {
// Always flush if oldest event older than a minute or newer than now // Always flush if any event is newer or more than a minute older than the current event
let borrow = self.queue.borrow(); let borrow = self.queue.borrow();
if borrow if borrow
.iter() .iter()
.any(|e| e.created_at < min || e.created_at > Timestamp::now()) .any(|e| e.created_at < time.sub(UNDO_DELAY) || e.created_at > time)
{ {
drop(borrow); drop(borrow);
debug!("Flushing event queue because it is older than a minute"); debug!("Flushing event queue because it is offset from the current event");
self.force_flush(); self.force_flush();
} }
} }
let mut queue = self.queue.borrow_mut(); let mut queue = self.queue.borrow_mut();
Ok(event_builder.sign_with_keys(&self.keys).inspect(|event| { if event.kind == TRACKING_KIND {
if event.kind == TRACKING_KIND // Remove extraneous movements if tracking event is not at a custom time
&& event.created_at > min queue.retain(|e| e.kind != TRACKING_KIND);
&& event.created_at < tasks::now() }
{ queue.push(event.clone());
// Do not send redundant movements Ok(event)
queue.retain(|e| e.kind != TRACKING_KIND);
}
queue.push(event.clone());
})?)
} }
/// Sends all pending events /// Sends all pending events
pub(crate) fn force_flush(&self) { pub(crate) fn force_flush(&self) {