123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- <?php
- defined('GNUSOCIAL') || die();
- class ShowmessageAction extends Action
- {
- protected $message = null;
- protected $from = null;
- protected $attentions = null;
- protected $user = null;
-
- function prepare($args = [])
- {
- parent::prepare($args);
- if (!$this->trimmed('message')) {
- return true;
- }
- $this->message = Notice::getKV('id', $this->trimmed('message'));
- if (!$this->message instanceof Notice) {
-
- $this->clientError(_m('No such message.'), 404);
- }
- $this->from = $this->message->getProfile();
- $this->attentions = $this->message->getAttentionProfiles();
- $this->user = common_current_user();
- if (empty($this->user) || $this->user->getID() != $this->from->getID()) {
- $receiver = false;
- foreach ($this->attentions as $attention) {
- if ($this->user->getID() == $attention->getID()) {
- $receiver = true;
- break;
- }
- }
-
- if (!$receiver) {
-
- throw new ClientException(_m('Only the sender and recipients may read this message.'), 403);
- }
- }
- return true;
- }
-
- function handle()
- {
- $this->showPage();
- }
-
- function title() : string
- {
- if ($this->user->getID() == $this->from->getID()) {
- if (sizeof($this->attentions) > 1) {
- return sprintf(_m('Message to many on %1$s'), common_exact_date($this->message->getCreated()));
- } else {
- $to = Profile::getKV('id', $this->attentions[0]->getID());
-
-
-
- return sprintf(_m('Message to %1$s on %2$s'),
- $to->getBestName(),
- common_exact_date($this->message->getCreated()));
- }
- } else {
-
-
-
- return sprintf(_m('Message from %1$s on %2$s'),
- $this->from->getBestName(),
- common_exact_date($this->message->getCreated()));
- }
- }
-
- function showContent()
- {
- $this->elementStart('ul', 'notices messages');
- $ml = new ShowMessageListItem($this, $this->message, $this->user, $this->from, $this->attentions);
- $ml->show();
- $this->elementEnd('ul');
- }
-
- function isReadOnly($args) : bool
- {
- return true;
- }
-
- function showAside() {
- }
- }
- class ShowMessageListItem extends MessageListItem
- {
- protected $user;
- protected $from;
- protected $attentions;
- function __construct($out, $message, $user, $from, $attentions)
- {
- parent::__construct($out, $message);
- $this->user = $user;
- $this->from = $from;
- $this->attentions = $attentions;
- }
- function getMessageProfile() : ?Profile
- {
- return $this->user->getID() == $this->from->getID() ?
- $this->attentions[0] : $this->from;
- }
- }
|