]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Start/End NoticeAsActivity modifications
authorMikael Nordfeldth <mmn@hethane.se>
Mon, 28 Jul 2014 07:40:07 +0000 (09:40 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Mon, 28 Jul 2014 07:40:07 +0000 (09:40 +0200)
More 'scoped' profiles and typing to the functions.
Also, there's no need to send an object as a reference.

classes/Notice.php
plugins/Activity/ActivityPlugin.php
plugins/Event/EventPlugin.php
plugins/GNUsocialPhotos/GNUsocialPhotosPlugin.php
plugins/NoticeTitle/NoticeTitlePlugin.php

index e9875d34240282162494bad51b7d00106b3f9688..3a71e4161f762b2e8f32db60a69b177161d86e15 100644 (file)
@@ -1751,7 +1751,7 @@ class Notice extends Managed_DataObject
         }
         $act = new Activity();
 
-        if (Event::handle('StartNoticeAsActivity', array($this, &$act))) {
+        if (Event::handle('StartNoticeAsActivity', array($this, $act, $scoped))) {
 
             $act->id      = $this->uri;
             $act->time    = strtotime($this->created);
@@ -1898,7 +1898,7 @@ class Notice extends Managed_DataObject
                 $act->editLink = $act->selfLink;
             }
 
-            Event::handle('EndNoticeAsActivity', array($this, &$act));
+            Event::handle('EndNoticeAsActivity', array($this, $act, $scoped));
         }
 
         self::cacheSet(Cache::codeKey('notice:as-activity:'.$this->id), $act);
index 6dc9730544344b2d18c7739fe29f265112d53ea2..3f2cee11d2ad197aa18bdb18797d3284d97f7267 100644 (file)
@@ -308,22 +308,21 @@ class ActivityPlugin extends Plugin
         return true;
     }
 
-    function onEndNoticeAsActivity($notice, &$activity)
+    public function onEndNoticeAsActivity(Notice $stored, Activity $act, Profile $scoped=null)
     {
-        switch ($notice->verb) {
+        switch ($stored->verb) {
         case ActivityVerb::FAVORITE:
-            $fave = Fave::getKV('uri', $notice->uri);
+            $fave = Fave::getKV('uri', $stored->uri);
             if (!empty($fave)) {
-                $notice = Notice::getKV('id', $fave->notice_id);
-                if (!empty($notice)) {
-                    $cur = common_current_user();
-                    $target = $notice->asActivity($cur->getProfile());
+                $stored = Notice::getKV('id', $fave->notice_id);
+                if (!empty($stored)) {
+                    $target = $stored->asActivity($scoped);
                     if ($target->verb == ActivityVerb::POST) {
                         // "I like the thing you posted"
-                        $activity->objects = $target->objects;
+                        $act->objects = $target->objects;
                     } else {
                         // "I like that you did whatever you did"
-                        $activity->objects = array($target);
+                        $act->objects = array($target);
                     }
                 }
             }
@@ -332,21 +331,21 @@ class ActivityPlugin extends Plugin
             // FIXME: do something here
             break;
         case ActivityVerb::JOIN:
-            $mem = Group_member::getKV('uri', $notice->uri);
+            $mem = Group_member::getKV('uri', $stored->uri);
             if (!empty($mem)) {
                 $group = $mem->getGroup();
-                $activity->objects = array(ActivityObject::fromGroup($group));
+                $act->objects = array(ActivityObject::fromGroup($group));
             }
             break;
         case ActivityVerb::LEAVE:
             // FIXME: ????
             break;
         case ActivityVerb::FOLLOW:
-            $sub = Subscription::getKV('uri', $notice->uri);
+            $sub = Subscription::getKV('uri', $stored->uri);
             if (!empty($sub)) {
                 $profile = Profile::getKV('id', $sub->subscribed);
                 if (!empty($profile)) {
-                    $activity->objects = array($profile->asActivityObject());
+                    $act->objects = array($profile->asActivityObject());
                 }
             }
             break;
index 9ec709af9a63db0324cff3eef07f21b4ef8b7fca..a5ddc4725571afa928738482dee021de7f1fa748 100644 (file)
@@ -243,12 +243,12 @@ class EventPlugin extends MicroAppPlugin
      *
      * @return ActivityObject
      */
-    function onEndNoticeAsActivity($notice, &$act) {
-        switch ($notice->object_type) {
+    function onEndNoticeAsActivity(Notice $stored, Activity $act, Profile $scoped=null) {
+        switch ($stored->object_type) {
         case RSVP::POSITIVE:
         case RSVP::NEGATIVE:
         case RSVP::POSSIBLE:
-            $act->verb = $notice->object_type;
+            $act->verb = $stored->object_type;
             break;
         }
         return true;
index c82efd0c5914b38c978f4d0ba13cfa6209028967..36956e5b9b3b750a90f15c4aacb691b3826c4526 100644 (file)
@@ -68,18 +68,18 @@ class GNUsocialPhotosPlugin extends Plugin
         return true;
     }
 
-    function onEndNoticeAsActivity($notice, &$activity)
+    function onEndNoticeAsActivity(Notice $stored, Activity $act, Profile $scoped=null)
     {
         common_log(LOG_INFO, 'photo plugin: EndNoticeAsActivity');
-        $photo = GNUsocialPhoto::getKV('notice_id', $notice->id);
+        $photo = GNUsocialPhoto::getKV('notice_id', $stored->id);
         if(!$photo) {
             common_log(LOG_INFO, 'not a photo.');
             return true;
         }
 
-        $activity->objects[0]->type = ActivityObject::PHOTO;
-        $activity->objects[0]->thumbnail = $photo->thumb_uri;
-        $activity->objects[0]->largerImage = $photo->uri;
+        $act->objects[0]->type = ActivityObject::PHOTO;
+        $act->objects[0]->thumbnail = $photo->thumb_uri;
+        $act->objects[0]->largerImage = $photo->uri;
         return false;
     }
 
index 4227703bfd8b35c71e06f00acec35f6f24b2bb10..1b910cc4084045c5f1718fcfb02780a9ac5ab40b 100644 (file)
@@ -217,19 +217,19 @@ class NoticeTitlePlugin extends Plugin
     /**
      * Show the notice title in Atom output
      *
-     * @param Notice      &$notice Notice being shown
-     * @param XMLStringer &$xs     output context
-     * @param string      &$output string to be output as title
+     * @param Notice      $notice Notice being shown
+     * @param Activity    $act   Activity object to be modified
+     * @param Profile     $scoped Currently logged in/scoped profile
      *
      * @return boolean hook value
      */
-    function onEndNoticeAsActivity($notice, &$activity)
+    function onEndNoticeAsActivity(Notice $stored, Activity $act, Profile $scoped=null)
     {
-        $title = Notice_title::fromNotice($notice);
+        $title = Notice_title::fromNotice($stored);
 
         if (!empty($title)) {
-            foreach ($activity->objects as $obj) {
-                if ($obj->id == $notice->uri) {
+            foreach ($act->objects as $obj) {
+                if ($obj->id == $stored->getUri()) {
                     $obj->title = $title;
                     break;
                 }