Display reshares on profile page
This commit is contained in:
parent
94beaaca76
commit
e9cd48ecca
@ -68,6 +68,18 @@ impl Reshare {
|
|||||||
.into_iter().nth(0)
|
.into_iter().nth(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_recents_for_author(conn: &PgConnection, user: &User, limit: i64) -> Vec<Reshare> {
|
||||||
|
reshares::table.filter(reshares::user_id.eq(user.id))
|
||||||
|
.order(reshares::creation_date.desc())
|
||||||
|
.limit(limit)
|
||||||
|
.load::<Reshare>(conn)
|
||||||
|
.expect("Error loading recent reshares for user")
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_post(&self, conn: &PgConnection) -> Option<Post> {
|
||||||
|
Post::get(conn, self.post_id)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn delete(&self, conn: &PgConnection) -> activity::Undo {
|
pub fn delete(&self, conn: &PgConnection) -> activity::Undo {
|
||||||
diesel::delete(self).execute(conn).unwrap();
|
diesel::delete(self).execute(conn).unwrap();
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ use models::{
|
|||||||
follows,
|
follows,
|
||||||
instance::Instance,
|
instance::Instance,
|
||||||
posts::Post,
|
posts::Post,
|
||||||
|
reshares::Reshare,
|
||||||
users::*
|
users::*
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -28,6 +29,7 @@ fn me(user: User) -> Redirect {
|
|||||||
fn details(name: String, conn: DbConn, account: Option<User>) -> Template {
|
fn details(name: String, conn: DbConn, account: Option<User>) -> Template {
|
||||||
let user = User::find_by_fqn(&*conn, name).unwrap();
|
let user = User::find_by_fqn(&*conn, name).unwrap();
|
||||||
let recents = Post::get_recents_for_author(&*conn, &user, 5);
|
let recents = Post::get_recents_for_author(&*conn, &user, 5);
|
||||||
|
let reshares = Reshare::get_recents_for_author(&*conn, &user, 5);
|
||||||
let user_id = user.id.clone();
|
let user_id = user.id.clone();
|
||||||
let n_followers = user.get_followers(&*conn).len();
|
let n_followers = user.get_followers(&*conn).len();
|
||||||
|
|
||||||
@ -47,6 +49,20 @@ fn details(name: String, conn: DbConn, account: Option<User>) -> Template {
|
|||||||
"date": p.creation_date.timestamp()
|
"date": p.creation_date.timestamp()
|
||||||
})
|
})
|
||||||
}).collect::<Vec<serde_json::Value>>(),
|
}).collect::<Vec<serde_json::Value>>(),
|
||||||
|
"reshares": reshares.into_iter().map(|r| {
|
||||||
|
let p = r.get_post(&*conn).unwrap();
|
||||||
|
json!({
|
||||||
|
"post": p,
|
||||||
|
"author": ({
|
||||||
|
let author = &p.get_authors(&*conn)[0];
|
||||||
|
let mut json = serde_json::to_value(author).unwrap();
|
||||||
|
json["fqn"] = serde_json::Value::String(author.get_fqn(&*conn));
|
||||||
|
json
|
||||||
|
}),
|
||||||
|
"url": format!("/~/{}/{}/", p.get_blog(&*conn).actor_id, p.slug),
|
||||||
|
"date": p.creation_date.timestamp()
|
||||||
|
})
|
||||||
|
}).collect::<Vec<serde_json::Value>>(),
|
||||||
"is_self": account.map(|a| a.id == user_id).unwrap_or(false),
|
"is_self": account.map(|a| a.id == user_id).unwrap_or(false),
|
||||||
"n_followers": n_followers
|
"n_followers": n_followers
|
||||||
}))
|
}))
|
||||||
|
@ -37,4 +37,11 @@
|
|||||||
{{ macros::post_card(article=article) }}
|
{{ macros::post_card(article=article) }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<h2>Recently reshared</h2>
|
||||||
|
<div class="cards">
|
||||||
|
{% for article in reshares %}
|
||||||
|
{{ macros::post_card(article=article) }}
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
Loading…
Reference in New Issue
Block a user