1 package LJ
::Event
::Befriended
;
3 use Scalar
::Util
qw(blessed);
8 my ($class, $u, $fromu) = @_;
10 my $uid = LJ
::want_userid
($u); ## friendid
11 my $fromuid = LJ
::want_userid
($fromu);
12 return $class->SUPER::new
($uid, $fromuid);
17 my @_ml_strings_en = (
18 'esn.public', # 'public',
19 'esn.befriended.subject', # '[[who]] added you as a friend!',
20 'esn.add_friend', # '[[openlink]]Add [[journal]] to your Friends list[[closelink]]',
21 'esn.read_journal', # '[[openlink]]Read [[postername]]\'s journal[[closelink]]',
22 'esn.view_profile', # '[[openlink]]View [[postername]]\'s profile[[closelink]]',
23 'esn.edit_friends', # '[[openlink]]Edit Friends[[closelink]]',
24 'esn.edit_groups', # '[[openlink]]Edit Friends groups[[closelink]]',
25 'esn.befriended.alert', # '[[who]] has added you as a friend.',
26 'esn.befriended.email_text', # 'Hi [[user]],
28 #[[poster]] has added you to their Friends list. They will now be able to read your[[entries]] entries on their Friends page.
31 'esn.befriended.openid_email_text', # 'Hi [[user]],
33 #[[poster]] has added you to their Friends list.
37 'esn.befriended.params.body', # [[user]] has added you as a friend.
38 'esn.befriended.params.subject', # Someone has addded you as friend.
39 'esn.befriended.actions.add.friend', # Add Friend
40 'esn.befriended.actions.view.profile', # View Profile
44 sub as_email_subject
{
46 return LJ
::Lang
::get_text
($u->prop('browselang'), 'esn.befriended.subject', undef, { who
=> $self->friend->display_username } );
50 my ($self, $u, $is_html) = @_;
52 my $lang = $u->prop('browselang');
53 my $user = $is_html ?
($u->ljuser_display) : ($u->display_username);
54 my $poster = $is_html ?
($self->friend->ljuser_display) : ($self->friend->display_username);
55 my $postername = $self->friend->user;
56 my $journal_url = $self->friend->journal_base;
57 my $journal_profile = $self->friend->profile_url;
60 LJ
::Lang
::get_text_multi
($lang, undef, \
@_ml_strings_en);
62 my $entries = LJ
::is_friend
($u, $self->friend) ?
"" : " " . LJ
::Lang
::get_text
($lang, 'esn.public', undef);
63 my $is_open_identity = $self->friend->is_identity;
66 who
=> $self->friend->display_username,
68 postername
=> $poster,
74 my $email_body_key = 'esn.befriended.' .
75 ($u->is_identity ?
'openid_' : '' ) . 'email_text';
77 return LJ
::Lang
::get_text
($lang, $email_body_key, undef, $vars) .
78 $self->format_options($is_html, $lang, $vars,
80 'esn.add_friend' => [ LJ
::is_friend
($u, $self->friend) ?
0 : 1,
81 # Why not $self->friend->addfriend_url ?
82 "$LJ::SITEROOT/friends/add.bml?user=$postername" ],
83 'esn.read_journal' => [ $is_open_identity ?
0 : 2,
85 'esn.view_profile' => [ 3, $journal_profile ],
86 'esn.edit_friends' => [ 4, "$LJ::SITEROOT/friends/edit.bml" ],
87 'esn.edit_groups' => [ 5, "$LJ::SITEROOT/friends/editgroups.bml" ],
94 return _as_email
($self, $u, 0);
99 return _as_email
($self, $u, 1);
104 return LJ
::load_userid
($self->arg1);
109 return sprintf("%s has added you as a friend.",
110 $self->friend->ljuser_display);
113 sub as_html_actions
{
117 my $friend = $self->friend;
118 my $ret .= "<div class='actions'>";
119 $ret .= $u->is_friend($friend)
120 ?
" <a href='" . $friend->profile_url . "'>View Profile</a>"
121 : " <a href='" . $friend->addfriend_url . "'>Add Friend</a>";
129 return sprintf("%s has added you as a friend.",
130 $self->friend->{user
});
134 my ($self, $u, $opt) = @_;
135 my $lang = $u->prop('browselang') || $LJ::DEFAULT_LANG
;
137 my $tinyurl = "http://m.livejournal.com/read/user/"
138 . $self->friend->user;
139 my $mparms = $opt->{mobile_url_extra_params
};
140 $tinyurl .= '?' . join('&', map {$_ . '=' . $mparms->{$_}} keys %$mparms) if $mparms;
141 $tinyurl = LJ
::Client
::BitLy
->shorten($tinyurl);
142 undef $tinyurl if $tinyurl =~ /^500/;
144 # [[friend]] has added you to their friends list. Reply with ADD [[friend]] to add them [[disclaimer]]
145 return LJ
::Lang
::get_text
($lang, 'notification.sms.befriended', undef, {
146 friend
=> $self->friend->user,
147 disclaimer
=> $LJ::SMS_DISCLAIMER
,
148 mobile_url
=> $tinyurl,
155 my $friend = $self->friend;
156 return '' unless $friend;
157 return LJ
::Lang
::get_text
($u->prop('browselang'),
158 'esn.befriended.alert', undef, { who
=> $friend->ljuser_display() });
161 sub subscription_as_html
{
162 my ($class, $subscr) = @_;
163 my $journal = $subscr->journal or croak
"No user";
164 my $journal_is_owner = LJ
::u_equals
($journal, $subscr->owner);
166 if ($journal_is_owner) {
167 return LJ
::Lang
::ml
('event.befriended.me'); # "Someone adds me as a friend";
169 my $user = $journal->ljuser_display;
170 return LJ
::Lang
::ml
('event.befriended.user', { user
=> $user } ); # "Someone adds $user as a friend";
175 my ($self, $target) = @_;
176 return $self->as_html_actions;
180 my ($self, $remote) = @_;
183 my $friend = $self->friend;
185 my $lang = $remote && $remote->prop('browselang') || $LJ::DEFAULT_LANG
;
189 if ($u->is_friend($friend)) {
191 action_url
=> $friend->profile_url,
192 action
=> LJ
::Lang
::get_text
($lang, "esn.befriended.actions.view.profile"),
196 action_url
=> $friend->addfriend_url,
197 action
=> LJ
::Lang
::get_text
($lang, "esn.befriended.actions.add.friend"),
202 body
=> LJ
::Lang
::get_text
($lang, "esn.befriended.params.body", undef, { user
=> $friend->ljuser_display } ),
203 userpic
=> $friend->userpic ?
$friend->userpic->url : '',
204 subject
=> LJ
::Lang
::get_text
($lang, "esn.befriended.params.subject"),
209 sub available_for_user
{
212 return $self->userid != $u->id ?
0 : 1;
215 sub is_subscription_visible_to
{
218 return $self->userid != $u->id ?
0 : 1;
221 sub is_tracking
{ 0 }
228 return LJ
::Lang
::get_text
($lang, "esn.push.notification.befriended", 1, {
229 user
=> $self->friend->user,
233 sub as_push_payload
{
237 'j' => $self->friend->user,
241 sub update_events_counter
{
247 my $etypeid = $self->etypeid;
248 return unless $etypeid;
250 my $friend = $self->friend;
251 return unless $friend;
253 my $friendid = $friend->userid;
254 return unless $friendid;
256 LJ
::Widget
::HomePage
::UpdatesForUser
->add_event($u, pack("nnN", int(rand(2**16)), $etypeid, $friendid));