From 6331d4f1714a2c4bc912ae7c4f5ea4f3d2a08947 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Thu, 9 Sep 2010 15:43:20 -0500 Subject: [PATCH] added welcome message to found() output --- docs/Empire.pod | 3 +++ lib/Lacuna.pm | 2 +- lib/Lacuna/DB/Result/Empire.pm | 4 +--- lib/Lacuna/RPC/Empire.pm | 8 ++++++-- lib/Lacuna/Tutorial.pm | 2 +- t/Empire.t | 3 ++- 6 files changed, 14 insertions(+), 8 deletions(-) diff --git a/docs/Empire.pod b/docs/Empire.pod index 4112cc2e..cd9c69c0 100644 --- a/docs/Empire.pod +++ b/docs/Empire.pod @@ -126,9 +126,12 @@ Set up an empire on it's new home world. Once this method is called, the species { "session_id" : "id-goes-here", + "welcome_message_id" : "id-goes-here", "status" : { ... } } +The C is a message id for a message in the inbox, that starts the tutorial. This is provided so the user can be prompted to read that message right away. + =head3 empire_id The empire to found. diff --git a/lib/Lacuna.pm b/lib/Lacuna.pm index 5e3dae92..6a7a69f0 100644 --- a/lib/Lacuna.pm +++ b/lib/Lacuna.pm @@ -7,7 +7,7 @@ use Config::JSON; useall __PACKAGE__; -our $VERSION = 2.1801; +our $VERSION = 2.1802; my $config = Config::JSON->new('/data/Lacuna-Server/etc/lacuna.conf'); my $db = Lacuna::DB->connect($config->get('db/dsn'),$config->get('db/username'),$config->get('db/password')); diff --git a/lib/Lacuna/DB/Result/Empire.pm b/lib/Lacuna/DB/Result/Empire.pm index ad861c11..ec1972e9 100644 --- a/lib/Lacuna/DB/Result/Empire.pm +++ b/lib/Lacuna/DB/Result/Empire.pm @@ -239,8 +239,6 @@ sub found { # send welcome Lacuna::Tutorial->new(empire=>$self)->start('explore_the_ui'); - - return $self; } sub find_home_planet { @@ -461,7 +459,7 @@ sub add_probe { if ($self->tutorial_stage ne 'turing') { Lacuna::Tutorial->new(empire=>$self)->finish; } - + return $self; } sub next_colony_cost { diff --git a/lib/Lacuna/RPC/Empire.pm b/lib/Lacuna/RPC/Empire.pm index 065ef2b6..606b9755 100644 --- a/lib/Lacuna/RPC/Empire.pm +++ b/lib/Lacuna/RPC/Empire.pm @@ -238,8 +238,12 @@ sub found { unless ($empire->stage eq 'new') { confess [1010, "This empire cannot be founded again.", $empire_id]; } - $empire->found(undef, $invite_code); - return { session_id => $empire->start_session({ api_key => $api_key, request => $plack_request })->id, status => $self->format_status($empire) }; + my $welcome = $empire->found(undef, $invite_code); + return { + session_id => $empire->start_session({ api_key => $api_key, request => $plack_request })->id, + status => $self->format_status($empire), + welcome_message_id => $welcome->id, + }; } sub get_status { diff --git a/lib/Lacuna/Tutorial.pm b/lib/Lacuna/Tutorial.pm index 7aabb691..406c6824 100644 --- a/lib/Lacuna/Tutorial.pm +++ b/lib/Lacuna/Tutorial.pm @@ -32,7 +32,7 @@ sub start { $self->empire->update; if (my $can = $self->can($stage)) { # safely call my $out = $can->($self); - $self->send($out); + return $self->send($out); } } diff --git a/t/Empire.t b/t/Empire.t index b19fff72..1ede4180 100644 --- a/t/Empire.t +++ b/t/Empire.t @@ -1,5 +1,5 @@ use lib '../lib'; -use Test::More tests => 27; +use Test::More tests => 28; use Test::Deep; use Data::Dumper; use 5.010; @@ -56,6 +56,7 @@ is($result->{error}{code}, 1002, 'api key required'); $result = $tester->post('empire', 'found', [$empire_id,'Anonymous']); my $session_id = $result->{result}{session_id}; ok(defined $session_id, 'empire logged in after foundation'); +ok($result->{result}{welcome_message_id}, 'we get a welcome message'); $result = $tester->post('empire', 'logout', [$session_id]); is($result->{result}, 1, 'logout'); -- 2.54.0