We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit d534ea7b authored by mattl's avatar mattl

Try the whole Salmon action for AlreadyFulfilledException

If we have already fulfilled the action, we don't have to send an error back.
parent c1dc13be
...@@ -113,8 +113,7 @@ class UsersalmonAction extends SalmonAction ...@@ -113,8 +113,7 @@ class UsersalmonAction extends SalmonAction
$oprofile = $this->ensureProfile(); $oprofile = $this->ensureProfile();
if ($oprofile instanceof Ostatus_profile) { if ($oprofile instanceof Ostatus_profile) {
common_log(LOG_INFO, sprintf('Setting up subscription from remote %s to local %s', $oprofile->getUri(), $this->target->getNickname())); common_log(LOG_INFO, sprintf('Setting up subscription from remote %s to local %s', $oprofile->getUri(), $this->target->getNickname()));
Subscription::start($oprofile->localProfile(), Subscription::start($oprofile->localProfile(), $this->target);
$this->target);
} else { } else {
common_log(LOG_INFO, "Can't set up subscription from remote; missing profile."); common_log(LOG_INFO, "Can't set up subscription from remote; missing profile.");
} }
...@@ -135,8 +134,6 @@ class UsersalmonAction extends SalmonAction ...@@ -135,8 +134,6 @@ class UsersalmonAction extends SalmonAction
Subscription::cancel($oprofile->localProfile(), $this->target); Subscription::cancel($oprofile->localProfile(), $this->target);
} catch (NoProfileException $e) { } catch (NoProfileException $e) {
common_debug('Could not find profile for Subscription: '.$e->getMessage()); common_debug('Could not find profile for Subscription: '.$e->getMessage());
} catch (AlreadyFulfilledException $e) {
common_debug('Subscription did not exist, so there was nothing to cancel');
} }
} else { } else {
common_log(LOG_ERR, "Can't cancel subscription from remote, didn't find the profile"); common_log(LOG_ERR, "Can't cancel subscription from remote, didn't find the profile");
...@@ -158,7 +155,7 @@ class UsersalmonAction extends SalmonAction ...@@ -158,7 +155,7 @@ class UsersalmonAction extends SalmonAction
if ($old instanceof Fave) { if ($old instanceof Fave) {
// TRANS: Client exception. // TRANS: Client exception.
throw new ClientException(_m('This is already a favorite.')); throw new AlreadyFulfilledException(_m('This is already a favorite.'));
} }
if (!Fave::addNew($profile, $notice)) { if (!Fave::addNew($profile, $notice)) {
...@@ -180,7 +177,7 @@ class UsersalmonAction extends SalmonAction ...@@ -180,7 +177,7 @@ class UsersalmonAction extends SalmonAction
'notice_id' => $notice->id)); 'notice_id' => $notice->id));
if (!$fave instanceof Fave) { if (!$fave instanceof Fave) {
// TRANS: Client exception. // TRANS: Client exception.
throw new ClientException(_m('Notice was not favorited!')); throw new AlreadyFulfilledException(_m('Notice was not favorited!'));
} }
$fave->delete(); $fave->delete();
......
...@@ -77,50 +77,56 @@ class SalmonAction extends Action ...@@ -77,50 +77,56 @@ class SalmonAction extends Action
parent::handle(); parent::handle();
common_log(LOG_DEBUG, "Got a " . $this->activity->verb); common_log(LOG_DEBUG, "Got a " . $this->activity->verb);
if (Event::handle('StartHandleSalmonTarget', array($this->activity, $this->target)) && try {
Event::handle('StartHandleSalmon', array($this->activity))) { if (Event::handle('StartHandleSalmonTarget', array($this->activity, $this->target)) &&
switch ($this->activity->verb) Event::handle('StartHandleSalmon', array($this->activity))) {
{ switch ($this->activity->verb) {
case ActivityVerb::POST: case ActivityVerb::POST:
$this->handlePost(); $this->handlePost();
break; break;
case ActivityVerb::SHARE: case ActivityVerb::SHARE:
$this->handleShare(); $this->handleShare();
break; break;
case ActivityVerb::FAVORITE: case ActivityVerb::FAVORITE:
$this->handleFavorite(); $this->handleFavorite();
break; break;
case ActivityVerb::UNFAVORITE: case ActivityVerb::UNFAVORITE:
$this->handleUnfavorite(); $this->handleUnfavorite();
break; break;
case ActivityVerb::FOLLOW: case ActivityVerb::FOLLOW:
case ActivityVerb::FRIEND: case ActivityVerb::FRIEND:
$this->handleFollow(); $this->handleFollow();
break; break;
case ActivityVerb::UNFOLLOW: case ActivityVerb::UNFOLLOW:
$this->handleUnfollow(); $this->handleUnfollow();
break; break;
case ActivityVerb::JOIN: case ActivityVerb::JOIN:
$this->handleJoin(); $this->handleJoin();
break; break;
case ActivityVerb::LEAVE: case ActivityVerb::LEAVE:
$this->handleLeave(); $this->handleLeave();
break; break;
case ActivityVerb::TAG: case ActivityVerb::TAG:
$this->handleTag(); $this->handleTag();
break; break;
case ActivityVerb::UNTAG: case ActivityVerb::UNTAG:
$this->handleUntag(); $this->handleUntag();
break; break;
case ActivityVerb::UPDATE_PROFILE: case ActivityVerb::UPDATE_PROFILE:
$this->handleUpdateProfile(); $this->handleUpdateProfile();
break; break;
default: default:
// TRANS: Client exception. // TRANS: Client exception.
throw new ClientException(_m('Unrecognized activity type.')); throw new ClientException(_m('Unrecognized activity type.'));
}
Event::handle('EndHandleSalmon', array($this->activity));
Event::handle('EndHandleSalmonTarget', array($this->activity, $this->target));
} }
Event::handle('EndHandleSalmon', array($this->activity)); } catch (AlreadyFulfilledException $e) {
Event::handle('EndHandleSalmonTarget', array($this->activity, $this->target)); // The action's results are already fulfilled. Maybe it was a
// duplicate? Maybe someone's database is out of sync?
// Let's just accept it and move on.
common_log(LOG_INFO, 'Salmon slap carried an event which had already been fulfilled.');
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment