]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/OStatus/actions/peopletagsalmon.php
Merge branch 'nightly', beginning of 1.2.x
[quix0rs-gnu-social.git] / plugins / OStatus / actions / peopletagsalmon.php
index a200ca9eef2a7890fdf8c362a5f68b2c1479adc5..46f4b0bdd848417af8c3db1eb2775bf6e1d1fbe9 100644 (file)
  * @package OStatusPlugin
  */
 
-if (!defined('STATUSNET')) {
-    exit(1);
-}
+if (!defined('GNUSOCIAL')) { exit(1); }
 
 class PeopletagsalmonAction extends SalmonAction
 {
     var $peopletag = null;
 
-    function prepare($args)
+    protected function prepare(array $args=array())
     {
         parent::prepare($args);
 
         $id = $this->trimmed('id');
 
         if (!$id) {
+            // TRANS: Client error displayed trying to perform an action without providing an ID.
             $this->clientError(_m('No ID.'));
         }
 
-        $this->peopletag = Profile_list::staticGet('id', $id);
+        $this->peopletag = Profile_list::getKV('id', $id);
 
-        if (empty($this->peopletag)) {
+        if (!$this->peopletag instanceof Profile_list) {
+            // TRANS: Client error displayed when referring to a non-existing list.
             $this->clientError(_m('No such list.'));
         }
 
-        $oprofile = Ostatus_profile::staticGet('peopletag_id', $id);
+        $this->target = $this->peopletag;
+
+        $remote_list = Ostatus_profile::getKV('peopletag_id', $id);
 
-        if (!empty($oprofile)) {
+        if ($remote_list instanceof Ostatus_profile) {
+            // TRANS: Client error displayed when trying to send a message to a remote list.
             $this->clientError(_m('Cannot accept remote posts for a remote list.'));
         }
 
@@ -81,21 +84,15 @@ class PeopletagsalmonAction extends SalmonAction
      *        currently we're doing the main logic in joingroup action
      *        and so have to repeat it here.
      */
-
     function handleSubscribe()
     {
-        $oprofile = $this->ensureProfile();
-        if (!$oprofile) {
-            $this->clientError(_m('Cannot read profile to set up profile tag subscription.'));
-        }
-        if ($oprofile->isGroup()) {
+        if ($this->oprofile->isGroup()) {
+            // TRANS: Client error displayed when trying to subscribe a group to a list.
             $this->clientError(_m('Groups cannot subscribe to lists.'));
         }
 
-        common_log(LOG_INFO, "Remote profile {$oprofile->uri} subscribing to local peopletag ".$this->peopletag->getBestName());
-        $profile = $oprofile->localProfile();
-
-        if ($this->peopletag->hasSubscriber($profile)) {
+        common_log(LOG_INFO, sprintf('Remote profile %s subscribing to local peopletag %s', $this->oprofile->getUri(), $this->peopletag->getBestName()));
+        if ($this->peopletag->hasSubscriber($this->actor)) {
             // Already a member; we'll take it silently to aid in resolving
             // inconsistencies on the other side.
             return true;
@@ -105,37 +102,36 @@ class PeopletagsalmonAction extends SalmonAction
         // his own updates?
 
         try {
-            Profile_tag_subscription::add($this->peopletag, $profile);
+            Profile_tag_subscription::add($this->peopletag, $this->actor);
         } catch (Exception $e) {
+            // TRANS: Server error displayed when subscribing a remote user to a list fails.
+            // TRANS: %1$s is a profile URI, %2$s is a list name.
             $this->serverError(sprintf(_m('Could not subscribe remote user %1$s to list %2$s.'),
-                                       $oprofile->uri, $this->peopletag->getBestName()));
+                                       $this->oprofile->getUri(), $this->peopletag->getBestName()));
         }
     }
 
     /**
-     * A remote user unsubscribed from our peopletag.
+     * A remote user unsubscribed from our list.
+     *
+     * @return void
+     * @throws Exception through clientError and serverError
      */
-
     function handleUnsubscribe()
     {
-        $oprofile = $this->ensureProfile();
-        if (!$oprofile) {
-            $this->clientError(_m('Cannot read profile to cancel list membership.'));
-        }
-        if ($oprofile->isGroup()) {
+        if ($this->oprofile->isGroup()) {
+            // TRANS: Client error displayed when trying to unsubscribe a group from a list.
             $this->clientError(_m('Groups cannot subscribe to lists.'));
         }
 
-        common_log(LOG_INFO, "Remote profile {$oprofile->uri} unsubscribing from local peopletag ".$this->peopletag->getBestName());
-        $profile = $oprofile->localProfile();
-
+        common_log(LOG_INFO, sprintf('Remote profile %s unsubscribing from local peopletag %s', $this->oprofile->getUri(), $this->peopletag->getBestName()));
         try {
-                Profile_tag_subscription::remove($this->peopletag->tagger, $this->peopletag->tag, $profile->id);
-
+            Profile_tag_subscription::remove($this->peopletag->tagger, $this->peopletag->tag, $this->actor->id);
         } catch (Exception $e) {
-            $this->serverError(sprintf(_m('Could not remove remote user %1$s from list %2$s.'),
-                                       $oprofile->uri, $this->peopletag->getBestName()));
-            return;
+            // 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.'),
+                                       $this->oprofile->getUri(), $this->peopletag->getBestName()));
         }
     }
 }