Skip to content

Commit

Permalink
[#1035] Convert esn_inbox endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
afuna committed Nov 6, 2014
1 parent dd796d4 commit b2dce25
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 136 deletions.
107 changes: 107 additions & 0 deletions cgi-bin/DW/Controller/RPC/MiscLegacy.pm
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ DW::Routing->register_rpc( "changerelation", \&change_relation_handler, format =
DW::Routing->register_rpc( "checkforusername", \&check_username_handler, format => 'json' );
DW::Routing->register_rpc( "controlstrip", \&control_strip_handler, format => 'json' );
DW::Routing->register_rpc( "ctxpopup", \&ctxpopup_handler, format => 'json' );
DW::Routing->register_rpc( "esn_inbox", \&esn_inbox_handler, format => 'json' );
DW::Routing->register_rpc( "getsecurityoptions", \&get_security_options_handler, format => 'json' );
DW::Routing->register_rpc( "gettags", \&get_tags_handler, format => 'json' );
DW::Routing->register_rpc( "userpicselect", \&get_userpics_handler, format => 'json' );
Expand Down Expand Up @@ -259,6 +260,112 @@ sub ctxpopup_handler {
return DW::RPC->out( %ret );
}

sub esn_inbox_handler {
my $r = DW::Request->get;
my $post = $r->post_args;

my $remote = LJ::get_remote();
return DW::RPC->err( "Sorry, you must be logged in to use this feature." )
unless $remote;

my $authas = delete $post->{authas};

my $action = $post->{action};
return DW::RPC->err( "No action specified" ) unless $action;

my $success = 0;
my %ret;

# do authas
my $u = LJ::get_authas_user( $authas ) || $remote;
return DW::RPC->err( "You could not be authenticated as the specified user." )
unless $u;

# get qids
my @qids;
@qids = split( ',', $post->{qids} ) if $post->{qids};

my @items;

if ( scalar @qids ) {
foreach my $qid ( @qids ) {
my $item = eval {LJ::NotificationItem->new( $u, $qid )};
push @items, $item if $item;
}
}

$ret{items} = [];
my $inbox = $u->notification_inbox;
my $cur_folder = $post->{cur_folder} || 'all';
my $itemid = $post->{itemid} && $post->{itemid} =~ /^\d+$/ ? $post->{itemid} + 0 : 0;

# do actions
if ( $action eq 'mark_read' ) {
$_->mark_read foreach @items;
$success = 1;
} elsif ( $action eq 'mark_unread' ) {
$_->mark_unread foreach @items;
$success = 1;
} elsif ( $action eq 'delete' ) {
foreach my $item (@items) {
push @{$ret{items}}, { qid => $item->qid, deleted => 1 };
$item->delete;
}

$success = 1;
} elsif ( $action eq 'delete_all' ) {
@items = $inbox->delete_all( $cur_folder, itemid => $itemid );

foreach my $item ( @items ) {
push @{$ret{items}}, { qid => $item->{qid}, deleted => 1 };
}

$success = 1;
} elsif ( $action eq 'mark_all_read' ) {
$inbox->mark_all_read( $cur_folder, itemid => $itemid );

$success = 1;
} elsif ($action eq 'set_default_expand_prop') {
$u->set_prop( 'esn_inbox_default_expand', $post->{default_expand} eq 'Y' ? 'Y' : 'N' );
} elsif ( $action eq 'get_unread_items' ) {
$ret{unread_count} = $u->notification_inbox->unread_count;
} elsif ( $action eq 'toggle_bookmark' ) {
my $up;
$up = LJ::Hooks::run_hook( 'upgrade_message', $u, 'bookmark' );
$up = "<br />$up" if ($up);

foreach my $item (@items) {
my $ret = $u->notification_inbox->toggle_bookmark($item->qid);
return DW::RPC->err( "Max number of bookmarks reached.$up" ) unless $ret;
}
$success = 1;
} else {
return DW::RPC->err( "Invalid action $action" );
}

foreach my $item ( $u->notification_inbox->items ) {
my $class = $item->event->class;
$class =~ s/LJ::Event:://;
push @{$ret{items}}, {
read => $item->read,
qid => $item->qid,
bookmarked => $u->notification_inbox->is_bookmark( $item->qid ),
category => $class,
};
}

return DW::RPC->out(
success => $success,
unread_all => $inbox->all_event_count,
unread_usermsg_recvd => $inbox->usermsg_recvd_event_count,
unread_friend => $inbox->circle_event_count,
unread_entrycomment => $inbox->entrycomment_event_count,
unread_pollvote => $inbox->pollvote_event_count,
unread_usermsg_sent => $inbox->usermsg_sent_event_count,
%ret,
);
}

sub get_security_options_handler {
my $r = DW::Request->get;
my $args = $r->get_args;
Expand Down
1 change: 0 additions & 1 deletion cgi-bin/LJ/Global/Defaults.pm
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ no strict "vars";
my %ajaxmapping = (
delcomment => "delcomment.bml",
talkscreen => "talkscreen.bml",
esn_inbox => "tools/endpoints/esn_inbox.bml",
esn_subs => "tools/endpoints/esn_subs.bml",
trans_save => "tools/endpoints/trans_save.bml",
dirsearch => "tools/endpoints/directorysearch.bml",
Expand Down
135 changes: 0 additions & 135 deletions htdocs/tools/endpoints/esn_inbox.bml

This file was deleted.

0 comments on commit b2dce25

Please sign in to comment.