"; return $ML{'.error.not_ready'} unless $remote->can_use_esn; return BML::redirect( LJ::create_url( "/inbox/new", cur_args => \%GET, keep_args => 1 ) ) if ! LJ::did_post() && LJ::BetaFeatures->user_in_beta( $remote => "inbox" ); LJ::need_res(qw( js/6alib/core.js js/6alib/dom.js js/6alib/view.js js/6alib/datasource.js js/6alib/checkallbutton.js js/6alib/selectable_table.js js/6alib/httpreq.js js/6alib/hourglass.js js/esn_inbox.js stc/esn.css stc/lj_base.css )); my $formauth = LJ::form_auth(); # get the user's inbox my $inbox = $remote->notification_inbox or return LJ::error_list( BML::ml('.error.couldnt_retrieve_inbox', { 'user' => $remote->{user} }) ); # 2 instances of action buttons # map each to one variable my @buttons = qw{markRead markUnread delete markAllRead deleteAll}; foreach my $button (@buttons) { for (my $i=1; $i<=2; $i++) { my $sfx_button = $button . "_" . $i; $GET{$button} = $GET{$sfx_button} if($GET{$sfx_button} && !$GET{$button}); $POST{$button} = $POST{$sfx_button} if($POST{$sfx_button} && !$POST{$button}); } } # Take a supplied filter but default it to undef unless it is valid $view = $POST{view} || $GET{view} || undef; $view = undef if $view && $view =~ /\W/; $view = undef if $view eq 'archive' && ! LJ::is_enabled('esn_archive'); $view = undef if $view && !LJ::NotificationInbox->can("${view}_items"); my $itemid = $view eq "singleentry" ? int( $POST{itemid} || $GET{itemid} || 0 ) : 0; # Bolds the selected View/Folder my $selected_folder = $view || 'all'; $selected_folder = "entrycomment" if $selected_folder eq "singleentry"; $selected_folder = qq( ); $head = $selected_folder; # get events sitting in inbox my @notifications = $inbox->items; my @errors; if (LJ::did_post()) { # operate on notices by default but switch if view parameter specified my $nitems = \@notifications; my $name = "all"; if ($view) { my @items = eval "\$inbox->${name}_items"; push @items, $inbox->usermsg_sent_items; $nitems = \@items; } if ($POST{markAllRead}) { $inbox->mark_all_read( $view, itemid => $itemid ); } elsif ($POST{deleteAll}) { $inbox->delete_all( $view, itemid => $itemid ); } else { # go through each item and see if it's checked foreach my $item (@$nitems) { my $qid = eval { $item->qid } or next; my $checked = $POST{"${name}_Check-$qid"}; next unless $checked; if ($POST{markRead}) { $item->mark_read; } elsif ($POST{markUnread}) { $item->mark_unread; } elsif ($POST{delete}) { $item->delete; } } # reload inbox after making changes @$nitems = eval "\$inbox->${name}_items"; } } # Allow bookmarking to work without Javascript # or before JS events are bound if ($GET{bookmark_off} && $GET{bookmark_off} =~ /^\d+$/) { push @errors, $ML{'.error.max_bookmarks'} unless $inbox->add_bookmark($GET{bookmark_off}); } if ($GET{bookmark_on} && $GET{bookmark_on} =~ /^\d+$/) { $inbox->remove_bookmark($GET{bookmark_on}); } # Pagination my $page = int($POST{page} || $GET{page}); $body .= LJ::error_list(@errors) if (@errors); my $viewarg = $view ? "&view=$view" : ""; my $itemidarg = $itemid ? "&itemid=$itemid" : ""; # Inbox Nav $body .= qq{
| }; $body .= LJ::Widget::InboxFolderNav->render( 'page' => 1, 'view' => $view ); $body .= qq{ | ![]() |
}; # Filter by view if specified my @all_items; if ($view) { if ( $view eq "singleentry" ) { @all_items = eval "\$inbox->${view}_items( $itemid )"; } else { @all_items = eval "\$inbox->${view}_items"; } } else { @all_items = $inbox->all_items; } my $itemcount = scalar @all_items; $body .= LJ::error_list( $@ ) if $@; # Pagination $page = int($POST{page} || $GET{page}); $body .= LJ::Widget::InboxFolder->render( folder => "all", reply_btn => 1, expand => $GET{expand}, inbox => $inbox, page => $page, view => $view, mode => $GET{mode}, items => \@all_items, itemid => $itemid, ); # Repeat refresh/manage links if we have more than a few items (15 max per page) $body .= qq{ } if $itemcount > 10; $body .= qq{ |