From fef9ebe0b20623c4e21cf720ea379338e6ef978e Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Tue, 18 Jul 2023 15:47:45 +0200 Subject: followee list: show if accounts are following back --- lib/Travelynx/Command/database.pm | 23 +++++++++++++++++++++++ lib/Travelynx/Model/Users.pm | 22 ++++++++++++++++++++-- templates/social_list.html.ep | 10 +++++++++- 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/lib/Travelynx/Command/database.pm b/lib/Travelynx/Command/database.pm index 022614b..a47f2ce 100644 --- a/lib/Travelynx/Command/database.pm +++ b/lib/Travelynx/Command/database.pm @@ -1780,6 +1780,29 @@ my @migrations = ( } ); }, + + # v43 -> v44 + # show inverse relation in followees as well + sub { + my ($db) = @_; + $db->query( + qq{ + drop view followees; + create view followees as select + relations.subject_id as self_id, + users.id as id, + users.name as name, + r2.predicate as inverse_predicate + from relations + join users on relations.object_id = users.id + left join relations as r2 + on relations.subject_id = r2.object_id + and relations.object_id = r2.subject_id + where relations.predicate = 1; + update schema_version set version = 44; + } + ); + }, ); # TODO add 'hafas' column to in_transit (and maybe journeys? undo/redo needs something to work with...) diff --git a/lib/Travelynx/Model/Users.pm b/lib/Travelynx/Model/Users.pm index 0665f6a..c51e612 100644 --- a/lib/Travelynx/Model/Users.pm +++ b/lib/Travelynx/Model/Users.pm @@ -1123,9 +1123,27 @@ sub get_followees { my $db = $opt{db} // $self->{pg}->db; my $uid = $opt{uid}; - my $res = $db->select( 'followees', [ 'id', 'name' ], { self_id => $uid } ); + my $res = $db->select( + 'followees', + [ 'id', 'name', 'inverse_predicate' ], + { self_id => $uid } + ); - return $res->hashes->each; + my @ret; + while ( my $row = $res->hash ) { + push( + @ret, + { + id => $row->{id}, + name => $row->{name}, + following_back => ( + $row->{inverse_predicate} + and $row->{inverse_predicate} == $predicate_atoi{follows} + ) ? 1 : 0, + } + ); + } + return @ret; } sub has_followees { diff --git a/templates/social_list.html.ep b/templates/social_list.html.ep index 1a3e441..ef47636 100644 --- a/templates/social_list.html.ep +++ b/templates/social_list.html.ep @@ -130,7 +130,10 @@
-
+
+ group
Folgt dir +
+
remove
Nicht mehr folgen
@@ -230,6 +233,11 @@ % } % elsif ($type eq 'follows') { + + % if ($entry->{following_back}) { + group + % } +