Messages from user
This commit is contained in:
parent
d592353384
commit
568a2a53ff
33
II/DB.pm
33
II/DB.pm
@ -24,13 +24,13 @@ sub check_hash {
|
|||||||
my ( $self, $hash, $echo ) = @_;
|
my ( $self, $hash, $echo ) = @_;
|
||||||
my $dbh = $self->{_dbh};
|
my $dbh = $self->{_dbh};
|
||||||
|
|
||||||
my $q = "select hash from echo where hash='$hash' and echo='$echo'";
|
my $q = "select hash from echo where hash='$hash' and echo='$echo'";
|
||||||
my $sth = $dbh->prepare($q);
|
my $sth = $dbh->prepare($q);
|
||||||
$sth->execute();
|
$sth->execute();
|
||||||
|
|
||||||
while ( my @h = $sth->fetchrow_array() ) {
|
while ( my @h = $sth->fetchrow_array() ) {
|
||||||
my ($base_hash) = @h;
|
my ($base_hash) = @h;
|
||||||
if ($hash eq $base_hash) {
|
if ( $hash eq $base_hash ) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -153,6 +153,35 @@ sub select_subg {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Select user messages
|
||||||
|
sub select_user {
|
||||||
|
my ( $self, $user ) = @_;
|
||||||
|
my $dbh = $self->{_dbh};
|
||||||
|
|
||||||
|
my $q
|
||||||
|
= "select from_user, to_user, subg, time, echo, post, hash from messages where from_user='$user' order by time desc";
|
||||||
|
|
||||||
|
my $sth = $dbh->prepare($q);
|
||||||
|
$sth->execute();
|
||||||
|
|
||||||
|
my @posts;
|
||||||
|
while ( my @hash = $sth->fetchrow_array() ) {
|
||||||
|
my ( $from, $to, $subg, $time, $echo, $post, $h ) = @hash;
|
||||||
|
my $data = {
|
||||||
|
from => "$from",
|
||||||
|
to => "$to",
|
||||||
|
subg => "$subg",
|
||||||
|
time => $time,
|
||||||
|
echo => "$echo",
|
||||||
|
post => "$post",
|
||||||
|
hash => $h,
|
||||||
|
};
|
||||||
|
push( @posts, $data );
|
||||||
|
}
|
||||||
|
|
||||||
|
return @posts;
|
||||||
|
}
|
||||||
|
|
||||||
sub from_me {
|
sub from_me {
|
||||||
my ( $self, $config ) = @_;
|
my ( $self, $config ) = @_;
|
||||||
my $dbh = $self->{_dbh};
|
my $dbh = $self->{_dbh};
|
||||||
|
25
II/Render.pm
25
II/Render.pm
@ -74,7 +74,7 @@ sub echo_mes {
|
|||||||
$render .= $t->echo($echo);
|
$render .= $t->echo($echo);
|
||||||
|
|
||||||
my $count = 0;
|
my $count = 0;
|
||||||
if ($view eq 'thread') {
|
if ( $view eq 'thread' ) {
|
||||||
while ( $count < @post ) {
|
while ( $count < @post ) {
|
||||||
|
|
||||||
# Render post
|
# Render post
|
||||||
@ -151,6 +151,29 @@ sub index {
|
|||||||
return $render;
|
return $render;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Messages from user
|
||||||
|
sub user {
|
||||||
|
my ( $self, $user ) = @_;
|
||||||
|
my $db = $self->{_db};
|
||||||
|
my $t = $self->{_template};
|
||||||
|
|
||||||
|
# Render header
|
||||||
|
my $render
|
||||||
|
= $t->head("ii :: Сообщения пользователя $user");
|
||||||
|
|
||||||
|
my @post = $db->select_user($user);
|
||||||
|
|
||||||
|
my $count = 0;
|
||||||
|
while ( $count < @post ) {
|
||||||
|
|
||||||
|
# Render post
|
||||||
|
$render .= $t->post( @post[$count] );
|
||||||
|
$count++;
|
||||||
|
}
|
||||||
|
$render .= $t->foot();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
# Render new message form
|
# Render new message form
|
||||||
sub send_new {
|
sub send_new {
|
||||||
my ( $self, $echo ) = @_;
|
my ( $self, $echo ) = @_;
|
||||||
|
15
iiplc.app
15
iiplc.app
@ -1,3 +1,4 @@
|
|||||||
|
#!/usr/bin/perl
|
||||||
# Copyright © 2014 Difrex <difrex.punk@gmail.com>
|
# Copyright © 2014 Difrex <difrex.punk@gmail.com>
|
||||||
# This work is free. You can redistribute it and/or modify it under the
|
# This work is free. You can redistribute it and/or modify it under the
|
||||||
# terms of the Do What The Fuck You Want To Public License, Version 2,
|
# terms of the Do What The Fuck You Want To Public License, Version 2,
|
||||||
@ -40,7 +41,7 @@ my $echo = sub {
|
|||||||
my $echo = $req->param('echo');
|
my $echo = $req->param('echo');
|
||||||
my $view = $req->param('view');
|
my $view = $req->param('view');
|
||||||
|
|
||||||
my $echo_messages = $render->echo_mes($echo, $view);
|
my $echo_messages = $render->echo_mes( $echo, $view );
|
||||||
|
|
||||||
return [ 200, [ 'Content-type' => 'text/html' ], ["$echo_messages"], ];
|
return [ 200, [ 'Content-type' => 'text/html' ], ["$echo_messages"], ];
|
||||||
};
|
};
|
||||||
@ -154,10 +155,22 @@ my $push = sub {
|
|||||||
return [ 302, [ 'Location' => "/e?echo=$echo" ], [], ];
|
return [ 302, [ 'Location' => "/e?echo=$echo" ], [], ];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# Messages from user
|
||||||
|
my $user = sub {
|
||||||
|
my $env = shift;
|
||||||
|
|
||||||
|
my $req = Plack::Request->new($env);
|
||||||
|
my $user = $req->param('user');
|
||||||
|
my $mes_from = $render->user($user);
|
||||||
|
|
||||||
|
return [ 200, [ 'Content-type' => 'text/html' ], [$mes_from], ];
|
||||||
|
};
|
||||||
|
|
||||||
builder {
|
builder {
|
||||||
mount '/' => $root;
|
mount '/' => $root;
|
||||||
mount '/e' => $echo;
|
mount '/e' => $echo;
|
||||||
mount '/s' => $thread;
|
mount '/s' => $thread;
|
||||||
|
mount '/u' => $user;
|
||||||
mount '/me' => $me;
|
mount '/me' => $me;
|
||||||
mount '/tree' => $tree;
|
mount '/tree' => $tree;
|
||||||
mount '/get/' => $get;
|
mount '/get/' => $get;
|
||||||
|
Loading…
Reference in New Issue
Block a user