DirectMessage moved into a plugin, not done yet

We still have to move some API calls into the new plugin.
This commit is contained in:
Mikael Nordfeldth
2014-11-07 15:47:10 +01:00
parent faae9d069a
commit 68143ff916
18 changed files with 116 additions and 58 deletions

View File

@@ -0,0 +1,167 @@
<?php
/**
* StatusNet, the distributed open-source microblogging tool
*
* common superclass for direct messages inbox and outbox
*
* PHP version 5
*
* LICENCE: This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Message
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @copyright 2008 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
/**
* common superclass for direct messages inbox and outbox
*
* @category Message
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
* @see InboxAction
* @see OutboxAction
*/
class MailboxAction extends Action
{
var $page = null;
function prepare($args)
{
parent::prepare($args);
$nickname = common_canonical_nickname($this->arg('nickname'));
$this->user = User::getKV('nickname', $nickname);
$this->page = $this->trimmed('page');
if (!$this->page) {
$this->page = 1;
}
common_set_returnto($this->selfUrl());
return true;
}
/**
* output page based on arguments
*
* @param array $args HTTP arguments (from $_REQUEST)
*
* @return void
*/
function handle($args)
{
parent::handle($args);
if (!$this->user) {
// TRANS: Client error displayed when trying to access a mailbox without providing a user.
$this->clientError(_('No such user.'), 404);
}
$cur = common_current_user();
if (!$cur || $cur->id != $this->user->id) {
// TRANS: Client error displayed when trying to access a mailbox that is not of the logged in user.
$this->clientError(_('Only the user can read their own mailboxes.'), 403);
}
$this->showPage();
}
function showNoticeForm()
{
$message_form = new MessageForm($this);
$message_form->show();
}
function showContent()
{
$message = $this->getMessages();
if ($message) {
$ml = $this->getMessageList($message);
$cnt = $ml->show();
$this->pagination($this->page > 1,
$cnt > MESSAGES_PER_PAGE,
$this->page,
$this->trimmed('action'),
array('nickname' => $this->user->nickname));
} else {
$this->element('p',
'guide',
// TRANS: Message displayed when there are no private messages in the inbox of a user.
_('You have no private messages. '.
'You can send private message to engage other users in conversation. '.
'People can send you messages for your eyes only.'));
}
}
function getMessages()
{
return null;
}
function getMessageList($message)
{
return null;
}
/**
* Show the page notice
*
* Shows instructions for the page
*
* @return void
*/
function showPageNotice()
{
$instr = $this->getInstructions();
$output = common_markup_to_html($instr);
$this->elementStart('div', 'instructions');
$this->raw($output);
$this->elementEnd('div');
}
/**
* Mailbox actions are read only
*
* @param array $args other arguments
*
* @return boolean
*/
function isReadOnly($args)
{
return true;
}
function showObjectNav()
{
$mm = new MailboxMenu($this);
$mm->show();
}
}

View File

@@ -0,0 +1,72 @@
<?php
/**
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2011, StatusNet, Inc.
*
* Private mailboxes menu
*
* PHP version 5
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Cache
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
*/
if (!defined('STATUSNET')) {
// This check helps protect against security problems;
// your code file can't be executed directly from the web.
exit(1);
}
/**
* Menu of existing mailboxes
*
* @category General
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
*/
class MailboxMenu extends Menu
{
function show()
{
$cur = common_current_user();
$nickname = $cur->nickname;
$this->out->elementStart('ul', array('class' => 'nav'));
$this->item('inbox',
array('nickname' => $nickname),
// TRANS: Menu item in mailbox menu. Leads to incoming private messages.
_m('MENU','Inbox'),
// TRANS: Menu item title in mailbox menu. Leads to incoming private messages.
_('Your incoming messages.'));
$this->item('outbox',
array('nickname' => $nickname),
// TRANS: Menu item in mailbox menu. Leads to outgoing private messages.
_m('MENU','Outbox'),
// TRANS: Menu item title in mailbox menu. Leads to outgoing private messages.
_('Your sent messages.'));
$this->out->elementEnd('ul');
}
}

View File

