]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Inform and make use of NoProfileException in OStatus actions
authorMikael Nordfeldth <mmn@hethane.se>
Mon, 19 May 2014 16:07:38 +0000 (18:07 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Mon, 19 May 2014 16:07:57 +0000 (18:07 +0200)
This is because Ostatus_profile->localProfile() throws NoProfileException
instead of returning null for profiles which don't exist in Profile table.

plugins/OStatus/actions/ostatussub.php
plugins/OStatus/actions/peopletagsalmon.php

index 8a8cfb9880eaf0cb7138840b4288d2100dfb7bbc..f349b5d534800084231f04846646ed5716d0e149 100644 (file)
@@ -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'),
index 12af8c2b31ce957f7eb19bd842c22498efcca986..11e146378736815fa00743050da1c0c27eb02ca5 100644 (file)
@@ -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()));
         }
     }
 }