summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--appinfo/database.xml268
-rw-r--r--appinfo/info.xml6
-rw-r--r--appinfo/routes.php20
-rw-r--r--lib/Command/NoteCreate.php150
-rw-r--r--lib/Controller/AccountController.php106
-rw-r--r--lib/Controller/ActivityPubController.php250
-rw-r--r--lib/Controller/SocialPubController.php132
-rw-r--r--lib/Db/ActorsRequest.php173
-rw-r--r--lib/Db/ActorsRequestBuilder.php129
-rw-r--r--lib/Db/CacheActorsRequest.php130
-rw-r--r--lib/Db/CacheActorsRequestBuilder.php122
-rw-r--r--lib/Db/CoreRequestBuilder.php28
-rw-r--r--lib/Db/NotesRequest.php86
-rw-r--r--lib/Db/NotesRequestBuilder.php124
-rw-r--r--lib/Exceptions/ActorAlreadyExistsException.php8
-rw-r--r--lib/Exceptions/ActorDoesNotExistException.php8
-rw-r--r--lib/Exceptions/CacheActorDoesNotExistException.php8
-rw-r--r--lib/Model/APHosts.php87
-rw-r--r--lib/Model/ActivityPub/ActivityCreate.php62
-rw-r--r--lib/Model/ActivityPub/Actor.php330
-rw-r--r--lib/Model/ActivityPub/Cache/CacheActor.php157
-rw-r--r--lib/Model/ActivityPub/Core.php443
-rw-r--r--lib/Model/ActivityPub/Note.php190
-rw-r--r--lib/Service/ActivityPub/InboxService.php76
-rw-r--r--lib/Service/ActivityPub/NoteService.php130
-rw-r--r--lib/Service/ActivityPubService.php491
-rw-r--r--lib/Service/ActivityStreamsService.php25
-rw-r--r--lib/Service/ActorService.php232
-rw-r--r--lib/Service/ClientCurlService.php214
-rw-r--r--lib/Service/ConfigService.php38
-rw-r--r--lib/Service/CurlService.php53
-rw-r--r--lib/Service/ICoreService.php39
-rw-r--r--lib/Service/MiscService.php58
-rw-r--r--lib/Service/ServicesService.php12
-rw-r--r--lib/Service/UriIdService.php86
-rw-r--r--lib/Tools/Model/Request.php49
-rw-r--r--lib/Tools/Traits/TNCDataResponse.php13
-rw-r--r--lib/webfinger.php66
-rw-r--r--templates/actor.php1
-rw-r--r--templates/followers.php1
-rw-r--r--templates/following.php1
41 files changed, 4544 insertions, 58 deletions
diff --git a/appinfo/database.xml b/appinfo/database.xml
index 1a615ac0..fe39af89 100644
--- a/appinfo/database.xml
+++ b/appinfo/database.xml
@@ -64,6 +64,7 @@
<primary>true</primary>
</field>
+ // @deprecated
<field>
<name>service_id</name>
<type>integer</type>
@@ -78,29 +79,40 @@
</field>
<field>
+ <name>username</name>
+ <type>text</type>
+ <length>63</length>
+ </field>
+
+ // @deprecated
+ <field>
<name>account</name>
<type>text</type>
<length>127</length>
</field>
+ // @deprecated
<field>
<name>account_id</name>
<type>integer</type>
<length>7</length>
</field>
+ // @deprecated
<field>
<name>status</name>
<type>integer</type>
<length>1</length>
</field>
+ // @deprecated
<field>
<name>auth</name>
<type>text</type>
<length>2000</length>
</field>
+ // @deprecated
<field>
<name>config</name>
<type>text</type>
@@ -115,5 +127,261 @@
</declaration>
</table>
+ <table>
+ <name>*dbprefix*social_server_actors</name>
+ <declaration>
+
+ <field>
+ <name>id</name>
+ <type>integer</type>
+ <length>7</length>
+ <unsigned>true</unsigned>
+ <notnull>true</notnull>
+ <autoincrement>true</autoincrement>
+ <primary>true</primary>
+ </field>
+
+ <field>
+ <name>type</name>
+ <type>text</type>
+ <length>15</length>
+ <notnull>true</notnull>
+ </field>
+
+ <field>
+ <name>user_id</name>
+ <type>text</type>
+ <length>63</length>
+ <notnull>true</notnull>
+ </field>
+
+ <field>
+ <name>preferred_username</name>
+ <type>text</type>
+ <length>127</length>
+ <notnull>true</notnull>
+ </field>
+
+ <field>
+ <name>public_key</name>
+ <type>text</type>
+ <length>1000</length>
+ </field>
+
+ <field>
+ <name>private_key</name>
+ <type>text</type>
+ <length>2000</length>
+ </field>
+
+ <field>
+ <name>creation</name>
+ <type>timestamp</type>
+ </field>
+
+ </declaration>
+ </table>
+
+ <table>
+ <name>*dbprefix*social_server_activities</name>
+ <declaration>
+
+ <field>
+ <name>id</name>
+ <type>text</type>
+ <length>127</length>
+ <notnull>true</notnull>
+ </field>
+
+ <field>
+ <name>activity</name>
+ <type>text</type>
+ <length>6000</length>
+ <notnull>true</notnull>
+ </field>
+
+ <field>
+ <name>object</name>
+ <type>text</type>
+ <length>127</length>
+ <notnull>true</notnull>
+ </field>
+
+ </declaration>
+ </table>
+
+ <table>
+ <name>*dbprefix*social_server_notes</name>
+ <declaration>
+
+ <field>
+ <name>id</name>
+ <type>text</type>
+ <length>127</length>
+ <notnull>true</notnull>
+ </field>
+
+ <!--<field>-->
+ <!--<name>type</name>-->
+ <!--<type>text</type>-->
+ <!--<length>15</length>-->
+ <!--<notnull>true</notnull>-->
+ <!--</field>-->
+
+ <field>
+ <name>to</name>
+ <type>text</type>
+ <length>127</length>
+ <notnull>true</notnull>
+ </field>
+
+ <field>
+ <name>to_array</name>
+ <type>text</type>
+ <length>2000</length>
+ <notnull>true</notnull>
+ </field>
+
+ <field>
+ <name>cc</name>
+ <type>text</type>
+ <length>127</length>
+ <notnull>true</notnull>
+ </field>
+
+ <field>
+ <name>bcc</name>
+ <type>text</type>
+ <length>127</length>
+ <notnull>true</notnull>
+ </field>
+
+ <field>
+ <name>content</name>
+ <type>text</type>
+ <length>3000</length>
+ <notnull>true</notnull>
+ </field>
+
+ <field>
+ <name>summary</name>
+ <type>text</type>
+ <length>255</length>
+ <notnull>true</notnull>
+ </field>
+
+ <field>
+ <name>published</name>
+ <type>text</type>
+ <length>31</length>
+ <notnull>true</notnull>
+ </field>
+
+ <field>
+ <name>attributed_to</name>
+ <type>text</type>
+ <length>127</length>
+ </field>
+
+ <field>
+ <name>in_reply_to</name>
+ <type>text</type>
+ <length>127</length>
+ </field>
+
+ <field>
+ <name>creation</name>
+ <type>timestamp</type>
+ </field>
+
+ </declaration>
+ </table>
+
+ <table>
+ <name>*dbprefix*social_cache_actors</name>
+ <declaration>
+
+ <field>
+ <name>id</name>
+ <type>integer</type>
+ <length>8</length>
+ <unsigned>true</unsigned>
+ <notnull>true</notnull>
+ <autoincrement>true</autoincrement>
+ <primary>true</primary>
+ </field>
+
+ <field>
+ <name>account</name>
+ <type>text</type>
+ <length>127</length>
+ <notnull>true</notnull>
+ </field>
+
+ <field>
+ <name>url</name>
+ <type>text</type>
+ <length>127</length>
+ <notnull>true</notnull>
+ </field>
+
+ <field>
+ <name>actor</name>
+ <type>text</type>
+ <length>8000</length>
+ <notnull>true</notnull>
+ </field>
+
+ <field>
+ <name>creation</name>
+ <type>timestamp</type>
+ </field>
+
+ </declaration>
+ </table>
+
+ <table>
+ <name>*dbprefix*social_cache_actors</name>
+ <declaration>
+
+ <field>
+ <name>id</name>
+ <type>integer</type>
+ <length>8</length>
+ <unsigned>true</unsigned>
+ <notnull>true</notnull>
+ <autoincrement>true</autoincrement>
+ <primary>true</primary>
+ </field>
+
+ <field>
+ <name>account</name>
+ <type>text</type>
+ <length>127</length>
+ <notnull>true</notnull>
+ </field>
+
+ <field>
+ <name>url</name>
+ <type>text</type>
+ <length>127</length>
+ <notnull>true</notnull>
+ </field>
+
+ <field>
+ <name>actor</name>
+ <type>text</type>
+ <length>8000</length>
+ <notnull>true</notnull>
+ </field>
+
+ <field>
+ <name>creation</name>
+ <type>timestamp</type>
+ </field>
+
+ </declaration>
+ </table>
+
</database>
diff --git a/appinfo/info.xml b/appinfo/info.xml
index 8c9e1088..058e8160 100644
--- a/appinfo/info.xml
+++ b/appinfo/info.xml
@@ -5,7 +5,7 @@
<name>Social</name>
<summary>🎉 Nextcloud becomes part of the federated social networks!</summary>
<description><![CDATA[test]]></description>
- <version>0.0.10</version>
+ <version>0.0.17</version>
<licence>agpl</licence>
<author mail="maxence@artificial-owl.com">Maxence Lange</author>
<author mail="jus@bitgrid.net">Julius Härtl</author>
@@ -26,4 +26,8 @@
</navigation>
</navigations>
+ <commands>
+ <command>OCA\Social\Command\NoteCreate</command>
+ </commands>
+
</info>
diff --git a/appinfo/routes.php b/appinfo/routes.php
index a5276275..20642577 100644
--- a/appinfo/routes.php
+++ b/appinfo/routes.php
@@ -39,6 +39,22 @@ return [
[
'name' => 'OAuth2#setCode', 'url' => '/client/oauth2/redirect/{serviceId}/',
'verb' => 'GET'
- ]
- ]
+ ],
+
+ ['name' => 'Account#create', 'url' => '/local/account/{username}', 'verb' => 'POST'],
+
+ ['name' => 'ActivityPub#sharedInbox', 'url' => '/inbox', 'verb' => 'POST'],
+ ['name' => 'ActivityPub#actor', 'url' => '/users/{username}', 'verb' => 'GET'],
+ ['name' => 'ActivityPub#aliasactor', 'url' => '/@{username}', 'verb' => 'GET'],
+ ['name' => 'ActivityPub#inbox', 'url' => '/@{username}/inbox', 'verb' => 'POST'],
+ ['name' => 'ActivityPub#outbox', 'url' => '/@{username}/outbox', 'verb' => 'POST'],
+ ['name' => 'ActivityPub#followers', 'url' => '/@{username}/followers', 'verb' => 'GET'],
+ ['name' => 'ActivityPub#following', 'url' => '/@{username}/following', 'verb' => 'GET'],
+
+ ['name' => 'SocialPub#displayPost', 'url' => '/@{username}/{postId}', 'verb' => 'GET']
+,
+ ['name' => 'ActivityPub#test', 'url' => '/inbox/{username}', 'verb' => 'POST'],
+
+
+]
];
diff --git a/lib/Command/NoteCreate.php b/lib/Command/NoteCreate.php
new file mode 100644
index 00000000..48c1193f
--- /dev/null
+++ b/lib/Command/NoteCreate.php
@@ -0,0 +1,150 @@
+<?php
+declare(strict_types=1);
+
+
+/**
+ * Nextcloud - Social Support
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later. See the COPYING file.
+ *
+ * @author Maxence Lange <maxence@artificial-owl.com>
+ * @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program 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.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+namespace OCA\Social\Command;
+
+use Exception;
+use OC\Core\Command\Base;
+use OCA\Social\Service\ActivityPub\NoteService;
+use OCA\Social\Service\ActivityPubService;
+use OCA\Social\Service\ActorService;
+use OCA\Social\Service\ConfigService;
+use OCA\Social\Service\CurlService;
+use OCA\Social\Service\MiscService;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Output\OutputInterface;
+
+
+class NoteCreate extends Base {
+
+ /** @var ConfigService */
+ private $configService;
+
+ /** @var ActivityPubService */
+ private $activityPubService;
+
+ /** @var ActorService */
+ private $actorService;
+
+ /** @var NoteService */
+ private $noteService;
+
+ /** @var CurlService */
+ private $curlService;
+
+ /** @var MiscService */
+ private $miscService;
+
+
+ /**
+ * Index constructor.
+ *
+ * @param ActivityPubService $activityPubService
+ * @param ActorService $actorService
+ * @param NoteService $noteService
+ * @param CurlService $curlService
+ * @param ConfigService $configService
+ * @param MiscService $miscService
+ */
+ public function __construct(
+ ActivityPubService $activityPubService, ActorService $actorService,
+ NoteService $noteService, CurlService $curlService,
+ ConfigService $configService, MiscService $miscService
+ ) {
+ parent::__construct();
+
+ $this->activityPubService = $activityPubService;
+ $this->actorService = $actorService;
+ $this->noteService = $noteService;
+ $this->curlService = $curlService;
+ $this->configService = $configService;
+ $this->miscService = $miscService;
+ }
+
+
+ /**
+ *
+ */
+ protected function configure() {
+ parent::configure();
+ $this->setName('social:note:create')
+ ->addOption(
+ 'replyTo', 'r', InputOption::VALUE_OPTIONAL, 'in reply to an existing thread'
+ )
+ ->addOption(
+ 'to', 't', InputOption::VALUE_OPTIONAL, 'to (default Public)'
+ )
+ ->addArgument('userid', InputArgument::REQUIRED, 'userId of the author')
+ ->addArgument('content', InputArgument::REQUIRED, 'content of the post')
+ ->setDescription('Create a new note');
+ }
+
+
+ /**
+ * @param InputInterface $input
+ * @param OutputInterface $output
+ *
+ * @throws Exception
+ */
+ protected function execute(InputInterface $input, OutputInterface $output) {
+
+ $userId = $input->getArgument('userid');
+ $content = $input->getArgument('content');
+ $to = $input->getOption('to');
+ $replyTo = $input->getOption('replyTo');
+
+ $note = $this->noteService->generateNote($userId, $content, ActivityPubService::TO_PUBLIC);
+
+ if ($to !== null) {
+ $note->setTo($to);
+ $note->addTag(
+ [
+ 'type' => 'Mention',
+ 'href' => $to
+ ]
+ );
+ }
+
+
+ if ($replyTo !== null) {
+ $note->setInReplyTo($replyTo);
+ }
+
+ $result = $this->activityPubService->createActivity($userId, $note, $activity);
+
+ echo 'object: ' . json_encode($activity, JSON_PRETTY_PRINT) . "\n";
+ echo 'result: ' . json_encode($result, JSON_PRETTY_PRINT) . "\n";
+
+ }
+
+}
+
diff --git a/lib/Controller/AccountController.php b/lib/Controller/AccountController.php
new file mode 100644
index 00000000..d68c0cca
--- /dev/null
+++ b/lib/Controller/AccountController.php
@@ -0,0 +1,106 @@
+<?php
+declare(strict_types=1);
+
+
+/**
+ * Nextcloud - Social Support
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later. See the COPYING file.
+ *
+ * @author Maxence Lange <maxence@artificial-owl.com>
+ * @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program 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.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Social\Controller;
+
+use daita\Traits\TArrayTools;
+use daita\Traits\TNCDataResponse;
+use Exception;
+use OCA\Social\AppInfo\Application;
+use OCA\Social\Service\ActivityPubService;
+use OCA\Social\Service\ActivityStreamsService;
+use OCA\Social\Service\ActorService;
+use OCA\Social\Service\ConfigService;
+use OCA\Social\Service\MiscService;
+use OCA\Social\Service\ServiceAccountsService;
+use OCA\Social\Service\ServicesService;
+use OCP\AppFramework\Controller;
+use OCP\AppFramework\Http\DataResponse;
+use OCP\IRequest;
+
+
+class AccountController extends Controller {
+
+ use TNCDataResponse;
+
+ /** @var string */
+ private $userId;
+
+ /** @var ConfigService */
+ private $configService;
+
+ /** @var ActorService */
+ private $actorService;
+
+ /** @var MiscService */
+ private $miscService;
+
+
+ /**
+ * AccountController constructor.
+ *
+ * @param IRequest $request
+ * @param string $userId
+ * @param ConfigService $configService
+ * @param ActorService $actorService
+ * @param MiscService $miscService
+ */
+ public function __construct(
+ IRequest $request, string $userId, ConfigService $configService,
+ ActorService $actorService, MiscService $miscService
+ ) {
+ parent::__construct(Application::APP_NAME, $request);
+
+ $this->userId = $userId;
+ $this->configService = $configService;
+ $this->actorService = $actorService;
+ $this->miscService = $miscService;
+ }
+
+
+ /**
+ * @NoAdminRequired
+ *
+ * @param array $data
+ *
+ * @return DataResponse
+ */
+ public function create(string $username): DataResponse {
+ try {
+ $this->actorService->createActor($this->userId, $username);
+
+ return $this->success([]);
+ } catch (Exception $e) {
+ return $this->fail($e->getMessage());
+ }
+ }
+
+
+}
+
diff --git a/lib/Controller/ActivityPubController.php b/lib/Controller/ActivityPubController.php
new file mode 100644
index 00000000..083ddecb
--- /dev/null
+++ b/lib/Controller/ActivityPubController.php
@@ -0,0 +1,250 @@
+<?php
+declare(strict_types=1);
+
+
+/**
+ * Nextcloud - Social Support
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later. See the COPYING file.
+ *
+ * @author Maxence Lange <maxence@artificial-owl.com>
+ * @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program 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.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Social\Controller;
+
+
+use daita\Traits\TNCDataResponse;
+use Exception;
+use OCA\Social\AppInfo\Application;
+use OCA\Social\Service\ActivityPubService;
+use OCA\Social\Service\ActorService;
+use OCA\Social\Service\MiscService;
+use OCP\AppFramework\Controller;
+use OCP\AppFramework\Http\Response;
+use OCP\IRequest;
+
+
+class ActivityPubController extends Controller {
+
+
+ use TNCDataResponse;
+
+
+ /** @var SocialPubController */
+ private $socialPubController;
+
+ /** @var ActivityPubService */
+ private $activityPubService;
+
+ /** @var ActorService */
+ private $actorService;
+
+ /** @var MiscService */
+ private $miscService;
+
+
+ /**
+ * ActivityPubController constructor.
+ *
+ * @param SocialPubController $socialPubController
+ * @param ActivityPubService $activityPubService
+ * @param ActorService $actorService
+ * @param IRequest $request
+ * @param MiscService $miscService
+ */
+ public fun