From c96f0aa30fce7995faac5a359a23e897fc656a93 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Mon, 14 Jul 2014 23:54:58 +0200 Subject: [PATCH] More Activity-based reasoning for saveActivity in Notice If we can, get the activity ID from the activity itself, instead of the supplied $options array. --- classes/Notice.php | 24 +++++++++++------------- lib/activity.php | 3 +++ plugins/Favorite/FavoritePlugin.php | 3 --- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/classes/Notice.php b/classes/Notice.php index 88a1394b88..89f41ad79b 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -712,24 +712,22 @@ class Notice extends Managed_DataObject 'and post again in a few minutes.')); } -/* This interferes with stuff like Favorites from old StatusNet installations (first object in objects is the favored notice) // Get ActivityObject properties - $actobj = count($act->objects)==1 ? $act->objects[0] : null; - if (!is_null($actobj) && $actobj->id) { - $options['uri'] = $actobj->id; - if ($actobj->link) { - $options['url'] = $actobj->link; - } elseif ($act->link) { - $options['url'] = $act->link; - } elseif (preg_match('!^https?://!', $actobj->id)) { - $options['url'] = $actobj->id; - } - } else { + if (!empty($act->id)) { // implied object $options['uri'] = $act->id; $options['url'] = $act->link; + } else { + $actobj = count($act->objects)==1 ? $act->objects[0] : null; + if (!is_null($actobj) && !empty($actobj->id)) { + $options['uri'] = $actobj->id; + if ($actobj->link) { + $options['url'] = $actobj->link; + } elseif (preg_match('!^https?://!', $actobj->id)) { + $options['url'] = $actobj->id; + } + } } -*/ $defaults = array( 'groups' => array(), diff --git a/lib/activity.php b/lib/activity.php index 8be37c5681..6fd04c4db1 100644 --- a/lib/activity.php +++ b/lib/activity.php @@ -244,6 +244,9 @@ class Activity if (!empty($targetEl)) { $this->target = new ActivityObject($targetEl); + } elseif (ActivityUtils::compareTypes($this->verb, array(ActivityVerb::FAVORITE))) { + // StatusNet didn't send a 'target' for their Favorite atom entries + $this->target = clone($this->objects[0]); } $this->summary = ActivityUtils::childContent($entry, 'summary'); diff --git a/plugins/Favorite/FavoritePlugin.php b/plugins/Favorite/FavoritePlugin.php index baa8df43c4..cc1ad0705a 100644 --- a/plugins/Favorite/FavoritePlugin.php +++ b/plugins/Favorite/FavoritePlugin.php @@ -179,9 +179,6 @@ class FavoritePlugin extends ActivityHandlerPlugin if (!isset($options['created'])) { $options['created'] = !empty($act->time) ? common_sql_date($act->time) : common_sql_now(); } - if (!isset($options['uri'])) { - $options['uri'] = !empty($act->id) ? $act->id : $act->selfLink; - } // We must have an objects[0] here because in isMyActivity we require the count to be == 1 $actobj = $act->objects[0]; -- 2.39.5