notify-on-always-show-events #692
@ -9,7 +9,11 @@ use serde::Serialize;
|
|||||||
use sqlx::{FromRow, Row, SqlitePool};
|
use sqlx::{FromRow, Row, SqlitePool};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
notification::Notification, role::Role, tripdetails::TripDetails, triptype::TripType,
|
notification::Notification,
|
||||||
|
role::Role,
|
||||||
|
trip,
|
||||||
|
tripdetails::{self, TripDetails},
|
||||||
|
triptype::TripType,
|
||||||
user::User,
|
user::User,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -216,6 +220,19 @@ WHERE trip_details.id=?
|
|||||||
.ok()
|
.ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn advertise(db: &SqlitePool, day: &str, planned_starting_time: &str, name: &str) {
|
||||||
|
let donau = Role::find_by_name(db, "Donau Linz").await.unwrap();
|
||||||
|
Notification::create_for_role(
|
||||||
|
db,
|
||||||
|
&donau,
|
||||||
|
&format!("Am {} um {} wurde ein neues Event angelegt: {} Wir freuen uns wenn du dabei mitmachst, die Anmeldung ist ab sofort offen :-)", day, planned_starting_time, name),
|
||||||
|
"Neues Event",
|
||||||
|
Some(&format!("/planned#{day}")),
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn create(
|
pub async fn create(
|
||||||
db: &SqlitePool,
|
db: &SqlitePool,
|
||||||
name: &str,
|
name: &str,
|
||||||
@ -223,14 +240,11 @@ WHERE trip_details.id=?
|
|||||||
trip_details: &TripDetails,
|
trip_details: &TripDetails,
|
||||||
) {
|
) {
|
||||||
if trip_details.always_show {
|
if trip_details.always_show {
|
||||||
let donau = Role::find_by_name(db, "Donau Linz").await.unwrap();
|
Self::advertise(
|
||||||
Notification::create_for_role(
|
|
||||||
db,
|
db,
|
||||||
&donau,
|
&trip_details.day,
|
||||||
&format!("Am {} um {} wurde ein neues Event angelegt: {} Wir freuen uns wenn du dabei mitmachst, die Anmeldung ist ab sofort offen :-)", trip_details.day, trip_details.planned_starting_time, name),
|
&trip_details.planned_starting_time,
|
||||||
"Neues Event",
|
name,
|
||||||
Some(&format!("/planned#{}", trip_details.day)),
|
|
||||||
None,
|
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
@ -274,6 +288,16 @@ WHERE trip_details.id=?
|
|||||||
.await
|
.await
|
||||||
.unwrap(); //Okay, as planned_event can only be created with proper DB backing
|
.unwrap(); //Okay, as planned_event can only be created with proper DB backing
|
||||||
|
|
||||||
|
if !tripdetails.always_show && update.always_show {
|
||||||
|
Self::advertise(
|
||||||
|
db,
|
||||||
|
&tripdetails.day,
|
||||||
|
&tripdetails.planned_starting_time,
|
||||||
|
update.name,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
|
||||||
if update.max_people == 0 && !was_already_cancelled {
|
if update.max_people == 0 && !was_already_cancelled {
|
||||||
let coxes = Registration::all_cox(db, self.id).await;
|
let coxes = Registration::all_cox(db, self.id).await;
|
||||||
for user in coxes {
|
for user in coxes {
|
||||||
|
Loading…
Reference in New Issue
Block a user