39 lines
1012 B
Rust
39 lines
1012 B
Rust
use crate::usimp::subscription;
|
|
use crate::usimp::*;
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
use serde_json::{from_value, to_value, Value};
|
|
|
|
#[derive(Serialize, Deserialize, Clone)]
|
|
struct Input {
|
|
room_id: Uuid,
|
|
events: Vec<Event>,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Clone)]
|
|
struct Output {
|
|
events: Vec<Uuid>,
|
|
}
|
|
|
|
pub async fn handle(input: &InputEnvelope, session: Option<Session>) -> Result<Value, Error> {
|
|
Ok(to_value(
|
|
new_event(from_value(input.data.clone())?, session).await?,
|
|
)?)
|
|
}
|
|
|
|
async fn new_event(input: Input, session: Option<Session>) -> Result<Output, Error> {
|
|
let _account = get_account_opt(&session)?;
|
|
let mut uuids = vec![];
|
|
// TODO check permissions
|
|
for mut event in input.events {
|
|
let uuid = match event.id {
|
|
Some(id) => id,
|
|
None => Uuid::new_v4(),
|
|
};
|
|
event.id = Some(uuid);
|
|
uuids.push(uuid);
|
|
subscription::push_room(&input.room_id, event).await?;
|
|
}
|
|
Ok(Output {events: uuids})
|
|
}
|