+
+ protected function profileTypeString(Profile $target)
+ {
+ // This is just used to have a definitive string response to "USERsalmon" or "GROUPsalmon"
+ switch ($target->getObjectType()) {
+ case ActivityObject::PERSON:
+ return 'user';
+ case ActivityObject::GROUP:
+ return 'group';
+ default:
+ throw new ServerException('Unknown profile type for WebFinger profile links');
+ }
+ }
+
+ protected function addWebFingerPersonLinks(XML_XRD $xrd, Profile $target)
+ {
+ $xrd->links[] = new XML_XRD_Element_Link(Discovery::UPDATESFROM,
+ common_local_url('ApiTimelineUser',
+ array('id' => $target->id, 'format' => 'atom')),
+ 'application/atom+xml');
+
+ // Get this profile's keypair
+ $magicsig = Magicsig::getKV('user_id', $target->id);
+ if (!$magicsig instanceof Magicsig && $target->isLocal()) {
+ $magicsig = Magicsig::generate($target->getUser());
+ }
+
+ if ($magicsig instanceof Magicsig) {
+ $xrd->links[] = new XML_XRD_Element_Link(Magicsig::PUBLICKEYREL,
+ 'data:application/magic-public-key,'. $magicsig->toString());
+ $xrd->links[] = new XML_XRD_Element_Link(Magicsig::DIASPORA_PUBLICKEYREL,
+ base64_encode($magicsig->exportPublicKey()));
+ }
+ }
+
+ public function onGetLocalAttentions(Profile $actor, array $attention_uris, array &$mentions, array &$groups)
+ {
+ list($mentions, $groups) = Ostatus_profile::filterAttention($actor, $attention_uris);
+ }
+
+ // FIXME: Maybe this shouldn't be so authoritative that it breaks other remote profile lookups?
+ static public function onCheckActivityAuthorship(Activity $activity, Profile &$profile)
+ {
+ try {
+ $oprofile = Ostatus_profile::ensureProfileURL($profile->getUrl());
+ $profile = $oprofile->checkAuthorship($activity);
+ } catch (Exception $e) {
+ common_log(LOG_ERR, 'Could not get a profile or check authorship ('.get_class($e).': "'.$e->getMessage().'") for activity ID: '.$activity->id);
+ $profile = null;
+ return false;
+ }
+ return true;
+ }
+
+ public function onProfileDeleteRelated(Profile $profile, array &$related)
+ {
+ // Ostatus_profile has a 'profile_id' property, which will be used to find the object
+ $related[] = 'Ostatus_profile';
+
+ // Magicsig has a "user_id" column instead, so we have to delete it more manually:
+ $magicsig = Magicsig::getKV('user_id', $profile->id);
+ if ($magicsig instanceof Magicsig) {
+ $magicsig->delete();
+ }
+ return true;
+ }