Add a page listing people someone follows (#444)

Nothing exceptional, the layout is the same as the followers page.

Fixes #325
This commit is contained in:
Baptiste Gelez
2019-02-26 13:13:00 +01:00
committed by GitHub
parent 7bac70a483
commit e28371bbe4
24 changed files with 1122 additions and 610 deletions
+23 -1
View File
@@ -568,7 +568,7 @@ impl User {
.map_err(Error::from)
}
pub fn get_following(&self, conn: &Connection) -> Result<Vec<User>> {
pub fn get_followed(&self, conn: &Connection) -> Result<Vec<User>> {
use schema::follows::dsl::*;
let f = follows.filter(follower_id.eq(self.id)).select(following_id);
users::table
@@ -577,6 +577,28 @@ impl User {
.map_err(Error::from)
}
pub fn count_followed(&self, conn: &Connection) -> Result<i64> {
use schema::follows;
follows::table
.filter(follows::follower_id.eq(self.id))
.count()
.get_result(conn)
.map_err(Error::from)
}
pub fn get_followed_page(&self, conn: &Connection, (min, max): (i32, i32)) -> Result<Vec<User>> {
use schema::follows;
let follows = follows::table
.filter(follows::follower_id.eq(self.id))
.select(follows::following_id)
.limit((max - min).into());
users::table
.filter(users::id.eq_any(follows))
.offset(min.into())
.load::<User>(conn)
.map_err(Error::from)
}
pub fn is_followed_by(&self, conn: &Connection, other_id: i32) -> Result<bool> {
use schema::follows;
follows::table