3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2011, StatusNet, Inc.
6 * Show a single group message
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Affero General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Affero General Public License for more details.
20 * You should have received a copy of the GNU Affero General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 * @category GroupPrivateMessage
25 * @author Evan Prodromou <evan@status.net>
26 * @copyright 2011 StatusNet, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
28 * @link http://status.net/
31 if (!defined('STATUSNET')) {
32 // This check helps protect against security problems;
33 // your code file can't be executed directly from the web.
38 * Show a single private group message
40 * @category GroupPrivateMessage
42 * @author Evan Prodromou <evan@status.net>
43 * @copyright 2011 StatusNet, Inc.
44 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
45 * @link http://status.net/
48 class ShowgroupmessageAction extends Action
56 * For initializing members of the class.
58 * @param array $argarray misc. arguments
60 * @return boolean true
63 function prepare($argarray)
65 parent::prepare($argarray);
67 $this->user = common_current_user();
69 if (empty($this->user)) {
70 throw new ClientException(_('Only logged-in users can view private messages.'),
74 $id = $this->trimmed('id');
76 $this->gm = Group_message::staticGet('id', $id);
78 if (empty($this->gm)) {
79 throw new ClientException(_('No such message'), 404);
82 $this->group = User_group::staticGet('id', $this->gm->to_group);
84 if (empty($this->group)) {
85 throw new ServerException(_('Group not found.'));
88 if (!$this->user->isMember($this->group)) {
89 throw new ClientException(_('Cannot read message.'), 403);
92 $this->sender = Profile::staticGet('id', $this->gm->from_profile);
94 if (empty($this->sender)) {
95 throw new ServerException(_('No sender found.'));
104 * @param array $argarray is ignored since it's now passed in in prepare()
109 function handle($argarray=null)
120 return sprintf(_('Message from %1$s to group %2$s on %3$s'),
121 $this->sender->nickname,
122 $this->group->nickname,
123 common_exact_date($this->gm->created));
127 * Show the content area.
130 function showContent()
132 $this->elementStart('ul', 'notices messages');
133 $gmli = new GroupMessageListItem($this, $this->gm);
135 $this->elementEnd('ul');
139 * Return true if read only.
143 * @param array $args other arguments
145 * @return boolean is read only action?
148 function isReadOnly($args)
154 * Return last modified, if applicable.
158 * @return string last modified http header
160 function lastModified()
162 return max(strtotime($this->group->modified),
163 strtotime($this->sender->modified),
164 strtotime($this->gm->modified));
168 * Return etag, if applicable.
172 * @return string etag http header
176 $avatar = $this->sender->getAvatar(AVATAR_STREAM_SIZE);
178 $avtime = ($avatar) ? strtotime($avatar->modified) : 0;
180 return 'W/"' . implode(':', array($this->arg('action'),
181 common_user_cache_hash(),
184 strtotime($this->sender->modified),
185 strtotime($this->group->modified),