From: Mikael Nordfeldth <mmn@hethane.se>
Date: Mon, 19 May 2014 16:07:38 +0000 (+0200)
Subject: Inform and make use of NoProfileException in OStatus actions
X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=0dad11bb855b94633eddc97527c6d46399d7628b;p=quix0rs-gnu-social.git

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

diff --git a/plugins/OStatus/actions/ostatussub.php b/plugins/OStatus/actions/ostatussub.php
index 8a8cfb9880..f349b5d534 100644
--- a/plugins/OStatus/actions/ostatussub.php
+++ b/plugins/OStatus/actions/ostatussub.php
@@ -155,8 +155,8 @@ class OStatusSubAction extends Action
      */
     function preview()
     {
-        $oprofile = $this->oprofile;
-        $profile = $oprofile->localProfile();
+        // Throws NoProfileException on localProfile when remote user's Profile not found
+        $profile = $this->oprofile->localProfile();
 
         if ($this->scoped->isSubscribed($profile)) {
             $this->element('div', array('class' => 'error'),
diff --git a/plugins/OStatus/actions/peopletagsalmon.php b/plugins/OStatus/actions/peopletagsalmon.php
index 12af8c2b31..11e1463787 100644
--- a/plugins/OStatus/actions/peopletagsalmon.php
+++ b/plugins/OStatus/actions/peopletagsalmon.php
@@ -83,6 +83,8 @@ class PeopletagsalmonAction extends SalmonAction
      * @fixme move permission checks and event call into common code,
      *        currently we're doing the main logic in joingroup action
      *        and so have to repeat it here.
+     *
+     * @throws NoProfileException from localProfile if missing locally stored Profile object
      */
     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());
         $profile = $oprofile->localProfile();
-
         if ($this->peopletag->hasSubscriber($profile)) {
             // Already a member; we'll take it silently to aid in resolving
             // inconsistencies on the other side.
@@ -120,11 +121,14 @@ class PeopletagsalmonAction extends SalmonAction
 
     /**
      * A remote user unsubscribed from our list.
+     *
+     * @return void
+     * @throws Exception through clientError and serverError
      */
     function handleUnsubscribe()
     {
         $oprofile = $this->ensureProfile();
-        if (!$oprofile) {
+        if (!$oprofile instanceof Ostatus_profile) {
             // TRANS: Client error displayed when trying to unsubscribe from non-existing list.
             $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());
-        $profile = $oprofile->localProfile();
-
         try {
-                Profile_tag_subscription::remove($this->peopletag->tagger, $this->peopletag->tag, $profile->id);
-
+            $profile = $oprofile->localProfile();
+            Profile_tag_subscription::remove($this->peopletag->tagger, $this->peopletag->tag, $profile->id);
         } catch (Exception $e) {
             // 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.
             $this->serverError(sprintf(_m('Could not unsubscribe remote user %1$s from list %2$s.'),
-                                       $oprofile->uri, $this->peopletag->getBestName()));
-            return;
+                                       $oprofile->getUri(), $this->peopletag->getBestName()));
         }
     }
 }