123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- <?php
- if (!defined('GNUSOCIAL')) { exit(1); }
- class NewmessageAction extends FormAction
- {
- var $content = null;
- var $to = null;
- var $other = null;
- protected $form = 'Message';
-
- function title()
- {
-
- return _('New message');
- }
- protected function doPreparation()
- {
- $this->content = $this->trimmed('content');
- $this->to = $this->trimmed('to');
- if ($this->to) {
- $this->other = Profile::getKV('id', $this->to);
- if (!$this->other instanceof Profile) {
-
- $this->clientError(_('No such user.'), 404);
- }
- if (!$this->other->isLocal()) {
-
- $this->clientError(_('You cannot send direct messages to federated users yet.'));
- }
- if (!$this->scoped->mutuallySubscribed($this->other)) {
-
-
- $this->clientError(_('You cannot send a message to this user.'), 404);
- }
- }
- return true;
- }
- protected function doPost()
- {
- assert($this->scoped instanceof Profile);
- if (empty($this->content)) {
-
- $this->clientError(_('No content!'));
- }
- $content_shortened = $this->scoped->shortenLinks($this->content);
- if (Message::contentTooLong($content_shortened)) {
-
-
- $this->clientError(sprintf(_m('That\'s too long. Maximum message size is %d character.',
- 'That\'s too long. Maximum message size is %d characters.',
- Message::maxContent()),
- Message::maxContent()));
- }
- if (!$this->other instanceof Profile) {
-
- $this->clientError(_('No recipient specified.'));
- } else if (!$this->scoped->mutuallySubscribed($this->other)) {
-
-
- $this->clientError(_('You cannot send a message to this user.'), 404);
- } else if ($this->scoped->id == $this->other->id) {
-
- $this->clientError(_('Do not send a message to yourself; ' .
- 'just say it to yourself quietly instead.'), 403);
- }
- $message = Message::saveNew($this->scoped->id, $this->other->id, $this->content, 'web');
- $message->notify();
- if (GNUsocial::isAjax()) {
-
-
- return sprintf(_('Direct message to %s sent.'), $this->other->getNickname());
- }
- $url = common_local_url('outbox', array('nickname' => $this->scoped->getNickname()));
- common_redirect($url, 303);
- }
- function showNoticeForm()
- {
-
- }
- }
|