]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/OStatus/actions/usersalmon.php
Merge remote-tracking branch 'mainline/1.0.x' into people_tags_rebase
[quix0rs-gnu-social.git] / plugins / OStatus / actions / usersalmon.php
index 5355aeba03fed5b2eca9c762709d3466aae00f4b..f5a93183e59e95265484f615b2b831b199e63502 100644 (file)
@@ -157,7 +157,7 @@ class UsersalmonAction extends SalmonAction
 
         if (!empty($old)) {
             // TRANS: Client exception.
-            throw new ClientException(_('This is already a favorite.'));
+            throw new ClientException(_m('This is already a favorite.'));
         }
 
         if (!Fave::addNew($profile, $notice)) {
@@ -179,12 +179,73 @@ class UsersalmonAction extends SalmonAction
                                    'notice_id' => $notice->id));
         if (empty($fave)) {
             // TRANS: Client exception.
-            throw new ClientException(_('Notice wasn\'t favorited!'));
+            throw new ClientException(_m('Notice was not favorited!'));
         }
 
         $fave->delete();
     }
 
+    function handleTag()
+    {
+        if ($this->activity->target->type == ActivityObject::_LIST) {
+            if ($this->activity->objects[0]->type != ActivityObject::PERSON) {
+                throw new ClientException("Not a person object");
+                return false;
+            }
+            // this is a peopletag
+            $tagged = User::staticGet('uri', $this->activity->objects[0]->id);
+
+            if (empty($tagged)) {
+                throw new ClientException("Unidentified profile being tagged");
+            }
+
+            if ($tagged->id !== $this->user->id) {
+                throw new ClientException("This user is not the one being tagged");
+            }
+
+            // save the list
+            $tagger = $this->ensureProfile();
+            $list   = Ostatus_profile::ensureActivityObjectProfile($this->activity->target);
+
+            $ptag = $list->localPeopletag();
+            $result = Profile_tag::setTag($ptag->tagger, $tagged->id, $ptag->tag);
+            if (!$result) {
+                throw new ClientException("The tag could not be saved.");
+            }
+        }
+    }
+
+    function handleUntag()
+    {
+        if ($this->activity->target->type == ActivityObject::_LIST) {
+            if ($this->activity->objects[0]->type != ActivityObject::PERSON) {
+                throw new ClientException("Not a person object");
+                return false;
+            }
+            // this is a peopletag
+            $tagged = User::staticGet('uri', $this->activity->objects[0]->id);
+
+            if (empty($tagged)) {
+                throw new ClientException("Unidentified profile being untagged");
+            }
+
+            if ($tagged->id !== $this->user->id) {
+                throw new ClientException("This user is not the one being untagged");
+            }
+
+            // save the list
+            $tagger = $this->ensureProfile();
+            $list   = Ostatus_profile::ensureActivityObjectProfile($this->activity->target);
+
+            $ptag = $list->localPeopletag();
+            $result = Profile_tag::unTag($ptag->tagger, $tagged->id, $ptag->tag);
+
+            if (!$result) {
+                throw new ClientException("The tag could not be deleted.");
+            }
+        }
+    }
+
     /**
      * @param ActivityObject $object
      * @return Notice