[DB][MODULES][ActivityPub] Cleanup table definitions
This commit is contained in:
parent
522f40ca2f
commit
f60bdaa2f0
|
@ -53,4 +53,5 @@ services:
|
||||||
|
|
||||||
Component\:
|
Component\:
|
||||||
resource: '../components/*/*.php'
|
resource: '../components/*/*.php'
|
||||||
|
exclude: '../components/*/{scripts,classes,lib,actions,locale,doc}'
|
||||||
tags: ['controller.service_arguments']
|
tags: ['controller.service_arguments']
|
||||||
|
|
|
@ -58,7 +58,8 @@ class ActivityPub extends Module
|
||||||
{
|
{
|
||||||
const PLUGIN_VERSION = '0.4.0alpha0';
|
const PLUGIN_VERSION = '0.4.0alpha0';
|
||||||
// So that this isn't hardcoded everywhere
|
// So that this isn't hardcoded everywhere
|
||||||
const ACTIVITYPUB_PUBLIC_TO = ['https://www.w3.org/ns/activitystreams#Public',
|
const ACTIVITYPUB_PUBLIC_TO = [
|
||||||
|
'https://www.w3.org/ns/activitystreams#Public',
|
||||||
'Public',
|
'Public',
|
||||||
'as:Public',
|
'as:Public',
|
||||||
];
|
];
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
// {{{ License
|
||||||
|
|
||||||
// This file is part of GNU social - https://www.gnu.org/software/social
|
// 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
|
// GNU social is free software: you can redistribute it and/or modify
|
||||||
|
@ -14,74 +17,37 @@
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
// 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/>.
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
/**
|
// }}}
|
||||||
* ActivityPub implementation for GNU social
|
|
||||||
*
|
|
||||||
* @package GNUsocial
|
|
||||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
|
||||||
* @copyright 2018-2019 Free Software Foundation, Inc http://www.fsf.org
|
|
||||||
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
|
||||||
* @link http://www.gnu.org/software/social/
|
|
||||||
*/
|
|
||||||
|
|
||||||
defined('GNUSOCIAL') || die();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ActivityPub Profile
|
* ActivityPub's Remote Actor
|
||||||
*
|
*
|
||||||
* @category Plugin
|
* @category Plugin
|
||||||
* @package GNUsocial
|
* @package GNUsocial
|
||||||
|
*
|
||||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||||
|
* @author Hugo Sales <hugo@fc.up.pt>
|
||||||
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
||||||
*/
|
*/
|
||||||
class Activitypub_profile extends Managed_DataObject
|
|
||||||
{
|
|
||||||
public $__table = 'activitypub_profile';
|
|
||||||
public $uri; // text() not_null
|
|
||||||
public $profile_id; // int(4) primary_key not_null
|
|
||||||
public $inboxuri; // text() not_null
|
|
||||||
public $sharedInboxuri; // text()
|
|
||||||
public $nickname; // varchar(64) multiple_key not_null
|
|
||||||
public $fullname; // text()
|
|
||||||
public $profileurl; // text()
|
|
||||||
public $homepage; // text()
|
|
||||||
public $bio; // text() multiple_key
|
|
||||||
public $location; // text()
|
|
||||||
public $created; // datetime()
|
|
||||||
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
|
|
||||||
|
|
||||||
/**
|
namespace Plugin\ActivityPub\Entity;
|
||||||
* Return table definition for Schema setup and DB_DataObject usage.
|
|
||||||
*
|
class ActivityPubActor
|
||||||
* @return array array of column definitions
|
{
|
||||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
// {{{ Autocode
|
||||||
*/
|
// }}} Autocode
|
||||||
public static function schemaDef()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'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']],
|
|
||||||
],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a pretty profile from a Profile object
|
* Generates a pretty profile from a Profile object
|
||||||
*
|
*
|
||||||
* @param Profile $profile
|
* @param Profile $profile
|
||||||
* @return array array to be used in a response
|
*
|
||||||
* @throws InvalidUrlException
|
* @throws InvalidUrlException
|
||||||
* @throws ServerException
|
* @throws ServerException
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
|
*
|
||||||
|
* @return array array to be used in a response
|
||||||
|
*
|
||||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||||
*/
|
*/
|
||||||
public static function profile_to_array(Profile $profile): array
|
public static function profile_to_array(Profile $profile): array
|
||||||
|
@ -96,8 +62,8 @@ class Activitypub_profile extends Managed_DataObject
|
||||||
'https://www.w3.org/ns/activitystreams',
|
'https://www.w3.org/ns/activitystreams',
|
||||||
'https://w3id.org/security/v1',
|
'https://w3id.org/security/v1',
|
||||||
[
|
[
|
||||||
'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers'
|
'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
|
||||||
]
|
],
|
||||||
],
|
],
|
||||||
'id' => $uri,
|
'id' => $uri,
|
||||||
'type' => 'Person',
|
'type' => 'Person',
|
||||||
|
@ -108,13 +74,13 @@ class Activitypub_profile extends Managed_DataObject
|
||||||
'outbox' => common_local_url('apActorOutbox', ['id' => $id]),
|
'outbox' => common_local_url('apActorOutbox', ['id' => $id]),
|
||||||
'preferredUsername' => $profile->getNickname(),
|
'preferredUsername' => $profile->getNickname(),
|
||||||
'name' => $profile->getBestName(),
|
'name' => $profile->getBestName(),
|
||||||
'summary' => ($desc = $profile->getDescription()) == null ? "" : $desc,
|
'summary' => ($desc = $profile->getDescription()) == null ? '' : $desc,
|
||||||
'url' => $profile->getUrl(),
|
'url' => $profile->getUrl(),
|
||||||
'manuallyApprovesFollowers' => false,
|
'manuallyApprovesFollowers' => false,
|
||||||
'publicKey' => [
|
'publicKey' => [
|
||||||
'id' => $uri . "#public-key",
|
'id' => $uri . '#public-key',
|
||||||
'owner' => $uri,
|
'owner' => $uri,
|
||||||
'publicKeyPem' => $public_key
|
'publicKeyPem' => $public_key,
|
||||||
],
|
],
|
||||||
'tag' => [],
|
'tag' => [],
|
||||||
'attachment' => [],
|
'attachment' => [],
|
||||||
|
@ -123,8 +89,8 @@ class Activitypub_profile extends Managed_DataObject
|
||||||
'mediaType' => 'image/png',
|
'mediaType' => 'image/png',
|
||||||
'height' => AVATAR_PROFILE_SIZE,
|
'height' => AVATAR_PROFILE_SIZE,
|
||||||
'width' => AVATAR_PROFILE_SIZE,
|
'width' => AVATAR_PROFILE_SIZE,
|
||||||
'url' => $profile->avatarUrl(AVATAR_PROFILE_SIZE)
|
'url' => $profile->avatarUrl(AVATAR_PROFILE_SIZE),
|
||||||
]
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($profile->isLocal()) {
|
if ($profile->isLocal()) {
|
||||||
|
@ -142,8 +108,8 @@ class Activitypub_profile extends Managed_DataObject
|
||||||
* Insert the current object variables into the database
|
* Insert the current object variables into the database
|
||||||
*
|
*
|
||||||
* @throws ServerException
|
* @throws ServerException
|
||||||
|
*
|
||||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||||
* @access public
|
|
||||||
*/
|
*/
|
||||||
public function do_insert(): void
|
public function do_insert(): void
|
||||||
{
|
{
|
||||||
|
@ -190,8 +156,10 @@ class Activitypub_profile extends Managed_DataObject
|
||||||
/**
|
/**
|
||||||
* Fetch the locally stored profile for this Activitypub_profile
|
* Fetch the locally stored profile for this Activitypub_profile
|
||||||
*
|
*
|
||||||
* @return Profile
|
|
||||||
* @throws NoProfileException if it was not found
|
* @throws NoProfileException if it was not found
|
||||||
|
*
|
||||||
|
* @return Profile
|
||||||
|
*
|
||||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||||
*/
|
*/
|
||||||
public function local_profile(): Profile
|
public function local_profile(): Profile
|
||||||
|
@ -207,8 +175,11 @@ class Activitypub_profile extends Managed_DataObject
|
||||||
* Generates an Activitypub_profile from a Profile
|
* Generates an Activitypub_profile from a Profile
|
||||||
*
|
*
|
||||||
* @param Profile $profile
|
* @param Profile $profile
|
||||||
* @return Activitypub_profile
|
*
|
||||||
* @throws Exception if no Activitypub_profile exists for given Profile
|
* @throws Exception if no Activitypub_profile exists for given Profile
|
||||||
|
*
|
||||||
|
* @return Activitypub_profile
|
||||||
|
*
|
||||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||||
*/
|
*/
|
||||||
public static function from_profile(Profile $profile): Activitypub_profile
|
public static function from_profile(Profile $profile): Activitypub_profile
|
||||||
|
@ -231,11 +202,11 @@ class Activitypub_profile extends Managed_DataObject
|
||||||
$fields = [
|
$fields = [
|
||||||
'nickname' => 'nickname',
|
'nickname' => 'nickname',
|
||||||
'fullname' => 'fullname',
|
'fullname' => 'fullname',
|
||||||
'bio' => 'bio'
|
'bio' => 'bio',
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($fields as $af => $pf) {
|
foreach ($fields as $af => $pf) {
|
||||||
$aprofile->$af = $profile->$pf;
|
$aprofile->{$af} = $profile->{$pf};
|
||||||
}
|
}
|
||||||
|
|
||||||
return $aprofile;
|
return $aprofile;
|
||||||
|
@ -245,6 +216,7 @@ class Activitypub_profile extends Managed_DataObject
|
||||||
* Travels an array of Profile and returns an array of Activitypub_profile
|
* Travels an array of Profile and returns an array of Activitypub_profile
|
||||||
*
|
*
|
||||||
* @param array of Profile $profiles
|
* @param array of Profile $profiles
|
||||||
|
*
|
||||||
* @return array of Activitypub_profile
|
* @return array of Activitypub_profile
|
||||||
*/
|
*/
|
||||||
public static function from_profile_collection(array $profiles): array
|
public static function from_profile_collection(array $profiles): array
|
||||||
|
@ -268,10 +240,13 @@ class Activitypub_profile extends Managed_DataObject
|
||||||
* as only remote users have ActivityPub_profiles on local instance
|
* as only remote users have ActivityPub_profiles on local instance
|
||||||
*
|
*
|
||||||
* @param Profile $profile
|
* @param Profile $profile
|
||||||
* @return Activitypub_profile
|
*
|
||||||
* @throws HTTP_Request2_Exception
|
* @throws HTTP_Request2_Exception
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
|
*
|
||||||
|
* @return Activitypub_profile
|
||||||
|
*
|
||||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||||
*/
|
*/
|
||||||
private static function create_from_local_profile(Profile $profile): Activitypub_profile
|
private static function create_from_local_profile(Profile $profile): Activitypub_profile
|
||||||
|
@ -285,13 +260,15 @@ class Activitypub_profile extends Managed_DataObject
|
||||||
}
|
}
|
||||||
|
|
||||||
$aprofile->created = $aprofile->modified = common_sql_now();
|
$aprofile->created = $aprofile->modified = common_sql_now();
|
||||||
|
|
||||||
|
$aprofile = new Activitypub_profile;
|
||||||
$aprofile->profile_id = $profile->getID();
|
$aprofile->profile_id = $profile->getID();
|
||||||
$aprofile->uri = $url;
|
$aprofile->uri = $url;
|
||||||
$aprofile->nickname = $profile->getNickname();
|
$aprofile->nickname = $profile->getNickname();
|
||||||
$aprofile->fullname = $profile->getFullname();
|
$aprofile->fullname = $profile->getFullname();
|
||||||
$aprofile->bio = substr($profile->getDescription(), 0, 1000);
|
$aprofile->bio = substr($profile->getDescription(), 0, 1000);
|
||||||
$aprofile->inboxuri = $inboxes["inbox"];
|
$aprofile->inboxuri = $inboxes['inbox'];
|
||||||
$aprofile->sharedInboxuri = $inboxes["sharedInbox"];
|
$aprofile->sharedInboxuri = $inboxes['sharedInbox'];
|
||||||
|
|
||||||
$aprofile->insert();
|
$aprofile->insert();
|
||||||
|
|
||||||
|
@ -302,6 +279,7 @@ class Activitypub_profile extends Managed_DataObject
|
||||||
* Returns sharedInbox if possible, inbox otherwise
|
* Returns sharedInbox if possible, inbox otherwise
|
||||||
*
|
*
|
||||||
* @return string Inbox URL
|
* @return string Inbox URL
|
||||||
|
*
|
||||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||||
*/
|
*/
|
||||||
public function get_inbox(): string
|
public function get_inbox(): string
|
||||||
|
@ -317,6 +295,7 @@ class Activitypub_profile extends Managed_DataObject
|
||||||
* Getter for uri property
|
* Getter for uri property
|
||||||
*
|
*
|
||||||
* @return string URI
|
* @return string URI
|
||||||
|
*
|
||||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||||
*/
|
*/
|
||||||
public function getUri(): string
|
public function getUri(): string
|
||||||
|
@ -328,6 +307,7 @@ class Activitypub_profile extends Managed_DataObject
|
||||||
* Getter for url property
|
* Getter for url property
|
||||||
*
|
*
|
||||||
* @return string URL
|
* @return string URL
|
||||||
|
*
|
||||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||||
*/
|
*/
|
||||||
public function getUrl(): string
|
public function getUrl(): string
|
||||||
|
@ -339,6 +319,7 @@ class Activitypub_profile extends Managed_DataObject
|
||||||
* Getter for id property
|
* Getter for id property
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
|
*
|
||||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||||
*/
|
*/
|
||||||
public function getID(): int
|
public function getID(): int
|
||||||
|
@ -351,8 +332,11 @@ class Activitypub_profile extends Managed_DataObject
|
||||||
*
|
*
|
||||||
* @param string $url
|
* @param string $url
|
||||||
* @param bool $grab_online whether to try online grabbing, defaults to true
|
* @param bool $grab_online whether to try online grabbing, defaults to true
|
||||||
* @return Activitypub_profile
|
*
|
||||||
* @throws Exception if it isn't possible to return an Activitypub_profile
|
* @throws Exception if it isn't possible to return an Activitypub_profile
|
||||||
|
*
|
||||||
|
* @return Activitypub_profile
|
||||||
|
*
|
||||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||||
*/
|
*/
|
||||||
public static function fromUri(string $url, bool $grab_online = true): Activitypub_profile
|
public static function fromUri(string $url, bool $grab_online = true): Activitypub_profile
|
||||||
|
@ -371,8 +355,11 @@ class Activitypub_profile extends Managed_DataObject
|
||||||
* an exception will be thrown.
|
* an exception will be thrown.
|
||||||
*
|
*
|
||||||
* @param string $addr WebFinger address
|
* @param string $addr WebFinger address
|
||||||
* @return Activitypub_profile
|
*
|
||||||
* @throws Exception on error conditions
|
* @throws Exception on error conditions
|
||||||
|
*
|
||||||
|
* @return Activitypub_profile
|
||||||
|
*
|
||||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||||
* @author GNU social
|
* @author GNU social
|
||||||
*/
|
*/
|
||||||
|
@ -419,8 +406,7 @@ class Activitypub_profile extends Managed_DataObject
|
||||||
|
|
||||||
// If there's an Hcard, let's grab its info
|
// If there's an Hcard, let's grab its info
|
||||||
if (array_key_exists('hcard', $hints)) {
|
if (array_key_exists('hcard', $hints)) {
|
||||||
if (!array_key_exists('profileurl', $hints) ||
|
if (!array_key_exists('profileurl', $hints) || $hints['hcard'] != $hints['profileurl']) {
|
||||||
$hints['hcard'] != $hints['profileurl']) {
|
|
||||||
$hcardHints = DiscoveryHints::fromHcardUrl($hints['hcard']);
|
$hcardHints = DiscoveryHints::fromHcardUrl($hints['hcard']);
|
||||||
$hints = array_merge($hcardHints, $hints);
|
$hints = array_merge($hcardHints, $hints);
|
||||||
}
|
}
|
||||||
|
@ -431,12 +417,12 @@ class Activitypub_profile extends Managed_DataObject
|
||||||
if (array_key_exists('profileurl', $hints)) {
|
if (array_key_exists('profileurl', $hints)) {
|
||||||
$profileUrl = $hints['profileurl'];
|
$profileUrl = $hints['profileurl'];
|
||||||
try {
|
try {
|
||||||
common_log(LOG_INFO, "Discovery on acct:$addr with profile URL $profileUrl");
|
common_log(LOG_INFO, "Discovery on acct:{$addr} with profile URL {$profileUrl}");
|
||||||
$aprofile = self::fromUri($hints['profileurl']);
|
$aprofile = self::fromUri($hints['profileurl']);
|
||||||
self::cacheSet(sprintf('activitypub_profile:webfinger:%s', $addr), $aprofile->getUri());
|
self::cacheSet(sprintf('activitypub_profile:webfinger:%s', $addr), $aprofile->getUri());
|
||||||
return $aprofile;
|
return $aprofile;
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
common_log(LOG_WARNING, "Failed creating profile from profile URL '$profileUrl': " . $e->getMessage());
|
common_log(LOG_WARNING, "Failed creating profile from profile URL '{$profileUrl}': " . $e->getMessage());
|
||||||
// keep looking
|
// keep looking
|
||||||
//
|
//
|
||||||
// @todo FIXME: This means an error discovering from profile page
|
// @todo FIXME: This means an error discovering from profile page
|
||||||
|
@ -457,7 +443,9 @@ class Activitypub_profile extends Managed_DataObject
|
||||||
*
|
*
|
||||||
* @param Profile $profile
|
* @param Profile $profile
|
||||||
* @param Activitypub_profile $aprofile
|
* @param Activitypub_profile $aprofile
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
|
*
|
||||||
* @author Bruno Casteleiro <brunoccast@fc.up.pt>
|
* @author Bruno Casteleiro <brunoccast@fc.up.pt>
|
||||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||||
*/
|
*/
|
||||||
|
@ -467,13 +455,13 @@ class Activitypub_profile extends Managed_DataObject
|
||||||
'profileurl' => 'profileurl',
|
'profileurl' => 'profileurl',
|
||||||
'nickname' => 'nickname',
|
'nickname' => 'nickname',
|
||||||
'fullname' => 'fullname',
|
'fullname' => 'fullname',
|
||||||
'bio' => 'bio'
|
'bio' => 'bio',
|
||||||
];
|
];
|
||||||
|
|
||||||
$orig = clone($profile);
|
$orig = clone $profile;
|
||||||
|
|
||||||
foreach ($fields as $af => $pf) {
|
foreach ($fields as $af => $pf) {
|
||||||
$profile->$pf = $aprofile->$af;
|
$profile->{$pf} = $aprofile->{$af};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($profile->id) {
|
if ($profile->id) {
|
||||||
|
@ -488,8 +476,11 @@ class Activitypub_profile extends Managed_DataObject
|
||||||
*
|
*
|
||||||
* @param Activitypub_profile $aprofile
|
* @param Activitypub_profile $aprofile
|
||||||
* @param array|false $res remote response, if array it updates, if false it deletes
|
* @param array|false $res remote response, if array it updates, if false it deletes
|
||||||
* @return Profile remote Profile object
|
*
|
||||||
* @throws NoProfileException
|
* @throws NoProfileException
|
||||||
|
*
|
||||||
|
* @return Profile remote Profile object
|
||||||
|
*
|
||||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||||
*/
|
*/
|
||||||
public static function update_profile(Activitypub_profile $aprofile, $res): Profile
|
public static function update_profile(Activitypub_profile $aprofile, $res): Profile
|
||||||
|
@ -498,7 +489,7 @@ class Activitypub_profile extends Managed_DataObject
|
||||||
$profile = $aprofile->local_profile();
|
$profile = $aprofile->local_profile();
|
||||||
$id = $profile->getID();
|
$id = $profile->getID();
|
||||||
$profile->delete();
|
$profile->delete();
|
||||||
throw new NoProfileException($id, "410 Gone");
|
throw new NoProfileException($id, '410 Gone');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_array($res)) {
|
if (!is_array($res)) {
|
||||||
|
@ -541,13 +532,16 @@ class Activitypub_profile extends Managed_DataObject
|
||||||
* Update remote user profile URI in local instance
|
* Update remote user profile URI in local instance
|
||||||
*
|
*
|
||||||
* @param string $uri
|
* @param string $uri
|
||||||
* @return void
|
*
|
||||||
* @throws Exception (if the update fails)
|
* @throws Exception (if the update fails)
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
* @author Bruno Casteleiro <brunoccast@fc.up.pt>
|
* @author Bruno Casteleiro <brunoccast@fc.up.pt>
|
||||||
*/
|
*/
|
||||||
public function updateUri(string $uri): void
|
public function updateUri(string $uri): void
|
||||||
{
|
{
|
||||||
$orig = clone($this);
|
$orig = clone $this;
|
||||||
$this->uri = $uri;
|
$this->uri = $uri;
|
||||||
$this->updateWithKeys($orig);
|
$this->updateWithKeys($orig);
|
||||||
}
|
}
|
||||||
|
@ -557,7 +551,9 @@ class Activitypub_profile extends Managed_DataObject
|
||||||
* given local profile
|
* given local profile
|
||||||
*
|
*
|
||||||
* @param Profile $profile profile object
|
* @param Profile $profile profile object
|
||||||
|
*
|
||||||
* @return int number of subscribers
|
* @return int number of subscribers
|
||||||
|
*
|
||||||
* @author Bruno Casteleiro <brunoccast@fc.up.pt>
|
* @author Bruno Casteleiro <brunoccast@fc.up.pt>
|
||||||
*/
|
*/
|
||||||
public static function subscriberCount(Profile $profile): int
|
public static function subscriberCount(Profile $profile): int
|
||||||
|
@ -591,7 +587,9 @@ class Activitypub_profile extends Managed_DataObject
|
||||||
* given local profile
|
* given local profile
|
||||||
*
|
*
|
||||||
* @param Profile $profile profile object
|
* @param Profile $profile profile object
|
||||||
|
*
|
||||||
* @return int number of subscriptions
|
* @return int number of subscriptions
|
||||||
|
*
|
||||||
* @author Bruno Casteleiro <brunoccast@fc.up.pt>
|
* @author Bruno Casteleiro <brunoccast@fc.up.pt>
|
||||||
*/
|
*/
|
||||||
public static function subscriptionCount(Profile $profile): int
|
public static function subscriptionCount(Profile $profile): int
|
||||||
|
@ -625,6 +623,7 @@ class Activitypub_profile extends Managed_DataObject
|
||||||
*
|
*
|
||||||
* @param Profile $profile
|
* @param Profile $profile
|
||||||
* @param $adder
|
* @param $adder
|
||||||
|
*
|
||||||
* @author Bruno Casteleiro <brunoccast@fc.up.pt>
|
* @author Bruno Casteleiro <brunoccast@fc.up.pt>
|
||||||
*/
|
*/
|
||||||
public static function updateSubscriberCount(Profile $profile, $adder): void
|
public static function updateSubscriberCount(Profile $profile, $adder): void
|
||||||
|
@ -641,6 +640,7 @@ class Activitypub_profile extends Managed_DataObject
|
||||||
*
|
*
|
||||||
* @param Profile $profile
|
* @param Profile $profile
|
||||||
* @param $adder
|
* @param $adder
|
||||||
|
*
|
||||||
* @author Bruno Casteleiro <brunoccast@fc.up.pt>
|
* @author Bruno Casteleiro <brunoccast@fc.up.pt>
|
||||||
*/
|
*/
|
||||||
public static function updateSubscriptionCount(Profile $profile, $adder): void
|
public static function updateSubscriptionCount(Profile $profile, $adder): void
|
||||||
|
@ -658,10 +658,12 @@ class Activitypub_profile extends Managed_DataObject
|
||||||
*
|
*
|
||||||
* @param Profile $profile profile object
|
* @param Profile $profile profile object
|
||||||
* @param int $offset [optional] index of the starting row to fetch from
|
* @param int $offset [optional] index of the starting row to fetch from
|
||||||
* @param int|null $limit [optional] maximum number of rows allowed for fetching. If it is omitted,
|
* @param null|int $limit [optional] maximum number of rows allowed for fetching. If it is omitted,
|
||||||
* then the sequence will have everything
|
* then the sequence will have everything
|
||||||
* from offset up until the end.
|
* from offset up until the end.
|
||||||
|
*
|
||||||
* @return array subscriber profile objects
|
* @return array subscriber profile objects
|
||||||
|
*
|
||||||
* @author Bruno Casteleiro <brunoccast@fc.up.pt>
|
* @author Bruno Casteleiro <brunoccast@fc.up.pt>
|
||||||
*/
|
*/
|
||||||
public static function getSubscribers(Profile $profile, int $offset = 0, ?int $limit = null): array
|
public static function getSubscribers(Profile $profile, int $offset = 0, ?int $limit = null): array
|
||||||
|
@ -702,8 +704,10 @@ class Activitypub_profile extends Managed_DataObject
|
||||||
*
|
*
|
||||||
* @param Profile $profile profile object
|
* @param Profile $profile profile object
|
||||||
* @param int $offset index of the starting row to fetch from
|
* @param int $offset index of the starting row to fetch from
|
||||||
* @param int|null $limit maximum number of rows allowed for fetching
|
* @param null|int $limit maximum number of rows allowed for fetching
|
||||||
|
*
|
||||||
* @return array subscribed profile objects
|
* @return array subscribed profile objects
|
||||||
|
*
|
||||||
* @author Bruno Casteleiro <brunoccast@fc.up.pt>
|
* @author Bruno Casteleiro <brunoccast@fc.up.pt>
|
||||||
*/
|
*/
|
||||||
public static function getSubscribed(Profile $profile, int $offset = 0, ?int $limit = null): array
|
public static function getSubscribed(Profile $profile, int $offset = 0, ?int $limit = null): array
|
||||||
|
@ -745,8 +749,11 @@ class Activitypub_profile extends Managed_DataObject
|
||||||
*
|
*
|
||||||
* @param Profile $actor subscriber profile object
|
* @param Profile $actor subscriber profile object
|
||||||
* @param Profile $other subscribed profile object
|
* @param Profile $other subscribed profile object
|
||||||
* @return void
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
* @author Bruno Casteleiro <brunoccast@fc.up.pt>
|
* @author Bruno Casteleiro <brunoccast@fc.up.pt>
|
||||||
*/
|
*/
|
||||||
public static function subscribeCacheUpdate(Profile $actor, Profile $other): void
|
public static function subscribeCacheUpdate(Profile $actor, Profile $other): void
|
||||||
|
@ -763,8 +770,11 @@ class Activitypub_profile extends Managed_DataObject
|
||||||
*
|
*
|
||||||
* @param Profile $actor subscriber profile object
|
* @param Profile $actor subscriber profile object
|
||||||
* @param Profile $other subscribed profile object
|
* @param Profile $other subscribed profile object
|
||||||
* @return void
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
* @author Bruno Casteleiro <brunoccast@fc.up.pt>
|
* @author Bruno Casteleiro <brunoccast@fc.up.pt>
|
||||||
*/
|
*/
|
||||||
public static function unsubscribeCacheUpdate(Profile $actor, Profile $other): void
|
public static function unsubscribeCacheUpdate(Profile $actor, Profile $other): void
|
||||||
|
@ -774,4 +784,24 @@ class Activitypub_profile extends Managed_DataObject
|
||||||
self::updateSubscriptionCount($actor, -1);
|
self::updateSubscriptionCount($actor, -1);
|
||||||
self::updateSubscriberCount($other, -1);
|
self::updateSubscriberCount($other, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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']],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
// {{{ License
|
||||||
|
|
||||||
// This file is part of GNU social - https://www.gnu.org/software/social
|
// 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
|
// GNU social is free software: you can redistribute it and/or modify
|
||||||
|
@ -14,64 +17,34 @@
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
// 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/>.
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ActivityPub implementation for GNU social
|
* ActivityPub Assymetric Key Storage System
|
||||||
*
|
*
|
||||||
* @package GNUsocial
|
* @package GNUsocial
|
||||||
|
*
|
||||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||||
|
* @author Hugo Sales <hugo@fc.up.pt>
|
||||||
* @copyright 2018-2019 Free Software Foundation, Inc http://www.fsf.org
|
* @copyright 2018-2019 Free Software Foundation, Inc http://www.fsf.org
|
||||||
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
||||||
* @link http://www.gnu.org/software/social/
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
defined('GNUSOCIAL') || die();
|
namespace Plugin\ActivityPub\Entity;
|
||||||
|
|
||||||
/**
|
class ActivityPubCryptKey
|
||||||
* ActivityPub Keys System
|
|
||||||
*
|
|
||||||
* @category Plugin
|
|
||||||
* @package GNUsocial
|
|
||||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
|
||||||
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
|
||||||
*/
|
|
||||||
class Activitypub_rsa extends Managed_DataObject
|
|
||||||
{
|
{
|
||||||
public $__table = 'activitypub_rsa';
|
// {{{ Autocode
|
||||||
public $profile_id; // int(4) primary_key not_null
|
// }}} Autocode
|
||||||
public $private_key; // text() not_null
|
|
||||||
public $public_key; // text() not_null
|
|
||||||
public $created; // datetime()
|
|
||||||
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return table definition for Schema setup and DB_DataObject usage.
|
|
||||||
*
|
|
||||||
* @return array array of column definitions
|
|
||||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
|
||||||
*/
|
|
||||||
public static function schemaDef()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'fields' => [
|
|
||||||
'profile_id' => ['type' => 'int', 'not null' => true],
|
|
||||||
'private_key' => ['type' => 'text'],
|
|
||||||
'public_key' => ['type' => 'text', 'not null' => true],
|
|
||||||
'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_rsa_profile_id_fkey' => ['profile', ['profile_id' => 'id']],
|
|
||||||
],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private key getter
|
* Private key getter
|
||||||
*
|
*
|
||||||
* @param Profile $profile
|
* @param Profile $profile
|
||||||
* @return string The private key
|
*
|
||||||
* @throws Exception Throws exception if tries to fetch a private key of an actor we don't own
|
* @throws Exception Throws exception if tries to fetch a private key of an actor we don't own
|
||||||
|
*
|
||||||
|
* @return string The private key
|
||||||
*/
|
*/
|
||||||
public function get_private_key(Profile $profile): string
|
public function get_private_key(Profile $profile): string
|
||||||
{
|
{
|
||||||
|
@ -95,9 +68,12 @@ class Activitypub_rsa extends Managed_DataObject
|
||||||
*
|
*
|
||||||
* @param Profile $profile
|
* @param Profile $profile
|
||||||
* @param bool $fetch=true Should attempt to fetch keys from a remote profile?
|
* @param bool $fetch=true Should attempt to fetch keys from a remote profile?
|
||||||
* @return string The public key
|
*
|
||||||
* @throws ServerException It should never occur, but if so, we break everything!
|
* @throws ServerException It should never occur, but if so, we break everything!
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
|
*
|
||||||
|
* @return string The public key
|
||||||
|
*
|
||||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||||
*/
|
*/
|
||||||
public function ensure_public_key(Profile $profile, bool $fetch = true): string
|
public function ensure_public_key(Profile $profile, bool $fetch = true): string
|
||||||
|
@ -112,7 +88,7 @@ class Activitypub_rsa extends Managed_DataObject
|
||||||
$apRSA->public_key = $this->public_key;
|
$apRSA->public_key = $this->public_key;
|
||||||
} else {
|
} else {
|
||||||
// ASSERT: This should never happen, but try to recover!
|
// ASSERT: This should never happen, but try to recover!
|
||||||
common_log(LOG_ERR, "Activitypub_rsa: An impossible thing has happened... Please let the devs know that it entered in line 116 at Activitypub_rsa.php");
|
common_log(LOG_ERR, 'Activitypub_rsa: An impossible thing has happened... Please let the devs know that it entered in line 116 at Activitypub_rsa.php');
|
||||||
if ($fetch) {
|
if ($fetch) {
|
||||||
$res = Activitypub_explorer::get_remote_user_activity($profile->getUri());
|
$res = Activitypub_explorer::get_remote_user_activity($profile->getUri());
|
||||||
Activitypub_rsa::update_public_key($profile, $res['publicKey']['publicKeyPem']);
|
Activitypub_rsa::update_public_key($profile, $res['publicKey']['publicKeyPem']);
|
||||||
|
@ -129,8 +105,8 @@ class Activitypub_rsa extends Managed_DataObject
|
||||||
* Insert the current object variables into the database.
|
* Insert the current object variables into the database.
|
||||||
*
|
*
|
||||||
* @throws ServerException
|
* @throws ServerException
|
||||||
|
*
|
||||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||||
* @access public
|
|
||||||
*/
|
*/
|
||||||
public function store_keys(): void
|
public function store_keys(): void
|
||||||
{
|
{
|
||||||
|
@ -146,6 +122,7 @@ class Activitypub_rsa extends Managed_DataObject
|
||||||
*
|
*
|
||||||
* @param string $private_key out
|
* @param string $private_key out
|
||||||
* @param string $public_key out
|
* @param string $public_key out
|
||||||
|
*
|
||||||
* @author PHP Manual Contributed Notes <dirt@awoms.com>
|
* @author PHP Manual Contributed Notes <dirt@awoms.com>
|
||||||
*/
|
*/
|
||||||
public static function generate_keys(?string &$private_key, ?string &$public_key): void
|
public static function generate_keys(?string &$private_key, ?string &$public_key): void
|
||||||
|
@ -164,16 +141,18 @@ class Activitypub_rsa extends Managed_DataObject
|
||||||
|
|
||||||
// Extract the public key from $res to $pubKey
|
// Extract the public key from $res to $pubKey
|
||||||
$pubKey = openssl_pkey_get_details($res);
|
$pubKey = openssl_pkey_get_details($res);
|
||||||
$public_key = $pubKey["key"];
|
$public_key = $pubKey['key'];
|
||||||
unset($pubKey);
|
unset($pubKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update public key.
|
* Update public key.
|
||||||
*
|
*
|
||||||
* @param Profile|Activitypub_profile $profile
|
* @param Activitypub_profile|Profile $profile
|
||||||
* @param string $public_key
|
* @param string $public_key
|
||||||
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
|
*
|
||||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||||
*/
|
*/
|
||||||
public static function update_public_key($profile, string $public_key): void
|
public static function update_public_key($profile, string $public_key): void
|
||||||
|
@ -187,4 +166,23 @@ class Activitypub_rsa extends Managed_DataObject
|
||||||
$apRSA->insert();
|
$apRSA->insert();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function schemaDef()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name' => 'activitypub_crypt_key',
|
||||||
|
'description' => 'assymetric key storage for activitypub',
|
||||||
|
'fields' => [
|
||||||
|
'gsactor_id' => ['type' => 'int', 'not null' => true],
|
||||||
|
'private_key' => ['type' => 'text'],
|
||||||
|
'public_key' => ['type' => 'text', 'not null' => true],
|
||||||
|
'created' => ['type' => 'datetime', 'description' => 'date this record was created'],
|
||||||
|
'modified' => ['type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'],
|
||||||
|
],
|
||||||
|
'primary key' => ['gsactor_id'],
|
||||||
|
'foreign keys' => [
|
||||||
|
'activitypub_rsa_gsactor_id_fkey' => ['gsactor', ['gsactor_id' => 'id']],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
60
plugins/ActivityPub/Entity/ActivityPubFollowRequests.php
Normal file
60
plugins/ActivityPub/Entity/ActivityPubFollowRequests.php
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// {{{ License
|
||||||
|
|
||||||
|
// 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/>.
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ActivityPub's Pending follow requests
|
||||||
|
*
|
||||||
|
* @category Plugin
|
||||||
|
* @package GNUsocial
|
||||||
|
*
|
||||||
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||||
|
* @author Hugo Sales <hugo@fc.up.pt>
|
||||||
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Plugin\ActivityPub\Entity;
|
||||||
|
|
||||||
|
class ActivityPubFollowRequests
|
||||||
|
{
|
||||||
|
// {{{ Autocode
|
||||||
|
// }}} Autocode
|
||||||
|
|
||||||
|
public static function schemaDef()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name' => 'activitypub_pending_follow_requests',
|
||||||
|
'fields' => [
|
||||||
|
'local_gsactor_id' => ['type' => 'int', 'not null' => true],
|
||||||
|
'remote_gsactor_id' => ['type' => 'int', 'not null' => true],
|
||||||
|
'relation_id' => ['type' => 'serial', 'not null' => true],
|
||||||
|
],
|
||||||
|
'primary key' => ['relation_id'],
|
||||||
|
'foreign keys' => [
|
||||||
|
'activitypub_pending_follow_requests_local_gsactor_id_fkey' => ['gsactor', ['local_gsactor_id' => 'id']],
|
||||||
|
'activitypub_pending_follow_requests_remote_gsactor_id_fkey' => ['gsactor', ['remote_gsactor_id' => 'id']],
|
||||||
|
],
|
||||||
|
'indexes' => [
|
||||||
|
'activitypub_pending_follow_requests_local_gsactor_id_idx' => ['local_gsactor_id'],
|
||||||
|
'activitypub_pending_follow_requests_remote_gsactor_id_idx' => ['remote_gsactor_id'],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,113 +0,0 @@
|
||||||
<?php
|
|
||||||
// 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/>.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ActivityPub implementation for GNU social
|
|
||||||
*
|
|
||||||
* @package GNUsocial
|
|
||||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
|
||||||
* @copyright 2018-2019 Free Software Foundation, Inc http://www.fsf.org
|
|
||||||
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
|
||||||
* @link http://www.gnu.org/software/social/
|
|
||||||
*/
|
|
||||||
|
|
||||||
defined('GNUSOCIAL') || die();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ActivityPub's Pending follow requests
|
|
||||||
*
|
|
||||||
* @category Plugin
|
|
||||||
* @package GNUsocial
|
|
||||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
|
||||||
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
|
||||||
*/
|
|
||||||
class Activitypub_pending_follow_requests extends Managed_DataObject
|
|
||||||
{
|
|
||||||
public $__table = 'activitypub_pending_follow_requests';
|
|
||||||
public $local_profile_id;
|
|
||||||
public $remote_profile_id;
|
|
||||||
private $_reldb = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return table definition for Schema setup and DB_DataObject usage.
|
|
||||||
*
|
|
||||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
|
||||||
* @return array array of column definitions
|
|
||||||
*/
|
|
||||||
public static function schemaDef()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'fields' => [
|
|
||||||
'local_profile_id' => ['type' => 'int', 'not null' => true],
|
|
||||||
'remote_profile_id' => ['type' => 'int', 'not null' => true],
|
|
||||||
'relation_id' => ['type' => 'serial', 'not null' => true],
|
|
||||||
],
|
|
||||||
'primary key' => ['relation_id'],
|
|
||||||
'foreign keys' => [
|
|
||||||
'activitypub_pending_follow_requests_local_profile_id_fkey' => ['profile', ['local_profile_id' => 'id']],
|
|
||||||
'activitypub_pending_follow_requests_remote_profile_id_fkey' => ['profile', ['remote_profile_id' => 'id']],
|
|
||||||
],
|
|
||||||
'indexes' => [
|
|
||||||
'activitypub_pending_follow_requests_local_profile_id_idx' => ['local_profile_id'],
|
|
||||||
'activitypub_pending_follow_requests_remote_profile_id_idx' => ['remote_profile_id'],
|
|
||||||
],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function __construct($actor, $remote_actor)
|
|
||||||
{
|
|
||||||
$this->local_profile_id = $actor;
|
|
||||||
$this->remote_profile_id = $remote_actor;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add Follow request to table.
|
|
||||||
*
|
|
||||||
* @return boolean true if added, false otherwise
|
|
||||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
|
||||||
*/
|
|
||||||
public function add()
|
|
||||||
{
|
|
||||||
return !$this->exists() && $this->insert();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if a Follow request is pending.
|
|
||||||
*
|
|
||||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
|
||||||
* @return boolean true if is pending, false otherwise
|
|
||||||
*/
|
|
||||||
public function exists()
|
|
||||||
{
|
|
||||||
$this->_reldb = clone($this);
|
|
||||||
if ($this->_reldb->find() > 0) {
|
|
||||||
$this->_reldb->fetch();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove a request from the pending table.
|
|
||||||
*
|
|
||||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
|
||||||
* @return boolean true if removed, false otherwise
|
|
||||||
*/
|
|
||||||
public function remove()
|
|
||||||
{
|
|
||||||
return $this->exists() && $this->_reldb->delete();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -36,11 +36,17 @@ namespace App\DependencyInjection\Compiler;
|
||||||
use App\Core\ModuleManager;
|
use App\Core\ModuleManager;
|
||||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
|
use Symfony\Component\DependencyInjection\Reference;
|
||||||
|
|
||||||
class ModuleManagerPass implements CompilerPassInterface
|
class ModuleManagerPass implements CompilerPassInterface
|
||||||
{
|
{
|
||||||
public function process(ContainerBuilder $container)
|
public function process(ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
ModuleManager::process();
|
ModuleManager::process();
|
||||||
|
$container->findDefinition('doctrine.orm.default_metadata_driver')
|
||||||
|
->addMethodCall('addDriver',
|
||||||
|
[new Reference('app.core.schemadef_driver'), 'Plugin\\Entity'])
|
||||||
|
->addMethodCall('addDriver',
|
||||||
|
[new Reference('app.core.schemadef_driver'), 'Component\\Entity']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user