madeon (madeon) wrote in changelog,
madeon
madeon
changelog

[livejournal] r22523: LJSUP-12902: Create notifications for re...

Committer: sbelyaev
LJSUP-12902: Create notifications for reposts
U   trunk/bin/upgrading/en.dat
A   trunk/cgi-bin/LJ/Event/JournalNewRepost.pm
U   trunk/cgi-bin/ljprotocol.pl
Modified: trunk/bin/upgrading/en.dat
===================================================================
--- trunk/bin/upgrading/en.dat	2012-07-31 08:45:04 UTC (rev 22522)
+++ trunk/bin/upgrading/en.dat	2012-07-31 09:30:37 UTC (rev 22523)
@@ -2233,6 +2233,24 @@
 esn.journal_new_entry.updated_their_journal|staleness=1
 esn.journal_new_entry.updated_their_journal=[[who]] updated their journal!
 
+esn.journal_new_repost.head_comm|staleness=1
+esn.journal_new_repost.head_comm=There is a new repost by [[reposter]] posted by [[poster]] [[about]] in [[community]]![[tags]]
+
+esn.journal_new_repost.head_user|staleness=1
+esn.journal_new_repost.head_user=[[reposter]] has repost entry [[about]].[[tags]]
+
+esn.journal_new_repost_community.subject|staleness=1
+esn.journal_new_repost_community.subject=[[reposter]] has reposted entry posted by [[poster]] in [[community]]
+
+esn.journal_new_repost.subject|staleness=1
+esn.journal_new_repost.subject=[[reposter]] has reposted post from [[poster]]
+
+esn.user_new_repost_community.ashtml|staleness=1
+esn.user_new_repost_community.ashtml=[[reposter]] has reposted entry posted by [[poster]] in [[community]]
+
+esn.user_new_repost.ashtml|staleness=1
+esn.user_new_repost.ashtml=[[reposter]] has repost entry [[about]].[[tags]]
+
 esn.mail_comments.alert.anonymous_edited_reply_to_a_comment|staleness=1
 esn.mail_comments.alert.anonymous_edited_reply_to_a_comment=Anonymous user edited a [[openlink]]reply[[closelink]] to a comment.
 

