Share plugin now handles showing form in NoticeOptionItems

This commit is contained in:
Mikael Nordfeldth 2015-03-12 16:33:34 +01:00
parent d24c4f349f
commit dcfcceb6f2
9 changed files with 22 additions and 133 deletions

View File

@ -225,10 +225,7 @@ class ShowstreamAction extends ProfileAction
function showNotices() function showNotices()
{ {
$pnl = null; $pnl = new NoticeList($this->notice, $this);
if (Event::handle('ShowStreamNoticeList', array($this->notice, $this, &$pnl))) {
$pnl = new ProfileNoticeList($this->notice, $this);
}
$cnt = $pnl->show(); $cnt = $pnl->show();
if (0 == $cnt) { if (0 == $cnt) {
$this->showEmptyListMessage(); $this->showEmptyListMessage();

View File

@ -302,6 +302,7 @@ $default =
'AuthCrypt' => array(), 'AuthCrypt' => array(),
'Cronish' => array(), 'Cronish' => array(),
'Favorite' => array(), 'Favorite' => array(),
'Share' => array(),
'LRDD' => array(), 'LRDD' => array(),
'StrictTransportSecurity' => array(), 'StrictTransportSecurity' => array(),
), ),

View File

@ -193,7 +193,6 @@ class NoticeListItem extends Widget
$this->out->elementStart('div', 'notice-options'); $this->out->elementStart('div', 'notice-options');
if (Event::handle('StartShowNoticeOptionItems', array($this))) { if (Event::handle('StartShowNoticeOptionItems', array($this))) {
$this->showReplyLink(); $this->showReplyLink();
$this->showRepeatForm();
$this->showDeleteLink(); $this->showDeleteLink();
Event::handle('EndShowNoticeOptionItems', array($this)); Event::handle('EndShowNoticeOptionItems', array($this));
} }
@ -605,34 +604,6 @@ class NoticeListItem extends Widget
} }
} }
/**
* show the form to repeat a notice
*
* @return void
*/
function showRepeatForm()
{
if ($this->notice->scope == Notice::PUBLIC_SCOPE ||
$this->notice->scope == Notice::SITE_SCOPE) {
$user = common_current_user();
if (!empty($user) &&
$user->id != $this->notice->profile_id) {
$this->out->text(' ');
$profile = $user->getProfile();
if ($profile->hasRepeated($this->notice)) {
$this->out->element('span', array('class' => 'repeated',
// TRANS: Title for repeat form status in notice list when a notice has been repeated.
'title' => _('Notice repeated.')),
// TRANS: Repeat form status in notice list when a notice has been repeated.
_('Repeated'));
} else {
$rf = new RepeatForm($this->out, $this->notice);
$rf->show();
}
}
}
}
/** /**
* finish the notice * finish the notice
* *

View File

@ -1,11 +0,0 @@
<?php
if (!defined('GNUSOCIAL')) { exit(1); }
class ProfileNoticeList extends NoticeList
{
function newListItem($notice)
{
return new ProfileNoticeListItem($notice, $this->out);
}
}

View File

@ -1,49 +0,0 @@
<?php
if (!defined('GNUSOCIAL')) { exit(1); }
// We don't show the author for a profile, since we already know who it is!
/**
* Slightly modified from standard list; the author & avatar are hidden
* in CSS. We used to remove them here too, but as it turns out that
* confuses the inline reply code... and we hide them in CSS anyway
* since realtime updates come through in original form.
*
* Remaining customization right now is for the repeat marker, where
* it'll list who the original poster was instead of who did the repeat
* (since the repeater is you, and the repeatee isn't shown!)
* This will remain inconsistent if realtime updates come through,
* since those'll get rendered as a regular NoticeListItem.
*/
class ProfileNoticeListItem extends DoFollowListItem
{
/**
* show a link to the author of repeat
*
* @return void
*/
function showRepeat()
{
if (!empty($this->repeat)) {
// FIXME: this code is almost identical to default; need to refactor
$attrs = array('href' => $this->profile->profileurl,
'class' => 'url');
if (!empty($this->profile->fullname)) {
$attrs['title'] = $this->profile->getFancyName();
}
$this->out->elementStart('span', 'repeat');
$text_link = XMLStringer::estring('a', $attrs, $this->profile->nickname);
// TRANS: Link to the author of a repeated notice. %s is a linked nickname.
$this->out->raw(sprintf(_('Repeat of %s'), $text_link));
$this->out->elementEnd('span');
}
}
}

