Changeset 23

Show
Ignore:
Timestamp:
02/25/07 23:03:18 (3 years ago)
Author:
eevee
Message:

Changed the thread view to use an iterator, which was a bit tricky and thus left out of the last commit. Really, I knew about it.
With that, lastpostid/lasttime have been changed to just mean the last post in the thread that majorly changed, NOT necessarily the one that will display last.
Added: Double-posting prevention. Identical second posts will be ignored; different second posts will be merged with the previous one.

Location:
veekun
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • veekun/lib/Vee/Controller/Forum.pm

    r22 r23  
    8585        order_by => 'FIND_IN_SET("sticky", me.flags) > 0 DESC, lastpost.time DESC', 
    8686        prefetch => { firstpost => 'user', lastpost => 'user' }, 
    87         offset => $skip, 
    88         rows => $perpage, 
     87        offset   => $skip, 
     88        rows     => $perpage, 
    8989    } ); 
    9090    # TODO: ugly but for now I don't know the best way to clean it up 
     
    133133    my $perpage = $c->site_opts->{page_sizes}{posts}; 
    134134    my $lastpage = ($skip + $perpage >= $thread->postct); 
    135     my @posts = $c->model('DBIC::Posts')->search( 
     135    my $posts_rs = $c->model('DBIC::Posts')->search( 
    136136        { 'me.threadid' => $id, ( $filter_user ? ( 'me.userid' => $filter_user->id ) : () ) }, 
    137137        { prefetch => [ 'user', { 'lastedit', 'user' } ], order_by => 'me.time ASC', offset => $skip, rows => $perpage + 1 } 
    138     );  # TODO: iterate 
     138    ); 
    139139     
    140140    my $form = new Vee::Form( 
     
    148148    my $threadflags = '';  # TODO 
    149149 
    150     $s->{page_title } = $thread->subject . ' - Forums'; 
     150    $s->{page_title} = $thread->subject . ' - Forums'; 
    151151    $s->{page_header} = $thread->subject; 
    152     $s->{link_name  } = 'forum'; 
    153     $s->{crumbs     } = [ '<a href="/forum">Forum Index</a>', '<a href="/forum/'.$thread->forum->id.'">'.$thread->forum->name.'</a>', qq'$threadflags<a href="/forum/thread/'.$thread->id.'">'.$thread->subject.'</a>' ]; 
     152    $s->{link_name = 'forum'; 
     153    $s->{crumbs}      = [ '<a href="/forum">Forum Index</a>', '<a href="/forum/'.$thread->forum->id.'">'.$thread->forum->name.'</a>', qq'$threadflags<a href="/forum/thread/'.$thread->id.'">'.$thread->subject.'</a>' ]; 
    154154    if ($filter_user) { push @{ $s->{crumbs} }, '<a href="/user/'.$filter_user->id.'">'.$filter_user->name.'</a>\'s posts' } 
    155     $s->{extra_css  } = 'forum'; 
    156     $s->{form       } = $form; 
    157     $s->{postbar_color} = sub { Vee::Utils::hsv2rgb(shift, 192, 192) }; # Remove after making global 
     155    $s->{extra_css}   = 'forum'; 
     156    $s->{form}        = $form; 
     157 
     158    $s->{postbar_color}     = sub { Vee::Utils::hsv2rgb(shift, 192, 192) }; # Remove after making global 
     159    $s->{physical_lastpost} = $thread->search_related('posts', undef, { order_by => [ 'time DESC', 'id DESC' ] })->single; 
    158160 
    159161    $s->{forum}       = $thread->forum; 
    160162    $s->{thread}      = $thread; 
    161163    $s->{page_islast} = $lastpage; 
    162     $s->{next_post}   = $lastpage ? undef : pop @posts; 
    163     $s->{posts}       = \@posts; 
    164 #    $s->{can_post}    = !$sess->test_post($thread, $thread->forumid), 
     164    $s->{posts_rs}    = $posts_rs; 
    165165    $s->{skip}        = $skip; 
    166166    $s->{filter}      = $filter; 
  • veekun/lib/Vee/Controller/Forum/Create.pm

    r20 r23  
    88use Vee::Utils::Forum; 
    99 
     10use DateTime; 
     11 
    1012=head1 NAME 
    1113 
     
    6163    if (@bbcode_errors) { 
    6264        $c->vee_abort("Your post contains invalid bbcode.  Please go back and fix it.  Also, vee really needs better error messages; sorry about that."); 
    63     }  
     65    } 
     66    $parsed_message = Vee::Utils::fix_newlines( $parsed_message ); 
    6467 
    6568    if ('preview' eq lc $c->req->params->{submit}) { 
    6669        $c->detach('post_preview'); 
    6770    } 
    68     
    69     # create the post 
    70     my $post = $c->model('DBIC')->schema->txn_do( sub { 
    71         my $post = $c->model('DBIC::Posts')->create({ 
    72             threadid => $thread->id, 
    73             userid   => $c->user->obj->id, 
    74             time     => time, 
    75             format   => 'bbcode', 
    76             message  => Vee::Utils::fix_newlines( $parsed_message ), 
    77         }); 
    78         # update thread's last-post stats 
    79         $thread->lastpostid( $post->id ); 
    80         $thread->lasttime( time ); 
    81         $thread->postct( $thread->postct + 1 ); 
    82         $thread->update; 
    83         # update forum's last-post stats 
    84         $thread->forum->lastpostid( $post->id ); 
    85         $thread->forum->postct( $thread->forum->postct + 1 ); 
    86         $thread->forum->update; 
    87         # update user's postcount 
    88         $c->user->obj->postct( $c->user->postct + 1 ); 
    89         $c->user->obj->update; 
    90         return $post; 
    91     } ); 
     71 
     72    # check for daabaru-post 
     73    # TODO: apply this to thread creation too?  not as common..  and merge as well? 
     74    my $last_post = $c->model('DBIC::Posts')->search({ 
     75        threadid => $thread->id, 
     76        time     => { '>=', time - $c->site_opts->{post_automerge_time} }, 
     77    }, { 
     78        order_by => 'time DESC', 
     79    })->single; 
     80 
     81    my $post; 
     82    # only do merging/prevention if the last post is this user's 
     83    if ($last_post and $last_post->userid == $c->user->obj->id) { 
     84        if ($last_post->message eq $parsed_message) { 
     85            $c->vee_abort("You have already posted that message recently."); 
     86        } 
     87 
     88        # different post; edit the last one 
     89        # TODO: what about formats/options of both posts?  not a problem now, but later.. 
     90        $post = $c->model('DBIC')->schema->txn_do( sub { 
     91            my $edit = $c->model('DBIC::Edits')->create({ 
     92                postid     => $last_post->id, 
     93                userid     => $c->user->obj->id, 
     94                time       => time, 
     95                oldmessage => $last_post->message, 
     96            }); 
     97            $last_post->message( 
     98                $last_post->message . 
     99                "\n[hr][i]Automerged:[/i]\n" . 
     100                $parsed_message 
     101            ); 
     102            $last_post->lasteditid( $edit->id ); 
     103            $last_post->update; 
     104 
     105            $thread->lastpostid( $last_post->id ); 
     106            $thread->lasttime( time ); 
     107            $thread->update 
     108 
     109            return $last_post; 
     110        } ); 
     111    } else { 
     112        # create the post 
     113        $post = $c->model('DBIC')->schema->txn_do( sub { 
     114            my $post = $c->model('DBIC::Posts')->create({ 
     115                threadid => $thread->id, 
     116                userid   => $c->user->obj->id, 
     117                time     => time, 
     118                format   => 'bbcode', 
     119                message  => $parsed_message, 
     120            }); 
     121            # update thread's last-post stats 
     122            $thread->lastpostid( $post->id ); 
     123            $thread->lasttime( time ); 
     124            $thread->postct( $thread->postct + 1 ); 
     125            $thread->update; 
     126            # update forum's last-post stats 
     127            $thread->forum->lastpostid( $post->id ); 
     128            $thread->forum->postct( $thread->forum->postct + 1 ); 
     129            $thread->forum->update; 
     130            # update user's postcount 
     131            $c->user->obj->postct( $c->user->postct + 1 ); 
     132            $c->user->obj->update; 
     133            return $post; 
     134        } ); 
     135    } 
    92136 
    93137    # finito! 
  • veekun/site_options.yml

    r21 r23  
    7070user_activity_timeout: 900 
    7171 
     72# Number of seconds before a user can double-post on a thread 
     73post_automerge_time: 1800 
     74 
    7275# URL for Subversion repository path to check for activity 
    7376# Note that at the moment this *requires* anon access! 
  • veekun/templates/forum/common.tt

    r14 r23  
    147147<td class="forum-count">[% thread.postct - 1 %]</td><td class="forum-count">[% thread.hitct %]</td> 
    148148<td class="forum-postinfo"> 
    149 [%     IF thread.lastpostid == thread.firstpostid -%] 
     149[%     IF thread.postct <= 1 -%] 
    150150- 
    151151[%     ELSE %] 
     
    175175 
    176176[% BLOCK forums_each %][%# forum -%] 
    177 [%#     last_post = sql.post_summary(forum.lastpost) %] 
    178 [%#     last_name = last_post.user.name %] 
    179 [%#     last_thread = sql.thread_info(last_post.threadid) -%] 
    180177<tr><td class="forum-icon"> 
    181178[% UNLESS forum.accessibility == 'normal' %]<img src="/images/icons/[% forum.accessibility %].png" alt="[% forum.accessibility %]" title="[% forum.accessibility %]"/>[% END %] 
  • veekun/templates/forum/thread/view.tt

    r5 r23  
    66[% this_pagelist = pagelist(skip, c.site_opts.page_sizes.posts, thread.postct, c.uri('Forum', 'thread', thread.id), c.req.params); this_pagelist %] 
    77[% INCLUDE posts_start %] 
    8 [% FOREACH p IN posts %] 
    9 [%     IF !loop.first %] 
    10 <div class="forum-postdiff">[% p.time - loop.prev.time | timespan %]</div> 
     8[% done_posts = 0 %] 
     9[% WHILE (p = posts_rs.next) %] 
     10[%     IF done_posts > 0 %] 
     11<div class="forum-postdiff">[% p.time - last_post_time | timespan %]</div> 
    1112[%     END %] 
    1213[%     INCLUDE posts_each post=p thread=thread forum=thread.forum show_deleted=0 %] 
     14[%     done_posts = done_posts + 1 %] 
     15[%     last_post_time = p.time %] 
     16[%     IF done_posts >= c.site_opts.page_sizes.posts; LAST; END %] 
    1317[% END %] 
    1418 
    15 [% IF !posts.size %] 
     19[% IF NOT done_posts %] 
    1620[%     IF filter %] 
    1721<div class="warning"><a href="/users/[% filter.id %]">[% filter.name %]</a> has no posts on this thread.</div> 
     
    2731 
    2832[% IF page_islast %] 
    29 <div class="forum-postdiff">[% time - posts.last.time | timespan %]<br/>since last post</div> 
     33<div class="forum-postdiff">[% time - last_post_time | timespan %]<br/>since last post</div> 
    3034[% ELSE %] 
    31 <div class="forum-postdiff">[% next_post.time - posts.last.time | timespan %]<br/>to first post on next page</div> 
     35<div class="forum-postdiff">[% posts_rs.next.time - last_post_time | timespan %]<br/>to first post on next page</div> 
    3236[% END %] 
    3337<form action="/forum/thread/[% thread.id %]" method="get" class="forum-filter"> 
     
    4751[% IF can_post(thread) %] 
    4852<h1>Reply to this thread</h1> 
    49 [%     IF thread.lastpost.time %] 
    50 [%         age = time - thread.lastpost.time %] 
     53[%     IF physical_lastpost.time %] 
     54[%         age = time - physical_lastpost.time %] 
    5155[%         IF age > 60 * 60 * 24 * 14 %] 
    5256<div class="warning"> <p>The last post on this thread is more than two weeks old.</p> <p>It has most likely been long forgotten.  Please consider whether posting is that good an idea.</p> </div> 
     
    5559[%         END %] 
    5660[%     END %] 
    57 [%     IF user AND thread.lastpost.userid AND thread.lastpost.userid == user.id %] 
    58 <div class="warning"> <p>The last post on this thread is yours; if you reply again, your new post will be combined with the old one and the thread will be bumped.  If you like, you can manually <a href="/forum/post/[% thread.lastpost.id %]/edit">edit the last post</a> instead.</p> </div> 
     61[%     IF user AND physical_lastpost.userid AND physical_lastpost.userid == user.id %] 
     62<div class="warning"> <p>The last post on this thread is yours; if you reply again, your new post will be combined with the old one and the thread will be bumped.  If you like, you can manually <a href="/forum/post/[% physical_lastpost.id %]/edit">edit the last post</a> instead.</p> </div> 
    5963[%     END %] 
    6064<form class="forum-reply" action="[% uri('Forum::Create', 'post') %]" method="post">