diff options
Diffstat (limited to 'lib/Travelynx/Model')
-rw-r--r-- | lib/Travelynx/Model/InTransit.pm | 51 | ||||
-rwxr-xr-x | lib/Travelynx/Model/Journeys.pm | 66 | ||||
-rw-r--r-- | lib/Travelynx/Model/Users.pm | 53 |
3 files changed, 160 insertions, 10 deletions
diff --git a/lib/Travelynx/Model/InTransit.pm b/lib/Travelynx/Model/InTransit.pm index d3b6d6b..78fd297 100644 --- a/lib/Travelynx/Model/InTransit.pm +++ b/lib/Travelynx/Model/InTransit.pm @@ -11,6 +11,22 @@ use 5.020; use DateTime; use JSON; +my %visibility_itoa = ( + 100 => 'public', + 80 => 'travelynx', + 60 => 'followers', + 30 => 'unlisted', + 10 => 'private', +); + +my %visibility_atoi = ( + public => 100, + travelynx => 80, + followers => 60, + unlisted => 30, + private => 10, +); + sub new { my ( $class, %opt ) = @_; @@ -117,11 +133,23 @@ sub get { } my $res = $db->select( $table, '*', { user_id => $uid } ); + my $ret; if ( $opt{with_data} ) { - return $res->expand->hash; + $ret = $res->expand->hash; + } + else { + $ret = $res->hash; } - return $res->hash; + + if ( $opt{with_visibility} and $ret ) { + $ret->{visibility_str} + = $ret->{visibility} + ? $visibility_itoa{ $ret->{visibility} } + : 'default'; + } + + return $ret; } sub get_all_active { @@ -449,4 +477,23 @@ sub update_user_data { ); } +sub update_visibility { + my ( $self, %opt ) = @_; + + my $uid = $opt{uid}; + my $db = $opt{db} // $self->{pg}->db; + + my $visibility; + + if ( $opt{visibility} and $visibility_atoi{ $opt{visibility} } ) { + $visibility = $visibility_atoi{ $opt{visibility} }; + } + + $db->update( + 'in_transit', + { visibility => $visibility }, + { user_id => $uid } + ); +} + 1; diff --git a/lib/Travelynx/Model/Journeys.pm b/lib/Travelynx/Model/Journeys.pm index 08d9ff0..a9c6200 100755 --- a/lib/Travelynx/Model/Journeys.pm +++ b/lib/Travelynx/Model/Journeys.pm @@ -15,6 +15,22 @@ use utf8; use DateTime; use JSON; +my %visibility_itoa = ( + 100 => 'public', + 80 => 'travelynx', + 60 => 'followers', + 30 => 'unlisted', + 10 => 'private', +); + +my %visibility_atoi = ( + public => 100, + travelynx => 80, + followers => 60, + unlisted => 30, + private => 10, +); + my @month_name = ( qw(Januar Februar März April Mai Juni Juli August September Oktober November Dezember) @@ -509,7 +525,7 @@ sub get { my @select = ( - qw(journey_id train_type train_line train_no checkin_ts sched_dep_ts real_dep_ts dep_eva dep_ds100 dep_name dep_lat dep_lon checkout_ts sched_arr_ts real_arr_ts arr_eva arr_ds100 arr_name arr_lat arr_lon cancelled edited route messages user_data) + qw(journey_id train_type train_line train_no checkin_ts sched_dep_ts real_dep_ts dep_eva dep_ds100 dep_name dep_lat dep_lon checkout_ts sched_arr_ts real_arr_ts arr_eva arr_ds100 arr_name arr_lat arr_lon cancelled edited route messages user_data visibility) ); my %where = ( user_id => $uid, @@ -548,6 +564,24 @@ sub get { push( @select, 'polyline' ); } + if ( $opt{min_visibility} ) { + if ( $visibility_atoi{ $opt{min_visibility} } ) { + $opt{min_visibility} = $visibility_atoi{ $opt{min_visibility} }; + } + if ( $opt{with_default_visibility} ) { + $where{visibility} = [ + -or => { '=', undef }, + { '>=', $opt{min_visibility} } + ]; + } + else { + $where{visibility} = [ + -and => { '!=', undef }, + { '>=', $opt{min_visibility} } + ]; + } + } + my @travels; my $res = $db->select( 'journeys_str', \@select, \%where, \%order ); @@ -577,8 +611,16 @@ sub get { route => $entry->{route}, edited => $entry->{edited}, user_data => $entry->{user_data}, + visibility => $entry->{visibility}, }; + if ( $opt{with_visibility} ) { + $ref->{visibility_str} + = $ref->{visibility} + ? $visibility_itoa{ $ref->{visibility} } + : 'default'; + } + if ( $opt{with_polyline} ) { $ref->{polyline} = $entry->{polyline}; } @@ -1703,4 +1745,26 @@ sub get_connection_targets { return @destinations; } +sub update_visibility { + my ( $self, %opt ) = @_; + + my $uid = $opt{uid}; + my $db = $opt{db} // $self->{pg}->db; + + my $visibility; + + if ( $opt{visibility} and $visibility_atoi{ $opt{visibility} } ) { + $visibility = $visibility_atoi{ $opt{visibility} }; + } + + $db->update( + 'journeys', + { visibility => $visibility }, + { + user_id => $uid, + id => $opt{id} + } + ); +} + 1; diff --git a/lib/Travelynx/Model/Users.pm b/lib/Travelynx/Model/Users.pm index 8f5ce1f..63cc261 100644 --- a/lib/Travelynx/Model/Users.pm +++ b/lib/Travelynx/Model/Users.pm @@ -11,6 +11,22 @@ use 5.020; use DateTime; use JSON; +my %visibility_itoa = ( + 100 => 'public', + 80 => 'travelynx', + 60 => 'followers', + 30 => 'unlisted', + 10 => 'private', +); + +my %visibility_atoi = ( + public => 100, + travelynx => 80, + followers => 60, + unlisted => 30, + private => 10, +); + my @sb_templates = ( undef, [ 'DBF', 'https://dbf.finalrewind.org/{name}?rt=1#{tt}{tn}' ], @@ -153,7 +169,16 @@ sub get_privacy_by_name { ); if ( my $user = $res->hash ) { - return $user; + return { + id => $user->{id}, + public_level => $user->{public_level}, # todo remove? + default_visibility => $user->{public_level} & 0x7f, + default_visibility_str => + $visibility_itoa{ $user->{public_level} & 0x7f }, + comments_visible => $user->{public_level} & 0x80 ? 1 : 0, + past_visible => ( $user->{public_level} & 0x300 ) >> 8, + past_all => $user->{public_level} & 0x400 ? 1 : 0, + }; } return; } @@ -164,6 +189,14 @@ sub set_privacy { my $uid = $opt{uid}; my $public_level = $opt{level}; + if ( not defined $public_level and defined $opt{default_visibility} ) { + $public_level + = ( $opt{default_visibility} & 0x7f ) + | ( $opt{comments_visible} ? 0x80 : 0x00 ) + | ( ( ( $opt{past_visible} // 0 ) << 8 ) & 0x300 ) + | ( $opt{past_all} ? 0x400 : 0 ); + } + $db->update( 'users', { public_level => $public_level }, { id => $uid } ); } @@ -333,12 +366,18 @@ sub get { )->hash; if ($user) { return { - id => $user->{id}, - name => $user->{name}, - status => $user->{status}, - is_public => $user->{public_level}, - email => $user->{email}, - sb_name => $user->{external_services} + id => $user->{id}, + name => $user->{name}, + status => $user->{status}, + is_public => $user->{public_level}, + default_visibility => $user->{public_level} & 0x7f, + default_visibility_str => + $visibility_itoa{ $user->{public_level} & 0x7f }, + comments_visible => $user->{public_level} & 0x80 ? 1 : 0, + past_visible => ( $user->{public_level} & 0x300 ) >> 8, + past_all => $user->{public_level} & 0x400 ? 1 : 0, + email => $user->{email}, + sb_name => $user->{external_services} ? $sb_templates[ $user->{external_services} & 0x07 ][0] : undef, sb_template => $user->{external_services} |