@@ -0,0 +1,209 @@
<?php
/**
* StatusNet, the distributed open-source microblogging tool
*
* Form for posting a direct message
*
* PHP version 5
*
* LICENCE: This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Form
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @author Sarven Capadisli <csarven@status.net>
* @copyright 2009 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
require_once INSTALLDIR.'/lib/form.php';
/**
* Form for posting a direct message
*
* @category Form
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @author Sarven Capadisli <csarven@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*
* @see HTMLOutputter
*/
class MessageForm extends Form
{
/**
* User to send a direct message to
*/
var $to = null;
/**
* Pre-filled content of the form
*/
var $content = null;
/**
* Constructor
*
* @param HTMLOutputter $out output channel
* @param User $to user to send a message to
* @param string $content content to pre-fill
*/
function __construct($out=null, $to=null, $content=null)
{
parent::__construct($out);
$this->to = $to;
$this->content = $content;
}
/**
* ID of the form
*
* @return string ID of the form
*/
function id()
{
return 'form_notice-direct';
}
/**
* Class of the form
*
* @return string class of the form
*/
function formClass()
{
return 'form_notice ajax-notice';
}
/**
* Action of the form
*
* @return string URL of the action
*/
function action()
{
return common_local_url('newmessage');
}
/**
* Legend of the Form
*
* @return void
*/
function formLegend()
{
// TRANS: Form legend for direct notice.
$this->out->element('legend', null, _('Send a direct notice'));
}
/**
* Data elements
*
* @return void
*/
function formData()
{
$user = common_current_user();
$mutual_users = $user->mutuallySubscribedUsers();
$mutual = array();
// TRANS: Label entry in drop-down selection box in direct-message inbox/outbox.
// TRANS: This is the default entry in the drop-down box, doubling as instructions
// TRANS: and a brake against accidental submissions with the first user in the list.
$mutual[0] = _('Select recipient:');
while ($mutual_users->fetch()) {
if ($mutual_users->id != $user->id) {
$mutual[$mutual_users->id] = $mutual_users->nickname;
}
}
$mutual_users->free();
unset($mutual_users);
if (count($mutual) == 1) {
// TRANS: Entry in drop-down selection box in direct-message inbox/outbox when no one is available to message.
$mutual[0] = _('No mutual subscribers.');
}
// TRANS: Dropdown label in direct notice form.
$this->out->dropdown('to', _('To'), $mutual, null, false,
($this->to) ? $this->to->id : null);
$this->out->element('textarea', array('class' => 'notice_data-text',
'cols' => 35,
'rows' => 4,
'name' => 'content'),
($this->content) ? $this->content : '');
$contentLimit = Message::maxContent();
if ($contentLimit > 0) {
$this->out->element('span',
array('class' => 'count'),
$contentLimit);
}
}
/**
* Action elements
*
* @return void
*/
function formActions()
{
$this->out->element('input', array('id' => 'notice_action-submit',
'class' => 'submit',
'name' => 'message_send',
'type' => 'submit',
// TRANS: Button text for sending a direct notice.
'value' => _m('Send button for sending notice', 'Send')));
}
/**
* Show the form
*
* Uses a recipe to output the form.
*
* @return void
* @see Widget::show()
*/
function show()
{
$this->elementStart('div', 'input_forms');
$this->elementStart(
'div',
array(
'id' => 'input_form_direct',
'class' => 'input_form current nonav'
)
);
parent::show();
$this->elementEnd('div');
$this->elementEnd('div');
}
}

View File

@@ -0,0 +1,107 @@
<?php
/**
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2011, StatusNet, Inc.
*
* The message list widget
*
* PHP version 5
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Widget
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
*/
if (!defined('STATUSNET')) {
// This check helps protect against security problems;
// your code file can't be executed directly from the web.
exit(1);
}
/**
* Message list widget
*
* @category Widget
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
*/
abstract class MessageList extends Widget
{
var $message;
/**
* Constructor
*
* @param HTMLOutputter $out Output context
* @param Message $message Stream of messages to show
*/
function __construct($out, $message)
{
parent::__construct($out);
$this->message = $message;
}
/**
* Show the widget
*
* Uses newItem() to create each new item.
*
* @return integer count of messages seen.
*/
function show()
{
$cnt = 0;
$this->out->elementStart('div', array('id' =>'notices_primary'));
// TRANS: Header in message list.
$this->out->element('h2', null, _('Messages'));
$this->out->elementStart('ul', 'notices messages');
while ($this->message->fetch() && $cnt <= MESSAGES_PER_PAGE) {
$cnt++;
if ($cnt > MESSAGES_PER_PAGE) {
break;
}
$mli = $this->newItem($this->message);
$mli->show();
}
$this->out->elementEnd('ul');
$this->out->elementEnd('div');
}
/**
* Create a new message item for a message
*
* @param Message $message The message to show
*
* @return MessageListItem an item to show
*/
abstract function newItem($message);
}

