Compare commits
4 Commits
49b2305cdb
...
6b88927880
Author | SHA1 | Date | |
---|---|---|---|
6b88927880 | |||
be94707228 | |||
f968d5d03b | |||
a52ee97a80 |
@ -76,8 +76,16 @@ impl Trip {
|
|||||||
.await;
|
.await;
|
||||||
if same_starting_datetime.len() > 1 {
|
if same_starting_datetime.len() > 1 {
|
||||||
for notify in same_starting_datetime {
|
for notify in same_starting_datetime {
|
||||||
if notify.id != trip_details.id {
|
// don't notify oneself
|
||||||
// notify everyone except oneself
|
if notify.id == trip_details.id {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// don't notify people who have cancelled their trip
|
||||||
|
if notify.cancelled(db) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(trip) = Trip::find_by_trip_details(db, notify.id).await {
|
if let Some(trip) = Trip::find_by_trip_details(db, notify.id).await {
|
||||||
let user = User::find_by_id(db, trip.cox_id as i32).await.unwrap();
|
let user = User::find_by_id(db, trip.cox_id as i32).await.unwrap();
|
||||||
Notification::create(
|
Notification::create(
|
||||||
@ -96,7 +104,6 @@ impl Trip {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn find_by_trip_details(db: &SqlitePool, tripdetails_id: i64) -> Option<Self> {
|
pub async fn find_by_trip_details(db: &SqlitePool, tripdetails_id: i64) -> Option<Self> {
|
||||||
sqlx::query_as!(
|
sqlx::query_as!(
|
||||||
|
@ -94,6 +94,10 @@ WHERE day = ? AND planned_starting_time = ?
|
|||||||
.await.unwrap()
|
.await.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn cancelled(&self, db: &SqlitePool) -> bool {
|
||||||
|
self.max_people == 0
|
||||||
|
}
|
||||||
|
|
||||||
/// This function is called when a person registers to a trip or when the cox changes the
|
/// This function is called when a person registers to a trip or when the cox changes the
|
||||||
/// amount of free places.
|
/// amount of free places.
|
||||||
pub async fn check_free_spaces(&self, db: &SqlitePool) {
|
pub async fn check_free_spaces(&self, db: &SqlitePool) {
|
||||||
@ -102,7 +106,7 @@ WHERE day = ? AND planned_starting_time = ?
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.max_people == 0 {
|
if self.cancelled(db) {
|
||||||
// Cox cancelled event, thus it's probably bad weather. Don't bother with sending
|
// Cox cancelled event, thus it's probably bad weather. Don't bother with sending
|
||||||
// notifications
|
// notifications
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user