Андрей (andy) wrote in changelog,
Андрей
andy
changelog

[ljcom] r8129: LJSV-878: implement more logic from the ...

Committer: ailyin
LJSV-878: implement more logic from the spec

U   trunk/cgi-bin/LJ/Event/NewVGift.pm
U   trunk/cgi-bin/LJ/Event/SupOfficialPost.pm
U   trunk/cgi-bin/LJ/Hooks/CreatePage.pm
U   trunk/cgi-bin/LJ/Pay.pm
Modified: trunk/cgi-bin/LJ/Event/NewVGift.pm
===================================================================
--- trunk/cgi-bin/LJ/Event/NewVGift.pm	2010-01-25 05:19:43 UTC (rev 8128)
+++ trunk/cgi-bin/LJ/Event/NewVGift.pm	2010-01-25 07:25:21 UTC (rev 8129)
@@ -182,10 +182,18 @@
         BML::ml('event.vgift.me');
 }
 
-sub is_tracking {
-    my ($self) = @_;
+sub available_for_user  {
+    my ($self, $u) = @_;
 
-    return $self->{'userid'} ? 1 : 0;
+    return $self->userid ? 0 : 1;
 }
 
+sub is_subscription_visible_to  {
+    my ($self, $u) = @_;
+
+    return $self->userid ? 0 : 1;
+}
+
+sub is_tracking { 0 }
+
 1;

Modified: trunk/cgi-bin/LJ/Event/SupOfficialPost.pm
===================================================================
--- trunk/cgi-bin/LJ/Event/SupOfficialPost.pm	2010-01-25 05:19:43 UTC (rev 8128)
+++ trunk/cgi-bin/LJ/Event/SupOfficialPost.pm	2010-01-25 07:25:21 UTC (rev 8129)
@@ -24,4 +24,14 @@
     return LJ::SUP->is_sup_enabled($u);
 }
 
+sub available_for_user {
+    my ($self, $u) = @_;
+
+    return LJ::SUP->is_sup_enabled($u);
+}
+
+sub is_tracking { 0 }
+
+sub schwartz_role { 'mass' }
+
 1;

Modified: trunk/cgi-bin/LJ/Hooks/CreatePage.pm
===================================================================
--- trunk/cgi-bin/LJ/Hooks/CreatePage.pm	2010-01-25 05:19:43 UTC (rev 8128)
+++ trunk/cgi-bin/LJ/Hooks/CreatePage.pm	2010-01-25 07:25:21 UTC (rev 8129)
@@ -208,25 +208,72 @@
         # Befriend oneself
         $u->add_friend($u);
 
-        $u->subscribe( event => 'OfficialPost', method => 'Inbox' );
-        $u->subscribe( event => 'OfficialPost', method => 'Email' )
-            if $arg->{news};
-        $u->subscribe( event => 'JournalNewComment', journal => $u, method => 'Inbox' );
-        $u->subscribe( event => 'JournalNewComment', journal => $u, method => 'Email' );
-        $u->subscribe( event => 'Befriended', journal => $u, method => 'Inbox' );
-        $u->subscribe( event => 'Befriended', journal => $u, method => 'Email' );
-        $u->subscribe( event => 'NewVGift', method => 'Inbox' );
-        $u->subscribe( event => 'NewVGift', method => 'Email' );
-        $u->subscribe( event => 'Birthday', method => 'Inbox' );
-        $u->subscribe( event => 'Birthday', method => 'Email' );
-        # Everyone is subscribed to UserMessageRecvd Inbox
-        $u->subscribe( event => 'UserMessageRecvd', journal => $u, method => 'Email' );
-        $u->subscribe( event => 'InvitedFriendJoins', journal => $u, method => 'Inbox' );
-        $u->subscribe( event => 'InvitedFriendJoins', journal => $u, method => 'Email' );
-        $u->subscribe( event => 'CommunityInvite', journal => $u, method => 'Inbox' );
-        $u->subscribe( event => 'CommunityInvite', journal => $u, method => 'Email' );
-        $u->subscribe( event => 'CommunityJoinRequest', journal => $u, method => 'Inbox' );
-        $u->subscribe( event => 'CommunityJoinRequest', journal => $u, method => 'Email' );
+        # we are not anymore using this. ugh.
+        LJ::update_user($u, {'opt_gettalkemail' => 'N'});
+
+        my @subs = (
+            'JournalNewComment-u',
+            'CommunityEntryReply',
+            'CommentReply',
+            'Befriended-u',
+            'Defriended-u',
+            'UserMessageRecvd-u',
+            'InvitedFriendJoins-u',
+            'CommunityInvite-u',
+            'CommunityJoinRequest-u',
+            'NewUserpic',
+            'Birthday',
+            'NewVGift',
+        );
+        
+        push @subs, (
+            'OfficialPost',
+            'SupOfficialPost',
+        ) if $arg->{'news'};
+
+        my $set = LJ::Subscription::GroupSet->fetch_for_user($u);
+        my $newset = $set->clone;
+
+        foreach my $subcode (@subs) {
+            my $journalid = 0;
+
+            if ($subcode =~ /\-u$/) {
+                $journalid = $u->id;
+                $subcode =~ s/\-u$//;
+            }
+
+            my $sub = bless({
+                'userid' => $u->id,
+                'journalid' => $journalid,
+                'etypeid' => LJ::Event->event_to_etypeid($subcode),
+                'arg1' => 0,
+                'arg2' => 0,
+                'is_dirty' => 0,
+                'ntypeid' => 0,
+                'createtime' => time,
+                'expiretime' => 0,
+                'flags' => 0,
+            }, 'LJ::Subscription');
+
+            foreach my $ntype (qw(Inbox Email)) {
+                my $ntypeid = LJ::NotificationMethod->method_to_ntypeid($ntype);
+                $sub->{'ntypeid'} = $ntypeid;
+
+                $newset->insert_sub($sub);
+            }
+        }
+
+        eval {
+            $set->update($newset);
+        };
+
+        if ($@) {
+            # theoretically, we didn't subscribe to any tracking subs yet,
+            # so there shouldn't be any errors, but if there are any,
+            # let's report
+
+            cluck "error subscribing user: " . $u->id;
+        }
     }
 });
 

Modified: trunk/cgi-bin/LJ/Pay.pm
===================================================================
--- trunk/cgi-bin/LJ/Pay.pm	2010-01-25 05:19:43 UTC (rev 8128)
+++ trunk/cgi-bin/LJ/Pay.pm	2010-01-25 07:25:21 UTC (rev 8129)
@@ -434,7 +434,7 @@
         unless $is_comm || $is_identity;
 
     # subscriptions
-    my $sub_count = grep { $_->active && $_->enabled } $u->find_subscriptions( method => 'Inbox' );
+    my $sub_count = $u->subscriptions_count;
     my $sub_max = $u->get_cap('subscriptions');
     $ret .= "<br />" . BML::ml('pay.widget.subscriptions', { numused => $sub_count, max => $sub_max })
         if $u->can_use_esn && !$u->is_community;

Tags: andy, ljcom, pm
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