Skip to content

Commit

Permalink
Profile: Add JSON renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
derf committed May 31, 2024
1 parent 5a72c60 commit 7b85844
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 29 deletions.
3 changes: 2 additions & 1 deletion lib/Travelynx.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2422,7 +2422,8 @@ sub startup {
->to( 'profile#user_status', format => undef );
$r->get('/ajax/status/#name')->to('profile#status_card');
$r->get('/ajax/status/:name/:ts')->to('profile#status_card');
$r->get('/p/:name')->to('profile#profile');
$r->get( '/p/:name' => [ format => [ 'html', 'json' ] ] )
->to( 'profile#profile', format => undef );
$r->get( '/p/:name/j/:id' => 'public_journey' )
->to('profile#journey_details');
$r->get('/.well-known/webfinger')->to('account#webfinger');
Expand Down
68 changes: 40 additions & 28 deletions lib/Travelynx/Controller/Profile.pm
Original file line number Diff line number Diff line change
Expand Up @@ -152,34 +152,46 @@ sub profile {
@journeys = $self->journeys->get(%opt);
}

$self->render(
'profile',
title => "travelynx: $name",
name => $name,
uid => $user->{id},
privacy => $user,
bio => $profile->{bio}{html},
metadata => $profile->{metadata},
is_self => $is_self,
following => ( $relation and $relation eq 'follows' ) ? 1 : 0,
follow_requested => ( $relation and $relation eq 'requests_follow' )
? 1
: 0,
can_follow => ( $my_user and $user->{accept_follows} and not $relation )
? 1
: 0,
can_request_follow =>
( $my_user and $user->{accept_follow_requests} and not $relation )
? 1
: 0,
follows_me => ( $inverse_relation and $inverse_relation eq 'follows' )
? 1
: 0,
follow_reqs_me =>
( $inverse_relation and $inverse_relation eq 'requests_follow' ) ? 1
: 0,
journey => $status,
journeys => [@journeys],
$self->respond_to(
json => {
json => {
name => $name,
uid => $user->{id},
bio => $profile->{bio}{html},
metadata => $profile->{metadata},
journeys => [@journeys],
}
},
any => {
template => 'profile',
title => "travelynx: $name",
name => $name,
uid => $user->{id},
privacy => $user,
bio => $profile->{bio}{html},
metadata => $profile->{metadata},
is_self => $is_self,
following => ( $relation and $relation eq 'follows' ) ? 1 : 0,
follow_requested => ( $relation and $relation eq 'requests_follow' )
? 1
: 0,
can_follow =>
( $my_user and $user->{accept_follows} and not $relation ) ? 1
: 0,
can_request_follow => (
$my_user and $user->{accept_follow_requests} and not $relation
) ? 1
: 0,
follows_me =>
( $inverse_relation and $inverse_relation eq 'follows' ) ? 1
: 0,
follow_reqs_me => (
$inverse_relation and $inverse_relation eq 'requests_follow'
) ? 1
: 0,
journey => $status,
journeys => [@journeys],
}
);
}

Expand Down

0 comments on commit 7b85844

Please sign in to comment.