123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- <?php
- defined('GNUSOCIAL') || die();
- class NewmessageAction extends FormAction
- {
- protected $form = 'Message';
- protected $to = null;
- protected $content = null;
-
- function title() : string
- {
-
- return _('New message');
- }
- protected function doPreparation()
- {
- if ($this->trimmed('to')) {
- $this->to = Profile::getKV('id', $this->trimmed('to'));
- if (!$this->to instanceof Profile) {
-
- $this->clientError(_('No such user.'), 404);
- }
- $this->formOpts['to'] = $this->to;
- }
- if ($this->trimmed('content')) {
- $this->content = $this->trimmed('content');
- $this->formOpts['content'] = $this->content;
- }
- if ($this->trimmed('to-box')) {
- $selected = explode(':', $this->trimmed('to-box'));
-
- if (sizeof($selected) == 2) {
- $this->to = Profile::getKV('id', $selected[1]);
-
- }
- }
- }
- protected function doPost()
- {
- assert($this->scoped instanceof Profile);
- if (empty($this->content)) {
-
- $this->clientError(_('No content!'));
- }
- $content_shortened = $this->scoped->shortenLinks($this->content);
- if (MessageModel::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.',
- MessageModel::maxContent()),
- MessageModel::maxContent()));
- }
-
- if (!$this->to instanceof Profile) {
- $mentions = common_find_mentions($this->content, $this->scoped);
- if (empty($mentions)) {
- $this->clientError(_('No recipients specified.'));
- }
- } else {
-
-
- try {
- if ($this->to->isLocal()) {
- $this->content = "@{$this->to->getNickname()} {$this->content}";
- } else {
- $this->content = '@' . substr($this->to->getAcctUri(), 5) . " {$this->content}";
- }
- } catch (ProfileNoAcctUriException $e) {
-
- }
- }
- $message = MessageModel::saveNew($this->scoped, $this->content);
- Event::handle('SendDirectMessage', [$message]);
- mail_notify_message($message);
- if (GNUsocial::isAjax()) {
-
-
- return sprintf(_('Direct message to %s sent.'), $this->to->getNickname());
- }
- $url = common_local_url('outbox', array('nickname' => $this->scoped->getNickname()));
- common_redirect($url, 303);
- }
- function showNoticeForm()
- {
-
- }
- }
|