Added: trunk/cgi-bin/LJ/Event/JournalNewRepost.pm
===================================================================
--- trunk/cgi-bin/LJ/Event/JournalNewRepost.pm	                        (rev 0)
+++ trunk/cgi-bin/LJ/Event/JournalNewRepost.pm	2012-07-31 09:30:37 UTC (rev 22523)
@@ -0,0 +1,394 @@
+package LJ::Event::JournalNewRepost;
+
+#
+# JournalNewRepost Event: Fired when a 'reposter' reposts 'entry' in 'journal'
+#
+
+use strict;
+use Scalar::Util qw(blessed);
+use Carp qw(croak);
+use Class::Autouse qw(LJ::Entry);
+use base 'LJ::Event';
+
+############################################################################
+# constructor & property overrides
+#
+
+sub new {
+    my ($class, $entry) = @_;
+    croak 'Not an LJ::Entry' unless blessed $entry && $entry->isa("LJ::Entry");
+    return $class->SUPER::new( $entry->poster, 
+                               $entry->journalid, 
+                               $entry->ditemid);
+}
+
+sub is_common { 0 }
+
+############################################################################
+# canonical accessors into the meaning of this event's arguments
+#  * poster:   user object who posted entry originally
+#  * journal:  journal u object where entry was posted
+#  * reposter: user who reposted entry
+#  * entry:    entry object which was posted (from journal, ditemid)
+#
+
+# user who posted the entry
+sub poster {
+    my ($self) = @_;
+    my $entry  = $self->entry;
+
+    return $self->u;
+}
+
+sub posterid {
+    my $self = shift;
+
+    return $self->poster->userid;
+}
+
+# journal entry was posted in
+sub journal {
+    my ($self) = @_;
+    my $entry  = $self->entry;
+
+    return $entry->journal;
+}
+
+sub journalid {
+    my ($self) = @_;
+    my $entry  = $self->entry; 
+
+    return $entry->journalid;
+}
+
+sub reposter {
+    my ($self) = @_;
+    return $self->u;
+}
+
+sub reposterid {
+    my ($self) = @_;
+
+    return $self->u->userid;
+}
+
+# entry which was posted
+sub entry {
+    my ($self) = @_;
+    my $real_entry = $self->real_entry;
+
+    return $real_entry->original_post;
+}
+
+sub real_entry {
+    my ($self) = @_;
+    return LJ::Entry->new($self->reposter, ditemid => $self->real_ditemid);
+}
+
+sub real_ditemid {
+    my $self = shift;
+    return $self->arg2;
+}
+
+############################################################################
+# subscription matching logic
+#
+
+sub matches_filter {
+    my ($self, $subscr) = @_;
+
+    # does the entry actually exist?
+    return 0 unless $self->journalid && $self->real_ditemid; # TODO: throw error?
+
+    # construct the entry so we can determine visibility
+    my $entry = $self->entry;
+    return 0 unless $entry && $entry->valid; # TODO: throw error?
+    return 0 unless $entry->visible_to($subscr->owner);
+
+    # journalid of 0 means 'all friends', so if the poster is
+    # a friend of the subscription owner, then they match
+    return 1 if ! $subscr->journalid && LJ::is_friend($subscr->owner, $self->poster);
+
+    # otherwise we have a journalid, see if it's the specific
+    # journal that the subscription is watching
+    return LJ::u_equals($subscr->journal, $self->poster);
+}
+
+
+############################################################################
+# methods for rendering ->as_*
+#
+
+sub as_string {
+    my ($self, $u) = @_;
+
+    my $lang     = ($u && $u->prop('browselang')) || $LJ::DEFAULT_LANG;
+    my $entry    = $self->entry;
+    my $journal  = $self->journal;
+
+    my $about = $entry->subject_text ? "\"" . $entry->subject_text . "\"" : '';
+
+    my $ml_string = $journal->is_community ? 'notification.string.usernewrepost_comm' : 
+                                             'notification.string.usernewrepost';
+
+    return LJ::Lang::get_text($lang, $ml_string, undef,
+                        {
+                            reposter      => $self->reposter->display_username,
+                            community     => $self->journal->display_username,
+                            about         => $about,
+                            poster        => $entry->poster->display_username,
+                            url           => $entry->url,
+                        });
+}
+
+sub as_sms {
+    my ($self, $u, $opt) = @_;
+    my $lang = ($u && $u->prop('browselang')) || $LJ::DEFAULT_LANG;
+
+    my $entry    = $self->entry;
+    my $journalu = $self->journal;
+    my $ml_string = $journalu->is_community ? 'notification.sms.usernewrepost_comm' : 
+                                              'notification.sms.usernewrepost';
+
+    my $tinyurl = 'http://m.livejournal.com/read/user/'
+         . $entry->journal->user . '/' . $entry->ditemid . '/';
+
+    my $mparms = $opt->{mobile_url_extra_params};
+    $tinyurl .= '?' . join('&', map {$_ . '=' . $mparms->{$_}} keys %$mparms) if $mparms;
+    $tinyurl = LJ::Client::BitLy->shorten($tinyurl);
+    undef $tinyurl if $tinyurl =~ /^500/;
+            
+    return LJ::Lang::get_text($lang, $ml_string, undef, {
+        reposter   => $self->poster->display_username,
+        community  => $entry->journal->display_username,
+        poster     => $entry->poster->display_username,
+        mobile_url => $tinyurl,
+    });    
+}
+
+sub as_alert {
+    my ($self, $u) = @_;
+
+    my $lang  = ($u && $u->prop('browselang')) || $LJ::DEFAULT_LANG;
+    my $entry = $self->entry;
+
+    my $journal = $self->journal;
+
+    my $ml_string = $journal->is_community ? 'esn.user_new_repost_community.alert' : 
+                                             'esn.user_new_repost.alert';
+
+    return LJ::Lang::get_text($lang, $ml_string, undef,
+        {
+            reposter    => $self->reposter->ljuser_display(),
+            community   => $entry->journal->ljuser_display(),
+            poster      => $entry->poster->ljuser_display(),
+            url         => "<a href=\"" . $entry->url . "\"/>" . $entry->url. "</a>",
+        });
+}
+
+sub as_html {
+    my ($self, $u) = @_;
+    
+    my $lang    = ($u && $u->prop('browselang')) || $LJ::DEFAULT_LANG;
+    my $entry   = $self->entry;
+    my $journal = $self->journal;
+    return "(Invalid entry)" unless $entry && $entry->valid;
+    my $url = $entry->url;
+
+    my $ml_string = $journal->is_community ? 'esn.user_new_repost_community.ashtml' :
+                                             'esn.user_new_repost.ashtml';
+
+    my $journal  = LJ::ljuser($self->journal);
+    my $poster   = LJ::ljuser($self->poster);
+    my $reposter = LJ::ljuser($self->reposter);
+    my $entry    = $self->entry; 
+
+    my $about = $entry->subject_text ? "\"" . $entry->subject_text . "\"" : '';
+
+    return LJ::Lang::get_text($lang, $ml_string, undef, 
+        {
+            reposter  => $reposter,
+            poster    => $poster,
+            community => $journal,
+            about     => $about,
+        }); 
+}
+
+sub as_html_actions {
+    my ($self) = @_;
+
+    my $entry = $self->entry;
+    my $url = $entry->url;
+    my $reply_url = $entry->url(mode => 'reply');
+
+    my $ret .= "<div class='actions'>";
+    $ret .= " <a href='$reply_url'>Reply</a>";
+    $ret .= " <a href='$url'>Link</a>";
+    $ret .= "</div>";
+
+    return $ret;
+}
+
+sub content {
+    my ($self, $target) = @_;
+    my $entry = $self->entry;
+
+    return undef unless $entry && $entry->valid;
+    return undef unless $entry->visible_to($target);
+
+    return $entry->event_html . $self->as_html_actions;
+}
+
+
+sub as_email_subject {
+    my ($self, $u) = @_;
+    my $lang = ($u && $u->prop('browselang')) || $LJ::DEFAULT_LANG;
+
+    my $entry    = $self->entry;
+    my $reposter = $self->reposter;
+    my $poster   = $self->poster;
+    my $journal  = $self->journal;
+
+    my $ml_string = $journal->is_community ? 'esn.journal_new_repost_community.subject' :
+                                             'esn.journal_new_repost.subject';
+
+    return LJ::Lang::get_text($lang, $ml_string, undef,
+        {
+            reposter    => $reposter->display_username,
+            poster      => $poster->display_username,
+            community   => $journal->display_username,    
+        });
+}
+
+sub _as_email {
+    my ($self, $u, $is_html) = @_;
+
+    my $lang  = ($u && $u->prop('browselang')) || $LJ::DEFAULT_LANG;
+    my $entry = $self->entry;
+
+    my $is_community = $entry->journal->is_community;
+
+    my $username = $is_html ? $u->ljuser_display :
+                              $u->display_username;
+
+    my $reposter = $self->reposter;
+    my $reposter_name = $is_html ? $reposter->ljuser_display :
+                                   $reposter->display_username;
+
+    my $poster_text = $self->entry->poster->display_username;
+    my $poster      = $is_html ? $entry->poster->ljuser_display :
+                                 $poster_text;
+
+    my $journal_text = $self->entry->journal->display_username;
+    my $journal      = $is_html ? $entry->journal->ljuser_display :
+                                  $journal_text;
+
+    my $journal_user = $self->entry->journal->user;
+    my $entry_url    = $self->entry->url;
+    my $journal_url  = $self->reposter->journal_base;
+
+    my $tags = '';
+    # add tag info for entries that have tags
+    if ($self->entry->tags) {
+        $tags = ' ' . LJ::Lang::get_text($lang, 'esn.tags', undef,
+                        {
+                            tags => join(', ', $self->entry->tags )
+                        });
+    }
+
+    my $about = '';
+    if ($self->entry->subject_text) {
+        $about = LJ::Lang::get_text($lang, 'esn.journal_new_entry.about', undef,
+                {
+                    title => $self->entry->subject_text 
+                });
+    }
+
+    my $opts = {
+        poster      => $poster,
+        journal     => $journal,
+        username    => $username,
+        is_html     => $is_html,
+    };
+
+    my $email = LJ::Lang::get_text($lang, 'esn.hi', undef, $opts);
+
+    $email .= $is_html ? '<br /><br />' : '\n\n';
+    my $ml_head_string = $is_community ? 'esn.journal_new_repost.head_comm' :
+                                         'esn.journal_new_repost.head_user';
+
+    # make hyperlinks for options
+    # tags 'poster' and 'journal' cannot contain html <a> tags
+    # when it used between [[openlink]] and [[closelink]] tags.
+    my $vars = { poster  => $poster_text, 
+                 journal => $journal_text, };
+
+    $email .= LJ::Lang::get_text($lang, $ml_head_string, undef,
+                {
+                    reposter    => $reposter_name,
+                    poster      => $reposter_name,
+                    community   => $journal,
+                    url         => $entry_url,
+                    tags        => $tags,
+                    about       => $about,
+                });
+
+    $email .= $is_html ? '<br /><br />' : '\n\n';
+
+    my $show_join_option = $self->entry->journal->is_comm && !LJ::is_friend($self->entry->journal, $u);
+
+    # Some special community (e.g. writersblock) don't want join option in esn.
+    $show_join_option = 0 if $show_join_option && LJ::run_hook('esn_hide_join_option_for_' . $self->entry->journal->user);
+
+    $email .= LJ::Lang::get_text($lang, 'esn.you_can', undef) .
+        $self->format_options($is_html, $lang, $vars,
+            {
+                'esn.view_entry'            => [ 1, $entry_url ],
+                'esn.read_recent_entries'   => [ $self->entry->journal->is_comm ? 2 : 0,
+                                                    $entry->journal->journal_base ],
+                'esn.join_community'        => [ $show_join_option ? 3 : 0,
+                                                    "$LJ::SITEROOT/community/join.bml?comm=$journal_user" ],
+                'esn.read_user_entries'     => [ 1, $journal_url ],
+                'esn.add_friend'            => [ LJ::is_friend($u, $self->reposter)? 0 : 5,
+                                                    "$LJ::SITEROOT/friends/add.bml?user=" . $u->user  ],
+            });
+
+    return $email;
+
+    
+}
+
+sub as_email_string {
+    my ($self, $u) = @_;
+    return $self->_as_email($u, 0);
+}
+
+sub as_email_html {
+    my ($self, $u) = @_;
+    return $self->_as_email($u, 1);
+}
+
+sub subscriptions {
+    my ($self, %args) = @_;
+   
+    my $entry = $self->real_entry;
+    my $event = LJ::Event::JournalNewEntry->new($entry);
+    my @entry_subs = $event->subscriptions(%args);
+
+    my @subs;
+    foreach my $subsc (@entry_subs) {
+        my $row = { userid  => $subsc->{'userid'},
+                    ntypeid => $subsc->{'ntypeid'},
+                  };
+
+        push @subs, LJ::Subscription->new_from_row($row);
+    }
+
+    return @subs;
+}
+
+sub available_for_user { 1 }
+sub is_tracking { 0 }
+sub is_subscription_visible_to { 1 }
+
+1;

