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

[livejournal] r16122: LJSV-878: implement more logic from the ...

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

U   trunk/cgi-bin/LJ/Event/Befriended.pm
U   trunk/cgi-bin/LJ/Event/Birthday.pm
U   trunk/cgi-bin/LJ/Event/CommentReply.pm
U   trunk/cgi-bin/LJ/Event/CommunityEntryReply.pm
U   trunk/cgi-bin/LJ/Event/CommunityInvite.pm
U   trunk/cgi-bin/LJ/Event/CommunityJoinApprove.pm
U   trunk/cgi-bin/LJ/Event/CommunityJoinReject.pm
U   trunk/cgi-bin/LJ/Event/CommunityJoinRequest.pm
U   trunk/cgi-bin/LJ/Event/Defriended.pm
U   trunk/cgi-bin/LJ/Event/InvitedFriendJoins.pm
U   trunk/cgi-bin/LJ/Event/JournalNewComment.pm
U   trunk/cgi-bin/LJ/Event/JournalNewEntry.pm
U   trunk/cgi-bin/LJ/Event/NewUserpic.pm
U   trunk/cgi-bin/LJ/Event/OfficialPost.pm
U   trunk/cgi-bin/LJ/Event/PollVote.pm
U   trunk/cgi-bin/LJ/Event/UserExpunged.pm
U   trunk/cgi-bin/LJ/Event/UserMessageRecvd.pm
U   trunk/cgi-bin/LJ/Event/UserMessageSent.pm
U   trunk/cgi-bin/LJ/Event/UserNewComment.pm
U   trunk/cgi-bin/LJ/Event/UserNewEntry.pm
U   trunk/cgi-bin/LJ/Event.pm
Modified: trunk/cgi-bin/LJ/Event/Befriended.pm
===================================================================
--- trunk/cgi-bin/LJ/Event/Befriended.pm	2010-01-25 06:43:30 UTC (rev 16121)
+++ trunk/cgi-bin/LJ/Event/Befriended.pm	2010-01-25 07:24:56 UTC (rev 16122)
@@ -159,6 +159,18 @@
     return $self->as_html_actions;
 }
 
+sub available_for_user  {
+    my ($self, $u) = @_;
+
+    return $self->userid != $u->id ? 0 : 1;
+}
+
+sub is_subscription_visible_to  {
+    my ($self, $u) = @_;
+
+    return $self->userid != $u->id ? 0 : 1;
+}
+
 sub is_tracking { 0 }
 
 1;

Modified: trunk/cgi-bin/LJ/Event/Birthday.pm
===================================================================
--- trunk/cgi-bin/LJ/Event/Birthday.pm	2010-01-25 06:43:30 UTC (rev 16121)
+++ trunk/cgi-bin/LJ/Event/Birthday.pm	2010-01-25 07:24:56 UTC (rev 16122)
@@ -166,10 +166,13 @@
     return $self->as_html_actions;
 }
 
-sub is_tracking {
-    my ($self) = @_;
+sub available_for_user  { 1 }
+sub is_subscription_visible_to  { 1 }
 
-    return $self->{'userid'} ? 1 : 0;
+sub is_tracking
+    my ($self, $u) = @_;
+
+    return $self->userid ? 1 : 0;
 }
 
 1;

Modified: trunk/cgi-bin/LJ/Event/CommentReply.pm
===================================================================
--- trunk/cgi-bin/LJ/Event/CommentReply.pm	2010-01-25 06:43:30 UTC (rev 16121)
+++ trunk/cgi-bin/LJ/Event/CommentReply.pm	2010-01-25 07:24:56 UTC (rev 16122)
@@ -10,6 +10,8 @@
 
 sub available_for_user  { 1 }
 
+sub is_subscription_visible_to { 1 }
+
 sub is_tracking { 0 }
 
 1;

Modified: trunk/cgi-bin/LJ/Event/CommunityEntryReply.pm
===================================================================
--- trunk/cgi-bin/LJ/Event/CommunityEntryReply.pm	2010-01-25 06:43:30 UTC (rev 16121)
+++ trunk/cgi-bin/LJ/Event/CommunityEntryReply.pm	2010-01-25 07:24:56 UTC (rev 16122)
@@ -10,6 +10,8 @@
 
 sub available_for_user  { 1 }
 
+sub is_subscription_visible_to { 1 }
+
 sub is_tracking { 0 }
 
 1;

Modified: trunk/cgi-bin/LJ/Event/CommunityInvite.pm
===================================================================
--- trunk/cgi-bin/LJ/Event/CommunityInvite.pm	2010-01-25 06:43:30 UTC (rev 16121)
+++ trunk/cgi-bin/LJ/Event/CommunityInvite.pm	2010-01-25 07:24:56 UTC (rev 16122)
@@ -160,6 +160,8 @@
     return BML::ml('event.comm_invite'); # "I receive an invitation to join a community";
 }
 
+sub available_for_user  { 1 }
+sub is_subscription_visible_to  { 1 }
 sub is_tracking { 0 }
 
 package LJ::Error::Event::CommunityInvite;

Modified: trunk/cgi-bin/LJ/Event/CommunityJoinApprove.pm
===================================================================
--- trunk/cgi-bin/LJ/Event/CommunityJoinApprove.pm	2010-01-25 06:43:30 UTC (rev 16121)
+++ trunk/cgi-bin/LJ/Event/CommunityJoinApprove.pm	2010-01-25 07:24:56 UTC (rev 16122)
@@ -98,6 +98,8 @@
     return LJ::load_userid($self->arg1);
 }
 
+sub available_for_user  { 1 }
+sub is_subscription_visible_to  { 0 }
 sub is_tracking { 0 }
 
 1;

Modified: trunk/cgi-bin/LJ/Event/CommunityJoinReject.pm
===================================================================
--- trunk/cgi-bin/LJ/Event/CommunityJoinReject.pm	2010-01-25 06:43:30 UTC (rev 16121)
+++ trunk/cgi-bin/LJ/Event/CommunityJoinReject.pm	2010-01-25 07:24:56 UTC (rev 16122)
@@ -89,6 +89,8 @@
     return LJ::load_userid($self->arg1);
 }
 
+sub available_for_user  { 1 }
+sub is_subscription_visible_to  { 0 }
 sub is_tracking { 0 }
 
 1;

Modified: trunk/cgi-bin/LJ/Event/CommunityJoinRequest.pm
===================================================================
--- trunk/cgi-bin/LJ/Event/CommunityJoinRequest.pm	2010-01-25 06:43:30 UTC (rev 16121)
+++ trunk/cgi-bin/LJ/Event/CommunityJoinRequest.pm	2010-01-25 07:24:56 UTC (rev 16122)
@@ -158,7 +158,10 @@
     return BML::ml('event.community_join_requst'); # Someone requests membership in a community I maintain';
 }
 
+sub available_for_user  { 1 }
+sub is_subscription_visible_to  { 1 }
 sub is_tracking { 0 }
+
 package LJ::Error::Event::CommunityJoinRequest;
 sub fields { 'u' }
 sub as_string {

Modified: trunk/cgi-bin/LJ/Event/Defriended.pm
===================================================================
--- trunk/cgi-bin/LJ/Event/Defriended.pm	2010-01-25 06:43:30 UTC (rev 16121)
+++ trunk/cgi-bin/LJ/Event/Defriended.pm	2010-01-25 07:24:56 UTC (rev 16122)
@@ -131,16 +131,23 @@
     return BML::ml('event.defriended.' . ($journal_is_owner ? 'me' : 'user'), { user => $journal->ljuser_display });
 }
 
-# only users with the track_defriended cap can use this
+sub content {
+    my ($self) = @_;
+
+    return $self->as_html_actions;
+}
+
 sub available_for_user  {
     my ($self, $u) = @_;
+
+    return 0 if $self->userid != $u->id;
     return $u->get_cap("track_defriended") ? 1 : 0;
 }
 
-sub content {
-    my ($self) = @_;
+sub is_subscription_visible_to  {
+    my ($self, $u) = @_;
 
-    return $self->as_html_actions;
+    return $self->userid != $u->id ? 0 : 1;
 }
 
 sub is_tracking { 0 }

Modified: trunk/cgi-bin/LJ/Event/InvitedFriendJoins.pm
===================================================================
--- trunk/cgi-bin/LJ/Event/InvitedFriendJoins.pm	2010-01-25 06:43:30 UTC (rev 16121)
+++ trunk/cgi-bin/LJ/Event/InvitedFriendJoins.pm	2010-01-25 07:24:56 UTC (rev 16122)
@@ -135,6 +135,8 @@
     return $self->as_html_actions;
 }
 
+sub available_for_user  { 1 }
+sub is_subscription_visible_to  { 1 }
 sub is_tracking { 0 }
 
 1;

Modified: trunk/cgi-bin/LJ/Event/JournalNewComment.pm
===================================================================
--- trunk/cgi-bin/LJ/Event/JournalNewComment.pm	2010-01-25 06:43:30 UTC (rev 16121)
+++ trunk/cgi-bin/LJ/Event/JournalNewComment.pm	2010-01-25 07:24:56 UTC (rev 16122)
@@ -561,22 +561,36 @@
 sub available_for_user  {
     my ($self, $u) = @_;
 
-    # not allowed to track replies to comments
-    return 0 if ! $u->get_cap('track_thread') &&
-        $self->arg2;
+    my $journal = $self->event_journal;
+    my ($arg1, $arg2) = ($self->arg1, $self->arg2);
 
-    return 1 if $self->arg1;
+    # user can always track all comments to their own journal
+    if (LJ::u_equals($journal, $u) && !$arg1 && !$arg2) {
+        return 1;
+    }
 
-    my $journal = $self->event_journal;
+    # user can track all comments to their community journal, provided
+    # that the community is paid
+    if (LJ::can_manage($u, $journal) && !$arg1 && !$arg2) {
+        return $journal->get_cap('maintainer_track_comments') ? 1 : 0;
+    }
 
-    return 1 if LJ::u_equals($u, $journal); # one can always subscribe to self
+    # user can always track comments to a specific entry
+    if ($arg1) {
+        return 1;
+    }
 
-    return 0 unless LJ::can_manage($u, $journal); # not a maintainer
-    return 0 unless $journal->get_cap('maintainer_track_commments');
+    # user can track comments left to a thread if and only if they have a paid
+    # account
+    if ($arg2) {
+        return $u->get_cap('track_thread') ? 1 : 0;
+    }
 
-    return 1;
+    return 0;
 }
 
+sub is_subscription_visible_to { 1 }
+
 sub get_disabled_pic {
     my ($self, $u) = @_;
 
@@ -729,7 +743,7 @@
     my ($self, $ownerid) = @_;
 
     return 1 if $self->arg1 || $self->arg2;
-    return 1 unless $self->{'userid'} == $ownerid;
+    return 1 unless $self->event_journal->id == $ownerid;
 
     return 0;
 }

Modified: trunk/cgi-bin/LJ/Event/JournalNewEntry.pm
===================================================================
--- trunk/cgi-bin/LJ/Event/JournalNewEntry.pm	2010-01-25 06:43:30 UTC (rev 16121)
+++ trunk/cgi-bin/LJ/Event/JournalNewEntry.pm	2010-01-25 07:24:56 UTC (rev 16122)
@@ -385,9 +385,12 @@
         return 0 unless scalar(@tagids);
     }
 
-    return $self->SUPER::is_subscription_visible_to($u);
+    return 1;
 }
 
+sub is_tracking { 1 }
+sub available_for_user { 1 }
+
 # when was this entry made?
 sub eventtime_unix {
     my $self = shift;

Modified: trunk/cgi-bin/LJ/Event/NewUserpic.pm
===================================================================
--- trunk/cgi-bin/LJ/Event/NewUserpic.pm	2010-01-25 06:43:30 UTC (rev 16121)
+++ trunk/cgi-bin/LJ/Event/NewUserpic.pm	2010-01-25 07:24:56 UTC (rev 16122)
@@ -140,20 +140,23 @@
         BML::ml('event.userpic_upload.me');
 }
 
-# only users with the track_user_newuserpic cap can use this
+sub is_tracking {
+    my ($self) = @_;
+
+    return $self->{'userid'} ? 1 : 0;
+}
+
 sub available_for_user  {
     my ($self, $u) = @_;
 
-    return 0 if ! $u->get_cap('track_user_newuserpic') &&
-        $self->{'userid'};
-
-    return 1;
+    return 1 unless $self->userid;
+    return $u->get_cap("track_user_newuserpic") ? 1 : 0;
 }
 
-sub is_tracking {
-    my ($self) = @_;
+sub is_tracking
+    my ($self, $u) = @_;
 
-    return $self->{'userid'} ? 1 : 0;
+    return $self->userid ? 1 : 0;
 }
 
 1;

Modified: trunk/cgi-bin/LJ/Event/OfficialPost.pm
===================================================================
--- trunk/cgi-bin/LJ/Event/OfficialPost.pm	2010-01-25 06:43:30 UTC (rev 16121)
+++ trunk/cgi-bin/LJ/Event/OfficialPost.pm	2010-01-25 07:24:56 UTC (rev 16122)
@@ -162,4 +162,6 @@
 
 sub is_tracking { 0 }
 
+sub is_subscription_visible_to { 1 }
+
 1;

Modified: trunk/cgi-bin/LJ/Event/PollVote.pm
===================================================================
--- trunk/cgi-bin/LJ/Event/PollVote.pm	2010-01-25 06:43:30 UTC (rev 16121)
+++ trunk/cgi-bin/LJ/Event/PollVote.pm	2010-01-25 07:24:56 UTC (rev 16122)
@@ -166,16 +166,21 @@
         BML::ml('event.poll_vote.me');  # "Someone votes in a poll I posted" unless $pollid;
 }
 
-# only users with the track_pollvotes cap can use this
 sub available_for_user  {
     my ($self, $u) = @_;
+
+    return 0 if $self->arg1;
+    return 0 unless LJ::u_equals($u, $self->u);
+
     return $u->get_cap("track_pollvotes") ? 1 : 0;
 }
 
-sub is_tracking {
-    my ($self) = @_;
+sub is_subscription_visible_to  {
+    my ($self, $u) = @_;
 
-    return $self->{'arg1'} ? 1 : 0;
+    return $self->arg1 ? 0 : 1;
 }
 
+sub is_tracking { 0 }
+
 1;

Modified: trunk/cgi-bin/LJ/Event/UserExpunged.pm
===================================================================
--- trunk/cgi-bin/LJ/Event/UserExpunged.pm	2010-01-25 06:43:30 UTC (rev 16121)
+++ trunk/cgi-bin/LJ/Event/UserExpunged.pm	2010-01-25 07:24:56 UTC (rev 16122)
@@ -95,4 +95,8 @@
     return $self->as_html_actions;
 }
 
+sub available_for_user  { 1 }
+sub is_subscription_visible_to  { 1 }
+sub is_tracking { 0 }
+
 1;

Modified: trunk/cgi-bin/LJ/Event/UserMessageRecvd.pm
===================================================================
--- trunk/cgi-bin/LJ/Event/UserMessageRecvd.pm	2010-01-25 06:43:30 UTC (rev 16121)
+++ trunk/cgi-bin/LJ/Event/UserMessageRecvd.pm	2010-01-25 07:24:56 UTC (rev 16122)
@@ -216,9 +216,6 @@
     return $ret;
 }
 
-# Event is always subscribed to
-sub always_checked { 1 }
-
 # return detailed data for XMLRPC::getinbox
 sub raw_info {
     my ($self, $target) = @_;
@@ -244,12 +241,20 @@
     return $res;
 }
 
