summaryrefslogtreecommitdiff
path: root/lib/Travelynx
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2023-07-16 23:01:23 +0200
committerBirte Kristina Friesel <derf@finalrewind.org>2023-07-16 23:01:23 +0200
commit19cd9f7a8d888302d8637af897d407fc34bab522 (patch)
tree00f08bc56704ed8a952fefec9875979f5690b721 /lib/Travelynx
parent49beb0922935b81a152477933a7f7cd03c76a90c (diff)
account: add a list of sent follow requests
Diffstat (limited to 'lib/Travelynx')
-rw-r--r--lib/Travelynx/Command/database.pm19
-rw-r--r--lib/Travelynx/Controller/Account.pm51
-rw-r--r--lib/Travelynx/Model/Users.pm20
3 files changed, 64 insertions, 26 deletions
diff --git a/lib/Travelynx/Command/database.pm b/lib/Travelynx/Command/database.pm
index a0dea45..022614b 100644
--- a/lib/Travelynx/Command/database.pm
+++ b/lib/Travelynx/Command/database.pm
@@ -1761,6 +1761,25 @@ my @migrations = (
}
);
},
+
+ # v42 -> v43
+ # list sent and received follow requests
+ sub {
+ my ($db) = @_;
+ $db->query(
+ qq{
+ alter view follow_requests rename to rx_follow_requests;
+ create view tx_follow_requests as select
+ relations.subject_id as self_id,
+ users.id as id,
+ users.name as name
+ from relations
+ join users on relations.object_id = users.id
+ where predicate = 2;
+ update schema_version set version = 43;
+ }
+ );
+ },
);
# TODO add 'hafas' column to in_transit (and maybe journeys? undo/redo needs something to work with...)
diff --git a/lib/Travelynx/Controller/Account.pm b/lib/Travelynx/Controller/Account.pm
index d7035d8..2664329 100644
--- a/lib/Travelynx/Controller/Account.pm
+++ b/lib/Travelynx/Controller/Account.pm
@@ -547,12 +547,24 @@ sub social_list {
my $kind = $self->stash('kind');
my $user = $self->current_user;
- if ( $kind eq 'follow-requests' ) {
+ if ( $kind eq 'follow-requests-received' ) {
my @follow_reqs
= $self->users->get_follow_requests( uid => $user->{id} );
$self->render(
'social_list',
- type => 'follow-requests',
+ type => 'follow-requests-received',
+ entries => [@follow_reqs],
+ notifications => $user->{notifications},
+ );
+ }
+ elsif ( $kind eq 'follow-requests-sent' ) {
+ my @follow_reqs = $self->users->get_follow_requests(
+ uid => $user->{id},
+ sent => 1
+ );
+ $self->render(
+ 'social_list',
+ type => 'follow-requests-sent',
entries => [@follow_reqs],
notifications => $user->{notifications},
);
@@ -994,10 +1006,10 @@ sub change_name {
return;
}
- # The users table has a unique constraint on the "name" column, so having
- # two users with the same name is not possible. The race condition
- # between the user_name_exists check in is_name_invalid and this
- # change_name call is harmless.
+ # The users table has a unique constraint on the "name" column, so having
+ # two users with the same name is not possible. The race condition
+ # between the user_name_exists check in is_name_invalid and this
+ # change_name call is harmless.
my $success = $self->users->change_name(
uid => $self->current_user->{id},
name => $new_name
@@ -1240,20 +1252,25 @@ sub confirm_mail {
}
sub account {
- my ($self) = @_;
- my $uid = $self->current_user->{id};
- my $follow_requests = $self->users->has_follow_requests( uid => $uid );
- my $followers = $self->users->has_followers( uid => $uid );
- my $following = $self->users->has_followees( uid => $uid );
- my $blocked = $self->users->has_blocked_users( uid => $uid );
+ my ($self) = @_;
+ my $uid = $self->current_user->{id};
+ my $rx_follow_requests = $self->users->has_follow_requests( uid => $uid );
+ my $tx_follow_requests = $self->users->has_follow_requests(
+ uid => $uid,
+ sent => 1
+ );
+ my $followers = $self->users->has_followers( uid => $uid );
+ my $following = $self->users->has_followees( uid => $uid );
+ my $blocked = $self->users->has_blocked_users( uid => $uid );
$self->render(
'account',
- api_token => $self->users->get_api_token( uid => $uid ),
- num_follow_requests => $follow_requests,
- num_followers => $followers,
- num_following => $following,
- num_blocked => $blocked,
+ api_token => $self->users->get_api_token( uid => $uid ),
+ num_rx_follow_requests => $rx_follow_requests,
+ num_tx_follow_requests => $tx_follow_requests,
+ num_followers => $followers,
+ num_following => $following,
+ num_blocked => $blocked,
);
$self->users->mark_seen( uid => $uid );
}
diff --git a/lib/Travelynx/Model/Users.pm b/lib/Travelynx/Model/Users.pm
index 8f1714d..0665f6a 100644
--- a/lib/Travelynx/Model/Users.pm
+++ b/lib/Travelynx/Model/Users.pm
@@ -809,8 +809,8 @@ sub get_relation {
}
return;
- #my $res_h = $db->select( 'relations', ['subject_id', 'predicate'],
- # { subject_id => [$uid, $target], object_id => [$target, $target] } )->hash;
+ #my $res_h = $db->select( 'relations', ['subject_id', 'predicate'],
+ # { subject_id => [$uid, $target], object_id => [$target, $target] } )->hash;
}
sub update_notifications {
@@ -1096,11 +1096,12 @@ sub has_followers {
sub get_follow_requests {
my ( $self, %opt ) = @_;
- my $db = $opt{db} // $self->{pg}->db;
- my $uid = $opt{uid};
+ my $db = $opt{db} // $self->{pg}->db;
+ my $uid = $opt{uid};
+ my $table = $opt{sent} ? 'tx_follow_requests' : 'rx_follow_requests';
my $res
- = $db->select( 'follow_requests', [ 'id', 'name' ], { self_id => $uid } );
+ = $db->select( $table, [ 'id', 'name' ], { self_id => $uid } );
return $res->hashes->each;
}
@@ -1108,11 +1109,12 @@ sub get_follow_requests {
sub has_follow_requests {
my ( $self, %opt ) = @_;
- my $db = $opt{db} // $self->{pg}->db;
- my $uid = $opt{uid};
+ my $db = $opt{db} // $self->{pg}->db;
+ my $uid = $opt{uid};
+ my $table = $opt{sent} ? 'tx_follow_requests' : 'rx_follow_requests';
- return $db->select( 'follow_requests', 'count(*) as count',
- { self_id => $uid } )->hash->{count};
+ return $db->select( $table, 'count(*) as count', { self_id => $uid } )
+ ->hash->{count};
}
sub get_followees {