2008-09-18 02:47:41 +09:00
|
|
|
<?php
|
2019-08-20 06:51:51 +09:00
|
|
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
|
|
|
//
|
|
|
|
// GNU social is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// GNU social is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2009-01-21 12:16:52 +09:00
|
|
|
/**
|
2019-08-20 06:51:51 +09:00
|
|
|
* GNUsocial implementation of Direct Messages
|
2009-01-21 12:16:52 +09:00
|
|
|
*
|
2019-08-20 06:51:51 +09:00
|
|
|
* @package GNUsocial
|
|
|
|
* @author Mikael Nordfeldth <mmn@hethane.se>
|
|
|
|
* @author Bruno Casteleiro <brunoccast@fc.up.pt>
|
|
|
|
* @copyright 2019 Free Software Foundation, Inc http://www.fsf.org
|
|
|
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
2008-09-18 02:47:41 +09:00
|
|
|
*/
|
2019-08-20 06:51:51 +09:00
|
|
|
|
|
|
|
defined('GNUSOCIAL') || die();
|
2008-09-18 02:47:41 +09:00
|
|
|
|
2009-01-21 12:16:52 +09:00
|
|
|
/**
|
2019-08-20 06:51:51 +09:00
|
|
|
* Action for showing a single message
|
2009-01-21 12:16:52 +09:00
|
|
|
*
|
2019-08-20 06:51:51 +09:00
|
|
|
* @category Plugin
|
|
|
|
* @package GNUsocial
|
|
|
|
* @author Evan Prodromou <evan@status.net>
|
|
|
|
* @author Bruno Casteleiro <brunoccast@fc.up.pt>
|
|
|
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
2009-01-21 12:16:52 +09:00
|
|
|
*/
|
2011-02-09 01:33:36 +09:00
|
|
|
class ShowmessageAction extends Action
|
2008-12-24 04:49:23 +09:00
|
|
|
{
|
2019-08-20 06:51:51 +09:00
|
|
|
protected $message = null;
|
|
|
|
protected $from = null;
|
|
|
|
protected $attentions = null;
|
|
|
|
protected $user = null;
|
2008-09-18 02:47:41 +09:00
|
|
|
|
2009-01-21 12:16:52 +09:00
|
|
|
/**
|
2019-08-20 06:51:51 +09:00
|
|
|
* Load attributes based on database arguments.
|
2009-01-21 12:16:52 +09:00
|
|
|
*
|
|
|
|
* @param array $args $_REQUEST array
|
2019-08-20 06:51:51 +09:00
|
|
|
* @return bool success flag
|
2009-01-21 12:16:52 +09:00
|
|
|
*/
|
2019-08-20 06:51:51 +09:00
|
|
|
function prepare($args = [])
|
2009-01-21 12:16:52 +09:00
|
|
|
{
|
|
|
|
parent::prepare($args);
|
2010-10-31 08:16:59 +09:00
|
|
|
|
2019-08-20 06:51:51 +09:00
|
|
|
if (!$this->trimmed('message')) {
|
|
|
|
return true;
|
|
|
|
}
|
2010-10-31 08:16:59 +09:00
|
|
|
|
2019-08-20 06:51:51 +09:00
|
|
|
$this->message = Notice::getKV('id', $this->trimmed('message'));
|
2008-09-18 02:47:41 +09:00
|
|
|
|
2019-08-20 06:51:51 +09:00
|
|
|
if (!$this->message instanceof Notice) {
|
2010-10-31 08:16:59 +09:00
|
|
|
// TRANS: Client error displayed requesting a single message that does not exist.
|
2019-08-20 06:51:51 +09:00
|
|
|
$this->clientError(_m('No such message.'), 404);
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
2009-01-21 12:16:52 +09:00
|
|
|
|
2019-08-20 06:51:51 +09:00
|
|
|
$this->from = $this->message->getProfile();
|
|
|
|
$this->attentions = $this->message->getAttentionProfiles();
|
|
|
|
|
2009-01-21 12:16:52 +09:00
|
|
|
$this->user = common_current_user();
|
|
|
|
|
2019-08-20 06:51:51 +09:00
|
|
|
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) {
|
|
|
|
// TRANS: Client error displayed requesting a single direct message the requesting user was not a party in.
|
|
|
|
throw new ClientException(_m('Only the sender and recipients may read this message.'), 403);
|
|
|
|
}
|
2011-02-09 01:33:36 +09:00
|
|
|
}
|
|
|
|
|
2009-01-21 12:16:52 +09:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-20 06:51:51 +09:00
|
|
|
/**
|
|
|
|
* Handler method.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-06-01 11:05:11 +09:00
|
|
|
function handle()
|
2009-01-21 12:16:52 +09:00
|
|
|
{
|
2011-02-09 01:33:36 +09:00
|
|
|
$this->showPage();
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
2010-10-31 08:16:59 +09:00
|
|
|
|
2019-08-20 06:51:51 +09:00
|
|
|
/**
|
|
|
|
* Title of the page.
|
|
|
|
*
|
|
|
|
* @return string page title
|
|
|
|
*/
|
|
|
|
function title() : string
|
2010-10-31 08:16:59 +09:00
|
|
|
{
|
2019-08-20 06:51:51 +09:00
|
|
|
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());
|
|
|
|
// @todo FIXME: Might be nice if the timestamp could be localised.
|
|
|
|
// TRANS: Page title for single direct message display when viewing user is the sender.
|
|
|
|
// TRANS: %1$s is the addressed user's nickname, $2$s is a timestamp.
|
|
|
|
return sprintf(_m('Message to %1$s on %2$s'),
|
|
|
|
$to->getBestName(),
|
|
|
|
common_exact_date($this->message->getCreated()));
|
|
|
|
}
|
|
|
|
} else {
|
2010-10-31 08:16:59 +09:00
|
|
|
// @todo FIXME: Might be nice if the timestamp could be localised.
|
|
|
|
// TRANS: Page title for single message display.
|
|
|
|
// TRANS: %1$s is the sending user's nickname, $2$s is a timestamp.
|
2019-08-20 06:51:51 +09:00
|
|
|
return sprintf(_m('Message from %1$s on %2$s'),
|
|
|
|
$this->from->getBestName(),
|
|
|
|
common_exact_date($this->message->getCreated()));
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
|
|
|
}
|
2010-10-31 08:16:59 +09:00
|
|
|
|
2019-08-20 06:51:51 +09:00
|
|
|
/**
|
|
|
|
* Show content.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-02-09 01:33:36 +09:00
|
|
|
function showContent()
|
2008-12-24 04:33:23 +09:00
|
|
|
{
|
2011-02-09 01:33:36 +09:00
|
|
|
$this->elementStart('ul', 'notices messages');
|
2019-08-20 06:51:51 +09:00
|
|
|
$ml = new ShowMessageListItem($this, $this->message, $this->user, $this->from, $this->attentions);
|
2011-02-09 01:33:36 +09:00
|
|
|
$ml->show();
|
|
|
|
$this->elementEnd('ul');
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
2010-10-31 08:16:59 +09:00
|
|
|
|
2019-08-20 06:51:51 +09:00
|
|
|
/**
|
|
|
|
* Is this action read-only?
|
|
|
|
*
|
|
|
|
* @param array $args other arguments
|
|
|
|
* @return bool true if read-only action, false otherwise
|
|
|
|
*/
|
|
|
|
function isReadOnly($args) : bool
|
2008-12-24 04:33:23 +09:00
|
|
|
{
|
2011-02-09 01:33:36 +09:00
|
|
|
return true;
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
2009-01-21 12:16:52 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Don't show aside
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-02-09 01:33:36 +09:00
|
|
|
function showAside() {
|
2019-08-20 06:51:51 +09:00
|
|
|
|
2009-01-21 12:16:52 +09:00
|
|
|
}
|
2011-02-09 01:33:36 +09:00
|
|
|
}
|
2010-10-31 08:16:59 +09:00
|
|
|
|
2019-08-20 06:51:51 +09:00
|
|
|
/**
|
|
|
|
* showmessage action's MessageListItem widget.
|
|
|
|
*
|
|
|
|
* @category Plugin
|
|
|
|
* @package GNUsocial
|
|
|
|
* @author Evan Prodromou <evan@status.net>
|
|
|
|
* @author Bruno Casteleiro <brunoccast@fc.up.pt>
|
|
|
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
|
|
|
*/
|
2011-02-09 01:33:36 +09:00
|
|
|
class ShowMessageListItem extends MessageListItem
|
|
|
|
{
|
2019-08-20 06:51:51 +09:00
|
|
|
protected $user;
|
|
|
|
protected $from;
|
|
|
|
protected $attentions;
|
2011-02-09 01:33:36 +09:00
|
|
|
|
2019-08-20 06:51:51 +09:00
|
|
|
function __construct($out, $message, $user, $from, $attentions)
|
2009-01-21 12:16:52 +09:00
|
|
|
{
|
2011-02-09 01:33:36 +09:00
|
|
|
parent::__construct($out, $message);
|
2019-08-20 06:51:51 +09:00
|
|
|
|
|
|
|
$this->user = $user;
|
|
|
|
$this->from = $from;
|
|
|
|
$this->attentions = $attentions;
|
2009-01-21 12:16:52 +09:00
|
|
|
}
|
2009-01-23 18:15:15 +09:00
|
|
|
|
2019-08-20 06:51:51 +09:00
|
|
|
function getMessageProfile() : ?Profile
|
2009-01-23 18:15:15 +09:00
|
|
|
{
|
2019-08-20 06:51:51 +09:00
|
|
|
return $this->user->getID() == $this->from->getID() ?
|
|
|
|
$this->attentions[0] : $this->from;
|
2009-01-23 18:15:15 +09:00
|
|
|
}
|
|
|
|
}
|