User feed

This commit is contained in:
Bat
2018-09-05 15:21:50 +01:00
parent 36f272b209
commit 1496598a45
4 changed files with 56 additions and 0 deletions
+14
View File
@@ -136,6 +136,20 @@ impl Post {
.expect("Error loading local posts page")
}
/// Give a page of customized user feed, based on a list of followed users
pub fn user_feed_page(conn: &PgConnection, followed: Vec<i32>, (min, max): (i32, i32)) -> Vec<Post> {
use schema::post_authors;
let post_ids = post_authors::table.filter(post_authors::author_id.eq(any(followed)))
.select(post_authors::post_id);
posts::table.order(posts::creation_date.desc())
.filter(posts::id.eq(any(post_ids)))
.offset(min.into())
.limit((max - min).into())
.load::<Post>(conn)
.expect("Error loading user feed page")
}
pub fn get_authors(&self, conn: &PgConnection) -> Vec<User> {
use schema::users;
use schema::post_authors;