Files
Plume/src/routes/notifications.rs
T
Baptiste Gelez 8f1ab3485e Add some feedback when performing some actions (#552)
* Add a way to display flash messages

* Make the flash messages look nice

* Add actual feedback messages

* cargo fmt

* Move flash messages to PlumeRocket

And add trait to convert PlumeRocket to BaseContext

* Remove useless lifetime
2019-04-30 11:04:25 +01:00

34 lines
1009 B
Rust

use rocket::response::{Flash, Redirect};
use rocket_i18n::I18n;
use plume_common::utils;
use plume_models::{notifications::Notification, users::User, PlumeRocket};
use routes::{errors::ErrorPage, Page};
use template_utils::{IntoContext, Ructe};
#[get("/notifications?<page>")]
pub fn notifications(
user: User,
page: Option<Page>,
rockets: PlumeRocket,
) -> Result<Ructe, ErrorPage> {
let page = page.unwrap_or_default();
Ok(render!(notifications::index(
&rockets.to_context(),
Notification::page_for_user(&*rockets.conn, &user, page.limits())?,
page.0,
Page::total(Notification::count_for_user(&*rockets.conn, &user)? as i32)
)))
}
#[get("/notifications?<page>", rank = 2)]
pub fn notifications_auth(i18n: I18n, page: Option<Page>) -> Flash<Redirect> {
utils::requires_login(
&i18n!(
i18n.catalog,
"To see your notifications, you need to be logged in"
),
uri!(notifications: page = page),
)
}