forked from janek/mostr
fix(tasks): properly process movement with history-based position
This commit is contained in:
parent
ebfe632497
commit
506a73060a
21
src/tasks.rs
21
src/tasks.rs
|
@ -598,23 +598,34 @@ impl Tasks {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns all recent events from history until the first event at or before the given timestamp.
|
||||||
|
fn history_until(&self, stamp: Timestamp) -> impl Iterator<Item=&Event> {
|
||||||
|
self.history.get(&self.sender.pubkey()).map(|hist| {
|
||||||
|
hist.iter().rev().take_while_inclusive(move |e| e.created_at > stamp)
|
||||||
|
}).into_iter().flatten()
|
||||||
|
}
|
||||||
|
|
||||||
|
const MAX_OFFSET: u64 = 9;
|
||||||
|
|
||||||
pub(crate) fn move_to(&mut self, id: Option<EventId>) {
|
pub(crate) fn move_to(&mut self, id: Option<EventId>) {
|
||||||
self.view.clear();
|
self.view.clear();
|
||||||
if id == self.get_position() {
|
let pos = self.get_position();
|
||||||
|
if id == pos {
|
||||||
debug!("Flushing Tasks because of move in place");
|
debug!("Flushing Tasks because of move in place");
|
||||||
self.flush();
|
self.flush();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let now = Timestamp::now();
|
let now = Timestamp::now();
|
||||||
let offset: u64 = self.get_own_history().map_or(0, |hist| {
|
let offset: u64 = self.history_until(Timestamp::now()).skip_while(|e| e.created_at.as_u64() > now.as_u64() + Self::MAX_OFFSET).count() as u64;
|
||||||
hist.iter().rev().take_while(|e| e.created_at >= now).skip_while(|e| e.created_at.as_u64() > now.as_u64() + 99).count() as u64
|
if offset >= Self::MAX_OFFSET {
|
||||||
});
|
warn!("Whoa you are moving around quickly! Give me a few seconds to process.")
|
||||||
|
}
|
||||||
self.submit(
|
self.submit(
|
||||||
build_tracking(id)
|
build_tracking(id)
|
||||||
.custom_created_at(Timestamp::from(now.as_u64() + offset))
|
.custom_created_at(Timestamp::from(now.as_u64() + offset))
|
||||||
);
|
);
|
||||||
if !id.and_then(|id| self.tasks.get(&id)).is_some_and(|t| t.parent_id() == self.get_position().as_ref()) {
|
if !id.and_then(|id| self.tasks.get(&id)).is_some_and(|t| t.parent_id() == pos.as_ref()) {
|
||||||
debug!("Flushing Tasks because of move beyond child");
|
debug!("Flushing Tasks because of move beyond child");
|
||||||
self.flush();
|
self.flush();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue