]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/Activity/ActivityPlugin.php
Merge branch 'subscribers_as_addressees' into 'nightly'
[quix0rs-gnu-social.git] / plugins / Activity / ActivityPlugin.php
index ec8d6d69119c0ea8034ed3eb929996668b7f4140..5144eb46662f3f86a4c1c25969b008aef3da4c99 100644 (file)
@@ -73,18 +73,18 @@ class ActivityPlugin extends Plugin
         // TRANS: %1$s is a profile URL, %2$s is a profile name,
         // TRANS: %3$s is a profile URL, %4$s is a profile name.
         $rendered = sprintf(_m('<a href="%1$s">%2$s</a> started following <a href="%3$s">%4$s</a>.'),
-                            $profile->profileurl,
+                            $profile->getUrl(),
                             $profile->getBestName(),
-                            $other->profileurl,
+                            $other->getUrl(),
                             $other->getBestName());
         // TRANS: Text for "started following" item in activity plugin.
         // TRANS: %1$s is a profile name, %2$s is a profile URL,
         // TRANS: %3$s is a profile name, %4$s is a profile URL.
         $content  = sprintf(_m('%1$s (%2$s) started following %3$s (%4$s).'),
                             $profile->getBestName(),
-                            $profile->profileurl,
+                            $profile->getUrl(),
                             $other->getBestName(),
-                            $other->profileurl);
+                            $other->getUrl());
 
         $notice = Notice::saveNew($profile->id,
                                   $content,
@@ -111,18 +111,18 @@ class ActivityPlugin extends Plugin
         // TRANS: %1$s is a profile URL, %2$s is a profile name,
         // TRANS: %3$s is a profile URL, %4$s is a profile name.
         $rendered = sprintf(_m('<a href="%1$s">%2$s</a> stopped following <a href="%3$s">%4$s</a>.'),
-                            $profile->profileurl,
+                            $profile->getUrl(),
                             $profile->getBestName(),
-                            $other->profileurl,
+                            $other->getUrl(),
                             $other->getBestName());
         // TRANS: Text for "stopped following" item in activity plugin.
         // TRANS: %1$s is a profile name, %2$s is a profile URL,
         // TRANS: %3$s is a profile name, %4$s is a profile URL.
         $content  = sprintf(_m('%1$s (%2$s) stopped following %3$s (%4$s).'),
                             $profile->getBestName(),
-                            $profile->profileurl,
+                            $profile->getUrl(),
                             $other->getBestName(),
-                            $other->profileurl);
+                            $other->getUrl());
 
         $uri = TagURI::mint('stop-following:%d:%d:%s',
                             $profile->id,
@@ -142,50 +142,6 @@ class ActivityPlugin extends Plugin
         return true;
     }
 
