summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2023-02-15 20:01:43 +0100
committerDaniel Friesel <derf@finalrewind.org>2023-02-15 20:01:43 +0100
commit978c7b03c2a333eb48b9d223c3a010a35211d1ac (patch)
tree058e0158dbc9f23f2ae21d2a2f8b76d8239a4ffe /lib
parent1e1c71cfd876b75ead06b019eabe41a01d0eb972 (diff)
journey: add share button
Diffstat (limited to 'lib')
-rwxr-xr-xlib/Travelynx.pm3
-rwxr-xr-xlib/Travelynx/Controller/Traveling.pm39
2 files changed, 37 insertions, 5 deletions
diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm
index c4f6bca..9a9617d 100755
--- a/lib/Travelynx.pm
+++ b/lib/Travelynx.pm
@@ -2155,7 +2155,8 @@ sub startup {
$r->get('/ajax/status/#name')->to('traveling#public_status_card');
$r->get('/ajax/status/:name/:ts')->to('traveling#public_status_card');
$r->get('/p/:name')->to('traveling#public_profile');
- $r->get('/p/:name/j/:id')->to('traveling#public_journey_details');
+ $r->get( '/p/:name/j/:id' => 'public_journey' )
+ ->to('traveling#public_journey_details');
$r->get('/.well-known/webfinger')->to('account#webfinger');
$r->post('/api/v1/import')->to('api#import_v1');
$r->post('/api/v1/travel')->to('api#travel_v1');
diff --git a/lib/Travelynx/Controller/Traveling.pm b/lib/Travelynx/Controller/Traveling.pm
index 80758f3..dd247f3 100755
--- a/lib/Travelynx/Controller/Traveling.pm
+++ b/lib/Travelynx/Controller/Traveling.pm
@@ -1677,7 +1677,8 @@ sub journey_details {
my ($self) = @_;
my $journey_id = $self->stash('id');
- my $uid = $self->current_user->{id};
+ my $user = $self->current_user;
+ my $uid = $user->{id};
$self->param( journey_id => $journey_id );
@@ -1704,11 +1705,41 @@ sub journey_details {
journeys => [$journey],
include_manual => 1,
);
+ my $share_text;
+ my $with_share = $user->{is_public} & 0x40 ? 1 : 0;
+ if ( not $with_share and $user->{is_public} & 0x20 ) {
+ my $month_ago = DateTime->now( time_zone => 'Europe/Berlin' )
+ ->subtract( weeks => 4 )->epoch;
+ $with_share = $journey->{rt_dep_ts} > $month_ago ? 1 : 0;
+ }
+
+ if ($with_share) {
+ my $delay = 'pünktlich ';
+ if ( $journey->{rt_arrival} != $journey->{sched_arrival} ) {
+ $delay = sprintf(
+ 'mit %+d ',
+ (
+ $journey->{rt_arrival}->epoch
+ - $journey->{sched_arrival}->epoch
+ ) / 60
+ );
+ }
+ $share_text
+ = $journey->{km_route}
+ ? sprintf( '%.0f km', $journey->{km_route} )
+ : 'Fahrt';
+ $share_text .= sprintf( ' mit %s %s – Ankunft %sum %s',
+ $journey->{type}, $journey->{no},
+ $delay, $journey->{rt_arrival}->strftime('%H:%M') );
+ }
+
$self->render(
'journey',
- error => undef,
- journey => $journey,
- with_map => 1,
+ error => undef,
+ journey => $journey,
+ with_map => 1,
+ with_share => $with_share,
+ share_text => $share_text,
%{$map_data},
);
}