if ($activity->context instanceof ActivityContext) {
foreach ($activity->context->attention as $uri=>$type) {
-
- $profile = Profile::fromURI($uri);
-
- if (!empty($profile)) {
- $options['replies'][] = $uri;
- } else {
- $group = User_group::getKV('uri', $uri);
- if (!empty($group)) {
- $options['groups'][] = $group->id;
+ try {
+ $profile = Profile::fromUri($uri);
+ if ($profile->isGroup()) {
+ $options['groups'][] = $profile->id;
} else {
- // @fixme: hook for discovery here
- common_log(LOG_WARNING, sprintf('AtomPub post with unknown attention URI %s', $uri));
+ $options['replies'][] = $uri;
}
+ } catch (UnknownUriException $e) {
+ common_log(LOG_WARNING, sprintf('AtomPub post with unknown attention URI %s', $uri));
}
}
}
// XXX: OStatus discovery (maybe)
-
- $profile = Profile::fromURI($person->id);
-
- if (empty($profile)) {
+ try {
+ $profile = Profile::fromUri($person->id);
+ } catch (UnknownUriException $e) {
// TRANS: Client exception thrown when subscribing to a non-existing profile.
// TRANS: %s is the unknown profile ID.
$this->clientError(sprintf(_('Unknown profile %s.'), $person->id));
$sender = Profile::getKV($this->profile_id);
foreach (array_unique($uris) as $uri) {
-
- $profile = Profile::fromURI($uri);
-
- if (!$profile instanceof Profile) {
+ try {
+ $profile = Profile::fromUri($uri);
+ } catch (UnknownUriException $e) {
common_log(LOG_WARNING, "Unable to determine profile for URI '$uri'");
continue;
}
return $feed;
}
- static function fromURI($uri)
+ /*
+ * Get a Profile object by URI. Will call external plugins for help
+ * using the event StartGetProfileFromURI.
+ *
+ * @param string $uri A unique identifier for a resource (profile/group/whatever)
+ */
+ static function fromUri($uri)
{
$profile = null;
if (Event::handle('StartGetProfileFromURI', array($uri, &$profile))) {
- // Get a local user
+ // Get a local user when plugin lookup (like OStatus) fails
$user = User::getKV('uri', $uri);
- if (!empty($user)) {
+ if ($user instanceof User) {
$profile = $user->getProfile();
}
Event::handle('EndGetProfileFromURI', array($uri, $profile));
}
+ if (!$profile instanceof Profile) {
+ throw new UnknownUriException($uri);
+ }
+
return $profile;
}
$other = $activity->objects[0];
- $otherProfile = Profile::fromUri($other->id);
-
- if (empty($otherProfile)) {
+ try {
+ $otherProfile = Profile::fromUri($other->id);
// TRANS: Client exception thrown when trying to subscribe to an unknown profile.
+ } catch (UnknownUriException $e) {
+ // Let's convert it to a client exception instead of server.
throw new ClientException(_('Unknown profile.'));
}
list ($act, $sink, $userURI, $remoteURI) = $data;
$user = User::getKV('uri', $userURI);
- $remote = Profile::fromURI($remoteURI);
+ try {
+ $remote = Profile::fromUri($remoteURI);
+ } catch (UnknownUriException $e) {
+ // Don't retry. It's hard to tell whether it's because of
+ // lookup failures or because the URI is permanently gone.
+ // If we knew it was temporary, we'd return false here.
+ return true;
+ }
try {
$this->moveActivity($act, $sink, $user, $remote);
"Moving subscription to {$act->objects[0]->id} by ".
"{$act->actor->id} to {$remote->nickname}.");
$sink->postActivity($act);
- $other = Profile::fromURI($act->objects[0]->id);
- if (!empty($other)) {
+ try {
+ $other = Profile::fromUri($act->objects[0]->id);
Subscription::cancel($user->getProfile(), $other);
+ } catch (UnknownUriException $e) {
+ // Can't cancel subscription if we don't know who to alert
}
} else {
$otherUser = User::getKV('uri', $act->actor->id);
$options['replies'] = array(); // TODO: context->attention
foreach ($activity->context->attention as $attnUrl=>$type) {
- $other = Profile::fromURI($attnUrl);
- if ($other instanceof Profile) {
- $options['replies'][] = $attnUrl;
- } else {
- // Maybe we can get rid of this since every User_group got a Profile?
- // TODO: Make sure the above replies get sorted properly for groups (or handled afterwards)
- $group = User_group::getKV('uri', $attnUrl);
- if ($group instanceof User_group) {
- $options['groups'][] = $attnUrl;
+ try {
+ $other = Profile::fromUri($attnUrl);
+ if ($other->isGroup()) {
+ $options['groups'][] = $other->id;
+ } else {
+ $options['replies'][] = $attnUrl;
}
+ } catch (UnknownUriException $e) {
+ // We simply don't know this URI, despite lookup attempts.
}
}