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('STATUSNET')) {
38 * Action for posting new direct messages
42 * @author Evan Prodromou <evan@status.net>
43 * @author Zach Copley <zach@status.net>
44 * @author Sarven Capadisli <csarven@status.net>
45 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
46 * @link http://status.net/
49 class NewmessageAction extends FormAction
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');
70 * Handle input, produce output
72 * @param array $args $_REQUEST contents
77 protected function prepare(array $args=array())
79 parent::prepare($args);
81 $this->content = $this->trimmed('content');
82 $this->to = $this->trimmed('to');
86 $this->other = Profile::getKV('id', $this->to);
88 if (!$this->other instanceof Profile) {
89 // TRANS: Client error displayed trying to send a direct message to a non-existing user.
90 $this->clientError(_('No such user.'), 404);
93 if (!$this->other->isLocal()) {
94 // TRANS: Explains that current federation does not support direct, private messages yet.
95 $this->clientError(_('You cannot send direct messages to federated users yet.'));
98 if (!$this->scoped->mutuallySubscribed($this->other)) {
99 // TRANS: Client error displayed trying to send a direct message to a user while sender and
100 // TRANS: receiver are not subscribed to each other.
101 $this->clientError(_('You cannot send a message to this user.'), 404);
108 protected function handlePost()
110 parent::handlePost();
112 assert($this->scoped instanceof Profile); // XXX: maybe an error instead...
114 if (!$this->content) {
115 // TRANS: Form validator error displayed trying to send a direct message without content.
116 $this->clientError(_('No content!'));
118 $content_shortened = $this->scoped->shortenLinks($this->content);
120 if (Message::contentTooLong($content_shortened)) {
121 // TRANS: Form validation error displayed when message content is too long.
122 // TRANS: %d is the maximum number of characters for a message.
123 $this->clientError(sprintf(_m('That\'s too long. Maximum message size is %d character.',
124 'That\'s too long. Maximum message size is %d characters.',
125 Message::maxContent()),
126 Message::maxContent()));
131 // TRANS: Form validation error displayed trying to send a direct message without specifying a recipient.
132 $this->clientError(_('No recipient specified.'));
133 } else if (!$this->scoped->mutuallySubscribed($this->other)) {
134 // TRANS: Client error displayed trying to send a direct message to a user while sender and
135 // TRANS: receiver are not subscribed to each other.
136 $this->clientError(_('You cannot send a message to this user.'), 404);
137 } else if ($this->scoped->id == $this->other->id) {
138 // TRANS: Client error displayed trying to send a direct message to self.
139 $this->clientError(_('Do not send a message to yourself; ' .
140 'just say it to yourself quietly instead.'), 403);
143 $message = Message::saveNew($this->scoped->id, $this->other->id, $this->content, 'web');
146 if ($this->boolean('ajax')) {
147 $this->startHTML('text/xml;charset=utf-8');
148 $this->elementStart('head');
149 // TRANS: Page title after sending a direct message.
150 $this->element('title', null, _('Message sent'));
151 $this->elementEnd('head');
152 $this->elementStart('body');
153 $this->element('p', array('id' => 'command_result'),
154 // TRANS: Confirmation text after sending a direct message.
155 // TRANS: %s is the direct message recipient.
156 sprintf(_('Direct message to %s sent.'),
157 $this->other->nickname));
158 $this->elementEnd('body');
161 $url = common_local_url('outbox',
162 array('nickname' => $this->scoped->nickname));
163 common_redirect($url, 303);
168 * Show an Ajax-y error message
170 * Goes back to the browser, where it's shown in a popup.
172 * @param string $msg Message to show
177 function ajaxErrorMsg($msg)
179 $this->startHTML('text/xml;charset=utf-8', true);
180 $this->elementStart('head');
181 // TRANS: Page title after an AJAX error occurred on the "send direct message" page.
182 $this->element('title', null, _('Ajax Error'));
183 $this->elementEnd('head');
184 $this->elementStart('body');
185 $this->element('p', array('id' => 'error'), $msg);
186 $this->elementEnd('body');
190 function showForm($msg = null)
192 if ($msg && $this->boolean('ajax')) {
193 $this->ajaxErrorMsg($msg);
198 if ($this->trimmed('ajax')) {
199 $this->startHTML('text/xml;charset=utf-8');
200 $this->elementStart('head');
201 // TRANS: Page title on page for sending a direct message.
202 $this->element('title', null, _('New message'));
203 $this->elementEnd('head');
204 $this->elementStart('body');
205 $this->showNoticeForm();
206 $this->elementEnd('body');
214 function showPageNotice()
217 $this->element('p', 'error', $this->msg);
221 // Do nothing (override)
223 function showNoticeForm()
225 $message_form = new MessageForm($this, $this->other, $this->content);
226 $message_form->show();