forked from GNUsocial/gnu-social
Consolidate some precondition checks for repeats, fix a couple bits in the repeat command.
Notice::saveNew() now does these checks directly when making a repeat: * make sure the original is valid and existing * stop you from repeating your own message * stop you from repeating something you've previously repeated * prevent repeats of any non-public messages * explicit inScope() check to make sure you can read the original too (just in case there's a funky extension at play that changes scoping rules) These error conditions throw exceptions, which the caller either uses as an error message or passes on up the stack, without having to duplicate the checks in each i/o channel.
This commit is contained in:
@@ -537,44 +537,15 @@ class RepeatCommand extends Command
|
||||
{
|
||||
$notice = $this->getNotice($this->other);
|
||||
|
||||
if($this->user->id == $notice->profile_id)
|
||||
{
|
||||
// TRANS: Error text shown when trying to repeat an own notice.
|
||||
$channel->error($this->user, _('Cannot repeat your own notice.'));
|
||||
return;
|
||||
}
|
||||
|
||||
// Is it OK to repeat that notice (general enough scope)?
|
||||
|
||||
if ($notice->scope != Notice::SITE_SCOPE &&
|
||||
$notice->scope != Notice::PUBLIC_SCOPE) {
|
||||
$channel->error($this->user, _('You may not repeat a private notice.'));
|
||||
}
|
||||
|
||||
$profile = $this->user->getProfile();
|
||||
|
||||
// Can the profile actually see that notice?
|
||||
|
||||
if (!$notice->inScope($profile)) {
|
||||
$channel->error($this->user, _('You have no access to that notice.'));
|
||||
}
|
||||
|
||||
if ($profile->hasRepeated($notice->id)) {
|
||||
// TRANS: Error text shown when trying to repeat an notice that was already repeated by the user.
|
||||
$channel->error($this->user, _('Already repeated that notice.'));
|
||||
return;
|
||||
}
|
||||
|
||||
$repeat = $notice->repeat($this->user->id, $channel->source);
|
||||
|
||||
if ($repeat) {
|
||||
try {
|
||||
$repeat = $notice->repeat($this->user->id, $channel->source());
|
||||
$recipient = $notice->getProfile();
|
||||
|
||||
// TRANS: Message given having repeated a notice from another user.
|
||||
// TRANS: %s is the name of the user for which the notice was repeated.
|
||||
$channel->output($this->user, sprintf(_('Notice from %s repeated.'), $recipient->nickname));
|
||||
} else {
|
||||
// TRANS: Error text shown when repeating a notice fails with an unknown reason.
|
||||
$channel->error($this->user, _('Error repeating notice.'));
|
||||
} catch (Exception $e) {
|
||||
$channel->error($this->user, $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user