Call it compareVerbs when comparing verbs

This commit is contained in:
Mikael Nordfeldth 2015-09-10 15:27:40 +02:00
parent 404d5781fc
commit 9ad9b91efb
5 changed files with 15 additions and 10 deletions

View File

@ -244,7 +244,7 @@ class Activity
if (!empty($targetEl)) { if (!empty($targetEl)) {
$this->target = new ActivityObject($targetEl); $this->target = new ActivityObject($targetEl);
} elseif (ActivityUtils::compareTypes($this->verb, array(ActivityVerb::FAVORITE))) { } elseif (ActivityUtils::compareVerbs($this->verb, array(ActivityVerb::FAVORITE))) {
// StatusNet didn't send a 'target' for their Favorite atom entries // StatusNet didn't send a 'target' for their Favorite atom entries
$this->target = clone($this->objects[0]); $this->target = clone($this->objects[0]);
} }

View File

@ -104,7 +104,7 @@ abstract class ActivityHandlerPlugin extends Plugin
function isMyVerb($verb) { function isMyVerb($verb) {
$verb = $verb ?: ActivityVerb::POST; // post is the default verb $verb = $verb ?: ActivityVerb::POST; // post is the default verb
return ActivityUtils::compareTypes($verb, $this->verbs()); return ActivityUtils::compareVerbs($verb, $this->verbs());
} }
function isMyType($type) { function isMyType($type) {
@ -389,7 +389,7 @@ abstract class ActivityHandlerPlugin extends Plugin
} elseif ($target instanceof Profile && $target->isLocal()) { } elseif ($target instanceof Profile && $target->isLocal()) {
$original = null; $original = null;
// FIXME: Shouldn't favorites show up with a 'target' activityobject? // FIXME: Shouldn't favorites show up with a 'target' activityobject?
if (!ActivityUtils::compareTypes($activity->verb, array(ActivityVerb::POST)) && isset($activity->objects[0])) { if (!ActivityUtils::compareVerbs($activity->verb, array(ActivityVerb::POST)) && isset($activity->objects[0])) {
// If this is not a post, it's a verb targeted at something (such as a Favorite attached to a note) // If this is not a post, it's a verb targeted at something (such as a Favorite attached to a note)
if (!empty($activity->objects[0]->id)) { if (!empty($activity->objects[0]->id)) {
$activity->context->replyToID = $activity->objects[0]->id; $activity->context->replyToID = $activity->objects[0]->id;
@ -413,7 +413,7 @@ abstract class ActivityHandlerPlugin extends Plugin
$actor = $oactor->localProfile(); $actor = $oactor->localProfile();
// FIXME: will this work in all cases? I made it work for Favorite... // FIXME: will this work in all cases? I made it work for Favorite...
if (ActivityUtils::compareTypes($activity->verb, array(ActivityVerb::POST))) { if (ActivityUtils::compareVerbs($activity->verb, array(ActivityVerb::POST))) {
$object = $activity->objects[0]; $object = $activity->objects[0];
} else { } else {
$object = $activity; $object = $activity;

View File

@ -348,7 +348,7 @@ class ActivityUtils
return null; return null;
} }
static function compareTypes($type, $objects) // this does verbs too! static function compareTypes($type, $objects)
{ {
$type = self::resolveUri($type); $type = self::resolveUri($type);
foreach ((array)$objects as $object) { foreach ((array)$objects as $object) {
@ -359,6 +359,11 @@ class ActivityUtils
return false; return false;
} }
static function compareVerbs($type, $objects)
{
return self::compareTypes($type, $objects);
}
static function resolveUri($uri, $make_relative=false) static function resolveUri($uri, $make_relative=false)
{ {
if (empty($uri)) { if (empty($uri)) {

View File

@ -527,8 +527,8 @@ class FavoritePlugin extends ActivityVerbHandlerPlugin
$expected_verb = $exists ? ActivityVerb::UNFAVORITE : ActivityVerb::FAVORITE; $expected_verb = $exists ? ActivityVerb::UNFAVORITE : ActivityVerb::FAVORITE;
switch (true) { switch (true) {
case $exists && ActivityUtils::compareTypes($verb, array(ActivityVerb::FAVORITE, ActivityVerb::LIKE)): case $exists && ActivityUtils::compareVerbs($verb, array(ActivityVerb::FAVORITE, ActivityVerb::LIKE)):
case !$exists && ActivityUtils::compareTypes($verb, array(ActivityVerb::UNFAVORITE, ActivityVerb::UNLIKE)): case !$exists && ActivityUtils::compareVerbs($verb, array(ActivityVerb::UNFAVORITE, ActivityVerb::UNLIKE)):
common_redirect(common_local_url('activityverb', common_redirect(common_local_url('activityverb',
array('id' => $target->getID(), array('id' => $target->getID(),
'verb' => ActivityUtils::resolveUri($expected_verb, true)))); 'verb' => ActivityUtils::resolveUri($expected_verb, true))));
@ -543,10 +543,10 @@ class FavoritePlugin extends ActivityVerbHandlerPlugin
protected function doActionPost(ManagedAction $action, $verb, Notice $target, Profile $scoped) protected function doActionPost(ManagedAction $action, $verb, Notice $target, Profile $scoped)
{ {
switch (true) { switch (true) {
case ActivityUtils::compareTypes($verb, array(ActivityVerb::FAVORITE, ActivityVerb::LIKE)): case ActivityUtils::compareVerbs($verb, array(ActivityVerb::FAVORITE, ActivityVerb::LIKE)):
Fave::addNew($scoped, $target); Fave::addNew($scoped, $target);
break; break;
case ActivityUtils::compareTypes($verb, array(ActivityVerb::UNFAVORITE, ActivityVerb::UNLIKE)): case ActivityUtils::compareVerbs($verb, array(ActivityVerb::UNFAVORITE, ActivityVerb::UNLIKE)):
Fave::removeEntry($scoped, $target); Fave::removeEntry($scoped, $target);
break; break;
default: default:

View File

@ -357,7 +357,7 @@ class Fave extends Managed_DataObject
$target = self::getTargetFromStored($stored); $target = self::getTargetFromStored($stored);
// The following logic was copied from StatusNet's Activity plugin // The following logic was copied from StatusNet's Activity plugin
if (ActivityUtils::compareTypes($target->verb, array(ActivityVerb::POST))) { if (ActivityUtils::compareVerbs($target->verb, array(ActivityVerb::POST))) {
// "I like the thing you posted" // "I like the thing you posted"
$act->objects = $target->asActivity()->objects; $act->objects = $target->asActivity()->objects;
} else { } else {