Make process*() functions return existing or new notice
This commit is contained in:
parent
0eeb175904
commit
0ad7411343
|
@ -345,7 +345,7 @@ abstract class MicroAppPlugin extends Plugin
|
||||||
*
|
*
|
||||||
* @return boolean hook value
|
* @return boolean hook value
|
||||||
*/
|
*/
|
||||||
function onStartHandleFeedEntryWithProfile($activity, $oprofile)
|
function onStartHandleFeedEntryWithProfile($activity, $oprofile, &$notice)
|
||||||
{
|
{
|
||||||
if ($this->isMyActivity($activity)) {
|
if ($this->isMyActivity($activity)) {
|
||||||
|
|
||||||
|
@ -364,7 +364,7 @@ abstract class MicroAppPlugin extends Plugin
|
||||||
'source' => 'ostatus');
|
'source' => 'ostatus');
|
||||||
|
|
||||||
// $actor is an ostatus_profile
|
// $actor is an ostatus_profile
|
||||||
$this->saveNoticeFromActivity($activity, $actor->localProfile(), $options);
|
$notice = $this->saveNoticeFromActivity($activity, $actor->localProfile(), $options);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -463,18 +463,23 @@ class Ostatus_profile extends Managed_DataObject
|
||||||
* @param DOMElement $entry
|
* @param DOMElement $entry
|
||||||
* @param DOMElement $feed for context
|
* @param DOMElement $feed for context
|
||||||
* @param string $source identifier ("push" or "salmon")
|
* @param string $source identifier ("push" or "salmon")
|
||||||
|
*
|
||||||
|
* @return Notice Notice representing the new (or existing) activity
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function processEntry($entry, $feed, $source)
|
public function processEntry($entry, $feed, $source)
|
||||||
{
|
{
|
||||||
$activity = new Activity($entry, $feed);
|
$activity = new Activity($entry, $feed);
|
||||||
$this->processActivity($activity, $source);
|
return $this->processActivity($activity, $source);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function processActivity($activity, $source)
|
public function processActivity($activity, $source)
|
||||||
{
|
{
|
||||||
|
$notice = null;
|
||||||
|
|
||||||
// The "WithProfile" events were added later.
|
// The "WithProfile" events were added later.
|
||||||
|
|
||||||
if (Event::handle('StartHandleFeedEntryWithProfile', array($activity, $this)) &&
|
if (Event::handle('StartHandleFeedEntryWithProfile', array($activity, $this, &$notice)) &&
|
||||||
Event::handle('StartHandleFeedEntry', array($activity))) {
|
Event::handle('StartHandleFeedEntry', array($activity))) {
|
||||||
|
|
||||||
switch ($activity->verb) {
|
switch ($activity->verb) {
|
||||||
|
@ -487,7 +492,7 @@ class Ostatus_profile extends Managed_DataObject
|
||||||
case ActivityObject::STATUS:
|
case ActivityObject::STATUS:
|
||||||
case ActivityObject::COMMENT:
|
case ActivityObject::COMMENT:
|
||||||
case null:
|
case null:
|
||||||
$this->processPost($activity, $source);
|
$notice = $this->processPost($activity, $source);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// TRANS: Client exception.
|
// TRANS: Client exception.
|
||||||
|
@ -495,24 +500,28 @@ class Ostatus_profile extends Managed_DataObject
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ActivityVerb::SHARE:
|
case ActivityVerb::SHARE:
|
||||||
$result = $this->processShare($activity, $source);
|
$notice = $this->processShare($activity, $source);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
common_log(LOG_INFO, "Ignoring activity with unrecognized verb $activity->verb");
|
common_log(LOG_INFO, "Ignoring activity with unrecognized verb $activity->verb");
|
||||||
}
|
}
|
||||||
|
|
||||||
Event::handle('EndHandleFeedEntry', array($activity));
|
Event::handle('EndHandleFeedEntry', array($activity));
|
||||||
Event::handle('EndHandleFeedEntryWithProfile', array($activity, $this));
|
Event::handle('EndHandleFeedEntryWithProfile', array($activity, $this, $notice));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $notice;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function processShare($activity, $method)
|
public function processShare($activity, $method)
|
||||||
{
|
{
|
||||||
|
$notice = null;
|
||||||
|
|
||||||
$oprofile = $this->checkAuthorship($activity);
|
$oprofile = $this->checkAuthorship($activity);
|
||||||
|
|
||||||
if (empty($oprofile)) {
|
if (empty($oprofile)) {
|
||||||
common_log(LOG_INFO, "No author matched share activity");
|
common_log(LOG_INFO, "No author matched share activity");
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count($activity->objects) != 1) {
|
if (count($activity->objects) != 1) {
|
||||||
|
@ -529,16 +538,10 @@ class Ostatus_profile extends Managed_DataObject
|
||||||
|
|
||||||
// Save the item (or check for a dupe)
|
// Save the item (or check for a dupe)
|
||||||
|
|
||||||
$other->processActivity($shared, $method);
|
$sharedNotice = $other->processActivity($shared, $method);
|
||||||
|
|
||||||
// XXX: process*() should return the new or existing notice. They don't, so we have to
|
|
||||||
// go fishing for it now.
|
|
||||||
|
|
||||||
$sharedId = ($shared->id) ? $shared->id : $shared->objects[0]->id;
|
|
||||||
|
|
||||||
$sharedNotice = Notice::staticGet('uri', $sharedId);
|
|
||||||
|
|
||||||
if (empty($sharedNotice)) {
|
if (empty($sharedNotice)) {
|
||||||
|
$sharedId = ($shared->id) ? $shared->id : $shared->objects[0]->id;
|
||||||
throw new ClientException(sprintf(_m("Failed to save activity %s"),
|
throw new ClientException(sprintf(_m("Failed to save activity %s"),
|
||||||
$sharedId));
|
$sharedId));
|
||||||
}
|
}
|
||||||
|
@ -552,7 +555,7 @@ class Ostatus_profile extends Managed_DataObject
|
||||||
$dupe = Notice::staticGet('uri', $sourceUri);
|
$dupe = Notice::staticGet('uri', $sourceUri);
|
||||||
if ($dupe) {
|
if ($dupe) {
|
||||||
common_log(LOG_INFO, "OStatus: ignoring duplicate post: $sourceUri");
|
common_log(LOG_INFO, "OStatus: ignoring duplicate post: $sourceUri");
|
||||||
return false;
|
return $dupe;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We'll also want to save a web link to the original notice, if provided.
|
// We'll also want to save a web link to the original notice, if provided.
|
||||||
|
@ -689,10 +692,12 @@ class Ostatus_profile extends Managed_DataObject
|
||||||
$options['urls'][] = $href;
|
$options['urls'][] = $href;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Notice::saveNew($oprofile->profile_id,
|
$notice = Notice::saveNew($oprofile->profile_id,
|
||||||
$content,
|
$content,
|
||||||
'ostatus',
|
'ostatus',
|
||||||
$content);
|
$content);
|
||||||
|
|
||||||
|
return $notice;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -704,10 +709,12 @@ class Ostatus_profile extends Managed_DataObject
|
||||||
*/
|
*/
|
||||||
public function processPost($activity, $method)
|
public function processPost($activity, $method)
|
||||||
{
|
{
|
||||||
|
$notice = null;
|
||||||
|
|
||||||
$oprofile = $this->checkAuthorship($activity);
|
$oprofile = $this->checkAuthorship($activity);
|
||||||
|
|
||||||
if (empty($oprofile)) {
|
if (empty($oprofile)) {
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// It's not always an ActivityObject::NOTE, but... let's just say it is.
|
// It's not always an ActivityObject::NOTE, but... let's just say it is.
|
||||||
|
@ -721,7 +728,7 @@ class Ostatus_profile extends Managed_DataObject
|
||||||
$dupe = Notice::staticGet('uri', $sourceUri);
|
$dupe = Notice::staticGet('uri', $sourceUri);
|
||||||
if ($dupe) {
|
if ($dupe) {
|
||||||
common_log(LOG_INFO, "OStatus: ignoring duplicate post: $sourceUri");
|
common_log(LOG_INFO, "OStatus: ignoring duplicate post: $sourceUri");
|
||||||
return false;
|
return $dupe;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We'll also want to save a web link to the original notice, if provided.
|
// We'll also want to save a web link to the original notice, if provided.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user