current_room INTEGER REFERENCES room(id)
);
-CREATE TABLE message (
- id INTEGER PRIMARY KEY,
- posted TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
- author INTEGER REFERENCES account(id),
- room INTEGER REFERENCES room(id),
- content TEXT
-);
-
-INSERT INTO account (username, password) VALUES ('chaz', 'mypass');
-INSERT INTO account (username, password) VALUES ('jdoe', 'foobar');
-
#__PACKAGE__->config(namespace => 'room');
use Chatty::Form::RoomCreate;
-use Chatty::Form::MessageCreate;
has 'roomcreate_form' => (
isa => 'Chatty::Form::RoomCreate',
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
$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
+++ /dev/null
-package Chatty::Form::MessageCreate;
-
-use HTML::FormHandler::Moose;
-extends 'HTML::FormHandler::Model::DBIC';
-use namespace::autoclean;
-
-has '+item_class' => (default => 'Message');
-
-has_field 'content' => (input_class => 'validate[required]', label => 'Message', required => 1);
-has_field 'submit' => (type => 'Submit', value => 'Create');
-
-__PACKAGE__->meta->make_immutable;
-1;
=head1 GENERATED BY
-Catalyst::Helper::Model::DBIC::Schema - 0.55
+Catalyst::Helper::Model::DBIC::Schema - 0.59
=head1 AUTHOR
+use utf8;
package Chatty::Schema;
# Created by DBIx::Class::Schema::Loader
# DO NOT MODIFY THE FIRST PART OF THIS FILE
use Moose;
-use namespace::autoclean;
+use MooseX::MarkAsMethods autoclean => 1;
extends 'DBIx::Class::Schema';
__PACKAGE__->load_namespaces;
-# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-10-12 22:19:43
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:cnsy0B+9E32Gp6UQcsNpuA
+# Created by DBIx::Class::Schema::Loader v0.07015 @ 2012-01-03 16:46:04
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Kti71GT2ETr1GjBJljQ1Zg
# You can replace this text with custom code or comments, and it will be preserved on regeneration
+use utf8;
package Chatty::Schema::Result::Account;
# Created by DBIx::Class::Schema::Loader
# DO NOT MODIFY THE FIRST PART OF THIS FILE
+=head1 NAME
+
+Chatty::Schema::Result::Account
+
+=cut
+
use strict;
use warnings;
use Moose;
use MooseX::NonMoose;
-use namespace::autoclean;
+use MooseX::MarkAsMethods autoclean => 1;
extends 'DBIx::Class::Core';
-__PACKAGE__->load_components("InflateColumn::DateTime", "TimeStamp");
+=head1 COMPONENTS LOADED
-=head1 NAME
+=over 4
-Chatty::Schema::Result::Account
+=item * L<DBIx::Class::InflateColumn::DateTime>
+
+=back
+
+=cut
+
+__PACKAGE__->load_components("InflateColumn::DateTime");
+
+=head1 TABLE: C<account>
=cut
is_auto_increment: 1
is_nullable: 0
-=head2 email
-
- data_type: 'text'
- is_nullable: 1
-
=head2 username
data_type: 'text'
__PACKAGE__->add_columns(
"id",
{ data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
- "email",
- { data_type => "text", is_nullable => 1 },
"username",
{ data_type => "text", is_nullable => 1 },
"password",
"current_room",
{ data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
);
+
+=head1 PRIMARY KEY
+
+=over 4
+
+=item * L</id>
+
+=back
+
+=cut
+
__PACKAGE__->set_primary_key("id");
+
+=head1 UNIQUE CONSTRAINTS
+
+=head2 C<username_unique>
+
+=over 4
+
+=item * L</username>
+
+=back
+
+=cut
+
__PACKAGE__->add_unique_constraint("username_unique", ["username"]);
=head1 RELATIONS
},
);
-=head2 messages
-
-Type: has_many
-
-Related object: L<Chatty::Schema::Result::Message>
-
-=cut
-
-__PACKAGE__->has_many(
- "messages",
- "Chatty::Schema::Result::Message",
- { "foreign.author" => "self.id" },
- { cascade_copy => 0, cascade_delete => 0 },
-);
-
-# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-10-17 20:21:50
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:jbeLiaDPsjHNHj5O11tPFA
+# Created by DBIx::Class::Schema::Loader v0.07015 @ 2012-01-03 16:58:35
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:vESFaWXuN0WYXW2Y18BfRg
# You can replace this text with custom code or comments, and it will be preserved on regeneration
+++ /dev/null
-package Chatty::Schema::Result::Message;
-
-# Created by DBIx::Class::Schema::Loader
-# DO NOT MODIFY THE FIRST PART OF THIS FILE
-
-use strict;
-use warnings;
-
-use Moose;
-use MooseX::NonMoose;
-use namespace::autoclean;
-extends 'DBIx::Class::Core';
-
-__PACKAGE__->load_components("InflateColumn::DateTime", "TimeStamp");
-
-=head1 NAME
-
-Chatty::Schema::Result::Message
-
-=cut
-
-__PACKAGE__->table("message");
-
-=head1 ACCESSORS
-
-=head2 id
-
- data_type: 'integer'
- is_auto_increment: 1
- is_nullable: 0
-
-=head2 posted
-
- data_type: 'timestamp'
- default_value: current_timestamp
- is_nullable: 1
-
-=head2 author
-
- data_type: 'integer'
- is_foreign_key: 1
- is_nullable: 1
-
-=head2 room
-
- data_type: 'integer'
- is_foreign_key: 1
- is_nullable: 1
-
-=head2 content
-
- data_type: 'text'
- is_nullable: 1
-
-=cut
-
-__PACKAGE__->add_columns(
- "id",
- { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
- "posted",
- {
- data_type => "timestamp",
- default_value => \"current_timestamp",
- is_nullable => 1,
- },
- "author",
- { data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
- "room",
- { data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
- "content",
- { data_type => "text", is_nullable => 1 },
-);
-__PACKAGE__->set_primary_key("id");
-
-=head1 RELATIONS
-
-=head2 room
-
-Type: belongs_to
-
-Related object: L<Chatty::Schema::Result::Room>
-
-=cut
-
-__PACKAGE__->belongs_to(
- "room",
- "Chatty::Schema::Result::Room",
- { id => "room" },
- {
- is_deferrable => 1,
- join_type => "LEFT",
- on_delete => "CASCADE",
- on_update => "CASCADE",
- },
-);
-
-=head2 author
-
-Type: belongs_to
-
-Related object: L<Chatty::Schema::Result::Account>
-
-=cut
-
-__PACKAGE__->belongs_to(
- "author",
- "Chatty::Schema::Result::Account",
- { id => "author" },
- {
- is_deferrable => 1,
- join_type => "LEFT",
- on_delete => "CASCADE",
- on_update => "CASCADE",
- },
-);
-
-
-# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-10-17 20:21:50
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:R28y3tHGM5FZTILUAO/0XA
-
-
-# You can replace this text with custom code or comments, and it will be preserved on regeneration
-__PACKAGE__->meta->make_immutable;
-1;
+use utf8;
package Chatty::Schema::Result::Room;
# Created by DBIx::Class::Schema::Loader
# DO NOT MODIFY THE FIRST PART OF THIS FILE
+=head1 NAME
+
+Chatty::Schema::Result::Room
+
+=cut
+
use strict;
use warnings;
use Moose;
use MooseX::NonMoose;
-use namespace::autoclean;
+use MooseX::MarkAsMethods autoclean => 1;
extends 'DBIx::Class::Core';
-__PACKAGE__->load_components("InflateColumn::DateTime", "TimeStamp");
+=head1 COMPONENTS LOADED
-=head1 NAME
+=over 4
-Chatty::Schema::Result::Room
+=item * L<DBIx::Class::InflateColumn::DateTime>
+
+=back
+
+=cut
+
+__PACKAGE__->load_components("InflateColumn::DateTime");
+
+=head1 TABLE: C<room>
=cut
is_nullable => 1,
},
);
+
+=head1 PRIMARY KEY
+
+=over 4
+
+=item * L</id>
+
+=back
+
+=cut
+
__PACKAGE__->set_primary_key("id");
+
+=head1 UNIQUE CONSTRAINTS
+
+=head2 C<name_unique>
+
+=over 4
+
+=item * L</name>
+
+=back
+
+=cut
+
__PACKAGE__->add_unique_constraint("name_unique", ["name"]);
=head1 RELATIONS
{ cascade_copy => 0, cascade_delete => 0 },
);
-=head2 messages
-
-Type: has_many
-
-Related object: L<Chatty::Schema::Result::Message>
-
-=cut
-
-__PACKAGE__->has_many(
- "messages",
- "Chatty::Schema::Result::Message",
- { "foreign.room" => "self.id" },
- { cascade_copy => 0, cascade_delete => 0 },
-);
-
-# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-10-17 20:21:50
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:U0zHyxd2zFVEnATmgpd+Ag
+# Created by DBIx::Class::Schema::Loader v0.07015 @ 2012-01-03 16:46:51
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:36bNroQtVWZPWUMc+6yAQw
# You can replace this text with custom code or comments, and it will be preserved on regeneration
[% META title = 'Live' -%]
+[% BLOCK js_include -%]
+ <script type="text/javascript" src="http://data.chatty.com/meteor.js"></script>
+[% END -%]
[% BLOCK js -%]
-$('form').validationEngine();
+ Meteor.hostid = '' + Math.floor(999*Math.random());
+ Meteor.host = "data."+location.hostname;
+ Meteor.registerEventCallback("process", addMessage);
+ Meteor.registerEventCallback("eof", function() {
+ addMessage("** stream closed **");
+ });
+ Meteor.registerEventCallback("reset", function() {
+ addMessage("** stream reset **");
+ });
+ Meteor.registerEventCallback("changemode", function(mode) {
+ addMessage("** mode changed to "+mode+" **");
+ });
+ Meteor.joinChannel("[% room.id %]", 5);
+ Meteor.mode = 'stream';
+ Meteor.connect();
+
+ function addMessage(line) {
+ $("#chat").append("<p>"+line+"</p>");
+ $("#chat").stop().animate({scrollTop:$("#chat").prop("scrollHeight")}, 350);
+ };
+
+ $("#submit").click(function(e) {
+ $.getJSON("", {msg: $("#msg").val()},
+ function(data) {
+ });
+ $("#msg").val("");
+ e.preventDefault();
+ });
+ $("#msg").focus();
[% END -%]
<h1>Room: [% room.name %]</h1>
-[% FOREACH msg IN messages -%]
-<p>[% msg.author.username %] ([% msg.posted %]): [% msg.content %]</p>
-[% END -%]
-[% form.render -%]
+<div id="chat" style="height: 300px; overflow: auto"></div>
+<form id="chat_send">
+ <i>Say your thing:</i>
+ <input id="msg" type="input"></input>
+ <input id="submit" type="submit" value="Send"></input>
+<form>
<script type="text/javascript" src="http://cdn.jquerytools.org/1.2.6/full/jquery.tools.min.js"></script>
<script type="text/javascript" src="[% c.uri_for('/static/js/jquery.validationEngine-2.2.1.min.js') %]"></script>
<script type="text/javascript" src="[% c.uri_for('/static/js/jquery.validationEngine-en.js') %]"></script>
+[% TRY; INCLUDE js_include; CATCH; ''; END -%]
<script type="text/javascript">
$(function () {
[% IF error -%]