Add a button to reshare

This commit is contained in:
Bat 2018-05-19 10:57:39 +01:00
parent 63eb1a7e98
commit 9b98a45f2e
3 changed files with 21 additions and 0 deletions

View File

@ -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<Reshare> {
use schema::reshares;
reshares::table.filter(reshares::post_id.eq(self.id))
.load::<Reshare>(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)

View File

@ -39,6 +39,8 @@ fn details(blog: String, slug: String, conn: DbConn, user: Option<User>) -> Temp
}).collect::<Vec<serde_json::Value>>(),
"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()
}))

View File

@ -33,6 +33,17 @@
Add yours
{% endif %}
</a>
<p>
{{ n_reshares }} reshare{{ n_reshares | pluralize }}
</p>
<a class="button" href="reshare">
{% if has_reshared %}
I don't want to reshare this anymore
{% else %}
Reshare
{% endif %}
</a>
</div>
<h2>Comments</h2>