Changeset 14119

Show
Ignore:
Timestamp:
08/05/08 14:36:18 (5 years ago)
Author:
ssafronova
Message:

LJSUP-2330: sendmessage command added, getinbox now return msgid & parent_msgid

Location:
trunk/cgi-bin
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/cgi-bin/LJ/Event/UserMessageRecvd.pm

    r14118 r14119  
    237237    $res->{subject} = $msg->subject; 
    238238    $res->{body} = $msg->body; 
     239    $res->{msgid} = $msg->msgid; 
     240    $res->{parent} = $msg->parent_msgid if $msg->parent_msgid; 
    239241 
    240242    return $res; 
  • trunk/cgi-bin/ljprotocol.pl

    r14109 r14119  
    7171     "210" => [ E_PERM, "Client tried to edit with corrupt data.  Preventing." ], 
    7272     "211" => [ E_PERM, "Invalid or malformed tag list" ], 
     73     "212" => [ E_PERM, "Message body is too long" ], 
    7374 
    7475     # Access Errors 
     
    8889     "313" => [ E_TEMP, "Must use existing tags for entries in this journal (can't create new ones)" ], 
    8990     "314" => [ E_PERM, "Only paid users allowed to use this request" ], 
     91     "315" => [ E_PERM, "User messaging is currently disabled" ], 
    9092 
    9193     # Limit errors 
     
    190192    if ($method eq "getfriendspage")   { return getfriendspage(@args);   } 
    191193    if ($method eq "getinbox")         { return getinbox(@args);         } 
     194    if ($method eq "sendmessage")      { return sendmessage(@args);      } 
    192195 
    193196    $r->notes("codepath" => "") if $r; 
     
    326329} 
    327330 
     331 
     332sub sendmessage 
     333{ 
     334    my ($req, $err, $flags) = @_; 
     335 
     336    return fail($err, 315) if $LJ::DISABLED{user_messaging}; 
     337 
     338    return undef unless authenticate($req, $err, $flags); 
     339    my $u = $flags->{'u'}; 
     340 
     341    return fail($err, 314) unless $u->get_cap('paid'); 
     342    my $msg_limit = LJ::get_cap($u, "usermessage_length"); 
     343 
     344    my @errors; 
     345 
     346    my $subject_text = LJ::strip_html($req->{'subject'}); 
     347    return fail($err, 208, 'subject') 
     348        unless LJ::text_in($subject_text); 
     349 
     350    # strip HTML from body and test encoding and length 
     351    my $body_text = LJ::strip_html($req->{'body'}); 
     352    return fail($err, 208, 'body') 
     353        unless LJ::text_in($body_text); 
     354 
     355    my ($msg_len_b, $msg_len_c) = LJ::text_length($body_text); 
     356    return fail($err, 212, 'found: ' . LJ::commafy($msg_len_c) . ' characters, it should not exceed ' . LJ::commafy($msg_limit)) 
     357        unless ($msg_len_c <= $msg_limit); 
     358 
     359    my @to = (ref $req->{'to'}) ? @{$req->{'to'}} : ($req->{'to'}); 
     360    return fail($err, 200) unless scalar @to; 
     361 
     362    # remove duplicates 
     363    my %to = map { lc($_), 1 } @to; 
     364    @to = keys %to; 
     365 
     366    my @msg; 
     367    BML::set_language('en'); # FIXME 
     368 
     369    foreach my $to (@to) { 
     370        my $tou = LJ::load_user($to); 
     371        return fail($err, 100, $to) 
     372            unless $tou; 
     373 
     374        my $msg = LJ::Message->new({ 
     375                    journalid => $u->userid, 
     376                    otherid => $tou->userid, 
     377                    subject => $subject_text, 
     378                    body => $body_text, 
     379                    parent_msgid => defined $req->{'parent'} ? $req->{'parent'} + 0 : undef, 
     380                    userpic => $req->{'userpic'} || undef, 
     381                  }); 
     382 
     383        push @msg, $msg  
     384            if $msg->can_send(\@errors); 
     385    } 
     386    return fail($err, 203, join('; ')) 
     387        if scalar @errors; 
     388 
     389    foreach my $msg (@msg) { 
     390        $msg->send(\@errors); 
     391    } 
     392 
     393    return { 'sent_count' => scalar @msg,  
     394             (@errors ? ('last_errors' => \@errors) : () ), 
     395           }; 
     396} 
     397 
    328398sub login 
    329399{