-sub is_tracking {
-    my ($self, $ownerid) = @_;
+sub available_for_user  {
+    my ($self, $u) = @_;
 
-    return $self->{'userid'} == $ownerid ? 0 : 1;
+    return $self->userid != $u->id ? 0 : 1;
 }
 
+sub is_subscription_visible_to  {
+    my ($self, $u) = @_;
+
+    return $self->userid != $u->id ? 0 : 1;
+}
+
+sub is_tracking { 0 }
+
 sub is_subscription_ntype_disabled_for {
     my ($self, $ntypeid, $u) = @_;
 

Modified: trunk/cgi-bin/LJ/Event/UserMessageSent.pm
===================================================================
--- trunk/cgi-bin/LJ/Event/UserMessageSent.pm	2010-01-25 06:43:30 UTC (rev 16121)
+++ trunk/cgi-bin/LJ/Event/UserMessageSent.pm	2010-01-25 07:24:56 UTC (rev 16122)
@@ -65,7 +65,7 @@
     return $body;
 }
 
-# override parent class sbuscriptions method to always return
+# override parent class subscriptions method to always return
 # a subscription object for the user
 sub subscriptions {
     my ($self, %args) = @_;
@@ -135,4 +135,14 @@
     return $res;
 }
 
+sub available_for_user  {
+    my ($self, $u) = @_;
+
+    return $self->userid != $u->id ? 0 : 1;
+}
+
+sub is_subscription_visible_to  { 0 }
+
+sub is_tracking { 0 }
+
 1;

Modified: trunk/cgi-bin/LJ/Event/UserNewComment.pm
===================================================================
--- trunk/cgi-bin/LJ/Event/UserNewComment.pm	2010-01-25 06:43:30 UTC (rev 16121)
+++ trunk/cgi-bin/LJ/Event/UserNewComment.pm	2010-01-25 07:24:56 UTC (rev 16122)
@@ -26,4 +26,8 @@
     return LJ::Comment->new($self->journal, jtalkid => $self->arg1);
 }
 
+sub available_for_user { 0 }
+sub is_tracking { 1 }
+sub is_subscription_visible_to { 1 }
+
 1;

Modified: trunk/cgi-bin/LJ/Event/UserNewEntry.pm
===================================================================
--- trunk/cgi-bin/LJ/Event/UserNewEntry.pm	2010-01-25 06:43:30 UTC (rev 16121)
+++ trunk/cgi-bin/LJ/Event/UserNewEntry.pm	2010-01-25 07:24:56 UTC (rev 16122)
@@ -158,4 +158,8 @@
         BML::ml('event.user_new_entry.any'); # "Any of my friends posts a new entry anywhere."
 }
 
+sub available_for_user { 0 }
+sub is_tracking { 1 }
+sub is_subscription_visible_to { 1 }
+
 1;

Modified: trunk/cgi-bin/LJ/Event.pm
===================================================================
--- trunk/cgi-bin/LJ/Event.pm	2010-01-25 06:43:30 UTC (rev 16121)
+++ trunk/cgi-bin/LJ/Event.pm	2010-01-25 07:24:56 UTC (rev 16122)
@@ -124,6 +124,7 @@
 # my $journal = $event->u;
 # my $arg1    = $event->arg1;
 sub event_journal { &u; }
+sub userid        { $_[0]->{userid}; }
 sub u    {  LJ::load_userid($_[0]->{userid}) }
 sub arg1 {  $_[0]->{args}[0] }
 sub arg2 {  $_[0]->{args}[1] }
@@ -726,19 +727,11 @@
 # from showing for good -- when this is done, LJ::Widget::SubscribeInterface
 # will never show it, regardless of what is passed to it.
 #
-# this is a virtual function; base class function returns 1 if the user is
-# able to subscribe to the event and is not an OpenID one (this is done because
-# non-OpenID users are always able to upgrade their account type to change
-# that).
+# this is a virtual function; base class function returns 1 for "yes"
 #
 # next unless $event->is_subscription_visible_to($u);
-sub is_subscription_visible_to {
-    my ($self, $u) = @_;
+sub is_subscription_visible_to { 1 }
 
-    return 0 if !$self->available_for_user($u) && $u->is_identity;
-    return 1;
-}
-
 # return a string containing HTML code with information for the user about
 # what they can do to have this subscription available (e.g. upgrade account).
 #
@@ -799,13 +792,22 @@
 # * !available_for_user        (the 'disabled' key)
 # * get_disabled_pic           (the 'disabled_pic' key)
 #
+# note that this function forces the event to be invisible in case user is
+# unable to subscribe to this event and is unable to upgrade to it [that is, is
+# an OpenID user].
+#
 # my $interface_info = $event->get_interface_status($u);
 sub get_interface_status {
     my ($self, $u) = @_;
 
+    my $available = $self->available_for_user($u);
+
+    my $visible = $self->is_subscription_visible_to($u);
+    $visible &&= ($available || !$u->is_identity);
+
     return {
-        'visible' => $self->is_subscription_visible_to($u),
-        'disabled' => !$self->available_for_user($u),
+        'visible' => $visible,
+        'disabled' => !$available,
         'disabled_pic' => $self->get_disabled_pic($u),
     };
 }

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