summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rwxr-xr-xlib/Travelynx.pm17
-rw-r--r--lib/Travelynx/Command/database.pm74
-rw-r--r--lib/Travelynx/Model/InTransit.pm16
3 files changed, 92 insertions, 15 deletions
diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm
index 0359b7b..7a5f38c 100755
--- a/lib/Travelynx.pm
+++ b/lib/Travelynx.pm
@@ -1467,7 +1467,10 @@ sub startup {
extra_data => $in_transit->{data},
comment => $in_transit->{user_data}{comment},
visibility => $in_transit->{visibility},
- visibility_str => $in_transit->{visibility_str},
+ visibility_str => $in_transit->{visibility_str},
+ effective_visibility => $in_transit->{effective_visibility},
+ effective_visibility_str =>
+ $in_transit->{effective_visibility_str},
};
my $traewelling = $self->traewelling->get(
@@ -1702,6 +1705,9 @@ sub startup {
comment => $latest->{user_data}{comment},
visibility => $latest->{visibility},
visibility_str => $latest->{visibility_str},
+ effective_visibility => $latest->{effective_visibility},
+ effective_visibility_str =>
+ $latest->{effective_visibility_str},
};
}
@@ -1765,13 +1771,8 @@ sub startup {
},
intermediateStops => [],
visibility => {
- level => $status->{visibility}
- // $privacy->{default_visibility},
- desc => (
- $status->{visibility_str} eq 'default'
- ? $privacy->{default_visibility_str}
- : $status->{visibility_str}
- ),
+ level => $status->{effective_visibility},
+ desc => $status->{effective_visibility_str},
}
};
diff --git a/lib/Travelynx/Command/database.pm b/lib/Travelynx/Command/database.pm
index d15330d..b0ce0f5 100644
--- a/lib/Travelynx/Command/database.pm
+++ b/lib/Travelynx/Command/database.pm
@@ -1643,6 +1643,80 @@ my @migrations = (
}
$db->update( 'schema_version', { version => 40 } );
},
+
+ # v40 -> v41
+ # Compute effective visibility in in_transit_str and journeys_str.
+ sub {
+ my ($db) = @_;
+ $db->query(
+ qq{
+ drop view in_transit_str;
+ drop view journeys_str;
+ create view in_transit_str as select
+ user_id,
+ train_type, train_line, train_no, train_id,
+ extract(epoch from checkin_time) as checkin_ts,
+ extract(epoch from sched_departure) as sched_dep_ts,
+ extract(epoch from real_departure) as real_dep_ts,
+ checkin_station_id as dep_eva,
+ dep_station.ds100 as dep_ds100,
+ dep_station.name as dep_name,
+ dep_station.lat as dep_lat,
+ dep_station.lon as dep_lon,
+ extract(epoch from checkout_time) as checkout_ts,
+ extract(epoch from sched_arrival) as sched_arr_ts,
+ extract(epoch from real_arrival) as real_arr_ts,
+ checkout_station_id as arr_eva,
+ arr_station.ds100 as arr_ds100,
+ arr_station.name as arr_name,
+ arr_station.lat as arr_lat,
+ arr_station.lon as arr_lon,
+ polyline_id,
+ polylines.polyline as polyline,
+ visibility,
+ coalesce(visibility, users.public_level & 127) as effective_visibility,
+ cancelled, route, messages, user_data,
+ dep_platform, arr_platform, data
+ from in_transit
+ left join polylines on polylines.id = polyline_id
+ left join users on users.id = user_id
+ left join stations as dep_station on checkin_station_id = dep_station.eva
+ left join stations as arr_station on checkout_station_id = arr_station.eva
+ ;
+ create view journeys_str as select
+ journeys.id as journey_id, user_id,
+ train_type, train_line, train_no, train_id,
+ extract(epoch from checkin_time) as checkin_ts,
+ extract(epoch from sched_departure) as sched_dep_ts,
+ extract(epoch from real_departure) as real_dep_ts,
+ checkin_station_id as dep_eva,
+ dep_station.ds100 as dep_ds100,
+ dep_station.name as dep_name,
+ dep_station.lat as dep_lat,
+ dep_station.lon as dep_lon,
+ extract(epoch from checkout_time) as checkout_ts,
+ extract(epoch from sched_arrival) as sched_arr_ts,
+ extract(epoch from real_arrival) as real_arr_ts,
+ checkout_station_id as arr_eva,
+ arr_station.ds100 as arr_ds100,
+ arr_station.name as arr_name,
+ arr_station.lat as arr_lat,
+ arr_station.lon as arr_lon,
+ polylines.polyline as polyline,
+ visibility,
+ coalesce(visibility, users.public_level & 127) as effective_visibility,
+ cancelled, edited, route, messages, user_data,
+ dep_platform, arr_platform
+ from journeys
+ left join polylines on polylines.id = polyline_id
+ left join users on users.id = user_id
+ left join stations as dep_station on checkin_station_id = dep_station.eva
+ left join stations as arr_station on checkout_station_id = arr_station.eva
+ ;
+ update schema_version set version = 41;
+ }
+ );
+ },
);
# TODO add 'hafas' column to in_transit (and maybe journeys? undo/redo needs something to work with...)
diff --git a/lib/Travelynx/Model/InTransit.pm b/lib/Travelynx/Model/InTransit.pm
index 2848e8e..ca3e570 100644
--- a/lib/Travelynx/Model/InTransit.pm
+++ b/lib/Travelynx/Model/InTransit.pm
@@ -147,6 +147,8 @@ sub get {
= $ret->{visibility}
? $visibility_itoa{ $ret->{visibility} }
: 'default';
+ $ret->{effective_visibility_str}
+ = $visibility_itoa{ $ret->{effective_visibility} };
}
return $ret;
@@ -331,13 +333,13 @@ sub unset_arrival_data {
sub update_departure {
my ( $self, %opt ) = @_;
- my $uid = $opt{uid};
- my $db = $opt{db} // $self->{pg}->db;
+ my $uid = $opt{uid};
+ my $db = $opt{db} // $self->{pg}->db;
my $dep_eva = $opt{dep_eva};
my $arr_eva = $opt{arr_eva};
- my $train = $opt{train};
- my $route = $opt{route};
- my $json = JSON->new;
+ my $train = $opt{train};
+ my $route = $opt{route};
+ my $json = JSON->new;
$route = $self->_merge_old_route(
db => $db,
@@ -359,8 +361,8 @@ sub update_departure {
),
},
{
- user_id => $uid,
- train_no => $train->train_no,
+ user_id => $uid,
+ train_no => $train->train_no,
checkin_station_id => $dep_eva,
checkout_station_id => $arr_eva,
}