Subscriptions working
This commit is contained in:
28
src/usimp/handler/new_event.rs
Normal file
28
src/usimp/handler/new_event.rs
Normal file
@ -0,0 +1,28 @@
|
||||
use crate::usimp::*;
|
||||
use crate::usimp::subscription;
|
||||
|
||||
use serde_json::{Value, from_value, to_value};
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
struct Input {
|
||||
room_id: String,
|
||||
events: Vec<Event>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
struct Output {
|
||||
}
|
||||
|
||||
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(&session)?;
|
||||
// TODO check permissions
|
||||
for event in input.events {
|
||||
subscription::push(input.room_id.as_str(), event).await?;
|
||||
}
|
||||
Ok(Output {})
|
||||
}
|
Reference in New Issue
Block a user