Commit 34b57035 authored by mmn's avatar mmn

Fix Direct Message functionality.

parent 7d191f80
......@@ -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)) {
......
......@@ -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);
......
......@@ -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);
}
}
......@@ -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);
}
......
......@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment