Create a new event LJ::Event::JournalNewComment::TopLevel. Also adds a
way to group related events together.
Patch by fu.
diffs (328 lines):
diff -r 2abdaecdcfe8 -r 7cdd223d44fb bin/upgrading/en.dat
--- a/bin/upgrading/en.dat Wed Jul 21 19:17:02 2010 -0700
+++ b/bin/upgrading/en.dat Wed Jul 21 19:39:13 2010 -0700
@@ -1925,6 +1925,18 @@ event.journal_new_entry.taglist.full=Oth
event.journal_new_entry.user=[[user]] posts a new entry.
+event.journal_new_top_comment.my_journal.deleted=Someone makes a new top-level
comment on a deleted entry in my journal
+
+event.journal_new_top_comment.my_journal.titled_entry=Someone makes a new
top-level comment on <a href='[[entryurl]]'>[[entrydesc]]</a> in my journal
+
+event.journal_new_top_comment.my_journal.untitled_entry=Someone makes a new
top-level comment on <a href='[[entryurl]]'>an entry</a> in my journal
+
+event.journal_new_top_comment.user_journal.deleted=Someone makes a new
top-level comment on a deleted entry in [[user]]
+
+event.journal_new_top_comment.user_journal.titled_entry=Someone makes a new
top-level comment on <a href='[[entryurl]]'>[[entrydesc]]</a> in [[user]]
+
+event.journal_new_top_comment.user_journal.untitled_entry=Someone makes a new
top-level comment on <a href='[[entryurl]]'>an entry</a> in [[user]]
+
event.officialpost=[[sitename]] makes a new announcement
event.poll_vote.id=Someone votes in poll #[[pollid]]
diff -r 2abdaecdcfe8 -r 7cdd223d44fb cgi-bin/LJ/ESN.pm
--- a/cgi-bin/LJ/ESN.pm Wed Jul 21 19:17:02 2010 -0700
+++ b/cgi-bin/LJ/ESN.pm Wed Jul 21 19:39:13 2010 -0700
@@ -56,7 +56,14 @@ sub jobs_of_unique_matching_subs {
warn "jobs of unique subs (@subs) matching event (@$params)\n";
}
- foreach my $s (grep { $evt->matches_filter($_) } @subs) {
+ my %related = map { $_=> 1 } $evt->related_events;
+
+ foreach my $s ( grep {
+ $related{$_->etypeid}
+ ? bless( $evt, $_->event_class )->matches_filter( $_ )
+ : $evt->matches_filter( $_ )
+ } @subs ) {
+
next if $has_done{$s->unique}++;
push @subjobs, TheSchwartz::Job->new(
funcname =>
'LJ::Worker::ProcessSub',
diff -r 2abdaecdcfe8 -r 7cdd223d44fb cgi-bin/LJ/Event.pm
--- a/cgi-bin/LJ/Event.pm Wed Jul 21 19:17:02 2010 -0700
+++ b/cgi-bin/LJ/Event.pm Wed Jul 21 19:39:13 2010 -0700
@@ -34,6 +34,8 @@ foreach my $event (@EVENTS) {
# ($u,$journalid,$ditemid)
# LJ::Event::JournalNewComment -- a journal has a new comment in it
# ($ju,$jtalkid) # TODO: should probably
be ($ju,$jitemid,$jtalkid)
+# LJ::Event::JournalNewComment::TopLevel -- a journal has a new top-level
comment in it
+# ($ju,$jitemid)
# LJ::Event::UserNewComment -- a user left a new comment somewhere
# ($u,$journalid,$jtalkid)
# LJ::Event::AddedToCircle -- user $fromuserid added $u to their
circle; $actionid is 1 (trust) or 2 (watch)
@@ -311,15 +313,17 @@ sub subscriptions {
my $udbh = LJ::get_cluster_master($cid)
or die;
+ my $events_list = join( ",", $self->related_events );
+
# first we find exact matches (or all matches)
my $journal_match = $allmatch ? "" : "AND journalid=?";
my $limit_sql = ($limit && $limit_remain) ? "LIMIT $limit_remain" : '';
my $sql = "SELECT userid, subid, is_dirty, journalid, etypeid, " .
"arg1, arg2, ntypeid, createtime, expiretime, flags " .
- "FROM subs WHERE etypeid=? $journal_match $and_enabled $limit_sql";
+ "FROM subs WHERE etypeid IN ($events_list) $journal_match
$and_enabled $limit_sql";
my $sth = $udbh->prepare($sql);
- my @args = ($self->etypeid);
+ my @args;
push @args, $self->u->id unless $allmatch;
$sth->execute(@args);
if ($sth->err) {
@@ -339,10 +343,10 @@ sub subscriptions {
my $sth = $udbh->prepare(
"SELECT userid, subid, is_dirty,
journalid, etypeid, " .
"arg1, arg2, ntypeid, createtime,
expiretime, flags " .
- "FROM subs USE INDEX(PRIMARY) WHERE
etypeid=? AND journalid=0 $and_enabled AND userid IN ($jidlist)"
+ "FROM subs USE INDEX(PRIMARY) WHERE
etypeid IN ($events_list) AND journalid=0 $and_enabled AND userid IN ($jidlist)"
);
- $sth->execute($self->etypeid);
+ $sth->execute;
die $sth->errstr if $sth->err;
while (my $row = $sth->fetchrow_hashref) {
@@ -428,6 +432,13 @@ sub etypeid {
or return undef;
return $tm->class_to_typeid($class);
+}
+
+# return a list of related events, for considering as one group
+# to avoid dupes when processing subs
+# list includes your own etypeid
+sub related_events {
+ return $_[0]->etypeid;
}
# Class method
diff -r 2abdaecdcfe8 -r 7cdd223d44fb cgi-bin/LJ/Event/JournalNewComment.pm
--- a/cgi-bin/LJ/Event/JournalNewComment.pm Wed Jul 21 19:17:02 2010 -0700
+++ b/cgi-bin/LJ/Event/JournalNewComment.pm Wed Jul 21 19:39:13 2010 -0700
@@ -26,6 +26,10 @@ sub new {
my ($class, $comment) = @_;
croak 'Not an LJ::Comment' unless blessed $comment &&
$comment->isa("LJ::Comment");
return $class->SUPER::new($comment->journal, $comment->jtalkid);
+}
+
+sub related_events {
+ return map { $_->etypeid } ( $_[0],
"LJ::Event::JournalNewComment::TopLevel" );
}
sub is_common { 1 }
@@ -326,13 +330,13 @@ sub as_html_actions {
# 33
event.journal_new_comment.user_journal.untitled_entry.untitled_thread.anonymous=Someone
comments under <a href='[[threadurl]]'>the thread</a> by (Anonymous) in <a
href='[[entryurl]]'>en entry</a> in [[user]]
# -- now, let's begin.
sub subscription_as_html {
- my ($class, $subscr) = @_;
+ my ( $class, $subscr, $key_prefix ) = @_;
my $arg1 = $subscr->arg1;
my $arg2 = $subscr->arg2;
my $journal = $subscr->journal;
- my $key = 'event.journal_new_comment';
+ my $key = $key_prefix || 'event.journal_new_comment';
if (!$journal) {
### 01 event.journal_new_comment.friend=Someone comments in any journal on my
friends page
diff -r 2abdaecdcfe8 -r 7cdd223d44fb
cgi-bin/LJ/Event/JournalNewComment/TopLevel.pm
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/cgi-bin/LJ/Event/JournalNewComment/TopLevel.pm Wed Jul 21 19:39:13
2010 -0700
@@ -0,0 +1,47 @@
+#!/usr/bin/perl
+#
+# LJ::Event::JournalNewComment::TopLevel - Event that's fired when someone
makes a new top-level comment to an entry
+#
+# Authors:
+# Afuna <[email protected]>
+#
+# Copyright (c) 2010 by Dreamwidth Studios, LLC.
+#
+# This program is free software; you may redistribute it and/or modify it under
+# the same terms as Perl itself. For a copy of the license, please reference
+# 'perldoc perlartistic' or 'perldoc perlgpl'.
+
+package LJ::Event::JournalNewComment::TopLevel;
+use strict;
+
+use base 'LJ::Event::JournalNewComment';
+
+sub subscription_as_html {
+ return LJ::Event::JournalNewComment->subscription_as_html( $_[1],
"event.journal_new_top_comment" );
+}
+
+sub matches_filter {
+ my ($self, $subscr) = @_;
+
+ my $sjid = $subscr->journalid;
+ my $ejid = $self->event_journal->{userid};
+
+ # check that subscription's journal is the same as event's journal
+ return 0 if $sjid && $sjid != $ejid;
+
+
+ my $comment = $self->comment;
+ my $entry = $comment->entry;
+ return 0 unless $entry;
+
+ # check that event's entry is the entry we're interested in (subscribed to)
+ my $wanted_ditemid = $subscr->arg1;
+ return 0 if $wanted_ditemid && $entry->ditemid != $wanted_ditemid;
+
+ # we're only interested if it's a top-level comment
+ return 1 unless $comment->parenttalkid;
+
+ return 0;
+}
+
+1;
diff -r 2abdaecdcfe8 -r 7cdd223d44fb cgi-bin/LJ/NotificationInbox.pm
--- a/cgi-bin/LJ/NotificationInbox.pm Wed Jul 21 19:17:02 2010 -0700
+++ b/cgi-bin/LJ/NotificationInbox.pm Wed Jul 21 19:39:13 2010 -0700
@@ -179,7 +179,7 @@ sub singleentry_items {
sub singleentry_items {
my ( $self, $itemid ) = @_;
return grep {
- $_->event->class eq "LJ::Event::JournalNewComment"
+ ( $_->event->class eq "LJ::Event::JournalNewComment" ||
$_->event->class eq "LJ::Event::JournalNewComment::TopLevel" )
&& $_->event->comment
&& $_->event->comment->entry # may have been deleted, which breaks
all filter to entry comments
&& $_->event->comment->entry->ditemid == $itemid
@@ -297,7 +297,7 @@ sub instantiate_comment_singletons {
# instantiate all the comment singletons so that they will all be
# loaded efficiently later as soon as preload_rows is called on
# the first comment object
- my @comment_items = grep { $_->event && $_->event->class eq
'LJ::Event::JournalNewComment' } $self->items;
+ my @comment_items = grep { $_->event && ( $_->event->class eq
'LJ::Event::JournalNewComment' || $_->event->class eq
'LJ::Event::JournalNewComment::TopLevel' ) } $self->items;
my @comment_events = map { $_->event } @comment_items;
# instantiate singletons
LJ::Comment->new($_->event_journal, jtalkid => $_->jtalkid) foreach
@comment_events;
@@ -755,7 +755,7 @@ sub circle_event_list {
}
sub entrycomment_event_list {
- my @events = ( 'JournalNewEntry', 'JournalNewComment');
+ my @events = ( 'JournalNewEntry', 'JournalNewComment',
'JournalNewComment::TopLevel' );
return @events;
}
diff -r 2abdaecdcfe8 -r 7cdd223d44fb cgi-bin/ljdefaults.pl
--- a/cgi-bin/ljdefaults.pl Wed Jul 21 19:17:02 2010 -0700
+++ b/cgi-bin/ljdefaults.pl Wed Jul 21 19:39:13 2010 -0700
@@ -205,6 +205,7 @@
JournalNewComment
JournalNewEntry
UserNewComment
+ JournalNewComment::TopLevel
UserNewEntry
CommunityInvite
CommunityJoinRequest
diff -r 2abdaecdcfe8 -r 7cdd223d44fb htdocs/manage/subscriptions/entry.bml
--- a/htdocs/manage/subscriptions/entry.bml Wed Jul 21 19:17:02 2010 -0700
+++ b/htdocs/manage/subscriptions/entry.bml Wed Jul 21 19:39:13 2010 -0700
@@ -61,6 +61,14 @@ body<=
default_selected => 1,
flags => LJ::Subscription::TRACKING,
),
+
+ LJ::Subscription::Pending->new( $remote,
+ event => "JournalNewComment::TopLevel",
+ arg1 => $ditemid,
+ journal => $journal,
+ default_selected => 0,
+ flags => LJ::Subscription::TRACKING,
+ ),
],
}
];
diff -r 2abdaecdcfe8 -r 7cdd223d44fb t/esn-journalnewcomment.t
--- a/t/esn-journalnewcomment.t Wed Jul 21 19:17:02 2010 -0700
+++ b/t/esn-journalnewcomment.t Wed Jul 21 19:39:13 2010 -0700
@@ -11,7 +11,7 @@ use LJ::Test qw(memcache_stress temp_use
use LJ::Test qw(memcache_stress temp_user);
use FindBin qw($Bin);
-plan tests => 27;
+plan tests => 36;
# we want to test eight major cases here, matching and not matching for
# four types of subscriptions, all of subscr etypeid = JournalNewComment
@@ -22,6 +22,9 @@ plan tests => 27;
# S3: n ditemid jtalkid all new comments UNDER comment n/jtalkid (in
ditemid)
# S4: 0 0 0 all new comments from any journal you watch
# -- NOTE: This test is disabled unless JournalNewComment allows it
+
+# we also want to test for matching and not matching cases for
JournalNewComment::TopLevel
+# a subclass of JournalNewComment
my %got_email = (); # userid -> received email
@@ -220,6 +223,65 @@ test_esn_flow(sub {
$subsc->delete;
}
+
+ # LJ::Event::JournalNewComment::TopLevel
+ my $u2e5 = eval { $u2->t_post_fake_entry };
+
+ # subscribe to replies to a thread
+ my $subsc = $u1->subscribe(
+ event => "JournalNewComment::TopLevel",
+ method => "Email",
+ journal => $u2,
+ arg1 => $u2e5->ditemid,
+ );
+ ok( $subsc, "Subscribed" );
+
+ # post a top-level comment
+ $comment = $u2e5->t_enter_comment;
+ ok( $comment, "Posted comment" );
+
+ $proc_events->();
+
+ $email = $got_email{$u1->{userid}};
+ ok( $email, "Got notified" );
+
+ $email = $got_email{$u2->{userid}};
+ ok( ! $email, "Unsubscribed watcher not notified" );
+
+ # reply to a comment on this entry, make sure we're not notified
+ my $reply = $comment->t_reply;
+ ok( $reply, "Posted reply" );
+
+ $email = $got_notified->( $u1 );
+ ok( ! $email, "didn't get notified" );
+
+ $subsc->delete;
+
+ my $u2e6 = eval { $u2->t_post_fake_entry };
+ $subsc = $u1->subscribe(
+ event => "JournalNewComment",
+ method => "Email",
+ journal => $u2,
+ arg1 => $u2e6->ditemid,
+ );
+
+ my $subsc2 = $u1->subscribe(
+ event => "JournalNewComment::TopLevel",
+ method => "Email",
+ journal => $u2,
+ arg1 => $u2e6->ditemid,
+ );
+ ok( $subsc2, "Subscribed to new top-level comments on this journal" );
+
+ $comment = $u2e6->t_enter_comment( u => $u2 );
+ ok( $comment, "Posted comment" );
+
+ $proc_events->();
+ is( $got_email{$u1->userid}, 1, "No duplicate emails");
+
+ $subsc->delete;
+ $subsc2->delete;
+
});
sub test_esn_flow {
_______________________________________________
dw-changelog mailing list
[email protected]
http://lists.dwscoalition.org/mailman/listinfo/dw-changelog