Notice->repeat() function takes Profile as argument now

This commit is contained in:
Mikael Nordfeldth 2014-05-18 21:03:10 +02:00
parent c4c4835899
commit b0cc9292b1
6 changed files with 21 additions and 30 deletions

View 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);
}

View 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!'));

View 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,

View 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.

View 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');
}
}

View 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);