From 0be1aa6acb62c13b4bcb4bd52a9c76df5f248e45 Mon Sep 17 00:00:00 2001 From: Yorhel Date: Sat, 12 Oct 2019 14:11:06 +0200 Subject: v2rw: Convert user notifications interface (/u+/notifies) --- lib/VNDB/Handler/Users.pm | 151 ---------------------------------------------- 1 file changed, 151 deletions(-) (limited to 'lib/VNDB/Handler/Users.pm') diff --git a/lib/VNDB/Handler/Users.pm b/lib/VNDB/Handler/Users.pm index e10fcaa5..933825e7 100644 --- a/lib/VNDB/Handler/Users.pm +++ b/lib/VNDB/Handler/Users.pm @@ -15,8 +15,6 @@ TUWF::register( qr{u([1-9]\d*)/posts} => \&posts, qr{u([1-9]\d*)/del(/[od])?} => \&delete, qr{u/(all|[0a-z])} => \&list, - qr{u([1-9]\d*)/notifies} => \¬ifies, - qr{u([1-9]\d*)/notify/([1-9]\d*)} => \&readnotify, ); @@ -188,154 +186,5 @@ sub list { } -sub notifies { - my($self, $uid) = @_; - - my $u = $self->dbUserGet(uid => $uid)->[0]; - return $self->htmlDenied if !$u->{id} || $uid != $self->authInfo->{id}; - - my $f = $self->formValidate( - { get => 'p', required => 0, default => 1, template => 'page' }, - { get => 'r', required => 0, default => 0, enum => [0,1] }, - ); - return $self->resNotFound if $f->{_err}; - - # changing the notification settings - my $saved; - if($self->reqMethod() eq 'POST' && $self->reqPost('set')) { - return if !$self->authCheckCode; - my $frm = $self->formValidate( - { post => 'notify_dbedit', required => 0, default => 0, enum => [0,1] }, - { post => 'notify_announce', required => 0, default => 0, enum => [0,1] } - ); - return $self->resNotFound if $frm->{_err}; - $self->authPref($_, $frm->{$_}) for ('notify_dbedit', 'notify_announce'); - $saved = 1; - - # updating notifications - } elsif($self->reqMethod() eq 'POST') { - return if !$self->authCheckCode; - my $frm = $self->formValidate( - { post => 'notifysel', multi => 1, required => 0, template => 'id' }, - { post => 'markread', required => 0 }, - { post => 'remove', required => 0 } - ); - return $self->resNotFound if $frm->{_err}; - my @ids = grep $_, @{$frm->{notifysel}}; - $self->dbNotifyMarkRead(@ids) if @ids && $frm->{markread}; - $self->dbNotifyRemove(@ids) if @ids && $frm->{remove}; - } - - my($list, $np) = $self->dbNotifyGet( - uid => $uid, - page => $f->{p}, - results => 25, - what => 'titles', - read => $f->{r} == 1 ? undef : 0, - reverse => $f->{r} == 1, - ); - - $self->htmlHeader(title => 'My notifications', noindex => 1); - $self->htmlMainTabs(u => $u); - div class => 'mainbox'; - h1 'My notifications'; - p class => 'browseopts'; - a !$f->{r} ? (class => 'optselected') : (), href => "/u$uid/notifies?r=0", 'Unread notifications'; - a $f->{r} ? (class => 'optselected') : (), href => "/u$uid/notifies?r=1", 'All notifications'; - end; - p 'No notifications!' if !@$list; - end; - - my $code = $self->authGetCode("/u$uid/notifies"); - - my %ntypes = ( - pm => 'Private Message', - dbdel => 'Entry you contributed to has been deleted', - listdel => 'VN in your (wish)list has been deleted', - dbedit => 'Entry you contributed to has been edited', - announce => 'Site announcement', - ); - - if(@$list) { - form action => "/u$uid/notifies?r=$f->{r};formcode=$code", method => 'post', id => 'notifies'; - $self->htmlBrowse( - items => $list, - options => $f, - nextpage => $np, - class => 'notifies', - pageurl => "/u$uid/notifies?r=$f->{r}", - header => [ - [ '' ], - [ 'Type' ], - [ 'Age' ], - [ 'ID' ], - [ 'Action' ], - ], - row => sub { - my($s, $n, $l) = @_; - Tr $l->{read} ? () : (class => 'unread'); - td class => 'tc1'; - input type => 'checkbox', name => 'notifysel', value => "$l->{id}"; - end; - td class => 'tc2', $ntypes{$l->{ntype}}; - td class => 'tc3', fmtage $l->{date}; - td class => 'tc4'; - a href => "/u$uid/notify/$l->{id}", "$l->{ltype}$l->{iid}".($l->{subid}?".$l->{subid}":''); - end; - td class => 'tc5 clickable', id => "notify_$l->{id}"; - txt $l->{ltype} eq 't' ? 'Edit of ' : $l->{subid} == 1 ? 'New thread ' : 'Reply to '; - i $l->{c_title}; - txt ' by '; - i VNWeb::HTML::user_displayname($l); - end; - end 'tr'; - }, - footer => sub { - Tr; - td colspan => 5; - input type => 'checkbox', class => 'checkall', name => 'notifysel', value => 0; - txt ' '; - input type => 'submit', name => 'markread', value => 'mark selected read'; - input type => 'submit', name => 'remove', value => 'remove selected'; - b class => 'grayedout', ' (Read notifications are automatically removed after one month)'; - end; - end; - } - ); - end; - } - - form method => 'post', action => "/u$uid/notifies?formcode=$code"; - div class => 'mainbox'; - h1 'Settings'; - div class => 'notice', 'Settings successfully saved.' if $saved; - p; - for('dbedit', 'announce') { - input type => 'checkbox', name => "notify_$_", id => "notify_$_", value => 1, - $self->authPref("notify_$_") ? (checked => 'checked') : (); - label for => "notify_$_", $_ eq 'dbedit' - ? ' Notify me about edits of database entries I contributed to.' - : ' Notify me about site announcements.'; - br; - } - input type => 'submit', name => 'set', value => 'Save'; - end; - end; - end 'form'; - $self->htmlFooter; -} - - -sub readnotify { - my($self, $uid, $nid) = @_; - return $self->htmlDenied if !$self->authInfo->{id} || $uid != $self->authInfo->{id}; - my $n = $self->dbNotifyGet(uid => $uid, id => $nid)->[0]; - return $self->resNotFound if !$n->{iid}; - $self->dbNotifyMarkRead($n->{id}) if !$n->{read}; - # NOTE: for t+.+ IDs, this will create a double redirect, which is rather awkward... - $self->resRedirect("/$n->{ltype}$n->{iid}".($n->{subid}?".$n->{subid}":''), 'perm'); -} - - 1; -- cgit v1.2.3