]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Fix Direct Message functionality.
authorMikael Nordfeldth <mmn@hethane.se>
Tue, 29 Apr 2014 18:37:58 +0000 (20:37 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Tue, 29 Apr 2014 18:37:58 +0000 (20:37 +0200)
actions/apidirectmessagenew.php
actions/newmessage.php
classes/Profile.php
classes/User.php
lib/command.php

index 9624e516957e671ec7a0eada8d78bdfba17d39a6..653fa3a9ed0ce88c045d996d509393a5fd64faa7 100644 (file)
@@ -51,7 +51,7 @@ class ApiDirectMessageNewAction extends ApiAuthAction
 {
     protected $needPost = true;
 
-    var $other   = null;
+    var $other   = null;    // Profile we're sending to
     var $content = null;
 
     /**
@@ -77,7 +77,7 @@ class ApiDirectMessageNewAction extends ApiAuthAction
         $screen_name = $this->trimmed('screen_name');
 
         if (isset($user_param) || isset($user_id) || isset($screen_name)) {
-            $this->other = $this->getTargetUser($user_param);
+            $this->other = $this->getTargetProfile($user_param);
         }
 
         return true;
@@ -108,7 +108,7 @@ class ApiDirectMessageNewAction extends ApiAuthAction
             }
         }
 
-        if (empty($this->other)) {
+        if (!$this->other instanceof Profile) {
             // TRANS: Client error displayed if a recipient user could not be found (403).
             $this->clientError(_('Recipient user not found.'), 403);
         } else if (!$this->user->mutuallySubscribed($this->other)) {
index 96ada1cee8ef1d72249b5d66c6a37d07b5f6fa58..428a55762ce60b3e2b19701c0fdf7fba1f4d6151 100644 (file)
@@ -78,21 +78,24 @@ class NewmessageAction extends FormAction
     {
         parent::prepare($args);
 
-        $user = $this->scoped->getUser();
-
         $this->content = $this->trimmed('content');
         $this->to = $this->trimmed('to');
 
         if ($this->to) {
 
-            $this->other = User::getKV('id', $this->to);
+            $this->other = Profile::getKV('id', $this->to);
 
-            if (!$this->other) {
+            if (!$this->other instanceof Profile) {
                 // TRANS: Client error displayed trying to send a direct message to a non-existing user.
                 $this->clientError(_('No such user.'), 404);
             }
 
-            if (!$user->mutuallySubscribed($this->other)) {
+            if (!$this->other->isLocal()) {
+                // TRANS: Explains that current federation does not support direct, private messages yet.
+                $this->clientError(_('You cannot send direct messages to federated users yet.'));
+            }
+
+            if (!$this->scoped->mutuallySubscribed($this->other)) {
                 // TRANS: Client error displayed trying to send a direct message to a user while sender and
                 // TRANS: receiver are not subscribed to each other.
                 $this->clientError(_('You cannot send a message to this user.'), 404);
@@ -106,14 +109,13 @@ class NewmessageAction extends FormAction
     {
         parent::handlePost();
 
-        assert($this->scoped); // XXX: maybe an error instead...
-        $user = $this->scoped->getUser();
+        assert($this->scoped instanceof Profile); // XXX: maybe an error instead...
 
         if (!$this->content) {
             // TRANS: Form validator error displayed trying to send a direct message without content.
             $this->clientError(_('No content!'));
         } else {
-            $content_shortened = $user->shortenLinks($this->content);
+            $content_shortened = $this->scoped->shortenLinks($this->content);
 
             if (Message::contentTooLong($content_shortened)) {
                 // TRANS: Form validation error displayed when message content is too long.
@@ -128,7 +130,7 @@ class NewmessageAction extends FormAction
         if (!$this->other) {
             // TRANS: Form validation error displayed trying to send a direct message without specifying a recipient.
             $this->clientError(_('No recipient specified.'));
-        } else if (!$user->mutuallySubscribed($this->other)) {
+        } else if (!$this->scoped->mutuallySubscribed($this->other)) {
             // TRANS: Client error displayed trying to send a direct message to a user while sender and
             // TRANS: receiver are not subscribed to each other.
             $this->clientError(_('You cannot send a message to this user.'), 404);
index c40e0e0b17ccdada4a7e230b8210482cddc69072..3f0b87e79fc550ebb68c6c31b3ba0608e5278930 100644 (file)
@@ -756,7 +756,7 @@ class Profile extends Managed_DataObject
      * @param Profile $other
      * @return boolean
      */
-    function hasPendingSubscription($other)
+    function hasPendingSubscription(Profile $other)
     {
         return Subscription_queue::exists($this, $other);
     }
@@ -767,7 +767,7 @@ class Profile extends Managed_DataObject
      * @param Profile $other
      * @return boolean
      */
-    function mutuallySubscribed($other)
+    function mutuallySubscribed(Profile $other)
     {
         return $this->isSubscribed($other) &&
           $other->isSubscribed($this);
@@ -1548,4 +1548,20 @@ class Profile extends Managed_DataObject
     {
         return $this;
     }
+
+    /**
+     * This will perform shortenLinks with the connected User object.
+     *
+     * Won't work on remote profiles or groups, so expect a
+     * NoSuchUserException if you don't know it's a local User.
+     *
+     * @param string $text      String to shorten
+     * @param boolean $always   Disrespect minimum length etc.
+     *
+     * @return string link-shortened $text
+     */
+    public function shortenLinks($text, $always=false)
+    {
+        return $this->getUser()->shortenLinks($text, $always);
+    }
 }
index 55e52772453f498e80ddfd19c24c9fd0f4400853..7a4564c80dbb0dc5f1b21de9b30cddd4709def05 100644 (file)
@@ -142,7 +142,7 @@ class User extends Managed_DataObject
         return $this->getProfile()->isSubscribed($other);
     }
 
-    function hasPendingSubscription($other)
+    function hasPendingSubscription(Profile $other)
     {
         return $this->getProfile()->hasPendingSubscription($other);
     }
@@ -440,7 +440,7 @@ class User extends Managed_DataObject
         return $this->getProfile()->hasFave($notice);
     }
 
-    function mutuallySubscribed($other)
+    function mutuallySubscribed(Profile $other)
     {
         return $this->getProfile()->mutuallySubscribed($other);
     }
index d15fe43ce17f2356ce18027024112202dab0a3ad..bc0dd894de6d7f396dac1d17eb7d7786ca2459b0 100644 (file)
@@ -586,7 +586,7 @@ class MessageCommand extends Command
     function handle($channel)
     {
         try {
-            $other = $this->getUser($this->other);
+            $other = $this->getUser($this->other)->getProfile();
         } catch (CommandException $e) {
             try {
                 $profile = $this->getProfile($this->other);
@@ -619,7 +619,7 @@ class MessageCommand extends Command
             return;
         }
 
-        if (!$other) {
+        if (!$other instanceof Profile) {
             // TRANS: Error text shown when trying to send a direct message to a user that does not exist.
             $channel->error($this->user, _('No such user.'));
             return;