summaryrefslogtreecommitdiff
path: root/lib/Travelynx/Model/InTransit.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Travelynx/Model/InTransit.pm')
-rw-r--r--lib/Travelynx/Model/InTransit.pm51
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;