use super::{ActionCallError, ActionProvider, Caller, Pending, RemoteActionMessage};
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct Here {
pub who: String,
pub name: String,
pub kind: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub works_in: Option<HereWindow>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub devices: Vec<String>,
}
pub const PRESENCE: &str = "tilo.presence";
pub const KEY_GRANTS: &str = "tilo.grants";
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct HereWindow {
pub app: String,
pub document: String,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub enum WatchScope {
Records,
Here,
}
pub const CHANGED_UNAVAILABLE: &str =
"this provider cannot tell when the workspace's records or its people changed";
pub(super) fn noticed<H: ActionProvider>(
provider: &H,
caller: &Caller,
correlation: u64,
scope: WatchScope,
) -> Pending<RemoteActionMessage> {
let respond = move |result| RemoteActionMessage::ChangedResponse {
correlation,
result,
};
match provider.changed(caller, scope) {
Some(changed) => changed.map(respond),
None => Pending::ready(respond(Err(ActionCallError::Unavailable {
reason: CHANGED_UNAVAILABLE.into(),
}))),
}
}