$notice = Notice::getKV($id);
$token = $this->checkSessionToken();
- if (Fave::existsForProfile($notice, $profile)) {
- // TRANS: Client error.
- throw new AlreadyFulfilledException(_m('This notice is already a favorite!'));
- }
-
// Throws exception
$stored = Fave::addNew($profile, $notice);
);
}
- // Note: Twitter lets you fave things repeatedly via API.
-
- if (Fave::existsForProfile($this->notice, $this->scoped)) {
- $this->clientError(
- // TRANS: Client error displayed when trying to mark a notice favourite that already is a favourite.
- _('This status is already a favorite.'),
- 403,
- $this->format
- );
+ try {
+ $stored = Fave::addNew($this->scoped, $this->notice);
+ } catch (AlreadyFulfilledException $e) {
+ // Note: Twitter lets you fave things repeatedly via API.
+ $this->clientError($e->getMessage(), 403);
}
- // throws exception on failure
- $stored = Fave::addNew($this->scoped, $this->notice);
-
if ($this->format == 'xml') {
$this->showSingleXmlStatus($this->notice);
} elseif ($this->format == 'json') {
protected function doPost()
{
- if (Fave::existsForProfile($this->target, $this->scoped)) {
- // TRANS: Client error displayed when trying to mark a notice as favorite that already is a favorite.
- throw new AlreadyFulfilledException(_('You have already favorited this!'));
- }
-
- // throws exception on failure
+ // throws exception on failure, might be an AlreadyFulfilledException
$stored = Fave::addNew($this->scoped, $this->target);
// TRANS: Message when a favor action has been taken for a notice.
* @throws Exception on failure
*/
static function addNew(Profile $actor, Notice $target) {
+ if (self::existsForProfile($target, $actor)) {
+ // TRANS: Client error displayed when trying to mark a notice as favorite that already is a favorite.
+ throw new AlreadyFulfilledException(_('You have already favorited this!'));
+ }
+
$act = new Activity();
$act->type = ActivityObject::ACTIVITY;
$act->verb = ActivityVerb::FAVORITE;
{
$notice = $this->getNotice($this->other);
- $fave = new Fave();
- $fave->user_id = $this->user->id;
- $fave->notice_id = $notice->id;
- $fave->find();
-
- if ($fave->fetch()) {
- // TRANS: Error message text shown when a favorite could not be set because it has already been favorited.
- $channel->error($this->user, _('Could not create favorite: Already favorited.'));
- return;
- }
-
try {
$fave = Fave::addNew($this->user->getProfile(), $notice);
} catch (Exception $e) {