-    function onEndFavorNotice($profile, $notice)
-    {
-        //  Only do this if config is enabled
-        if(!$this->StartLike) return true;
-
-        if (!$profile->isLocal()) {
-            return true;
-        }
-
-        $author = $notice->getProfile();
-        $fave   = Fave::pkeyGet(array('user_id' => $profile->id,
-                                      'notice_id' => $notice->id));
-
-        // TRANS: Text for "liked" item in activity plugin.
-        // TRANS: %1$s is a profile URL, %2$s is a profile name,
-        // TRANS: %3$s is a notice URL, %4$s is an author name.
-        $rendered = sprintf(_m('<a href="%1$s">%2$s</a> liked <a href="%3$s">%4$s\'s update</a>.'),
-                            $profile->profileurl,
-                            $profile->getBestName(),
-                            $notice->bestUrl(),
-                            $author->getBestName());
-        // TRANS: Text for "liked" item in activity plugin.
-        // TRANS: %1$s is a profile name, %2$s is a profile URL,
-        // TRANS: %3$s is an author name, %4$s is a notice URL.
-        $content  = sprintf(_m('%1$s (%2$s) liked %3$s\'s status (%4$s).'),
-                            $profile->getBestName(),
-                            $profile->profileurl,
-                            $author->getBestName(),
-                            $notice->bestUrl());
-
-        $notice = Notice::saveNew($profile->id,
-                                  $content,
-                                  ActivityPlugin::SOURCE,
-                                  array('rendered' => $rendered,
-                                        'urls' => array(),
-                                        'replies' => array($author->getUri()),
-                                        'uri' => $fave->getURI(),
-                                        'verb' => ActivityVerb::FAVORITE,
-                                        'object_type' => (($notice->verb == ActivityVerb::POST) ?
-                                                         $notice->object_type : ActivityObject::ACTIVITY)));
-
-        return true;
-    }
-
     function onEndDisfavorNotice($profile, $notice)
     {
         // Only do this if config is enabled
@@ -200,18 +156,18 @@ class ActivityPlugin extends Plugin
         // TRANS: %1$s is a profile URL, %2$s is a profile name,
         // TRANS: %3$s is a notice URL, %4$s is an author name.
         $rendered = sprintf(_m('<a href="%1$s">%2$s</a> stopped liking <a href="%3$s">%4$s\'s update</a>.'),
-                            $profile->profileurl,
+                            $profile->getUrl(),
                             $profile->getBestName(),
-                            $notice->bestUrl(),
+                            $notice->getUrl(),
                             $author->getBestName());
         // TRANS: Text for "stopped liking" item in activity plugin.
         // TRANS: %1$s is a profile name, %2$s is a profile URL,
         // TRANS: %3$s is an author name, %4$s is a notice URL.
         $content  = sprintf(_m('%1$s (%2$s) stopped liking %3$s\'s status (%4$s).'),
                             $profile->getBestName(),
-                            $profile->profileurl,
+                            $profile->getUrl(),
                             $author->getBestName(),
-                            $notice->bestUrl());
+                            $notice->getUrl());
 
         $uri = TagURI::mint('unlike:%d:%d:%s',
                             $profile->id,
@@ -245,7 +201,7 @@ class ActivityPlugin extends Plugin
         // TRANS: %1$s is a profile URL, %2$s is a profile name,
         // TRANS: %3$s is a group URL, %4$s is a group name.
         $rendered = sprintf(_m('<a href="%1$s">%2$s</a> joined the group <a href="%3$s">%4$s</a>.'),
-                            $profile->profileurl,
+                            $profile->getUrl(),
                             $profile->getBestName(),
                             $group->homeUrl(),
                             $group->getBestName());
@@ -254,7 +210,7 @@ class ActivityPlugin extends Plugin
         // TRANS: %3$s is a group name, %4$s is a group URL.
         $content  = sprintf(_m('%1$s (%2$s) joined the group %3$s (%4$s).'),
                             $profile->getBestName(),
-                            $profile->profileurl,
+                            $profile->getUrl(),
                             $group->getBestName(),
                             $group->homeUrl());
 
@@ -286,7 +242,7 @@ class ActivityPlugin extends Plugin
         // TRANS: %1$s is a profile URL, %2$s is a profile name,
         // TRANS: %3$s is a group URL, %4$s is a group name.
         $rendered = sprintf(_m('<a href="%1$s">%2$s</a> left the group <a href="%3$s">%4$s</a>.'),
-                            $profile->profileurl,
+                            $profile->getUrl(),
                             $profile->getBestName(),
                             $group->homeUrl(),
                             $group->getBestName());
@@ -295,7 +251,7 @@ class ActivityPlugin extends Plugin
         // TRANS: %3$s is a group name, %4$s is a group URL.
         $content  = sprintf(_m('%1$s (%2$s) left the group %3$s (%4$s).'),
                             $profile->getBestName(),
-                            $profile->profileurl,
+                            $profile->getUrl(),
                             $group->getBestName(),
                             $group->homeUrl());
 
@@ -323,15 +279,11 @@ class ActivityPlugin extends Plugin
         $adapter = null;
 
         switch ($notice->verb) {
-        case ActivityVerb::FAVORITE:
-        case ActivityVerb::UNFAVORITE:
-            $adapter = new SystemListItem($nli);
-            break;
         case ActivityVerb::JOIN:
             $adapter = new JoinListItem($nli);
             break;
         case ActivityVerb::LEAVE:
-            $adapter = new JoinListItem($nli);
+            $adapter = new LeaveListItem($nli);
             break;
         case ActivityVerb::FOLLOW:
             $adapter = new FollowListItem($nli);
@@ -352,45 +304,30 @@ class ActivityPlugin extends Plugin
         return true;
     }
 
-    function onEndNoticeAsActivity($notice, &$activity)
+    public function onEndNoticeAsActivity(Notice $stored, Activity $act, Profile $scoped=null)
     {
-        switch ($notice->verb) {
-        case ActivityVerb::FAVORITE:
-            $fave = Fave::getKV('uri', $notice->uri);
-            if (!empty($fave)) {
-                $notice = Notice::getKV('id', $fave->notice_id);
-                if (!empty($notice)) {
-                    $cur = common_current_user();
-                    $target = $notice->asActivity($cur);
-                    if ($target->verb == ActivityVerb::POST) {
-                        // "I like the thing you posted"
-                        $activity->objects = $target->objects;
-                    } else {
-                        // "I like that you did whatever you did"
-                        $activity->objects = array($target);
-                    }
-                }
-            }
-            break;
+        switch ($stored->verb) {
         case ActivityVerb::UNFAVORITE:
             // FIXME: do something here
             break;
         case ActivityVerb::JOIN:
-            $mem = Group_member::getKV('uri', $notice->uri);
-            if (!empty($mem)) {
+            $mem = Group_member::getKV('uri', $stored->getUri());
+            if ($mem instanceof Group_member) {
                 $group = $mem->getGroup();
-                $activity->objects = array(ActivityObject::fromGroup($group));
+                $act->title = $stored->getTitle();
+                $act->objects = array(ActivityObject::fromGroup($group));
             }
             break;
         case ActivityVerb::LEAVE:
             // FIXME: ????
             break;
         case ActivityVerb::FOLLOW:
-            $sub = Subscription::getKV('uri', $notice->uri);
-            if (!empty($sub)) {
+            $sub = Subscription::getKV('uri', $stored->uri);
+            if ($sub instanceof Subscription) {
                 $profile = Profile::getKV('id', $sub->subscribed);
-                if (!empty($profile)) {
-                    $activity->objects = array(ActivityObject::fromProfile($profile));
+                if ($profile instanceof Profile) {
+                    $act->title = $stored->getTitle();
+                    $act->objects = array($profile->asActivityObject());
                 }
             }
             break;
@@ -402,7 +339,7 @@ class ActivityPlugin extends Plugin
         return true;
     }
 
-    function onPluginVersion(&$versions)
+    function onPluginVersion(array &$versions)
     {
         $versions[] = array('name' => 'Activity',
                             'version' => self::VERSION,