View File

@@ -0,0 +1,194 @@
<?php
/**
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2011, StatusNet, Inc.
*
* A single list item for showing in a message list
*
* PHP version 5
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Widget
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
*/
if (!defined('STATUSNET')) {
// This check helps protect against security problems;
// your code file can't be executed directly from the web.
exit(1);
}
/**
* A single item in a message list
*
* @category Widget
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
*/
abstract class MessageListItem extends Widget
{
var $message;
/**
* Constructor
*
* @param HTMLOutputter $out Output context
* @param Message $message Message to show
*/
function __construct($out, $message)
{
parent::__construct($out);
$this->message = $message;
}
/**
* Show the widget
*
* @return void
*/
function show()
{
$this->out->elementStart('li', array('class' => 'h-entry notice',
'id' => 'message-' . $this->message->id));
$profile = $this->getMessageProfile();
$this->out->elementStart('a', array('href' => $profile->profileurl,
'class' => 'p-author'));
$avatarUrl = $profile->avatarUrl(AVATAR_STREAM_SIZE);
$this->out->element('img', array('src' => $avatarUrl,
'class' => 'avatar u-photo',
'width' => AVATAR_STREAM_SIZE,
'height' => AVATAR_STREAM_SIZE,
'alt' => $profile->getBestName()));
$this->out->element('span', array('class' => 'nickname fn'), $profile->getNickname());
$this->out->elementEnd('a');
// FIXME: URL, image, video, audio
$this->out->elementStart('div', array('class' => 'e-content'));
$this->out->raw($this->message->rendered);
$this->out->elementEnd('div');
$messageurl = common_local_url('showmessage',
array('message' => $this->message->id));
// XXX: we need to figure this out better. Is this right?
if (strcmp($this->message->uri, $messageurl) != 0 &&
preg_match('/^http/', $this->message->uri)) {
$messageurl = $this->message->uri;
}
$this->out->elementStart('div', 'entry-metadata');
$this->out->elementStart('a', array('rel' => 'bookmark',
'class' => 'timestamp',
'href' => $messageurl));
$dt = common_date_iso8601($this->message->created);
$this->out->element('time', array('class' => 'dt-published',
'datetime' => common_date_iso8601($this->message->created),
// TRANS: Timestamp title (tooltip text) for NoticeListItem
'title' => common_exact_date($this->message->created)),
common_date_string($this->message->created));
$this->out->elementEnd('a');
if ($this->message->source) {
$this->out->elementStart('span', 'source');
// FIXME: bad i18n. Device should be a parameter (from %s).
// TRANS: Followed by notice source (usually the client used to send the notice).
$this->out->text(_('from'));
$this->showSource($this->message->source);
$this->out->elementEnd('span');
}
$this->out->elementEnd('div');
$this->out->elementEnd('li');
}
/**
* Dummy method. Serves no other purpose than to make strings available used
* in self::showSource() through xgettext.
*
* @return void
*/
function messageListItemDummyMessages()
{
// A dummy array with messages. These will get extracted by xgettext and
// are used in self::showSource().
$dummy_messages = array(
// TRANS: A possible notice source (web interface).
_m('SOURCE','web'),
// TRANS: A possible notice source (XMPP).
_m('SOURCE','xmpp'),
// TRANS: A possible notice source (e-mail).
_m('SOURCE','mail'),
// TRANS: A possible notice source (OpenMicroBlogging).
_m('SOURCE','omb'),
// TRANS: A possible notice source (Application Programming Interface).
_m('SOURCE','api'),
);
}
/**
* Show the source of the message
*
* Returns either the name (and link) of the API client that posted the notice,
* or one of other other channels.
*
* @param string $source the source of the message
*
* @return void
*/
function showSource($source)
{
$source_name = _m('SOURCE',$source);
switch ($source) {
case 'web':
case 'xmpp':
case 'mail':
case 'omb':
case 'api':
$this->out->element('span', 'device', $source_name);
break;
default:
$ns = Notice_source::getKV($source);
if ($ns) {
$this->out->elementStart('span', 'device');
$this->out->element('a', array('href' => $ns->url,
'rel' => 'external'),
$ns->name);
$this->out->elementEnd('span');
} else {
$this->out->element('span', 'device', $source_name);
}
break;
}
return;
}
/**
* Return the profile to show in the message item
*
* Overridden in sub-classes to show sender, receiver, or whatever
*
* @return Profile profile to show avatar and name of
*/
abstract function getMessageProfile();
}