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/
47 class ShowgroupmessageAction extends Action
55 * For initializing members of the class.
57 * @param array $argarray misc. arguments
59 * @return boolean true
61 function prepare($argarray)
63 parent::prepare($argarray);
65 $this->user = common_current_user();
67 if (empty($this->user)) {
68 // TRANS: Client exception thrown when trying to view group private messages without being logged in.
69 throw new ClientException(_m('Only logged-in users can view private messages.'),
73 $id = $this->trimmed('id');
75 $this->gm = Group_message::getKV('id', $id);
77 if (empty($this->gm)) {
78 // TRANS: Client exception thrown when trying to view a non-existing group private message.
79 throw new ClientException(_m('No such message.'), 404);
82 $this->group = User_group::getKV('id', $this->gm->to_group);
84 if (empty($this->group)) {
85 // TRANS: Server exception thrown when trying to view group private messages for a non-exsting group.
86 throw new ServerException(_m('Group not found.'));
89 if (!$this->user->isMember($this->group)) {
90 // TRANS: Client exception thrown when trying to view a group private message without being a group member.
91 throw new ClientException(_m('Cannot read message.'), 403);
94 $this->sender = Profile::getKV('id', $this->gm->from_profile);
96 if (empty($this->sender)) {
97 // TRANS: Server exception thrown when trying to view a group private message without a sender.
98 throw new ServerException(_m('No sender found.'));
107 * @param array $argarray is ignored since it's now passed in in prepare()
111 function handle($argarray=null)
121 // TRANS: Title for private group message.
122 // TRANS: %1$s is the sender name, %2$s is the group name, %3$s is a timestamp.
123 return sprintf(_m('Message from %1$s to group %2$s on %3$s'),
124 $this->sender->nickname,
125 $this->group->nickname,
126 common_exact_date($this->gm->created));
130 * Show the content area.
132 function showContent()
134 $this->elementStart('ul', 'notices messages');
135 $gmli = new GroupMessageListItem($this, $this->gm);
137 $this->elementEnd('ul');
141 * Return true if read only.
145 * @param array $args other arguments
147 * @return boolean is read only action?
149 function isReadOnly($args)
155 * Return last modified, if applicable.
159 * @return string last modified http header
161 function lastModified()
163 return max(strtotime($this->group->modified),
164 strtotime($this->sender->modified),
165 strtotime($this->gm->modified));
169 * Return etag, if applicable.
173 * @return string etag http header
178 $avatar = $this->sender->getAvatar(AVATAR_STREAM_SIZE);
179 $avtime = strtotime($avatar->modified);
180 } catch (Exception $e) {
184 return 'W/"' . implode(':', array($this->arg('action'),
185 common_user_cache_hash(),
188 strtotime($this->sender->modified),
189 strtotime($this->group->modified),