123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- <?php
- if (!defined('STATUSNET')) {
-
-
- exit(1);
- }
- class ShowgroupmessageAction extends Action
- {
- var $gm;
- var $group;
- var $sender;
- var $user;
-
- function prepare(array $args = [])
- {
- parent::prepare($args);
- $this->user = common_current_user();
- if (empty($this->user)) {
-
- throw new ClientException(_m('Only logged-in users can view private messages.'),
- 403);
- }
- $id = $this->trimmed('id');
- $this->gm = Group_message::getKV('id', $id);
- if (empty($this->gm)) {
-
- throw new ClientException(_m('No such message.'), 404);
- }
- $this->group = User_group::getKV('id', $this->gm->to_group);
- if (empty($this->group)) {
-
- throw new ServerException(_m('Group not found.'));
- }
- if (!$this->user->isMember($this->group)) {
-
- throw new ClientException(_m('Cannot read message.'), 403);
- }
- $this->sender = Profile::getKV('id', $this->gm->from_profile);
- if (empty($this->sender)) {
-
- throw new ServerException(_m('No sender found.'));
- }
- return true;
- }
-
- function handle()
- {
- $this->showPage();
- }
-
- function title()
- {
-
-
- return sprintf(_m('Message from %1$s to group %2$s on %3$s'),
- $this->sender->nickname,
- $this->group->nickname,
- common_exact_date($this->gm->created));
- }
-
- function showContent()
- {
- $this->elementStart('ul', 'notices messages');
- $gmli = new GroupMessageListItem($this, $this->gm);
- $gmli->show();
- $this->elementEnd('ul');
- }
-
- function isReadOnly($args)
- {
- return true;
- }
-
- function lastModified()
- {
- return max(strtotime($this->group->modified),
- strtotime($this->sender->modified),
- strtotime($this->gm->modified));
- }
-
- function etag()
- {
- try {
- $avatar = $this->sender->getAvatar(AVATAR_STREAM_SIZE);
- $avtime = strtotime($avatar->modified);
- } catch (Exception $e) {
- $avtime = 0;
- }
- return 'W/"' . implode(':', array($this->arg('action'),
- common_user_cache_hash(),
- common_language(),
- $this->gm->id,
- strtotime($this->sender->modified),
- strtotime($this->group->modified),
- $avtime)) . '"';
- }
- }
|