Display notifications

This commit is contained in:
Bat 2018-05-13 14:35:55 +01:00
parent 726c2c7e82
commit b91f567777
5 changed files with 43 additions and 1 deletions

View File

@ -67,6 +67,8 @@ fn main() {
routes::instance::configure, routes::instance::configure,
routes::instance::post_config, routes::instance::post_config,
routes::notifications::notifications,
routes::user::me, routes::user::me,
routes::user::details, routes::user::details,
routes::user::followers, routes::user::followers,

View File

@ -1,8 +1,9 @@
use diesel::{self, PgConnection, RunQueryDsl, QueryDsl, ExpressionMethods}; use diesel::{self, PgConnection, RunQueryDsl, QueryDsl, ExpressionMethods};
use models::users::User;
use schema::notifications; use schema::notifications;
#[derive(Queryable, Identifiable)] #[derive(Queryable, Identifiable, Serialize)]
pub struct Notification { pub struct Notification {
pub id: i32, pub id: i32,
pub title: String, pub title: String,
@ -35,4 +36,10 @@ impl Notification {
.expect("Couldn't load notification by ID") .expect("Couldn't load notification by ID")
.into_iter().nth(0) .into_iter().nth(0)
} }
pub fn find_for_user(conn: &PgConnection, user: &User) -> Vec<Notification> {
notifications::table.filter(notifications::user_id.eq(user.id))
.load::<Notification>(conn)
.expect("Couldn't load user notifications")
}
} }

View File

@ -5,6 +5,7 @@ pub mod blogs;
pub mod comments; pub mod comments;
pub mod instance; pub mod instance;
pub mod likes; pub mod likes;
pub mod notifications;
pub mod posts; pub mod posts;
pub mod session; pub mod session;
pub mod user; pub mod user;

View File

@ -0,0 +1,13 @@
use rocket_contrib::Template;
use db_conn::DbConn;
use models::notifications::Notification;
use models::users::User;
#[get("/notifications")]
fn notifications(conn: DbConn, user: User) -> Template {
Template::render("notifications/index", json!({
"account": user,
"notifications": Notification::find_for_user(&*conn, &user)
}))
}

View File

@ -0,0 +1,19 @@
{% extends "base" %}
{% block title %}
Notifications
{% endblock title %}
{% block content %}
<h1>Notifications</h1>
<div>
{% for notification in notifications %}
<div>
<h3><a href="{% if notification.link %}{{ notification.link }}{% else %}#{% endif %}">{{ notification.title }}</h3>
{% if notification.content %}
<p>{{ notification.content }}</p>
{% endif %}
</div>
{% endfor %}
</div>
{% endblock content %}