use super::world::World;
use crate::boundary::{Gesture, codec};
impl World {
pub(in crate::shell::acceptance) fn follows(&mut self) {
use crate::boundary::follow::{Follow, Frame};
let Some(question) = self.tail.standing() else {
self.followed = None;
return;
};
let key = question.to_string();
if self.followed.as_ref().map(|(at, _)| at.as_str()) != Some(key.as_str()) {
let Ok(Gesture::Ask(crate::boundary::Query::Follow { workspace, agent })) =
codec::decode(&question)
else {
return;
};
let Ok(ws) = self.model.derivation().ws_path(&workspace) else {
return;
};
self.followed = Some((
key.clone(),
Follow::new(self.model.snapshot_cell(), ws, agent),
));
}
let Some((_, follow)) = self.followed.as_mut() else {
return;
};
match follow.poll() {
Frame::Ready(stream) => self.tail.publish(&key, Some(stream)),
Frame::Over => {
self.tail.publish(&key, None);
self.followed = None;
}
Frame::Waiting => {}
}
}
}