1 package Newslash::Web::Controller::User;
2 use Mojo::Base 'Mojolicious::Controller';
4 use List::Util qw(any);
7 my ($c, $tab, $f) = @_;
8 my $users = $c->model('users');
9 my $user = $c->stash('user');
11 my $nickname = $c->stash('nickname') || "";
12 $nickname =~ s/\A~(.*)\z/$1/;
15 $the_user = $users->select(nickname => $nickname);
17 $c->render('Not found', status => '404');
21 $the_user->{config} = $users->configs->select(uid => $the_user->{uid});
22 my $items = $f->($c, $the_user);
25 if ($user->{uid} != $the_user->{uid}) {
26 my $friends = $user->{relations}->{friends};
27 my $foes = $user->{relations}->{foes};
28 if (any { $the_user->{uid} eq $_ } keys %$friends) {
31 if (any { $the_user->{uid} eq $_ } keys @$foes) {
36 my $page = { type => "user" };
37 my $content_type_table = { home => "recent",
38 comments => "comment",
39 journals => "journal",
40 submissions => "submission"
42 $page->{content_type} = $content_type_table->{$tab} || "user";
44 $c->render(template => "user/base",
48 the_user => $the_user,
51 $c->stats->add_event_counter("userhome_view");
57 my $query_func = sub {
58 my ($c, $the_user) = @_;
59 my $items = $c->model('timeline')->select(uid => $the_user->{uid}, limit => 10);
62 $c->_base_render(home => $query_func);
67 my $query_func = sub {
68 my ($c, $the_user) = @_;
69 my $items = $c->model('journals')->select(uid => $the_user->{uid},
70 order_by => { create_time => "DESC" },
74 $c->_base_render(journals => $query_func);
79 my $query_func = sub {
80 my ($c, $the_user) = @_;
81 my $items = $c->model('comments')->select(uid => $the_user->{uid},
82 order_by => { create_time => "DESC" },
86 $c->_base_render(comments => $query_func);
91 my $query_func = sub {
92 my ($c, $the_user) = @_;
93 my $items = $c->model('submissions')->select(uid => $the_user->{uid},
94 order_by => { create_time => "DESC" },
98 $c->_base_render(submissions => $query_func);
103 my $query_func = sub {
104 my ($c, $the_user) = @_;
105 my $items = $c->model('users')->friends->friends(uid => $the_user->{uid});
108 $c->_base_render(friends => $query_func);
113 my $query_func = sub {
114 my ($c, $the_user) = @_;
115 my $items = $c->model('users')->friends->foes(uid => $the_user->{uid});
118 $c->_base_render(foes => $query_func);
123 my $query_func = sub {
124 my ($c, $the_user) = @_;
125 my $items = $c->model('users')->friends->fans(uid => $the_user->{uid});
128 $c->_base_render(fans => $query_func);
133 my $query_func = sub {
134 my ($c, $the_user) = @_;
135 my $items = $c->model('users')->friends->freaks(uid => $the_user->{uid});
138 $c->_base_render(freaks => $query_func);
143 my $query_func = sub {
144 my ($c, $the_user) = @_;
145 my $items = $c->model('users')->achievements->select(uid => $the_user->{uid});
148 $c->_base_render(achievements => $query_func);