View File

@ -137,21 +137,4 @@ class GNUsocialProfileExtensionsPlugin extends Plugin
array('nickname' => $nav->action->trimmed('nickname'))), _('Bio'), array('nickname' => $nav->action->trimmed('nickname'))), _('Bio'),
_('The user\'s extended profile'), $nav->action->trimmed('action') == 'bio', 'nav_bio'); _('The user\'s extended profile'), $nav->action->trimmed('action') == 'bio', 'nav_bio');
} }
//Why the heck is this shoved into this plugin!?!? It deserves its own!
function onShowStreamNoticeList($notice, $action, &$pnl)
{
//TODO: This function is called after the notices in $notice are superfluously retrieved in showstream.php
$newnotice = new Notice();
$newnotice->profile_id = $action->user->id;
$newnotice->orderBy('modified DESC');
$newnotice->whereAdd('reply_to IS NULL');
$newnotice->limit(($action->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
$newnotice->find();
$pnl = new NoticeTree($newnotice, $action);
return false;
}
} }

View File

@ -39,10 +39,7 @@ class RemoteProfileAction extends ShowstreamAction
$this->raw(common_markup_to_html($markdown)); $this->raw(common_markup_to_html($markdown));
}else{ }else{
$pnl = null; $pnl = new NoticeList($this->notice, $this);
if (Event::handle('ShowStreamNoticeList', array($this->notice, $this, &$pnl))) {
$pnl = new ProfileNoticeList($this->notice, $this);
}
$cnt = $pnl->show(); $cnt = $pnl->show();
if (0 == $cnt) { if (0 == $cnt) {
$this->showEmptyListMessage(); $this->showEmptyListMessage();

View File

@ -161,22 +161,16 @@ class SharePlugin extends ActivityVerbHandlerPlugin
// ActivityObject is instead turned into an Activity // ActivityObject is instead turned into an Activity
$object = new Activity(); $object = new Activity();
$object->verb = ActivityVerb::SHARE; $object->verb = ActivityVerb::SHARE;
$object->type = $notice->object_type;
$object->title = sprintf(_('%1$s repeated a notice by %2$s'),
$object->getProfile()->getNickname(),
$target->getProfile()->getNickname());
$object->content = $notice->rendered; $object->content = $notice->rendered;
$this->extendActivity($stored, $act);
return $object; return $object;
} }
public function deleteRelated(Notice $notice) public function deleteRelated(Notice $notice)
{ {
try { // No action needed as we don't have a separate table for share objects.
$fave = Fave::fromStored($notice); return true;
$fave->delete();
} catch (NoResultException $e) {
// Cool, no problem. We wanted to get rid of it anyway.
}
} }
// API stuff // API stuff
@ -260,20 +254,26 @@ class SharePlugin extends ActivityVerbHandlerPlugin
* *
* @return void * @return void
*/ */
public function onStartShowNoticeOptionItems($nli) public function onEndShowNoticeOptionItems($nli)
{ {
if (Event::handle('StartShowFaveForm', array($nli))) { // FIXME: Use bitmasks (but be aware that PUBLIC_SCOPE is 0!)
if ($nli->notice->scope == Notice::PUBLIC_SCOPE ||
$nli->notice->scope == Notice::SITE_SCOPE) {
$scoped = Profile::current(); $scoped = Profile::current();
if ($scoped instanceof Profile) { if ($scoped instanceof Profile &&
if (Fave::existsForProfile($nli->notice, $scoped)) { $scoped->getID() !== $nli->notice->getProfile()->getID()) {
$disfavor = new DisfavorForm($nli->out, $nli->notice);
$disfavor->show(); if ($scoped->hasRepeated($nli->notice)) {
$nli->out->element('span', array('class' => 'repeated',
// TRANS: Title for repeat form status in notice list when a notice has been repeated.
'title' => _('Notice repeated.')),
// TRANS: Repeat form status in notice list when a notice has been repeated.
_('Repeated'));
} else { } else {
$favor = new FavorForm($nli->out, $nli->notice); $repeat = new RepeatForm($nli->out, $nli->notice);
$favor->show(); $repeat->show();
} }
} }
Event::handle('EndShowFaveForm', array($nli));
} }
} }