$fave->notice_id = $notice->id;
$fave->created = common_sql_now();
$fave->modified = common_sql_now();
- $fave->uri = self::newURI($profile,
+ $fave->uri = self::newUri($profile,
$notice,
$fave->created);
function asActivity()
{
- $notice = Notice::getKV('id', $this->notice_id);
-
- if (!$notice) {
- throw new Exception("Fave for non-existent notice: " . $this->notice_id);
- }
-
- $profile = Profile::getKV('id', $this->user_id);
-
- if (!$profile) {
- throw new Exception("Fave by non-existent profile: " . $this->user_id);
- }
+ $notice = $this->getTarget();
+ $profile = $this->getActor();
$act = new Activity();
// FIXME: rationalize this with URL below
- $act->id = $this->getURI();
+ $act->id = $this->getUri();
$act->time = strtotime($this->modified);
// TRANS: Activity title when marking a notice as favorite.
$notice->getUrl());
$act->actor = $profile->asActivityObject();
- $act->objects[] = ActivityObject::fromNotice($notice);
+ // $act->target = $notice->asActivityObject();
+ // $act->objects = array(clone($act->target));
+ $act->objects[] = $notice->asActivityObject();
$url = common_local_url('AtomPubShowFavorite',
- array('profile' => $this->user_id,
- 'notice' => $this->notice_id));
+ array('profile' => $profile->id,
+ 'notice' => $notice->id));
$act->selfLink = $url;
$act->editLink = $url;
return $object;
}
- static public function verbToTitle($verb)
- {
- return ucfirst($verb);
- }
-
static public function getObjectType()
{
return 'activity';
{
$actobj = new ActivityObject();
$actobj->id = $this->getUri();
- $actobj->type = ActivityUtils::resolveUri($this->getObjectType());
+ $actobj->type = ActivityUtils::resolveUri(self::getObjectType());
$actobj->actor = $this->getActorObject();
$actobj->target = $this->getTarget()->asActivityObject();
$actobj->objects = array(clone($actobj->target));
- $actobj->title = Stored_ActivityVerb::verbToTitle($this->verb);
$actobj->verb = ActivityVerb::FAVORITE;
+ $actobj->title = ActivityUtils::verbToTitle($actobj->verb);
return $actobj;
}
+ /**
+ * @param ActivityObject $actobj The _favored_ notice (which we're "in-reply-to")
+ * @param Notice $stored The _activity_ notice, i.e. the favor itself.
+ */
static public function parseActivityObject(ActivityObject $actobj, Notice $stored)
{
- // The ActivityObject we get here is the _favored_ notice (kind of what we're "in-reply-to")
- // The Notice we get is the _activity_ stored in our Notice table
-
- $type = isset($actobj->type) ? ActivityUtils::resolveUri($actobj->type, true) : ActivityObject::NOTE;
- $local = ActivityUtils::findLocalObject($actobj->getIdentifiers(), $type);
+ $local = ActivityUtils::findLocalObject($actobj->getIdentifiers());
if (!$local instanceof Notice) {
// $local always returns something, but this was not what we expected. Something is wrong.
throw new Exception('Something other than a Notice was returned from findLocalObject');
{
$object = self::parseActivityObject($actobj, $stored);
$object->insert(); // exception throwing!
+ Event::handle('EndFavorNotice', array($stored->getProfile(), $object->getTarget()));
return $object;
}
public function getTarget()
{
// throws exception on failure
- return ActivityUtils::findLocalObject(array($this->uri));
+ $target = new Notice();
+ $target->id = $this->notice_id;
+ if (!$target->find(true)) {
+ throw new NoResultException($target);
+ }
+
+ return $target;
}
public function getTargetObject()
return $this->getActor()->asActivityObject();
}
- public function getURI()
+ public function getUri()
{
if (!empty($this->uri)) {
return $this->uri;
}
// We (should've in this case) created it ourselves, so we tag it ourselves
- return self::newURI($this->getActor(), $this->getTarget(), $this->created);
+ return self::newUri($this->getActor(), $this->getTarget(), $this->created);
}
- static function newURI(Profile $actor, Managed_DataObject $target, $created=null)
+ static function newUri(Profile $actor, Managed_DataObject $target, $created=null)
{
if (is_null($created)) {
$created = common_sql_now();