3 * StatusNet, the distributed open-source microblogging tool
5 * Show a single message
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 * @copyright 2008-2009 StatusNet, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27 * @link http://status.net/
29 if (!defined('STATUSNET') && !defined('LACONICA')) {
34 * Show a single message
38 * @author Evan Prodromou <evan@status.net>
39 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
40 * @link http://status.net/
43 class ShowmessageAction extends Action
46 * Message object to show
57 * Load attributes based on database arguments
59 * Loads all the DB stuff
61 * @param array $args $_REQUEST array
63 * @return success flag
65 function prepare($args)
67 parent::prepare($args);
71 $id = $this->trimmed('message');
72 $this->message = Message::staticGet('id', $id);
74 if (!$this->message) {
75 // TRANS: Client error displayed requesting a single message that does not exist.
76 $this->clientError(_('No such message.'), 404);
80 $this->user = common_current_user();
82 if (empty($this->user) ||
83 ($this->user->id != $this->message->from_profile &&
84 $this->user->id != $this->message->to_profile)) {
85 // TRANS: Client error displayed requesting a single direct message the requesting user was not a party in.
86 throw new ClientException(_('Only the sender and recipient ' .
87 'may read this message.'), 403);
93 function handle($args)
100 if ($this->user->id == $this->message->from_profile) {
101 $to = $this->message->getTo();
102 // @todo FIXME: Might be nice if the timestamp could be localised.
103 // TRANS: Page title for single direct message display when viewing user is the sender.
104 // TRANS: %1$s is the addressed user's nickname, $2$s is a timestamp.
105 return sprintf(_('Message to %1$s on %2$s'),
107 common_exact_date($this->message->created));
108 } else if ($this->user->id == $this->message->to_profile) {
109 $from = $this->message->getFrom();
110 // @todo FIXME: Might be nice if the timestamp could be localised.
111 // TRANS: Page title for single message display.
112 // TRANS: %1$s is the sending user's nickname, $2$s is a timestamp.
113 return sprintf(_('Message from %1$s on %2$s'),
115 common_exact_date($this->message->created));
120 function showContent()
122 $this->elementStart('ul', 'notices messages');
123 $ml = new ShowMessageListItem($this, $this->message, $this->user);
125 $this->elementEnd('ul');
128 function isReadOnly($args)
139 function showAside() {
143 class ShowMessageListItem extends MessageListItem
147 function __construct($out, $message, $user)
149 parent::__construct($out, $message);
153 function getMessageProfile()
155 if ($this->user->id == $this->message->from_profile) {
156 return $this->message->getTo();
157 } else if ($this->user->id == $this->message->to_profile) {
158 return $this->message->getFrom();
160 // This shouldn't happen