use super::{Aim, Model};
use crate::reply::queue::QueueRow;
use crate::ui::Channel;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Asking {
pub channel: Channel,
pub rows: Vec<QueueRow>,
}
impl Model {
pub fn begin_queue(&mut self) {
self.stand(super::Listing::Queue);
}
pub fn close_queue(&mut self) {
self.put_down(super::Listing::Queue);
}
pub(super) fn asking(&mut self, channel: &Channel, rows: Vec<QueueRow>) {
let answered = Asking {
channel: channel.clone(),
rows,
};
match self
.waiting
.iter_mut()
.find(|held| held.channel.name == channel.name)
{
Some(held) => *held = answered,
None => self.waiting.push(answered),
}
}
pub fn wall(&self, workspace: &str) -> Option<Aim> {
self.roster.iter().find_map(|chunk| {
chunk
.walls
.iter()
.find(|wall| wall.workspace == workspace)
.and_then(|wall| chunk.channel.address(wall))
.map(|address| Aim {
channel: chunk.channel.name.clone(),
address,
})
})
}
pub fn post_seen(&mut self, row: &QueueRow) {
if let Some(aim) = self.wall(&row.workspace) {
self.outbox.push(super::Posted::act(crate::verbs::seen(
aim.address,
row.agent.clone(),
)));
}
}
pub fn go_to(&mut self, row: &QueueRow) {
let Some(aim) = self.wall(&row.workspace) else {
return;
};
self.aim_at(&aim.channel, &aim.address);
self.select(&row.agent.clone());
self.close_queue();
}
}
#[cfg(test)]
mod tests;