X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fchatty;a=blobdiff_plain;f=lib%2FChatty%2FController%2FChat.pm;fp=lib%2FChatty%2FController%2FChat.pm;h=911c127ed95b18229c059b5891e86599a57e9a6d;hp=73fe2744e99c32ecfcfba61b6a222feabad8857c;hb=e26179af9aaf7cae5a0aa68ad87a50e4b1e1aba5;hpb=429699124ffcdd7a426b8db4223602639b9163ee diff --git a/lib/Chatty/Controller/Chat.pm b/lib/Chatty/Controller/Chat.pm index 73fe274..911c127 100644 --- a/lib/Chatty/Controller/Chat.pm +++ b/lib/Chatty/Controller/Chat.pm @@ -7,7 +7,6 @@ BEGIN { extends 'Catalyst::Controller' } #__PACKAGE__->config(namespace => 'room'); use Chatty::Form::RoomCreate; -use Chatty::Form::MessageCreate; has 'roomcreate_form' => ( isa => 'Chatty::Form::RoomCreate', @@ -16,13 +15,6 @@ has 'roomcreate_form' => ( default => sub { Chatty::Form::RoomCreate->new } ); -has 'messagecreate_form' => ( - isa => 'Chatty::Form::MessageCreate', - is => 'rw', - lazy => 1, - default => sub { Chatty::Form::MessageCreate->new } -); - =head1 NAME Chatty::Controller::Chat - Catalyst Controller @@ -100,27 +92,17 @@ sub view :Chained(room) :PathPart('') :Args(1) { $c->stash(room => $c->model('DB::Room')->find($room)); $c->detach('/missing') if !$c->stash->{room}; - $c->stash(messages => [$c->model('DB::Message')->search(room => $room)]); - - $c->stash(form => $self->messagecreate_form); + my $name = $c->user->obj->username; - my $new_message = $c->model('DB::Message')->new_result({ - author => $c->user->obj->id, - room => $c->stash->{room}->id - }); - $self->messagecreate_form->process( - item => $new_message, - params => $c->req->params - ); - - if (!$self->messagecreate_form->is_valid) { - if ($c->req->method eq 'POST') { - $c->stash->{error} = "The form has a validation error. Try again..."; - } + my $msg = $c->req->param('msg'); + if ($msg) { + $c->model('Meteor')->addMessage($room, "$name: $msg"); + $c->stash->{json} = \1; + $c->forward('View::JSON'); return; } - $c->res->redirect($c->uri_for_action('/chat/view', $c->stash->{room}->id)); + $c->model('Meteor')->addMessage($room, "** $name has entered **"); } =head1 AUTHOR