Matrix notification
This commit is contained in:
parent
86495543ce
commit
2de26f5ffc
7 changed files with 1090 additions and 17 deletions
|
|
@ -1,6 +1,7 @@
|
|||
use crate::{config::*, db::*, helpers, queries::*, templates::*};
|
||||
|
||||
use argon2::{Argon2, PasswordHash, PasswordVerifier};
|
||||
use crossbeam_channel::Sender;
|
||||
use log::error;
|
||||
use std::sync::Arc;
|
||||
use tera::Context;
|
||||
|
|
@ -11,6 +12,9 @@ pub async fn start_server(config: Config, dbs: Dbs, templates: Templates) {
|
|||
let templates = Arc::new(templates);
|
||||
let config = Arc::new(config);
|
||||
|
||||
let (notify_send, notify_recv) = crossbeam_channel::bounded(10);
|
||||
tokio::spawn(crate::notify::run_notifier(config.clone(), notify_recv));
|
||||
|
||||
let mut app = tide::new();
|
||||
app.at(&format!("{}t/:topic", config.root_url)).get({
|
||||
let config = config.clone();
|
||||
|
|
@ -25,7 +29,13 @@ pub async fn start_server(config: Config, dbs: Dbs, templates: Templates) {
|
|||
let templates = templates.clone();
|
||||
let dbs = dbs.clone();
|
||||
move |req: tide::Request<()>| {
|
||||
handle_post_comments(req, config.clone(), templates.clone(), dbs.clone())
|
||||
handle_post_comments(
|
||||
req,
|
||||
config.clone(),
|
||||
templates.clone(),
|
||||
dbs.clone(),
|
||||
notify_send.clone(),
|
||||
)
|
||||
}
|
||||
});
|
||||
app.at(&format!("{}admin", config.root_url)).get({
|
||||
|
|
@ -176,6 +186,7 @@ async fn handle_post_comments(
|
|||
config: Arc<Config>,
|
||||
templates: Arc<Templates>,
|
||||
dbs: Dbs,
|
||||
notify_send: Sender<()>,
|
||||
) -> tide::Result<tide::Response> {
|
||||
match req.body_form::<CommentQuery>().await? {
|
||||
CommentQuery::NewComment(query) => {
|
||||
|
|
@ -215,6 +226,7 @@ async fn handle_post_comments(
|
|||
helpers::new_pending_comment(&comment, &dbs)
|
||||
.map_err(|e| error!("Adding pending comment: {:?}", e))
|
||||
.ok();
|
||||
notify_send.send(()).ok();
|
||||
}
|
||||
_ => todo!(),
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue