Fix the behavior of the follow button

There was a bug in Tera and in the User::is_following function.

Fix #146
This commit is contained in:
Bat
2018-07-20 17:51:32 +02:00
parent e581ef7d09
commit b0e75f4d63
3 changed files with 23 additions and 4 deletions
+11 -1
View File
@@ -281,7 +281,7 @@ impl User {
users::table.filter(users::id.eq(any(follows))).load::<User>(conn).unwrap()
}
pub fn is_following(&self, conn: &PgConnection, other_id: i32) -> bool {
pub fn is_followed_by(&self, conn: &PgConnection, other_id: i32) -> bool {
use schema::follows;
follows::table
.filter(follows::follower_id.eq(other_id))
@@ -291,6 +291,16 @@ impl User {
.len() > 0
}
pub fn is_following(&self, conn: &PgConnection, other_id: i32) -> bool {
use schema::follows;
follows::table
.filter(follows::follower_id.eq(self.id))
.filter(follows::following_id.eq(other_id))
.load::<Follow>(conn)
.expect("Couldn't load follow relationship")
.len() > 0
}
pub fn has_liked(&self, conn: &PgConnection, post: &Post) -> bool {
use schema::likes;
likes::table