Fix Direct Message functionality.
This commit is contained in:
parent
7d191f8062
commit
34b570352f
@ -51,7 +51,7 @@ class ApiDirectMessageNewAction extends ApiAuthAction
|
|||||||
{
|
{
|
||||||
protected $needPost = true;
|
protected $needPost = true;
|
||||||
|
|
||||||
var $other = null;
|
var $other = null; // Profile we're sending to
|
||||||
var $content = null;
|
var $content = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -77,7 +77,7 @@ class ApiDirectMessageNewAction extends ApiAuthAction
|
|||||||
$screen_name = $this->trimmed('screen_name');
|
$screen_name = $this->trimmed('screen_name');
|
||||||
|
|
||||||
if (isset($user_param) || isset($user_id) || isset($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;
|
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).
|
// TRANS: Client error displayed if a recipient user could not be found (403).
|
||||||
$this->clientError(_('Recipient user not found.'), 403);
|
$this->clientError(_('Recipient user not found.'), 403);
|
||||||
} else if (!$this->user->mutuallySubscribed($this->other)) {
|
} else if (!$this->user->mutuallySubscribed($this->other)) {
|
||||||
|
@ -78,21 +78,24 @@ class NewmessageAction extends FormAction
|
|||||||
{
|
{
|
||||||
parent::prepare($args);
|
parent::prepare($args);
|
||||||
|
|
||||||
$user = $this->scoped->getUser();
|
|
||||||
|
|
||||||
$this->content = $this->trimmed('content');
|
$this->content = $this->trimmed('content');
|
||||||
$this->to = $this->trimmed('to');
|
$this->to = $this->trimmed('to');
|
||||||
|
|
||||||
if ($this->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.
|
// TRANS: Client error displayed trying to send a direct message to a non-existing user.
|
||||||
$this->clientError(_('No such user.'), 404);
|
$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: Client error displayed trying to send a direct message to a user while sender and
|
||||||
// TRANS: receiver are not subscribed to each other.
|
// TRANS: receiver are not subscribed to each other.
|
||||||
$this->clientError(_('You cannot send a message to this user.'), 404);
|
$this->clientError(_('You cannot send a message to this user.'), 404);
|
||||||
@ -106,14 +109,13 @@ class NewmessageAction extends FormAction
|
|||||||
{
|
{
|
||||||
parent::handlePost();
|
parent::handlePost();
|
||||||
|
|
||||||
assert($this->scoped); // XXX: maybe an error instead...
|
assert($this->scoped instanceof Profile); // XXX: maybe an error instead...
|
||||||
$user = $this->scoped->getUser();
|
|
||||||
|
|
||||||
if (!$this->content) {
|
if (!$this->content) {
|
||||||
// TRANS: Form validator error displayed trying to send a direct message without content.
|
// TRANS: Form validator error displayed trying to send a direct message without content.
|
||||||
$this->clientError(_('No content!'));
|
$this->clientError(_('No content!'));
|
||||||
} else {
|
} else {
|
||||||
$content_shortened = $user->shortenLinks($this->content);
|
$content_shortened = $this->scoped->shortenLinks($this->content);
|
||||||
|
|
||||||
if (Message::contentTooLong($content_shortened)) {
|
if (Message::contentTooLong($content_shortened)) {
|
||||||
// TRANS: Form validation error displayed when message content is too long.
|
// TRANS: Form validation error displayed when message content is too long.
|
||||||
@ -128,7 +130,7 @@ class NewmessageAction extends FormAction
|
|||||||
if (!$this->other) {
|
if (!$this->other) {
|
||||||
// TRANS: Form validation error displayed trying to send a direct message without specifying a recipient.
|
// TRANS: Form validation error displayed trying to send a direct message without specifying a recipient.
|
||||||
$this->clientError(_('No recipient specified.'));
|
$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: Client error displayed trying to send a direct message to a user while sender and
|
||||||
// TRANS: receiver are not subscribed to each other.
|
// TRANS: receiver are not subscribed to each other.
|
||||||
$this->clientError(_('You cannot send a message to this user.'), 404);
|
$this->clientError(_('You cannot send a message to this user.'), 404);
|
||||||
|
@ -756,7 +756,7 @@ class Profile extends Managed_DataObject
|
|||||||
* @param Profile $other
|
* @param Profile $other
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
function hasPendingSubscription($other)
|
function hasPendingSubscription(Profile $other)
|
||||||
{
|
{
|
||||||
return Subscription_queue::exists($this, $other);
|
return Subscription_queue::exists($this, $other);
|
||||||
}
|
}
|
||||||
@ -767,7 +767,7 @@ class Profile extends Managed_DataObject
|
|||||||
* @param Profile $other
|
* @param Profile $other
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
function mutuallySubscribed($other)
|
function mutuallySubscribed(Profile $other)
|
||||||
{
|
{
|
||||||
return $this->isSubscribed($other) &&
|
return $this->isSubscribed($other) &&
|
||||||
$other->isSubscribed($this);
|
$other->isSubscribed($this);
|
||||||
@ -1548,4 +1548,20 @@ class Profile extends Managed_DataObject
|
|||||||
{
|
{
|
||||||
return $this;
|
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);
|
return $this->getProfile()->isSubscribed($other);
|
||||||
}
|
}
|
||||||
|
|
||||||
function hasPendingSubscription($other)
|
function hasPendingSubscription(Profile $other)
|
||||||
{
|
{
|
||||||
return $this->getProfile()->hasPendingSubscription($other);
|
return $this->getProfile()->hasPendingSubscription($other);
|
||||||
}
|
}
|
||||||
@ -440,7 +440,7 @@ class User extends Managed_DataObject
|
|||||||
return $this->getProfile()->hasFave($notice);
|
return $this->getProfile()->hasFave($notice);
|
||||||
}
|
}
|
||||||
|
|
||||||
function mutuallySubscribed($other)
|
function mutuallySubscribed(Profile $other)
|
||||||
{
|
{
|
||||||
return $this->getProfile()->mutuallySubscribed($other);
|
return $this->getProfile()->mutuallySubscribed($other);
|
||||||
}
|
}
|
||||||
|
@ -586,7 +586,7 @@ class MessageCommand extends Command
|
|||||||
function handle($channel)
|
function handle($channel)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$other = $this->getUser($this->other);
|
$other = $this->getUser($this->other)->getProfile();
|
||||||
} catch (CommandException $e) {
|
} catch (CommandException $e) {
|
||||||
try {
|
try {
|
||||||
$profile = $this->getProfile($this->other);
|
$profile = $this->getProfile($this->other);
|
||||||
@ -619,7 +619,7 @@ class MessageCommand extends Command
|
|||||||
return;
|
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.
|
// 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.'));
|
$channel->error($this->user, _('No such user.'));
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user