Commit 562dd7cc authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

add toot and tweet settings to traewelling checkin

parent 7ef1fe06
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -76,7 +76,9 @@ sub settings {
		$self->traewelling->set_sync(
			uid       => $uid,
			push_sync => $self->param('sync_source') eq 'travelynx' ? 1 : 0,
			pull_sync => $self->param('sync_source') eq 'traewelling' ? 1 : 0
			pull_sync => $self->param('sync_source') eq 'traewelling' ? 1 : 0,
			toot      => $self->param('toot') ? 1 : 0,
			tweet     => $self->param('tweet') ? 1 : 0,
		);
		$self->flash( success => 'traewelling' );
		$self->redirect_to('account');
@@ -94,6 +96,12 @@ sub settings {
	else {
		$self->param( sync_source => 'none' );
	}
	if ( $traewelling->{data}{toot} ) {
		$self->param( toot => 1 );
	}
	if ( $traewelling->{data}{tweet} ) {
		$self->param( tweet => 1 );
	}

	$self->render(
		'traewelling',
+3 −1
Original line number Diff line number Diff line
@@ -286,6 +286,8 @@ sub checkin {
		tripID      => $opt{trip_id},
		start       => q{} . $opt{dep_eva},
		destination => q{} . $opt{arr_eva},
		toot        => $opt{data}{toot} ? \1 : \0,
		tweet       => $opt{data}{tweet} ? \1 : \0,
	};
	my $trip_req = sprintf(
		"tripID=%s&lineName=%s%%20%s&start=%s",
@@ -321,7 +323,7 @@ sub checkin {
				);
				return;
			}
			$self->{log}->debug("... success!");
			$self->{log}->debug( "... success! " . $tx->res->body );

			# As of 2020-10-04, traewelling.de checkins do not yet return
			# "statusId". The patch is present on the develop branch and waiting
+12 −6
Original line number Diff line number Diff line
@@ -183,14 +183,20 @@ sub set_sync {
	my ( $self, %opt ) = @_;

	my $uid = $opt{uid};
	my $push_sync = $opt{push_sync};
	my $pull_sync = $opt{pull_sync};
	my $db  = $opt{db} // $self->{pg}->db;

	$self->{pg}->db->update(
	my $res_h
	  = $db->select( 'traewelling', 'data', { user_id => $uid } )->expand->hash;

	$res_h->{data}{toot}  = $opt{toot};
	$res_h->{data}{tweet} = $opt{tweet};

	$db->update(
		'traewelling',
		{
			push_sync => $push_sync,
			pull_sync => $pull_sync
			push_sync => $opt{push_sync},
			pull_sync => $opt{pull_sync},
			data      => JSON->new->encode( $res_h->{data} ),
		},
		{ user_id => $uid }
	);