2019-05-11 20:27:21 +09:00
|
|
|
<?php
|
2020-08-23 03:14:36 +09:00
|
|
|
|
|
|
|
// {{{ License
|
|
|
|
|
2019-05-11 20:27:21 +09:00
|
|
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
|
|
|
//
|
|
|
|
// GNU social is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// GNU social is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2020-08-23 03:14:36 +09:00
|
|
|
// }}}
|
2019-05-11 20:27:21 +09:00
|
|
|
|
|
|
|
/**
|
2020-08-23 03:14:36 +09:00
|
|
|
* ActivityPub's Remote Actor
|
2019-05-11 20:27:21 +09:00
|
|
|
*
|
|
|
|
* @category Plugin
|
|
|
|
* @package GNUsocial
|
2020-08-23 03:14:36 +09:00
|
|
|
*
|
2019-05-11 20:27:21 +09:00
|
|
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
2020-08-23 03:14:36 +09:00
|
|
|
* @author Hugo Sales <hugo@fc.up.pt>
|
2019-05-11 20:27:21 +09:00
|
|
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
|
|
|
*/
|
|
|
|
|
2020-08-23 03:14:36 +09:00
|
|
|
namespace Plugin\ActivityPub\Entity;
|
|
|
|
|
|
|
|
class ActivityPubActor
|
|
|
|
{
|
|
|
|
// {{{ Autocode
|
|
|
|
// }}} Autocode
|
2019-05-11 20:27:21 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates a pretty profile from a Profile object
|
|
|
|
*
|
|
|
|
* @param Profile $profile
|
2020-08-23 03:14:36 +09:00
|
|
|
*
|
2019-05-11 20:27:21 +09:00
|
|
|
* @throws InvalidUrlException
|
|
|
|
* @throws ServerException
|
2019-10-12 01:08:37 +09:00
|
|
|
* @throws Exception
|
2020-08-23 03:14:36 +09:00
|
|
|
*
|
|
|
|
* @return array array to be used in a response
|
|
|
|
*
|
2019-05-11 20:27:21 +09:00
|
|
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
|
|
|
*/
|
2020-07-22 07:21:27 +09:00
|
|
|
public static function profile_to_array(Profile $profile): array
|
2019-05-11 20:27:21 +09:00
|
|
|
{
|
2020-08-23 03:14:36 +09:00
|
|
|
$uri = $profile->getUri();
|
|
|
|
$id = $profile->getID();
|
|
|
|
$rsa = new Activitypub_rsa();
|
2019-05-11 20:27:21 +09:00
|
|
|
$public_key = $rsa->ensure_public_key($profile);
|
|
|
|
unset($rsa);
|
|
|
|
$res = [
|
2019-10-12 01:08:37 +09:00
|
|
|
'@context' => [
|
2019-05-11 20:27:21 +09:00
|
|
|
'https://www.w3.org/ns/activitystreams',
|
|
|
|
'https://w3id.org/security/v1',
|
|
|
|
[
|
2020-08-23 03:14:36 +09:00
|
|
|
'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
|
|
|
|
],
|
2019-05-11 20:27:21 +09:00
|
|
|
],
|
2020-08-23 03:14:36 +09:00
|
|
|
'id' => $uri,
|
|
|
|
'type' => 'Person',
|
|
|
|
'following' => common_local_url('apActorFollowing', ['id' => $id]),
|
|
|
|
'followers' => common_local_url('apActorFollowers', ['id' => $id]),
|
|
|
|
'liked' => common_local_url('apActorLiked', ['id' => $id]),
|
|
|
|
'inbox' => common_local_url('apInbox', ['id' => $id]),
|
|
|
|
'outbox' => common_local_url('apActorOutbox', ['id' => $id]),
|
|
|
|
'preferredUsername' => $profile->getNickname(),
|
|
|
|
'name' => $profile->getBestName(),
|
|
|
|
'summary' => ($desc = $profile->getDescription()) == null ? '' : $desc,
|
|
|
|
'url' => $profile->getUrl(),
|
2019-05-11 20:27:21 +09:00
|
|
|
'manuallyApprovesFollowers' => false,
|
2020-08-23 03:14:36 +09:00
|
|
|
'publicKey' => [
|
|
|
|
'id' => $uri . '#public-key',
|
|
|
|
'owner' => $uri,
|
|
|
|
'publicKeyPem' => $public_key,
|
2019-05-11 20:27:21 +09:00
|
|
|
],
|
2020-08-23 03:14:36 +09:00
|
|
|
'tag' => [],
|
2019-05-11 20:27:21 +09:00
|
|
|
'attachment' => [],
|
2020-08-23 03:14:36 +09:00
|
|
|
'icon' => [
|
|
|
|
'type' => 'Image',
|
2019-05-11 20:27:21 +09:00
|
|
|
'mediaType' => 'image/png',
|
2020-08-23 03:14:36 +09:00
|
|
|
'height' => AVATAR_PROFILE_SIZE,
|
|
|
|
'width' => AVATAR_PROFILE_SIZE,
|
|
|
|
'url' => $profile->avatarUrl(AVATAR_PROFILE_SIZE),
|
|
|
|
],
|
2019-05-11 20:27:21 +09:00
|
|
|
];
|
|
|
|
|
|
|
|
if ($profile->isLocal()) {
|
|
|
|
$res['endpoints']['sharedInbox'] = common_local_url('apInbox');
|
|
|
|
} else {
|
2020-08-23 03:14:36 +09:00
|
|
|
$aprofile = new Activitypub_profile();
|
|
|
|
$aprofile = $aprofile->from_profile($profile);
|
2019-05-11 20:27:21 +09:00
|
|
|
$res['endpoints']['sharedInbox'] = $aprofile->sharedInboxuri;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Insert the current object variables into the database
|
|
|
|
*
|
2019-10-12 01:08:37 +09:00
|
|
|
* @throws ServerException
|
2020-08-23 03:14:36 +09:00
|
|
|
*
|
2019-05-11 20:27:21 +09:00
|
|
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
|
|
|
*/
|
2020-07-22 07:21:27 +09:00
|
|
|
public function do_insert(): void
|
2019-05-11 20:27:21 +09:00
|
|
|
{
|
2020-03-31 16:13:52 +09:00
|
|
|
// Does any other protocol have this remote entity we're about to add ?
|
2020-07-06 02:26:49 +09:00
|
|
|
Event::handle('StartTFNLookup', [$this->uri, get_class($this), &$profile_id]);
|
|
|
|
if (!is_null($profile_id)) {
|
2020-03-31 16:13:52 +09:00
|
|
|
// Yes! Avoid creating a new profile
|
|
|
|
$this->profile_id = $profile_id;
|
2020-08-23 03:14:36 +09:00
|
|
|
$this->created = $this->modified = common_sql_now();
|
2020-03-31 16:13:52 +09:00
|
|
|
|
|
|
|
if ($this->insert() === false) {
|
|
|
|
$this->query('ROLLBACK');
|
|
|
|
throw new ServerException('Cannot save ActivityPub profile.');
|
|
|
|
}
|
2019-05-11 20:27:21 +09:00
|
|
|
|
2020-03-31 16:13:52 +09:00
|
|
|
// Update existing profile with received data
|
|
|
|
$profile = Profile::getKV('id', $profile_id);
|
|
|
|
self::update_local_profile($profile, $this);
|
2019-05-11 20:27:21 +09:00
|
|
|
|
2020-03-31 16:13:52 +09:00
|
|
|
// Ask TFN to handle profile duplication
|
|
|
|
Event::handle('EndTFNLookup', [get_class($this), $profile_id]);
|
|
|
|
} else {
|
|
|
|
// No, create both a new profile and remote profile
|
2020-08-23 03:14:36 +09:00
|
|
|
$profile = new Profile();
|
2020-03-31 16:13:52 +09:00
|
|
|
$profile->created = $this->created = $this->modified = common_sql_now();
|
|
|
|
self::update_local_profile($profile, $this);
|
|
|
|
|
|
|
|
$this->profile_id = $profile->insert();
|
|
|
|
if ($this->profile_id === false) {
|
|
|
|
$profile->query('ROLLBACK');
|
|
|
|
throw new ServerException('Profile insertion failed.');
|
|
|
|
}
|
2019-05-11 20:27:21 +09:00
|
|
|
|
2020-03-31 16:13:52 +09:00
|
|
|
$ok = $this->insert();
|
2019-05-11 20:27:21 +09:00
|
|
|
|
2020-03-31 16:13:52 +09:00
|
|
|
if ($ok === false) {
|
|
|
|
$profile->query('ROLLBACK');
|
|
|
|
$this->query('ROLLBACK');
|
|
|
|
throw new ServerException('Cannot save ActivityPub profile.');
|
|
|
|
}
|
2019-05-11 20:27:21 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetch the locally stored profile for this Activitypub_profile
|
|
|
|
*
|
|
|
|
* @throws NoProfileException if it was not found
|
2020-08-23 03:14:36 +09:00
|
|
|
*
|
|
|
|
* @return Profile
|
|
|
|
*
|
2019-05-11 20:27:21 +09:00
|
|
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
|
|
|
*/
|
2020-07-05 10:25:51 +09:00
|
|
|
public function local_profile(): Profile
|
2019-05-11 20:27:21 +09:00
|
|
|
{
|
|
|
|
$profile = Profile::getKV('id', $this->profile_id);
|
|
|
|
if (!$profile instanceof Profile) {
|
|
|
|
throw new NoProfileException($this->profile_id);
|
|
|
|
}
|
|
|
|
return $profile;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates an Activitypub_profile from a Profile
|
|
|
|
*
|
|
|
|
* @param Profile $profile
|
2020-08-23 03:14:36 +09:00
|
|
|
*
|
2019-05-11 20:27:21 +09:00
|
|
|
* @throws Exception if no Activitypub_profile exists for given Profile
|
2020-08-23 03:14:36 +09:00
|
|
|
*
|
|
|
|
* @return Activitypub_profile
|
|
|
|
*
|
2019-10-12 01:08:37 +09:00
|
|
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
2019-05-11 20:27:21 +09:00
|
|
|
*/
|
2019-10-21 04:07:46 +09:00
|
|
|
public static function from_profile(Profile $profile): Activitypub_profile
|
2019-05-11 20:27:21 +09:00
|
|
|
{
|
|
|
|
$profile_id = $profile->getID();
|
|
|
|
|
|
|
|
$aprofile = self::getKV('profile_id', $profile_id);
|
|
|
|
if (!$aprofile instanceof Activitypub_profile) {
|
|
|
|
// No Activitypub_profile for this profile_id,
|
|
|
|
if (!$profile->isLocal()) {
|
|
|
|
// create one!
|
|
|
|
$aprofile = self::create_from_local_profile($profile);
|
|
|
|
} else {
|
2019-10-12 01:08:37 +09:00
|
|
|
throw new Exception('No Activitypub_profile for Profile ID: ' . $profile_id . ', this is a local user.');
|
2019-05-11 20:27:21 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-21 04:07:46 +09:00
|
|
|
// extend the ap_profile with some information we
|
|
|
|
// don't store in the database
|
2019-05-11 20:27:21 +09:00
|
|
|
$fields = [
|
2019-10-12 01:08:37 +09:00
|
|
|
'nickname' => 'nickname',
|
|
|
|
'fullname' => 'fullname',
|
2020-08-23 03:14:36 +09:00
|
|
|
'bio' => 'bio',
|
2019-10-12 01:08:37 +09:00
|
|
|
];
|
2019-05-11 20:27:21 +09:00
|
|
|
|
|
|
|
foreach ($fields as $af => $pf) {
|
2020-08-23 03:14:36 +09:00
|
|
|
$aprofile->{$af} = $profile->{$pf};
|
2019-05-11 20:27:21 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
return $aprofile;
|
|
|
|
}
|
|
|
|
|
2020-07-22 07:21:27 +09:00
|
|
|
/**
|
|
|
|
* Travels an array of Profile and returns an array of Activitypub_profile
|
|
|
|
*
|
|
|
|
* @param array of Profile $profiles
|
2020-08-23 03:14:36 +09:00
|
|
|
*
|
2020-07-22 07:21:27 +09:00
|
|
|
* @return array of Activitypub_profile
|
|
|
|
*/
|
2019-10-12 01:08:37 +09:00
|
|
|
public static function from_profile_collection(array $profiles): array
|
|
|
|
{
|
2019-07-18 00:25:24 +09:00
|
|
|
$ap_profiles = [];
|
|
|
|
|
|
|
|
foreach ($profiles as $profile) {
|
|
|
|
try {
|
|
|
|
$ap_profiles[] = self::from_profile($profile);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
// Don't mind local profiles
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $ap_profiles;
|
|
|
|
}
|
|
|
|
|
2019-05-11 20:27:21 +09:00
|
|
|
/**
|
|
|
|
* Given an existent local profile creates an ActivityPub profile.
|
|
|
|
* One must be careful not to give a user profile to this function
|
|
|
|
* as only remote users have ActivityPub_profiles on local instance
|
|
|
|
*
|
|
|
|
* @param Profile $profile
|
2020-08-23 03:14:36 +09:00
|
|
|
*
|
2019-05-11 20:27:21 +09:00
|
|
|
* @throws HTTP_Request2_Exception
|
2019-10-12 01:08:37 +09:00
|
|
|
* @throws Exception
|
|
|
|
* @throws Exception
|
2020-08-23 03:14:36 +09:00
|
|
|
*
|
|
|
|
* @return Activitypub_profile
|
|
|
|
*
|
2019-05-11 20:27:21 +09:00
|
|
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
|
|
|
*/
|
2020-07-22 07:21:27 +09:00
|
|
|
private static function create_from_local_profile(Profile $profile): Activitypub_profile
|
2019-05-11 20:27:21 +09:00
|
|
|
{
|
|
|
|
$aprofile = new Activitypub_profile();
|
|
|
|
|
2020-08-23 03:14:36 +09:00
|
|
|
$url = $profile->getUri();
|
2019-05-11 20:27:21 +09:00
|
|
|
$inboxes = Activitypub_explorer::get_actor_inboxes_uri($url);
|
2020-07-23 23:54:12 +09:00
|
|
|
if ($inboxes === false) {
|
2019-05-11 20:27:21 +09:00
|
|
|
throw new Exception('This is not an ActivityPub user thus AProfile is politely refusing to proceed.');
|
|
|
|
}
|
|
|
|
|
|
|
|
$aprofile->created = $aprofile->modified = common_sql_now();
|
2020-08-23 03:14:36 +09:00
|
|
|
|
|
|
|
$aprofile = new Activitypub_profile;
|
|
|
|
$aprofile->profile_id = $profile->getID();
|
|
|
|
$aprofile->uri = $url;
|
|
|
|
$aprofile->nickname = $profile->getNickname();
|
|
|
|
$aprofile->fullname = $profile->getFullname();
|
|
|
|
$aprofile->bio = substr($profile->getDescription(), 0, 1000);
|
|
|
|
$aprofile->inboxuri = $inboxes['inbox'];
|
|
|
|
$aprofile->sharedInboxuri = $inboxes['sharedInbox'];
|
2019-05-11 20:27:21 +09:00
|
|
|
|
|
|
|
$aprofile->insert();
|
|
|
|
|
|
|
|
return $aprofile;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns sharedInbox if possible, inbox otherwise
|
|
|
|
*
|
|
|
|
* @return string Inbox URL
|
2020-08-23 03:14:36 +09:00
|
|
|
*
|
2019-10-12 01:08:37 +09:00
|
|
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
2019-05-11 20:27:21 +09:00
|
|
|
*/
|
2020-07-22 07:21:27 +09:00
|
|
|
public function get_inbox(): string
|
2019-05-11 20:27:21 +09:00
|
|
|
{
|
|
|
|
if (is_null($this->sharedInboxuri)) {
|
|
|
|
return $this->inboxuri;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->sharedInboxuri;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Getter for uri property
|
|
|
|
*
|
|
|
|
* @return string URI
|
2020-08-23 03:14:36 +09:00
|
|
|
*
|
2019-10-12 01:08:37 +09:00
|
|
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
2019-05-11 20:27:21 +09:00
|
|
|
*/
|
2020-07-22 07:21:27 +09:00
|
|
|
public function getUri(): string
|
2019-05-11 20:27:21 +09:00
|
|
|
{
|
|
|
|
return $this->uri;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Getter for url property
|
|
|
|
*
|
|
|
|
* @return string URL
|
2020-08-23 03:14:36 +09:00
|
|
|
*
|
2019-10-12 01:08:37 +09:00
|
|
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
2019-05-11 20:27:21 +09:00
|
|
|
*/
|
2020-07-22 07:21:27 +09:00
|
|
|
public function getUrl(): string
|
2019-05-11 20:27:21 +09:00
|
|
|
{
|
|
|
|
return $this->getUri();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Getter for id property
|
|
|
|
*
|
|
|
|
* @return int
|
2020-08-23 03:14:36 +09:00
|
|
|
*
|
2019-10-12 01:08:37 +09:00
|
|
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
2019-05-11 20:27:21 +09:00
|
|
|
*/
|
2020-07-22 07:21:27 +09:00
|
|
|
public function getID(): int
|
2019-05-11 20:27:21 +09:00
|
|
|
{
|
|
|
|
return $this->profile_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensures a valid Activitypub_profile when provided with a valid URI.
|
|
|
|
*
|
|
|
|
* @param string $url
|
2020-08-23 03:14:36 +09:00
|
|
|
* @param bool $grab_online whether to try online grabbing, defaults to true
|
|
|
|
*
|
2019-05-11 20:27:21 +09:00
|
|
|
* @throws Exception if it isn't possible to return an Activitypub_profile
|
2020-08-23 03:14:36 +09:00
|
|
|
*
|
|
|
|
* @return Activitypub_profile
|
|
|
|
*
|
2019-09-13 19:56:36 +09:00
|
|
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
2019-05-11 20:27:21 +09:00
|
|
|
*/
|
2020-07-22 07:21:27 +09:00
|
|
|
public static function fromUri(string $url, bool $grab_online = true): Activitypub_profile
|
2019-05-11 20:27:21 +09:00
|
|
|
{
|
|
|
|
try {
|
2019-09-13 19:56:36 +09:00
|
|
|
return self::from_profile(Activitypub_explorer::get_profile_from_url($url, $grab_online));
|
2019-05-11 20:27:21 +09:00
|
|
|
} catch (Exception $e) {
|
|
|
|
throw new Exception('No valid ActivityPub profile found for given URI.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Look up, and if necessary create, an Activitypub_profile for the remote
|
2019-09-13 19:56:36 +09:00
|
|
|
* entity with the given WebFinger address.
|
2019-05-11 20:27:21 +09:00
|
|
|
* This should never return null -- you will either get an object or
|
|
|
|
* an exception will be thrown.
|
|
|
|
*
|
2019-09-13 19:56:36 +09:00
|
|
|
* @param string $addr WebFinger address
|
2020-08-23 03:14:36 +09:00
|
|
|
*
|
2019-05-11 20:27:21 +09:00
|
|
|
* @throws Exception on error conditions
|
2020-08-23 03:14:36 +09:00
|
|
|
*
|
|
|
|
* @return Activitypub_profile
|
|
|
|
*
|
2019-10-12 01:08:37 +09:00
|
|
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
|
|
|
* @author GNU social
|
2019-05-11 20:27:21 +09:00
|
|
|
*/
|
2020-07-22 07:21:27 +09:00
|
|
|
public static function ensure_webfinger(string $addr): Activitypub_profile
|
2019-05-11 20:27:21 +09:00
|
|
|
{
|
|
|
|
// Normalize $addr, i.e. add 'acct:' if missing
|
|
|
|
$addr = Discovery::normalize($addr);
|
|
|
|
|
|
|
|
// Try the cache
|
|
|
|
$uri = self::cacheGet(sprintf('activitypub_profile:webfinger:%s', $addr));
|
|
|
|
|
|
|
|
if ($uri !== false) {
|
|
|
|
if (is_null($uri)) {
|
|
|
|
// Negative cache entry
|
|
|
|
// TRANS: Exception.
|
2019-09-13 19:56:36 +09:00
|
|
|
throw new Exception(_m('Not a valid WebFinger address (via cache).'));
|
2019-05-11 20:27:21 +09:00
|
|
|
}
|
|
|
|
try {
|
|
|
|
return self::fromUri($uri);
|
|
|
|
} catch (Exception $e) {
|
2019-09-13 19:56:36 +09:00
|
|
|
common_log(LOG_ERR, sprintf(__METHOD__ . ': WebFinger address cache inconsistent with database, did not find Activitypub_profile uri==%s', $uri));
|
2019-05-11 20:27:21 +09:00
|
|
|
self::cacheSet(sprintf('activitypub_profile:webfinger:%s', $addr), false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now, try some discovery
|
|
|
|
|
|
|
|
$disco = new Discovery();
|
|
|
|
|
|
|
|
try {
|
|
|
|
$xrd = $disco->lookup($addr);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
// Save negative cache entry so we don't waste time looking it up again.
|
|
|
|
// @todo FIXME: Distinguish temporary failures?
|
|
|
|
self::cacheSet(sprintf('activitypub_profile:webfinger:%s', $addr), null);
|
|
|
|
// TRANS: Exception.
|
2019-09-13 19:56:36 +09:00
|
|
|
throw new Exception(_m('Not a valid WebFinger address.'));
|
2019-05-11 20:27:21 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
$hints = array_merge(
|
2019-09-13 19:56:36 +09:00
|
|
|
['webfinger' => $addr],
|
2019-05-11 20:27:21 +09:00
|
|
|
DiscoveryHints::fromXRD($xrd)
|
2019-09-13 19:56:36 +09:00
|
|
|
);
|
2019-05-11 20:27:21 +09:00
|
|
|
|
|
|
|
// If there's an Hcard, let's grab its info
|
|
|
|
if (array_key_exists('hcard', $hints)) {
|
2020-08-23 03:14:36 +09:00
|
|
|
if (!array_key_exists('profileurl', $hints) || $hints['hcard'] != $hints['profileurl']) {
|
2019-05-11 20:27:21 +09:00
|
|
|
$hcardHints = DiscoveryHints::fromHcardUrl($hints['hcard']);
|
2020-08-23 03:14:36 +09:00
|
|
|
$hints = array_merge($hcardHints, $hints);
|
2019-05-11 20:27:21 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we got a profile page, try that!
|
|
|
|
$profileUrl = null;
|
|
|
|
if (array_key_exists('profileurl', $hints)) {
|
|
|
|
$profileUrl = $hints['profileurl'];
|
|
|
|
try {
|
2020-08-23 03:14:36 +09:00
|
|
|
common_log(LOG_INFO, "Discovery on acct:{$addr} with profile URL {$profileUrl}");
|
2019-05-11 20:27:21 +09:00
|
|
|
$aprofile = self::fromUri($hints['profileurl']);
|
|
|
|
self::cacheSet(sprintf('activitypub_profile:webfinger:%s', $addr), $aprofile->getUri());
|
|
|
|
return $aprofile;
|
|
|
|
} catch (Exception $e) {
|
2020-08-23 03:14:36 +09:00
|
|
|
common_log(LOG_WARNING, "Failed creating profile from profile URL '{$profileUrl}': " . $e->getMessage());
|
2019-05-11 20:27:21 +09:00
|
|
|
// keep looking
|
2019-09-13 19:56:36 +09:00
|
|
|
//
|
|
|
|
// @todo FIXME: This means an error discovering from profile page
|
|
|
|
// may give us a corrupt entry using the webfinger URI, which
|
|
|
|
// will obscure the correct page-keyed profile later on.
|
2019-05-11 20:27:21 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX: try hcard
|
|
|
|
// XXX: try FOAF
|
|
|
|
|
2019-09-13 19:56:36 +09:00
|
|
|
// TRANS: Exception. %s is a WebFinger address.
|
2019-05-11 20:27:21 +09:00
|
|
|
throw new Exception(sprintf(_m('Could not find a valid profile for "%s".'), $addr));
|
|
|
|
}
|
|
|
|
|
2020-03-31 16:13:52 +09:00
|
|
|
/**
|
|
|
|
* Update local profile with info from some AP profile
|
|
|
|
*
|
2020-08-23 03:14:36 +09:00
|
|
|
* @param Profile $profile
|
2020-03-31 16:13:52 +09:00
|
|
|
* @param Activitypub_profile $aprofile
|
2020-08-23 03:14:36 +09:00
|
|
|
*
|
2020-03-31 16:13:52 +09:00
|
|
|
* @return void
|
2020-08-23 03:14:36 +09:00
|
|
|
*
|
2020-03-31 16:13:52 +09:00
|
|
|
* @author Bruno Casteleiro <brunoccast@fc.up.pt>
|
|
|
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
|
|
|
*/
|
|
|
|
public static function update_local_profile(Profile $profile, Activitypub_profile $aprofile): void
|
|
|
|
{
|
|
|
|
$fields = [
|
|
|
|
'profileurl' => 'profileurl',
|
2020-08-23 03:14:36 +09:00
|
|
|
'nickname' => 'nickname',
|
|
|
|
'fullname' => 'fullname',
|
|
|
|
'bio' => 'bio',
|
2020-03-31 16:13:52 +09:00
|
|
|
];
|
|
|
|
|
2020-08-23 03:14:36 +09:00
|
|
|
$orig = clone $profile;
|
2020-03-31 16:13:52 +09:00
|
|
|
|
|
|
|
foreach ($fields as $af => $pf) {
|
2020-08-23 03:14:36 +09:00
|
|
|
$profile->{$pf} = $aprofile->{$af};
|
2020-03-31 16:13:52 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($profile->id) {
|
|
|
|
common_debug('Updating local Profile:' . $profile->id . ' from remote ActivityPub profile');
|
|
|
|
$profile->modified = common_sql_now();
|
|
|
|
$profile->update($orig);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-11 20:27:21 +09:00
|
|
|
/**
|
|
|
|
* Update remote user profile in local instance
|
|
|
|
*
|
|
|
|
* @param Activitypub_profile $aprofile
|
2020-08-23 03:14:36 +09:00
|
|
|
* @param array|false $res remote response, if array it updates, if false it deletes
|
|
|
|
*
|
2019-10-12 01:08:37 +09:00
|
|
|
* @throws NoProfileException
|
2020-08-23 03:14:36 +09:00
|
|
|
*
|
|
|
|
* @return Profile remote Profile object
|
|
|
|
*
|
2019-05-11 20:27:21 +09:00
|
|
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
|
|
|
*/
|
2020-07-21 20:01:56 +09:00
|
|
|
public static function update_profile(Activitypub_profile $aprofile, $res): Profile
|
2019-05-11 20:27:21 +09:00
|
|
|
{
|
2020-07-05 10:25:51 +09:00
|
|
|
if ($res === false) {
|
|
|
|
$profile = $aprofile->local_profile();
|
2020-08-23 03:14:36 +09:00
|
|
|
$id = $profile->getID();
|
2020-07-05 10:25:51 +09:00
|
|
|
$profile->delete();
|
2020-08-23 03:14:36 +09:00
|
|
|
throw new NoProfileException($id, '410 Gone');
|
2020-07-05 10:25:51 +09:00
|
|
|
}
|
|
|
|
|
2020-07-21 20:01:56 +09:00
|
|
|
if (!is_array($res)) {
|
|
|
|
throw new InvalidArgumentException('TypeError: Argument 2 passed to Activitypub_profile::update_profile() must be of the type array or bool(false).');
|
|
|
|
}
|
|
|
|
|
2019-05-11 20:27:21 +09:00
|
|
|
// ActivityPub Profile
|
2020-08-23 03:14:36 +09:00
|
|
|
$aprofile->uri = $res['id'];
|
|
|
|
$aprofile->nickname = $res['preferredUsername'];
|
|
|
|
$aprofile->fullname = $res['name'] ?? null;
|
|
|
|
$aprofile->bio = isset($res['summary']) ? substr(strip_tags($res['summary']), 0, 1000) : null;
|
|
|
|
$aprofile->inboxuri = $res['inbox'];
|
2020-03-28 12:13:06 +09:00
|
|
|
$aprofile->sharedInboxuri = $res['endpoints']['sharedInbox'] ?? $res['inbox'];
|
2020-08-23 03:14:36 +09:00
|
|
|
$aprofile->profileurl = $res['url'] ?? $aprofile->uri;
|
|
|
|
$aprofile->modified = common_sql_now();
|
2019-05-11 20:27:21 +09:00
|
|
|
|
|
|
|
$profile = $aprofile->local_profile();
|
|
|
|
|
|
|
|
// Profile
|
2020-03-31 16:13:52 +09:00
|
|
|
self::update_local_profile($profile, $aprofile);
|
2019-05-11 20:27:21 +09:00
|
|
|
$aprofile->update();
|
|
|
|
|
|
|
|
// Public Key
|
|
|
|
Activitypub_rsa::update_public_key($profile, $res['publicKey']['publicKeyPem']);
|
|
|
|
|
|
|
|
// Avatar
|
|
|
|
if (isset($res['icon']['url'])) {
|
|
|
|
try {
|
|
|
|
Activitypub_explorer::update_avatar($profile, $res['icon']['url']);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
// Let the exception go, it isn't a serious issue
|
2019-10-12 01:08:37 +09:00
|
|
|
common_debug('An error ocurred while grabbing remote avatar' . $e->getMessage());
|
2019-05-11 20:27:21 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $profile;
|
|
|
|
}
|
2019-07-09 03:23:48 +09:00
|
|
|
|
2020-03-28 04:25:43 +09:00
|
|
|
/**
|
|
|
|
* Update remote user profile URI in local instance
|
|
|
|
*
|
|
|
|
* @param string $uri
|
2020-08-23 03:14:36 +09:00
|
|
|
*
|
2020-03-28 04:25:43 +09:00
|
|
|
* @throws Exception (if the update fails)
|
2020-08-23 03:14:36 +09:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*
|
2020-03-28 04:25:43 +09:00
|
|
|
* @author Bruno Casteleiro <brunoccast@fc.up.pt>
|
|
|
|
*/
|
2020-07-22 07:21:27 +09:00
|
|
|
public function updateUri(string $uri): void
|
2020-03-28 04:25:43 +09:00
|
|
|
{
|
2020-08-23 03:14:36 +09:00
|
|
|
$orig = clone $this;
|
2020-03-28 04:25:43 +09:00
|
|
|
$this->uri = $uri;
|
|
|
|
$this->updateWithKeys($orig);
|
|
|
|
}
|
|
|
|
|
2019-07-09 03:23:48 +09:00
|
|
|
/**
|
|
|
|
* Getter for the number of subscribers of a
|
|
|
|
* given local profile
|
|
|
|
*
|
|
|
|
* @param Profile $profile profile object
|
2020-08-23 03:14:36 +09:00
|
|
|
*
|
2019-07-09 03:23:48 +09:00
|
|
|
* @return int number of subscribers
|
2020-08-23 03:14:36 +09:00
|
|
|
*
|
2019-07-09 03:23:48 +09:00
|
|
|
* @author Bruno Casteleiro <brunoccast@fc.up.pt>
|
|
|
|
*/
|
2019-10-12 01:08:37 +09:00
|
|
|
public static function subscriberCount(Profile $profile): int
|
|
|
|
{
|
2019-07-09 03:23:48 +09:00
|
|
|
$cnt = self::cacheGet(sprintf('activitypub_profile:subscriberCount:%d', $profile->id));
|
|
|
|
|
|
|
|
if ($cnt !== false && is_int($cnt)) {
|
|
|
|
return $cnt;
|
|
|
|
}
|
|
|
|
|
2020-08-23 03:14:36 +09:00
|
|
|
$user_table = common_database_tablename('user');
|
|
|
|
$sub = new Subscription();
|
2019-07-09 03:23:48 +09:00
|
|
|
$sub->subscribed = $profile->id;
|
2020-06-10 22:52:00 +09:00
|
|
|
$sub->_join .= "\n" . <<<END
|
|
|
|
INNER JOIN (
|
|
|
|
SELECT id AS subscriber FROM {$user_table}
|
|
|
|
UNION ALL
|
|
|
|
SELECT profile_id FROM activitypub_profile
|
|
|
|
) AS t1 USING (subscriber)
|
|
|
|
END;
|
2020-06-09 00:31:22 +09:00
|
|
|
$sub->whereAdd('subscriber <> subscribed');
|
2020-06-10 22:52:00 +09:00
|
|
|
$cnt = $sub->count('DISTINCT subscriber');
|
2019-07-09 03:23:48 +09:00
|
|
|
|
|
|
|
self::cacheSet(sprintf('activitypub_profile:subscriberCount:%d', $profile->id), $cnt);
|
|
|
|
|
|
|
|
return $cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Getter for the number of subscriptions of a
|
|
|
|
* given local profile
|
|
|
|
*
|
|
|
|
* @param Profile $profile profile object
|
2020-08-23 03:14:36 +09:00
|
|
|
*
|
2019-07-09 03:23:48 +09:00
|
|
|
* @return int number of subscriptions
|
2020-08-23 03:14:36 +09:00
|
|
|
*
|
2019-07-09 03:23:48 +09:00
|
|
|
* @author Bruno Casteleiro <brunoccast@fc.up.pt>
|
|
|
|
*/
|
2019-10-12 01:08:37 +09:00
|
|
|
public static function subscriptionCount(Profile $profile): int
|
|
|
|
{
|
2019-07-09 03:23:48 +09:00
|
|
|
$cnt = self::cacheGet(sprintf('activitypub_profile:subscriptionCount:%d', $profile->id));
|
|
|
|
|
|
|
|
if ($cnt !== false && is_int($cnt)) {
|
|
|
|
return $cnt;
|
|
|
|
}
|
|
|
|
|
2020-08-23 03:14:36 +09:00
|
|
|
$user_table = common_database_tablename('user');
|
|
|
|
$sub = new Subscription();
|
2019-07-09 03:23:48 +09:00
|
|
|
$sub->subscriber = $profile->id;
|
2020-06-10 22:52:00 +09:00
|
|
|
$sub->_join .= "\n" . <<<END
|
|
|
|
INNER JOIN (
|
|
|
|
SELECT id AS subscribed FROM {$user_table}
|
|
|
|
UNION ALL
|
|
|
|
SELECT profile_id FROM activitypub_profile
|
|
|
|
) AS t1 USING (subscribed)
|
|
|
|
END;
|
2020-06-09 00:31:22 +09:00
|
|
|
$sub->whereAdd('subscriber <> subscribed');
|
2020-06-10 22:52:00 +09:00
|
|
|
$cnt = $sub->count('DISTINCT subscribed');
|
2019-07-09 03:23:48 +09:00
|
|
|
|
|
|
|
self::cacheSet(sprintf('activitypub_profile:subscriptionCount:%d', $profile->id), $cnt);
|
|
|
|
|
|
|
|
return $cnt;
|
|
|
|
}
|
|
|
|
|
2020-07-22 07:21:27 +09:00
|
|
|
/**
|
|
|
|
* Increment or decrement subscriber count
|
|
|
|
*
|
|
|
|
* @param Profile $profile
|
|
|
|
* @param $adder
|
2020-08-23 03:14:36 +09:00
|
|
|
*
|
2020-07-22 07:21:27 +09:00
|
|
|
* @author Bruno Casteleiro <brunoccast@fc.up.pt>
|
|
|
|
*/
|
|
|
|
public static function updateSubscriberCount(Profile $profile, $adder): void
|
2019-10-12 01:08:37 +09:00
|
|
|
{
|
2019-07-09 03:23:48 +09:00
|
|
|
$cnt = self::cacheGet(sprintf('activitypub_profile:subscriberCount:%d', $profile->id));
|
|
|
|
|
|
|
|
if ($cnt !== false && is_int($cnt)) {
|
2019-10-12 01:08:37 +09:00
|
|
|
self::cacheSet(sprintf('activitypub_profile:subscriberCount:%d', $profile->id), $cnt + $adder);
|
2019-07-09 03:23:48 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-22 07:21:27 +09:00
|
|
|
/**
|
|
|
|
* Increment or decrement subscription count
|
|
|
|
*
|
|
|
|
* @param Profile $profile
|
|
|
|
* @param $adder
|
2020-08-23 03:14:36 +09:00
|
|
|
*
|
2020-07-22 07:21:27 +09:00
|
|
|
* @author Bruno Casteleiro <brunoccast@fc.up.pt>
|
|
|
|
*/
|
|
|
|
public static function updateSubscriptionCount(Profile $profile, $adder): void
|
2019-10-12 01:08:37 +09:00
|
|
|
{
|
2019-07-09 03:23:48 +09:00
|
|
|
$cnt = self::cacheGet(sprintf('activitypub_profile:subscriptionCount:%d', $profile->id));
|
|
|
|
|
|
|
|
if ($cnt !== false && is_int($cnt)) {
|
2019-10-12 01:08:37 +09:00
|
|
|
self::cacheSet(sprintf('activitypub_profile:subscriptionCount:%d', $profile->id), $cnt + $adder);
|
2019-07-09 03:23:48 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Getter for the subscriber profiles of a
|
|
|
|
* given local profile
|
|
|
|
*
|
2020-08-23 03:14:36 +09:00
|
|
|
* @param Profile $profile profile object
|
|
|
|
* @param int $offset [optional] index of the starting row to fetch from
|
|
|
|
* @param null|int $limit [optional] maximum number of rows allowed for fetching. If it is omitted,
|
|
|
|
* then the sequence will have everything
|
|
|
|
* from offset up until the end.
|
|
|
|
*
|
2019-07-09 03:23:48 +09:00
|
|
|
* @return array subscriber profile objects
|
2020-08-23 03:14:36 +09:00
|
|
|
*
|
2019-07-09 03:23:48 +09:00
|
|
|
* @author Bruno Casteleiro <brunoccast@fc.up.pt>
|
|
|
|
*/
|
2020-07-22 07:21:27 +09:00
|
|
|
public static function getSubscribers(Profile $profile, int $offset = 0, ?int $limit = null): array
|
2019-10-12 01:08:37 +09:00
|
|
|
{
|
2019-07-09 03:23:48 +09:00
|
|
|
$cache = false;
|
|
|
|
if ($offset + $limit <= Subscription::CACHE_WINDOW) {
|
|
|
|
$subs = self::cacheGet(sprintf('activitypub_profile:subscriberCollection:%d', $profile->id));
|
|
|
|
if ($subs !== false && is_array($subs)) {
|
|
|
|
return array_slice($subs, $offset, $limit);
|
|
|
|
}
|
|
|
|
|
|
|
|
$cache = true;
|
|
|
|
}
|
|
|
|
|
2020-08-23 03:14:36 +09:00
|
|
|
$subs = Subscription::getSubscriberIDs($profile->id, $offset, $limit);
|
2019-12-11 07:27:32 +09:00
|
|
|
$profiles = [];
|
2019-07-09 03:23:48 +09:00
|
|
|
|
2019-12-11 07:27:32 +09:00
|
|
|
$users = User::multiGet('id', $subs);
|
|
|
|
foreach ($users->fetchAll() as $user) {
|
|
|
|
$profiles[$user->id] = $user->getProfile();
|
|
|
|
}
|
2019-07-09 03:23:48 +09:00
|
|
|
|
2019-12-11 07:27:32 +09:00
|
|
|
$ap_profiles = Activitypub_profile::multiGet('profile_id', $subs);
|
|
|
|
foreach ($ap_profiles->fetchAll() as $ap) {
|
|
|
|
$profiles[$ap->getID()] = $ap->local_profile();
|
2019-07-09 03:23:48 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($cache) {
|
|
|
|
self::cacheSet(sprintf('activitypub_profile:subscriberCollection:%d', $profile->id), $profiles);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $profiles;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Getter for the subscribed profiles of a
|
|
|
|
* given local profile
|
|
|
|
*
|
2020-08-23 03:14:36 +09:00
|
|
|
* @param Profile $profile profile object
|
|
|
|
* @param int $offset index of the starting row to fetch from
|
|
|
|
* @param null|int $limit maximum number of rows allowed for fetching
|
|
|
|
*
|
2019-07-09 03:23:48 +09:00
|
|
|
* @return array subscribed profile objects
|
2020-08-23 03:14:36 +09:00
|
|
|
*
|
2019-07-09 03:23:48 +09:00
|
|
|
* @author Bruno Casteleiro <brunoccast@fc.up.pt>
|
|
|
|
*/
|
2020-07-22 07:21:27 +09:00
|
|
|
public static function getSubscribed(Profile $profile, int $offset = 0, ?int $limit = null): array
|
2019-10-12 01:08:37 +09:00
|
|
|
{
|
2019-07-09 03:23:48 +09:00
|
|
|
$cache = false;
|
|
|
|
if ($offset + $limit <= Subscription::CACHE_WINDOW) {
|
|
|
|
$subs = self::cacheGet(sprintf('activitypub_profile:subscribedCollection:%d', $profile->id));
|
|
|
|
if (is_array($subs)) {
|
|
|
|
return array_slice($subs, $offset, $limit);
|
|
|
|
}
|
|
|
|
|
|
|
|
$cache = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$subs = Subscription::getSubscribedIDs($profile->id, $offset, $limit);
|
|
|
|
|
2020-08-04 21:48:09 +09:00
|
|
|
$profiles = [];
|
2019-07-09 03:23:48 +09:00
|
|
|
|
2020-08-04 21:48:09 +09:00
|
|
|
$users = User::multiGet('id', $subs);
|
|
|
|
foreach ($users->fetchAll() as $user) {
|
|
|
|
$profiles[$user->id] = $user->getProfile();
|
|
|
|
}
|
|
|
|
|
|
|
|
$ap_profiles = Activitypub_profile::multiGet('profile_id', $subs);
|
|
|
|
foreach ($ap_profiles->fetchAll() as $ap) {
|
|
|
|
$profiles[$ap->getID()] = $ap->local_profile();
|
2019-07-09 03:23:48 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($cache) {
|
2019-10-12 01:08:37 +09:00
|
|
|
self::cacheSet(sprintf('activitypub_profile:subscribedCollection:%d', $profile->id), $profiles);
|
2019-07-09 03:23:48 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
return $profiles;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update cached values that are relevant to
|
|
|
|
* the users involved in a subscription
|
|
|
|
*
|
|
|
|
* @param Profile $actor subscriber profile object
|
|
|
|
* @param Profile $other subscribed profile object
|
2020-08-23 03:14:36 +09:00
|
|
|
*
|
2019-10-12 01:08:37 +09:00
|
|
|
* @throws Exception
|
2020-08-23 03:14:36 +09:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*
|
2019-07-09 03:23:48 +09:00
|
|
|
* @author Bruno Casteleiro <brunoccast@fc.up.pt>
|
|
|
|
*/
|
2020-07-22 07:21:27 +09:00
|
|
|
public static function subscribeCacheUpdate(Profile $actor, Profile $other): void
|
2019-10-12 01:08:37 +09:00
|
|
|
{
|
2019-07-09 03:23:48 +09:00
|
|
|
self::blow('activitypub_profile:subscribedCollection:%d', $actor->getID());
|
|
|
|
self::blow('activitypub_profile:subscriberCollection:%d', $other->id);
|
|
|
|
self::updateSubscriptionCount($actor, +1);
|
|
|
|
self::updateSubscriberCount($other, +1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update cached values that are relevant to
|
|
|
|
* the users involved in an unsubscription
|
|
|
|
*
|
|
|
|
* @param Profile $actor subscriber profile object
|
|
|
|
* @param Profile $other subscribed profile object
|
2020-08-23 03:14:36 +09:00
|
|
|
*
|
2019-10-12 01:08:37 +09:00
|
|
|
* @throws Exception
|
2020-08-23 03:14:36 +09:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*
|
2019-07-09 03:23:48 +09:00
|
|
|
* @author Bruno Casteleiro <brunoccast@fc.up.pt>
|
|
|
|
*/
|
2020-07-22 07:21:27 +09:00
|
|
|
public static function unsubscribeCacheUpdate(Profile $actor, Profile $other): void
|
2019-10-12 01:08:37 +09:00
|
|
|
{
|
2019-07-09 03:23:48 +09:00
|
|
|
self::blow('activitypub_profile:subscribedCollection:%d', $actor->getID());
|
|
|
|
self::blow('activitypub_profile:subscriberCollection:%d', $other->id);
|
|
|
|
self::updateSubscriptionCount($actor, -1);
|
|
|
|
self::updateSubscriberCount($other, -1);
|
|
|
|
}
|
2020-08-23 03:14:36 +09:00
|
|
|
|
|
|
|
public static function schemaDef()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'name' => 'activitypub_actor',
|
|
|
|
'description' => 'remote actor profiles',
|
|
|
|
'fields' => [
|
|
|
|
'uri' => ['type' => 'text', 'not null' => true],
|
|
|
|
'profile_id' => ['type' => 'int', 'not null' => true],
|
|
|
|
'inboxuri' => ['type' => 'text', 'not null' => true],
|
|
|
|
'sharedInboxuri' => ['type' => 'text'],
|
|
|
|
'created' => ['type' => 'datetime', 'description' => 'date this record was created'],
|
|
|
|
'modified' => ['type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'],
|
|
|
|
],
|
|
|
|
'primary key' => ['profile_id'],
|
|
|
|
'foreign keys' => [
|
|
|
|
'activitypub_profile_profile_id_fkey' => ['profile', ['profile_id' => 'id']],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
2019-05-11 20:27:21 +09:00
|
|
|
}
|