-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Whenever an actor makes an activity (like, announce, etc.) we now save it in our db, so the url we pass to other activity pub servers is valid and can return the correct json. All the factory and wrapper classes now return an `Activity` entity that can be converted to json using the new `ActivityJsonBuilder`
- Loading branch information
1 parent
7b8a9f2
commit c444eeb
Showing
41 changed files
with
1,024 additions
and
508 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DoctrineMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
final class Version20240820201944 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'Add the activity table'; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
$this->addSql('CREATE TABLE activity (uuid UUID NOT NULL, user_actor_id INT DEFAULT NULL, magazine_actor_id INT DEFAULT NULL, audience_id INT DEFAULT NULL, inner_activity_id UUID DEFAULT NULL, object_entry_id INT DEFAULT NULL, object_entry_comment_id INT DEFAULT NULL, object_post_id INT DEFAULT NULL, object_post_comment_id INT DEFAULT NULL, object_message_id INT DEFAULT NULL, object_user_id INT DEFAULT NULL, object_magazine_id INT DEFAULT NULL, type VARCHAR(255) NOT NULL, inner_activity_url TEXT DEFAULT NULL, object_generic TEXT DEFAULT NULL, target_string TEXT DEFAULT NULL, content_string TEXT DEFAULT NULL, activity_json TEXT DEFAULT NULL, PRIMARY KEY(uuid))'); | ||
$this->addSql('CREATE INDEX IDX_AC74095AF057164A ON activity (user_actor_id)'); | ||
$this->addSql('CREATE INDEX IDX_AC74095A2F5FA0A4 ON activity (magazine_actor_id)'); | ||
$this->addSql('CREATE INDEX IDX_AC74095A848CC616 ON activity (audience_id)'); | ||
$this->addSql('CREATE INDEX IDX_AC74095A1B4C3858 ON activity (inner_activity_id)'); | ||
$this->addSql('CREATE INDEX IDX_AC74095A6CE0A42A ON activity (object_entry_id)'); | ||
$this->addSql('CREATE INDEX IDX_AC74095AC3683D33 ON activity (object_entry_comment_id)'); | ||
$this->addSql('CREATE INDEX IDX_AC74095A4BC7838C ON activity (object_post_id)'); | ||
$this->addSql('CREATE INDEX IDX_AC74095ACC1812B0 ON activity (object_post_comment_id)'); | ||
$this->addSql('CREATE INDEX IDX_AC74095A20E5BA95 ON activity (object_message_id)'); | ||
$this->addSql('CREATE INDEX IDX_AC74095AA7205335 ON activity (object_user_id)'); | ||
$this->addSql('CREATE INDEX IDX_AC74095AFC1C2A13 ON activity (object_magazine_id)'); | ||
$this->addSql('COMMENT ON COLUMN activity.uuid IS \'(DC2Type:uuid)\''); | ||
$this->addSql('COMMENT ON COLUMN activity.inner_activity_id IS \'(DC2Type:uuid)\''); | ||
$this->addSql('ALTER TABLE activity ADD CONSTRAINT FK_AC74095AF057164A FOREIGN KEY (user_actor_id) REFERENCES "user" (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); | ||
$this->addSql('ALTER TABLE activity ADD CONSTRAINT FK_AC74095A2F5FA0A4 FOREIGN KEY (magazine_actor_id) REFERENCES magazine (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); | ||
$this->addSql('ALTER TABLE activity ADD CONSTRAINT FK_AC74095A848CC616 FOREIGN KEY (audience_id) REFERENCES magazine (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); | ||
$this->addSql('ALTER TABLE activity ADD CONSTRAINT FK_AC74095A1B4C3858 FOREIGN KEY (inner_activity_id) REFERENCES activity (uuid) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); | ||
$this->addSql('ALTER TABLE activity ADD CONSTRAINT FK_AC74095A6CE0A42A FOREIGN KEY (object_entry_id) REFERENCES entry (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); | ||
$this->addSql('ALTER TABLE activity ADD CONSTRAINT FK_AC74095AC3683D33 FOREIGN KEY (object_entry_comment_id) REFERENCES entry_comment (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); | ||
$this->addSql('ALTER TABLE activity ADD CONSTRAINT FK_AC74095A4BC7838C FOREIGN KEY (object_post_id) REFERENCES post (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); | ||
$this->addSql('ALTER TABLE activity ADD CONSTRAINT FK_AC74095ACC1812B0 FOREIGN KEY (object_post_comment_id) REFERENCES post_comment (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); | ||
$this->addSql('ALTER TABLE activity ADD CONSTRAINT FK_AC74095A20E5BA95 FOREIGN KEY (object_message_id) REFERENCES message (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); | ||
$this->addSql('ALTER TABLE activity ADD CONSTRAINT FK_AC74095AA7205335 FOREIGN KEY (object_user_id) REFERENCES "user" (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); | ||
$this->addSql('ALTER TABLE activity ADD CONSTRAINT FK_AC74095AFC1C2A13 FOREIGN KEY (object_magazine_id) REFERENCES magazine (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
$this->addSql('ALTER TABLE activity DROP CONSTRAINT FK_AC74095AF057164A'); | ||
$this->addSql('ALTER TABLE activity DROP CONSTRAINT FK_AC74095A2F5FA0A4'); | ||
$this->addSql('ALTER TABLE activity DROP CONSTRAINT FK_AC74095A848CC616'); | ||
$this->addSql('ALTER TABLE activity DROP CONSTRAINT FK_AC74095A1B4C3858'); | ||
$this->addSql('ALTER TABLE activity DROP CONSTRAINT FK_AC74095A6CE0A42A'); | ||
$this->addSql('ALTER TABLE activity DROP CONSTRAINT FK_AC74095AC3683D33'); | ||
$this->addSql('ALTER TABLE activity DROP CONSTRAINT FK_AC74095A4BC7838C'); | ||
$this->addSql('ALTER TABLE activity DROP CONSTRAINT FK_AC74095ACC1812B0'); | ||
$this->addSql('ALTER TABLE activity DROP CONSTRAINT FK_AC74095A20E5BA95'); | ||
$this->addSql('ALTER TABLE activity DROP CONSTRAINT FK_AC74095AA7205335'); | ||
$this->addSql('ALTER TABLE activity DROP CONSTRAINT FK_AC74095AFC1C2A13'); | ||
$this->addSql('DROP TABLE activity'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Entity; | ||
|
||
use App\Entity\Contracts\ActivityPubActivityInterface; | ||
use App\Entity\Contracts\ActivityPubActorInterface; | ||
use Doctrine\ORM\Mapping\Column; | ||
use Doctrine\ORM\Mapping\CustomIdGenerator; | ||
use Doctrine\ORM\Mapping\Entity; | ||
use Doctrine\ORM\Mapping\GeneratedValue; | ||
use Doctrine\ORM\Mapping\Id; | ||
use Doctrine\ORM\Mapping\JoinColumn; | ||
use Doctrine\ORM\Mapping\ManyToOne; | ||
use Symfony\Component\Uid\Uuid; | ||
|
||
#[Entity] | ||
class Activity | ||
{ | ||
#[Column(type: 'uuid'), Id, GeneratedValue(strategy: 'CUSTOM')] | ||
#[CustomIdGenerator(class: 'doctrine.uuid_generator')] | ||
public Uuid $uuid; | ||
|
||
#[Column] | ||
public string $type; | ||
|
||
#[ManyToOne, JoinColumn(nullable: true, onDelete: 'CASCADE')] | ||
public ?User $userActor; | ||
|
||
#[ManyToOne, JoinColumn(nullable: true, onDelete: 'CASCADE')] | ||
public ?Magazine $magazineActor; | ||
|
||
#[ManyToOne, JoinColumn(nullable: true, onDelete: 'CASCADE')] | ||
public ?Magazine $audience; | ||
|
||
#[ManyToOne, JoinColumn(referencedColumnName: 'uuid', nullable: true, onDelete: 'CASCADE', options: ['default' => null])] | ||
public ?Activity $innerActivity = null; | ||
|
||
#[Column(type: 'text', nullable: true)] | ||
public ?string $innerActivityUrl = null; | ||
|
||
#[ManyToOne, JoinColumn(nullable: true, onDelete: 'CASCADE')] | ||
public ?Entry $objectEntry = null; | ||
|
||
#[ManyToOne, JoinColumn(nullable: true, onDelete: 'CASCADE')] | ||
public ?EntryComment $objectEntryComment = null; | ||
|
||
#[ManyToOne, JoinColumn(nullable: true, onDelete: 'CASCADE')] | ||
public ?Post $objectPost = null; | ||
|
||
#[ManyToOne, JoinColumn(nullable: true, onDelete: 'CASCADE')] | ||
public ?PostComment $objectPostComment = null; | ||
|
||
#[ManyToOne, JoinColumn(nullable: true, onDelete: 'CASCADE')] | ||
public ?Message $objectMessage = null; | ||
|
||
#[ManyToOne, JoinColumn(nullable: true, onDelete: 'CASCADE')] | ||
public ?User $objectUser = null; | ||
|
||
#[ManyToOne, JoinColumn(nullable: true, onDelete: 'CASCADE')] | ||
public ?Magazine $objectMagazine = null; | ||
|
||
#[Column(type: 'text', nullable: true)] | ||
public ?string $objectGeneric = null; | ||
|
||
#[Column(type: 'text', nullable: true)] | ||
public ?string $targetString = null; | ||
|
||
#[Column(type: 'text', nullable: true)] | ||
public ?string $contentString = null; | ||
|
||
/** | ||
* This should only be set when the json should not get compiled. | ||
*/ | ||
#[Column(type: 'text', nullable: true)] | ||
public ?string $activityJson = null; | ||
|
||
public function __construct(string $type) | ||
{ | ||
$this->type = $type; | ||
} | ||
|
||
public function setObject(ActivityPubActivityInterface|Entry|EntryComment|Post|PostComment|ActivityPubActorInterface|User|Magazine|array|string $object): void | ||
{ | ||
if ($object instanceof Entry) { | ||
$this->objectEntry = $object; | ||
} elseif ($object instanceof EntryComment) { | ||
$this->objectEntryComment = $object; | ||
} elseif ($object instanceof Post) { | ||
$this->objectPost = $object; | ||
} elseif ($object instanceof PostComment) { | ||
$this->objectPostComment = $object; | ||
} elseif ($object instanceof Message) { | ||
$this->objectMessage = $object; | ||
} elseif ($object instanceof User) { | ||
$this->objectUser = $object; | ||
} elseif ($object instanceof Magazine) { | ||
$this->objectMagazine = $object; | ||
} elseif (\is_array($object)) { | ||
$this->objectGeneric = json_encode($object); | ||
} elseif (\is_string($object)) { | ||
$this->objectGeneric = $object; | ||
} else { | ||
throw new \LogicException(\get_class($object)); | ||
} | ||
} | ||
|
||
public function getObject(): Post|EntryComment|PostComment|Entry|Message|User|Magazine|array|string|null | ||
{ | ||
$o = $this->objectEntry ?? $this->objectEntryComment ?? $this->objectPost ?? $this->objectPostComment ?? $this->objectMessage ?? $this->objectUser ?? $this->objectMagazine; | ||
if (null !== $o) { | ||
return $o; | ||
} | ||
$o = json_decode($this->objectGeneric ?? ''); | ||
if (JSON_ERROR_NONE === json_last_error()) { | ||
return $o; | ||
} | ||
|
||
return $this->objectGeneric; | ||
} | ||
|
||
public function setActor(Magazine|User $actor): void | ||
{ | ||
if ($actor instanceof User) { | ||
$this->userActor = $actor; | ||
} else { | ||
$this->magazineActor = $actor; | ||
} | ||
} | ||
|
||
public function getActor(): Magazine|User|null | ||
{ | ||
return $this->userActor ?? $this->magazineActor; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.