]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Notice->repeat() function takes Profile as argument now
authorMikael Nordfeldth <mmn@hethane.se>
Sun, 18 May 2014 19:03:10 +0000 (21:03 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Sun, 18 May 2014 19:03:10 +0000 (21:03 +0200)
actions/apistatusesretweet.php
actions/repeat.php
classes/Notice.php
lib/command.php
plugins/SubMirror/classes/SubMirror.php
tests/ActivityGenerationTests.php

index ee391fdb4adc33ce02b6944ac3d9f79c27163679..922d395154f2a364c410dca2b45cf57f9c2ededf 100644 (file)
@@ -27,9 +27,7 @@
  * @link      http://status.net/
  */
 
-if (!defined('STATUSNET')) {
-    exit(1);
-}
+if (!defined('GNUSOCIAL')) { exit(1); }
 
 /**
  * Repeat a notice through the API
@@ -42,6 +40,8 @@ if (!defined('STATUSNET')) {
  */
 class ApiStatusesRetweetAction extends ApiAuthAction
 {
+    protected $needPost = true;
+
     var $original = null;
 
     /**
@@ -51,30 +51,19 @@ class ApiStatusesRetweetAction extends ApiAuthAction
      *
      * @return boolean success flag
      */
-    function prepare($args)
+    protected function prepare(array $args=array())
     {
         parent::prepare($args);
 
-        if ($_SERVER['REQUEST_METHOD'] != 'POST') {
-            // TRANS: Client error. POST is a HTTP command. It should not be translated.
-            $this->clientError(_('This method requires a POST.'),
-                               400, $this->format);
-            return false;
-        }
-
         $id = $this->trimmed('id');
 
         $this->original = Notice::getKV('id', $id);
 
-        if (empty($this->original)) {
+        if (!$this->original instanceof Notice) {
             // TRANS: Client error displayed trying to repeat a non-existing notice through the API.
-            $this->clientError(_('No such notice.'),
-                               400, $this->format);
-            return false;
+            $this->clientError(_('No such notice.'), 400, $this->format);
         }
 
-        $this->user = $this->auth_user;
-
         return true;
     }
 
@@ -87,11 +76,11 @@ class ApiStatusesRetweetAction extends ApiAuthAction
      *
      * @return void
      */
-    function handle($args)
+    protected function handle()
     {
-        parent::handle($args);
+        parent::handle();
 
-        $repeat = $this->original->repeat($this->user->id, $this->source);
+        $repeat = $this->original->repeat($this->scoped, $this->source);
 
         $this->showNotice($repeat);
     }
index 76104e2bbfaad1b68fa7585359605e241a43403f..501570ebf0f7d6c6e9ba08cdd0760196ec8354b0 100644 (file)
@@ -63,7 +63,7 @@ class RepeatAction extends FormAction
             $this->clientError(_('Notice not found.'));
         }
 
-        $this->repeat = $this->notice->repeat($this->scoped->id, 'web');
+        $this->repeat = $this->notice->repeat($this->scoped, 'web');
         if (!$this->repeat instanceof Notice) {
             // TRANS: Error when unable to repeat a notice for unknown reason.
             $this->clientError(_('Could not repeat notice for unknown reason. Please contact the webmaster!'));
index d331b111c35841917aa4a58e1fdcba4db9882811..54b698d62b9ec4355545455fa1961fb322d5b460 100644 (file)
@@ -1837,24 +1837,24 @@ class Notice extends Managed_DataObject
     /**
      * Convenience function for posting a repeat of an existing message.
      *
-     * @param int $repeater_id: profile ID of user doing the repeat
+     * @param Profile $repeater Profile which is doing the repeat
      * @param string $source: posting source key, eg 'web', 'api', etc
      * @return Notice
      *
      * @throws Exception on failure or permission problems
      */
-    function repeat($repeater_id, $source)
+    function repeat(Profile $repeater, $source)
     {
         $author = $this->getProfile();
 
         // TRANS: Message used to repeat a notice. RT is the abbreviation of 'retweet'.
         // TRANS: %1$s is the repeated user's name, %2$s is the repeated notice.
         $content = sprintf(_('RT @%1$s %2$s'),
-                           $author->nickname,
+                           $author->getNickname(),
                            $this->content);
 
         // Scope is same as this one's
-        return self::saveNew($repeater_id,
+        return self::saveNew($repeater->id,
                              $content,
                              $source,
                              array('repeat_of' => $this->id,
index bc0dd894de6d7f396dac1d17eb7d7786ca2459b0..abc22ed6a8ba294935ab0ecb23c4bfed49aa52f3 100644 (file)
@@ -23,10 +23,12 @@ require_once(INSTALLDIR.'/lib/channel.php');
 
 class Command
 {
+    protected $scoped = null;   // The Profile of the user performing the command
     var $user = null;
 
     function __construct($user=null)
     {
+        $this->scoped = $user->getProfile();
         $this->user = $user;
     }
 
@@ -659,7 +661,7 @@ class RepeatCommand extends Command
         $notice = $this->getNotice($this->other);
 
         try {
-            $repeat = $notice->repeat($this->user->id, $channel->source());
+            $repeat = $notice->repeat($this->scoped->id, $channel->source());
             $recipient = $notice->getProfile();
 
             // TRANS: Message given having repeated a notice from another user.
index 7c3e6af3ec1e8db3992db17d79d011e180cfa1a3..de63841e729e84f44f712d7efaa0c3bbb5f555ba 100644 (file)
@@ -179,7 +179,7 @@ class SubMirror extends Managed_DataObject
             return true;
         } else {
             common_log(LOG_INFO, "SubMirror plugin auto-repeating notice $notice->id for $profile->id");
-            return $notice->repeat($profile->id, 'mirror');
+            return $notice->repeat($profile, 'mirror');
         }
     }
 
index bf0dcb2377558e5ec4fdfa82126cbc7b46a7712d..f02f1be2fc4f6d47d36ea74e8437e0851598c026 100644 (file)
@@ -362,7 +362,7 @@ class ActivityGenerationTests extends PHPUnit_Framework_TestCase
     public function testRepeatLink()
     {
         $notice = $this->_fakeNotice($this->author1);
-        $repeat = $notice->repeat($this->author2->id, 'test');
+        $repeat = $notice->repeat($this->author2->getProfile(), 'test');
 
         $entry = $repeat->asAtomEntry();
 
@@ -451,7 +451,7 @@ class ActivityGenerationTests extends PHPUnit_Framework_TestCase
     {
         $notice = $this->_fakeNotice();
 
-        $repeat = $notice->repeat($this->author2->id, 'test');
+        $repeat = $notice->repeat($this->author2->getProfile(), 'test');
 
         $entry = $repeat->asAtomEntry();
 
@@ -466,7 +466,7 @@ class ActivityGenerationTests extends PHPUnit_Framework_TestCase
     {
         $notice = $this->_fakeNotice();
 
-        $repeat = $notice->repeat($this->author2->id, 'test');
+        $repeat = $notice->repeat($this->author2->getProfile(), 'test');
 
         $entry = $notice->asAtomEntry(false, false, false, $this->author2);