Inform and make use of NoProfileException in OStatus actions

This is because Ostatus_profile->localProfile() throws NoProfileException
instead of returning null for profiles which don't exist in Profile table.
This commit is contained in:
Mikael Nordfeldth 2014-05-19 18:07:38 +02:00
parent 63c20e59aa
commit 0dad11bb85
2 changed files with 11 additions and 10 deletions

View File

@ -155,8 +155,8 @@ class OStatusSubAction extends Action
*/ */
function preview() function preview()
{ {
$oprofile = $this->oprofile; // Throws NoProfileException on localProfile when remote user's Profile not found
$profile = $oprofile->localProfile(); $profile = $this->oprofile->localProfile();
if ($this->scoped->isSubscribed($profile)) { if ($this->scoped->isSubscribed($profile)) {
$this->element('div', array('class' => 'error'), $this->element('div', array('class' => 'error'),

View File

@ -83,6 +83,8 @@ class PeopletagsalmonAction extends SalmonAction
* @fixme move permission checks and event call into common code, * @fixme move permission checks and event call into common code,
* currently we're doing the main logic in joingroup action * currently we're doing the main logic in joingroup action
* and so have to repeat it here. * and so have to repeat it here.
*
* @throws NoProfileException from localProfile if missing locally stored Profile object
*/ */
function handleSubscribe() function handleSubscribe()
{ {
@ -98,7 +100,6 @@ class PeopletagsalmonAction extends SalmonAction
common_log(LOG_INFO, "Remote profile {$oprofile->uri} subscribing to local peopletag ".$this->peopletag->getBestName()); common_log(LOG_INFO, "Remote profile {$oprofile->uri} subscribing to local peopletag ".$this->peopletag->getBestName());
$profile = $oprofile->localProfile(); $profile = $oprofile->localProfile();
if ($this->peopletag->hasSubscriber($profile)) { if ($this->peopletag->hasSubscriber($profile)) {
// Already a member; we'll take it silently to aid in resolving // Already a member; we'll take it silently to aid in resolving
// inconsistencies on the other side. // inconsistencies on the other side.
@ -120,11 +121,14 @@ class PeopletagsalmonAction extends SalmonAction
/** /**
* A remote user unsubscribed from our list. * A remote user unsubscribed from our list.
*
* @return void
* @throws Exception through clientError and serverError
*/ */
function handleUnsubscribe() function handleUnsubscribe()
{ {
$oprofile = $this->ensureProfile(); $oprofile = $this->ensureProfile();
if (!$oprofile) { if (!$oprofile instanceof Ostatus_profile) {
// TRANS: Client error displayed when trying to unsubscribe from non-existing list. // TRANS: Client error displayed when trying to unsubscribe from non-existing list.
$this->clientError(_m('Cannot read profile to cancel list subscription.')); $this->clientError(_m('Cannot read profile to cancel list subscription.'));
} }
@ -134,17 +138,14 @@ class PeopletagsalmonAction extends SalmonAction
} }
common_log(LOG_INFO, "Remote profile {$oprofile->uri} unsubscribing from local peopletag ".$this->peopletag->getBestName()); common_log(LOG_INFO, "Remote profile {$oprofile->uri} unsubscribing from local peopletag ".$this->peopletag->getBestName());
$profile = $oprofile->localProfile();
try { try {
$profile = $oprofile->localProfile();
Profile_tag_subscription::remove($this->peopletag->tagger, $this->peopletag->tag, $profile->id); Profile_tag_subscription::remove($this->peopletag->tagger, $this->peopletag->tag, $profile->id);
} catch (Exception $e) { } catch (Exception $e) {
// TRANS: Client error displayed when trying to unsubscribe a remote user from a list fails. // TRANS: Client error displayed when trying to unsubscribe a remote user from a list fails.
// TRANS: %1$s is a profile URL, %2$s is a list name. // TRANS: %1$s is a profile URL, %2$s is a list name.
$this->serverError(sprintf(_m('Could not unsubscribe remote user %1$s from list %2$s.'), $this->serverError(sprintf(_m('Could not unsubscribe remote user %1$s from list %2$s.'),
$oprofile->uri, $this->peopletag->getBestName())); $oprofile->getUri(), $this->peopletag->getBestName()));
return;
} }
} }
} }