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

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

8
plume.md Normal file
View File

@ -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.

View File

@ -18,11 +18,12 @@
<a class="inline-block button" href="{{ user.ap_url }}">{{ "Open on {{ instance_url }}" | _(instance_url=instance_url) }}</a>
{% endif %}
{% if not is_self and account %}
{% set not_self = not is_self %}
{% if not_self and (account is defined) %}
{% if follows %}
<a href="follow/" class="inline-block button">{{ "Follow" | _ }}</a>
{% else %}
<a href="follow/" class="inline-block button">{{ "Unfollow" | _ }}</a>
{% else %}
<a href="follow/" class="inline-block button">{{ "Follow" | _ }}</a>
{% endif %}
{% endif %}
</div>