From 62c6ed58ba0abcd4f454c059665f4adb0e854b54 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Tue, 7 Jul 2015 19:18:45 +0200 Subject: [PATCH] DirectMessagePlugin actions modernified --- .../actions/apidirectmessage.php | 30 ++++++++----------- .../actions/apidirectmessagenew.php | 14 ++++----- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/plugins/DirectMessage/actions/apidirectmessage.php b/plugins/DirectMessage/actions/apidirectmessage.php index c18559f49d..17c445c276 100644 --- a/plugins/DirectMessage/actions/apidirectmessage.php +++ b/plugins/DirectMessage/actions/apidirectmessage.php @@ -30,9 +30,7 @@ * @link http://status.net/ */ -if (!defined('STATUSNET')) { - exit(1); -} +if (!defined('GNUSOCIAL')) { exit(1); } /** * Show a list of direct messages from or to the authenticating user @@ -62,13 +60,11 @@ class ApiDirectMessageAction extends ApiAuthAction * * @return boolean success flag */ - function prepare($args) + protected function prepare(array $args=array()) { parent::prepare($args); - $this->user = $this->auth_user; - - if (empty($this->user)) { + if (!$this->scoped instanceof Profile) { // TRANS: Client error given when a user was not found (404). $this->clientError(_('No such user.'), 404); } @@ -83,30 +79,30 @@ class ApiDirectMessageAction extends ApiAuthAction $this->title = sprintf( // TRANS: Title. %s is a user nickname. _("Direct messages from %s"), - $this->user->nickname + $this->scoped->getNickname() ); $this->subtitle = sprintf( // TRANS: Subtitle. %s is a user nickname. _("All the direct messages sent from %s"), - $this->user->nickname + $this->scoped->getNickname() ); - $this->link = $server . $this->user->nickname . '/outbox'; + $this->link = $server . $this->scoped->getNickname() . '/outbox'; $this->selfuri_base = common_root_url() . 'api/direct_messages/sent'; - $this->id = "tag:$taguribase:SentDirectMessages:" . $this->user->id; + $this->id = "tag:$taguribase:SentDirectMessages:" . $this->scoped->getID(); } else { $this->title = sprintf( // TRANS: Title. %s is a user nickname. _("Direct messages to %s"), - $this->user->nickname + $this->scoped->getNickname() ); $this->subtitle = sprintf( // TRANS: Subtitle. %s is a user nickname. _("All the direct messages sent to %s"), - $this->user->nickname + $this->scoped->getNickname() ); - $this->link = $server . $this->user->nickname . '/inbox'; + $this->link = $server . $this->scoped->getNickname() . '/inbox'; $this->selfuri_base = common_root_url() . 'api/direct_messages'; - $this->id = "tag:$taguribase:DirectMessages:" . $this->user->id; + $this->id = "tag:$taguribase:DirectMessages:" . $this->scoped->getID(); } $this->messages = $this->getMessages(); @@ -166,9 +162,9 @@ class ApiDirectMessageAction extends ApiAuthAction $message = new Message(); if ($this->arg('sent')) { - $message->from_profile = $this->user->id; + $message->from_profile = $this->scoped->getID(); } else { - $message->to_profile = $this->user->id; + $message->to_profile = $this->scoped->getID(); } if (!empty($this->max_id)) { diff --git a/plugins/DirectMessage/actions/apidirectmessagenew.php b/plugins/DirectMessage/actions/apidirectmessagenew.php index 653fa3a9ed..e2c7ab5ca7 100644 --- a/plugins/DirectMessage/actions/apidirectmessagenew.php +++ b/plugins/DirectMessage/actions/apidirectmessagenew.php @@ -30,9 +30,7 @@ * @link http://status.net/ */ -if (!defined('STATUSNET')) { - exit(1); -} +if (!defined('GNUSOCIAL')) { exit(1); } /** * Creates a new direct message from the authenticating user to @@ -65,7 +63,7 @@ class ApiDirectMessageNewAction extends ApiAuthAction { parent::prepare($args); - if (empty($this->user)) { + if (!$this->scoped instanceof Profile) { // TRANS: Client error when user not found for an API direct message action. $this->clientError(_('No such user.'), 404); } @@ -111,10 +109,10 @@ class ApiDirectMessageNewAction extends ApiAuthAction 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)) { + } else if (!$this->scoped->mutuallySubscribed($this->other)) { // TRANS: Client error displayed trying to direct message another user who's not a friend (403). $this->clientError(_('Cannot send direct messages to users who aren\'t your friend.'), 403); - } else if ($this->user->id == $this->other->id) { + } else if ($this->scoped->getID() === $this->other->getID()) { // Note: sending msgs to yourself is allowed by Twitter @@ -123,8 +121,8 @@ class ApiDirectMessageNewAction extends ApiAuthAction } $message = Message::saveNew( - $this->user->id, - $this->other->id, + $this->scoped->getID(), + $this->other->getID(), html_entity_decode($this->content, ENT_NOQUOTES, 'UTF-8'), $this->source ); -- 2.39.5