]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/newmessage.php
TagAction extends ManagedAction
[quix0rs-gnu-social.git] / actions / newmessage.php
index 5d097188fc0b3af822186dbc8afd92fc4704f547..428a55762ce60b3e2b19701c0fdf7fba1f4d6151 100644 (file)
@@ -74,25 +74,28 @@ class NewmessageAction extends FormAction
      * @return void
      */
 
-    protected function prepare($args)
+    protected function prepare(array $args=array())
     {
         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,17 +130,17 @@ 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);
-        } else if ($user->id == $this->other->id) {
+        } else if ($this->scoped->id == $this->other->id) {
             // TRANS: Client error displayed trying to send a direct message to self.
             $this->clientError(_('Do not send a message to yourself; ' .
                 'just say it to yourself quietly instead.'), 403);
         }
 
-        $message = Message::saveNew($user->id, $this->other->id, $this->content, 'web');
+        $message = Message::saveNew($this->scoped->id, $this->other->id, $this->content, 'web');
         $message->notify();
 
         if ($this->boolean('ajax')) {
@@ -154,10 +156,10 @@ class NewmessageAction extends FormAction
                 sprintf(_('Direct message to %s sent.'),
                     $this->other->nickname));
             $this->elementEnd('body');
-            $this->elementEnd('html');
+            $this->endHTML();
         } else {
             $url = common_local_url('outbox',
-                array('nickname' => $user->nickname));
+                array('nickname' => $this->scoped->nickname));
             common_redirect($url, 303);
         }
     }
@@ -182,7 +184,7 @@ class NewmessageAction extends FormAction
         $this->elementStart('body');
         $this->element('p', array('id' => 'error'), $msg);
         $this->elementEnd('body');
-        $this->elementEnd('html');
+        $this->endHTML();
     }
 
     function showForm($msg = null)
@@ -194,9 +196,7 @@ class NewmessageAction extends FormAction
 
         $this->msg = $msg;
         if ($this->trimmed('ajax')) {
-            header('Content-Type: text/xml;charset=utf-8');
-            $this->xw->startDocument('1.0', 'UTF-8');
-            $this->elementStart('html');
+            $this->startHTML('text/xml;charset=utf-8');
             $this->elementStart('head');
             // TRANS: Page title on page for sending a direct message.
             $this->element('title', null, _('New message'));