diff --git a/src/models/posts.rs b/src/models/posts.rs index dcb94837..cb3b4e3c 100644 --- a/src/models/posts.rs +++ b/src/models/posts.rs @@ -17,6 +17,7 @@ use models::{ blogs::Blog, likes::Like, post_authors::PostAuthor, + reshares::Reshare, users::User }; use schema::posts; @@ -127,6 +128,13 @@ impl Post { .expect("Couldn't load likes associted to post") } + pub fn get_reshares(&self, conn: &PgConnection) -> Vec { + use schema::reshares; + reshares::table.filter(reshares::post_id.eq(self.id)) + .load::(conn) + .expect("Couldn't load reshares associted to post") + } + pub fn update_ap_url(&self, conn: &PgConnection) { if self.ap_url.len() == 0 { diesel::update(self) diff --git a/src/routes/posts.rs b/src/routes/posts.rs index e213c869..53edda5c 100644 --- a/src/routes/posts.rs +++ b/src/routes/posts.rs @@ -39,6 +39,8 @@ fn details(blog: String, slug: String, conn: DbConn, user: Option) -> Temp }).collect::>(), "n_likes": post.get_likes(&*conn).len(), "has_liked": user.clone().map(|u| u.has_liked(&*conn, &post)).unwrap_or(false), + "n_reshares": post.get_reshares(&*conn).len(), + "has_reshared": user.clone().map(|u| u.has_reshared(&*conn, &post)).unwrap_or(false), "account": user, "date": &post.creation_date.timestamp() })) diff --git a/templates/posts/details.tera b/templates/posts/details.tera index eeacafb9..5c658d37 100644 --- a/templates/posts/details.tera +++ b/templates/posts/details.tera @@ -33,6 +33,17 @@ Add yours {% endif %} + +

+ {{ n_reshares }} reshare{{ n_reshares | pluralize }} +

+ + {% if has_reshared %} + I don't want to reshare this anymore + {% else %} + Reshare + {% endif %} +

Comments