From b0e75f4d63364333aae2185388b632649d11bb6f Mon Sep 17 00:00:00 2001 From: Bat Date: Fri, 20 Jul 2018 17:51:32 +0200 Subject: [PATCH] Fix the behavior of the follow button There was a bug in Tera and in the User::is_following function. Fix #146 --- plume-models/src/users.rs | 12 +++++++++++- plume.md | 8 ++++++++ templates/users/header.html.tera | 7 ++++--- 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 plume.md diff --git a/plume-models/src/users.rs b/plume-models/src/users.rs index e038f107..c43b15e8 100644 --- a/plume-models/src/users.rs +++ b/plume-models/src/users.rs @@ -281,7 +281,7 @@ impl User { users::table.filter(users::id.eq(any(follows))).load::(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::(conn) + .expect("Couldn't load follow relationship") + .len() > 0 + } + pub fn has_liked(&self, conn: &PgConnection, post: &Post) -> bool { use schema::likes; likes::table diff --git a/plume.md b/plume.md new file mode 100644 index 00000000..687307f5 --- /dev/null +++ b/plume.md @@ -0,0 +1,8 @@ +Page de présentation Plume + +Plume +Moteur de blog décentralisé. + +Les auteurs peuvent gérer différents blogs au sein d'un même site. + +Les articles sont également visibles sur d'autres sites Plume et vous pouvez interagir avec eux directement depuis d'autres plateformes telles que Mastodon. diff --git a/templates/users/header.html.tera b/templates/users/header.html.tera index c9e1797c..53864f7c 100644 --- a/templates/users/header.html.tera +++ b/templates/users/header.html.tera @@ -18,11 +18,12 @@ {{ "Open on {{ instance_url }}" | _(instance_url=instance_url) }} {% endif %} - {% if not is_self and account %} + {% set not_self = not is_self %} + {% if not_self and (account is defined) %} {% if follows %} - {{ "Follow" | _ }} - {% else %} {{ "Unfollow" | _ }} + {% else %} + {{ "Follow" | _ }} {% endif %} {% endif %}