aboutsummaryrefslogtreecommitdiffhomepage
path: root/Digitigrade/Model
diff options
context:
space:
mode:
Diffstat (limited to 'Digitigrade/Model')
-rw-r--r--Digitigrade/Model/Actor.php37
-rw-r--r--Digitigrade/Model/Note.php37
2 files changed, 74 insertions, 0 deletions
diff --git a/Digitigrade/Model/Actor.php b/Digitigrade/Model/Actor.php
index 8e8799d..5974f40 100644
--- a/Digitigrade/Model/Actor.php
+++ b/Digitigrade/Model/Actor.php
@@ -18,6 +18,43 @@ class Actor extends PushableModel {
public ActorEndpoints $endpoints;
public array $extensions = [];
+ /**
+ * Creates and saves a new local actor with the specified fields pre-set
+ * @param string $handle handle local part
+ * @param ?string $displayName display name (default = same as handle)
+ * @param ?string $bio biography / description
+ * @param bool $automated is this account automated? (e.g. a bot)
+ * @param bool $requestToFollow does this account check follow requests manually?
+ * @return self
+ */
+ public static function create(
+ string $handle,
+ ?string $displayName = null,
+ ?string $bio = null,
+ bool $automated = false,
+ bool $requestToFollow = true // setting this true by default as i think it's better for privacy
+ ): self {
+ $actor = new self();
+ $actor->uri = path_to_uri("/user/$handle");
+ $actor->isLocal = true;
+ $date = new \DateTimeImmutable();
+ $actor->created = $date;
+ $actor->modified = $date;
+ // don't really need to set this as it's generated by the view at /user/:handle
+ $actor->homepage = path_to_uri("/@/$handle");
+ $actor->handle = $handle;
+ $actor->displayName = $displayName ?? $handle;
+ $actor->bio = $bio;
+ $actor->automated = $automated;
+ $actor->requestToFollow = $requestToFollow;
+ // don't actually need to set these either
+ // just need to set the basicFeed since it's a required field
+ $actor->endpoints = new ActorEndpoints();
+ $actor->endpoints->basicFeed = path_to_uri("/user/$handle/basicFeed");
+ $actor->save();
+ return $actor;
+ }
+
protected function getUpdateWhereClause(\PDO $db): ?string {
if (self::findWhere('uri = ?', [$this->uri]) != null)
return 'uri = ' . $db->quote($this->uri);
diff --git a/Digitigrade/Model/Note.php b/Digitigrade/Model/Note.php
index 1e867fa..e80d972 100644
--- a/Digitigrade/Model/Note.php
+++ b/Digitigrade/Model/Note.php
@@ -29,6 +29,43 @@ class Note extends PushableModel {
public array $attachments = [];
public array $extensions = [];
+ /**
+ * Creates and saves a new note with the specified fields pre-set
+ * @param Actor $author who wrote the note
+ * @param string $plainContent text of the note, without any markup
+ * @param string $language ISO 639-3 3-letter language code
+ * @param ?string $summary summary line or content warning
+ * @param NotePrivacyScope $scope who is allowed to view this note
+ * @param bool $indexable whether this note should be findable e.g. in search results
+ * @return self
+ */
+ public static function create(
+ Actor $author,
+ string $plainContent,
+ string $language,
+ ?string $summary = null,
+ NotePrivacyScope $scope = NotePrivacyScope::PUBLIC ,
+ bool $indexable = true
+ ): self {
+ $note = new self();
+ // can't set the note uri properly until it's been saved and we have an id
+ $note->uri = "UNKNOWN";
+ $note->created = new \DateTimeImmutable();
+ $note->author = $author;
+ $note->summary = $summary;
+ $note->plainContent = $plainContent;
+ $note->language = $language;
+ $note->privacy = new NotePrivacy();
+ $note->privacy->scope = $scope;
+ $note->privacy->indexable = $indexable;
+
+ $note->save();
+ $note->uri = path_to_uri("/post/$note->id");
+ $note->save();
+
+ return $note;
+ }
+
protected function getUpdateWhereClause(\PDO $db): ?string {
if (self::findWhere('uri = ?', [$this->uri]) != null)
return 'uri = ' . $db->quote($this->uri);