Add a button to reshare
This commit is contained in:
parent
63eb1a7e98
commit
9b98a45f2e
@ -17,6 +17,7 @@ use models::{
|
|||||||
blogs::Blog,
|
blogs::Blog,
|
||||||
likes::Like,
|
likes::Like,
|
||||||
post_authors::PostAuthor,
|
post_authors::PostAuthor,
|
||||||
|
reshares::Reshare,
|
||||||
users::User
|
users::User
|
||||||
};
|
};
|
||||||
use schema::posts;
|
use schema::posts;
|
||||||
@ -127,6 +128,13 @@ impl Post {
|
|||||||
.expect("Couldn't load likes associted to 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) {
|
pub fn update_ap_url(&self, conn: &PgConnection) {
|
||||||
if self.ap_url.len() == 0 {
|
if self.ap_url.len() == 0 {
|
||||||
diesel::update(self)
|
diesel::update(self)
|
||||||
|
@ -39,6 +39,8 @@ fn details(blog: String, slug: String, conn: DbConn, user: Option<User>) -> Temp
|
|||||||
}).collect::<Vec<serde_json::Value>>(),
|
}).collect::<Vec<serde_json::Value>>(),
|
||||||
"n_likes": post.get_likes(&*conn).len(),
|
"n_likes": post.get_likes(&*conn).len(),
|
||||||
"has_liked": user.clone().map(|u| u.has_liked(&*conn, &post)).unwrap_or(false),
|
"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,
|
"account": user,
|
||||||
"date": &post.creation_date.timestamp()
|
"date": &post.creation_date.timestamp()
|
||||||
}))
|
}))
|
||||||
|
@ -33,6 +33,17 @@
|
|||||||
Add yours
|
Add yours
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</a>
|
</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>
|
</div>
|
||||||
|
|
||||||
<h2>Comments</h2>
|
<h2>Comments</h2>
|
||||||
|
Loading…
Reference in New Issue
Block a user