# This code was forked from the LiveJournal project owned and operated
# by Live Journal, Inc. The code has been modified and expanded by
# Dreamwidth Studios, LLC. These files were originally licensed under
# the terms of the license supplied by Live Journal, Inc, which can
# currently be found at:
#
# http://code.livejournal.org/trac/livejournal/browser/trunk/LICENSE-LiveJournal.txt
#
# In accordance with the original license, this code and all its
# modifications are provided under the GNU General Public License.
# A copy of that license can be found in the LICENSE file included as
# part of this distribution.
package LJ::Event::UserMessageRecvd;
use strict;
use Scalar::Util qw(blessed);
use Carp qw(croak);
use base 'LJ::Event';
use LJ::Message;
sub new {
my ( $class, $u, $msgid, $other_u ) = @_;
foreach ( $u, $other_u ) {
croak 'Not an LJ::User' unless blessed $_ && $_->isa("LJ::User");
}
return $class->SUPER::new( $u, $msgid, $other_u->{userid} );
}
sub arg_list {
return ( "Message id", "Sender userid" );
}
sub is_common { 1 }
sub as_email_subject {
my ( $self, $u ) = @_;
my $other_u = $self->load_message->other_u;
return LJ::Lang::get_default_text(
'esn.email.pm.subject',
{
sender => $self->load_message->other_u->display_username,
}
);
}
sub _as_email {
my ( $self, $u, $is_html ) = @_;
my $msg = $self->load_message;
my $compose_url =
LJ::BetaFeatures->user_in_beta( $u => "inbox" )
? "$LJ::SITEROOT/inbox/new/compose"
: "$LJ::SITEROOT/inbox/compose";
my $replyurl = "$compose_url?mode=reply&msgid=" . $msg->msgid;
my $other_u = $msg->other_u;
my $sender = $other_u->user;
my $inbox = "$LJ::SITEROOT/inbox/";
$inbox = "" . LJ::Lang::get_default_text('esn.your_inbox') . ""
if $is_html;
my $vars = {
user => $is_html ? ( $u->ljuser_display ) : ( $u->user ),
subject => $is_html ? $msg->subject : $msg->subject_raw,
body => $is_html ? $msg->body : $msg->body_raw,
sender => $is_html ? ( $other_u->ljuser_display ) : ( $other_u->user ),
postername => $other_u->display_name,
journal => $other_u->display_name,
sitenameshort => $LJ::SITENAMESHORT,
inbox => $inbox,
};
my $body = LJ::Lang::get_default_text( 'esn.email.pm_with_body', $vars )
. $self->format_options(
$is_html, undef, $vars,
{
'esn.reply_to_message' => [ 1, $replyurl ],
'esn.view_profile' => [ 2, $other_u->profile_url ],
'esn.read_journal' => [ $other_u->is_identity ? 0 : 3, $other_u->journal_base ],
'esn.add_watch' => [
$u->watches($other_u) ? 0 : 4,
"$LJ::SITEROOT/circle/$sender/edit?action=subscribe"
],
}
);
if ($is_html) {
$body =~ s/\n/\n
/g unless $body =~ m!
load(
{ msgid => $self->arg1, journalid => $self->u->{userid}, otherid => $self->arg2 } );
return $msg;
}
sub as_html {
my $self = shift;
my $msg = $self->load_message;
my $other_u = $msg->other_u;
my $pichtml = display_pic( $msg, $other_u );
my $subject = $msg->subject;
if ( $other_u->is_suspended ) {
$subject = "(Message from suspended user)";
}
my $ret;
$ret .= "