Modified: trunk/cgi-bin/ljprotocol.pl
===================================================================
--- trunk/cgi-bin/ljprotocol.pl	2012-07-31 08:45:04 UTC (rev 22522)
+++ trunk/cgi-bin/ljprotocol.pl	2012-07-31 09:30:37 UTC (rev 22523)
@@ -2978,10 +2978,14 @@
     $res->{'ditemid'} = $ditemid;
     $res->{'url'} = $entry->url;
 
-    push @jobs, LJ::Event::JournalNewEntry->new($entry)->fire_job;
-    if (!$flags->{'entryrepost'} && 
-            (!$LJ::DISABLED{'esn-userevents'} || $LJ::_T_FIRE_USERNEWENTRY)) {
-        push @jobs, LJ::Event::UserNewEntry->new($entry)->fire_job
+    if ($flags->{'entryrepost'}) {
+        push @jobs, LJ::Event::JournalNewRepost->new($entry)->fire_job; 
+    } else {
+        push @jobs, LJ::Event::JournalNewEntry->new($entry)->fire_job;
+
+        if (!$LJ::DISABLED{'esn-userevents'} || $LJ::_T_FIRE_USERNEWENTRY) {
+            push @jobs, LJ::Event::UserNewEntry->new($entry)->fire_job
+        }
     }
 
     push @jobs, LJ::EventLogRecord::NewEntry->new($entry)->fire_job;

Tags: dat, livejournal, madeon, pl, pm, sbelyaev
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments