3 * StatusNet, the distributed open-source microblogging tool
5 * Handler for posting new messages
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Evan Prodromou <evan@status.net>
25 * @author Zach Copley <zach@status.net>
26 * @author Sarven Capadisli <csarven@status.net>
27 * @copyright 2008-2009 StatusNet, Inc.
28 * @copyright 2013 Free Software Foundation, Inc.
29 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
30 * @link http://status.net/
33 if (!defined('GNUSOCIAL')) { exit(1); }
36 * Action for posting new direct messages
40 * @author Evan Prodromou <evan@status.net>
41 * @author Zach Copley <zach@status.net>
42 * @author Sarven Capadisli <csarven@status.net>
43 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
44 * @link http://status.net/
47 class NewmessageAction extends FormAction
53 protected $form = 'Message'; // will become MessageForm later
58 * Note that this usually doesn't get called unless something went wrong
60 * @return string page title
65 // TRANS: Page title for new direct message page.
66 return _('New message');
69 protected function doPreparation()
71 $this->content = $this->trimmed('content');
72 $this->to = $this->trimmed('to');
76 $this->other = Profile::getKV('id', $this->to);
78 if (!$this->other instanceof Profile) {
79 // TRANS: Client error displayed trying to send a direct message to a non-existing user.
80 $this->clientError(_('No such user.'), 404);
83 if (!$this->other->isLocal()) {
84 // TRANS: Explains that current federation does not support direct, private messages yet.
85 $this->clientError(_('You cannot send direct messages to federated users yet.'));
88 if (!$this->scoped->mutuallySubscribed($this->other)) {
89 // TRANS: Client error displayed trying to send a direct message to a user while sender and
90 // TRANS: receiver are not subscribed to each other.
91 $this->clientError(_('You cannot send a message to this user.'), 404);
98 protected function doPost()
100 assert($this->scoped instanceof Profile); // XXX: maybe an error instead...
102 if (empty($this->content)) {
103 // TRANS: Form validator error displayed trying to send a direct message without content.
104 $this->clientError(_('No content!'));
107 $content_shortened = $this->scoped->shortenLinks($this->content);
109 if (Message::contentTooLong($content_shortened)) {
110 // TRANS: Form validation error displayed when message content is too long.
111 // TRANS: %d is the maximum number of characters for a message.
112 $this->clientError(sprintf(_m('That\'s too long. Maximum message size is %d character.',
113 'That\'s too long. Maximum message size is %d characters.',
114 Message::maxContent()),
115 Message::maxContent()));
118 if (!$this->other instanceof Profile) {
119 // TRANS: Form validation error displayed trying to send a direct message without specifying a recipient.
120 $this->clientError(_('No recipient specified.'));
121 } else if (!$this->scoped->mutuallySubscribed($this->other)) {
122 // TRANS: Client error displayed trying to send a direct message to a user while sender and
123 // TRANS: receiver are not subscribed to each other.
124 $this->clientError(_('You cannot send a message to this user.'), 404);
125 } else if ($this->scoped->id == $this->other->id) {
126 // TRANS: Client error displayed trying to send a direct message to self.
127 $this->clientError(_('Do not send a message to yourself; ' .
128 'just say it to yourself quietly instead.'), 403);
131 $message = Message::saveNew($this->scoped->id, $this->other->id, $this->content, 'web');
134 if (GNUsocial::isAjax()) {
135 // TRANS: Confirmation text after sending a direct message.
136 // TRANS: %s is the direct message recipient.
137 return sprintf(_('Direct message to %s sent.'), $this->other->getNickname());
140 $url = common_local_url('outbox', array('nickname' => $this->scoped->getNickname()));
141 common_redirect($url, 303);
144 function showNoticeForm()
146 // Just don't show a NoticeForm