diff options
author | Daniel Friesel <derf@finalrewind.org> | 2023-02-27 22:14:54 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2023-02-27 22:14:54 +0100 |
commit | 6d261197e3138c80357ec485749e2089ef6ff96a (patch) | |
tree | 3089879a8863354e6b1cd669caf37bcb8558883a /lib/Travelynx/Model/InTransit.pm | |
parent | fb3878665b38f1e4c2439238c19cba0c9767f721 (diff) |
set visibility per journey (wip)
some odds and ends left to polish, but ready for testing
Diffstat (limited to 'lib/Travelynx/Model/InTransit.pm')
-rw-r--r-- | lib/Travelynx/Model/InTransit.pm | 51 |
1 files changed, 49 insertions, 2 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; |