diff --git a/lib/Synergy/Reactor/Vestaboard.pm b/lib/Synergy/Reactor/Vestaboard.pm index aaf7e9a2..d41286cf 100644 --- a/lib/Synergy/Reactor/Vestaboard.pm +++ b/lib/Synergy/Reactor/Vestaboard.pm @@ -50,6 +50,10 @@ has board_admins => ( }, ); +has secret_url_component => ( + is => 'ro', +); + sub listener_specs { return ( { @@ -260,6 +264,7 @@ sub state ($self) { return { user => $self->_user_state, lock => $self->_lock_state, + current_characters => $self->_current_characters, }; } @@ -285,6 +290,12 @@ has _lock_state => ( default => sub { {} }, ); +has _current_characters => ( + is => 'ro', + writer => '_set_current_characters', + default => sub { [ [], [], [], [], [], [] ] }, +); + sub current_lock ($self) { my $lock = $self->_lock_state; @@ -311,10 +322,14 @@ after register_with_hub => sub ($self, @) { if (my $state = $self->fetch_state) { $self->_set_user_state($state->{user}); $self->_set_lock_state($state->{lock}); + $self->_set_current_characters($state->{current_characters}) + if $self->_current_characters; } $self->_setup_asset_servers; + $self->_setup_content_server if $self->secret_url_component; + return; }; @@ -348,6 +363,26 @@ sub _setup_asset_servers ($self) { return; } +sub _setup_content_server ($self) { + my $secret = $self->secret_url_component; + + my $base = $self->http_path; + $base =~ s{/\z}{}; + my $path = "${base}/$secret"; + + $self->hub->server->register_path($path, sub ($env) { + return [ + 200, + [ + 'Content-Type', 'application/json', + ], + [ JSON::MaybeXS->new->encode($self->_current_characters) ], + ]; + }); + + return; +} + sub handle_vesta_lock ($self, $event) { $event->mark_handled; @@ -687,6 +722,13 @@ sub _pay_to_post_payload ($self, $event, $user, $payload) { expires_at => int(time + ($self->token_regen_period / 2)), }); + if ($payload->{characters}) { + # We might have "text" which we'll ignore for now. Later, we can make + # the text-posting command build characters locally instead of using + # the text-posting Vestaboard API. -- rjbs, 2021-09-04 + $self->_set_current_characters($payload->{characters}); + } + $self->save_state; return Future->done; })