diff options
| author | winter | 2025-03-15 18:35:59 +0000 |
|---|---|---|
| committer | winter | 2025-03-15 18:52:54 +0000 |
| commit | 61b122e88cc6783b4d0cf5142a22002f8e558c60 (patch) | |
| tree | 847b864a93f716157456891d4526077e5f0b93f7 /Digitigrade/Model | |
| parent | cb904ef3fb05ab106d5e5e12f6273b8117db4216 (diff) | |
implement pages
Diffstat (limited to 'Digitigrade/Model')
| -rw-r--r-- | Digitigrade/Model/Actor.php | 4 | ||||
| -rw-r--r-- | Digitigrade/Model/BlockRelation.php | 2 | ||||
| -rw-r--r-- | Digitigrade/Model/FollowRelation.php | 2 | ||||
| -rw-r--r-- | Digitigrade/Model/Interaction.php | 4 | ||||
| -rw-r--r-- | Digitigrade/Model/Note.php | 52 |
5 files changed, 58 insertions, 6 deletions
diff --git a/Digitigrade/Model/Actor.php b/Digitigrade/Model/Actor.php index 229582c..0541e1b 100644 --- a/Digitigrade/Model/Actor.php +++ b/Digitigrade/Model/Actor.php @@ -325,6 +325,10 @@ class Actor extends PushableModel implements RpcReceiver { return $this->handle . (($alwaysIncludeDomain || !$this->isLocal) ? '@' . hostname_from_uri($this->uri) : ''); } + public function getLocalUiHref(): string { + return '/@/' . $this->getFullHandle(); + } + public function jsonSerialize(): array { if ($this->deleted) { return [ diff --git a/Digitigrade/Model/BlockRelation.php b/Digitigrade/Model/BlockRelation.php index ca7166c..0b9054a 100644 --- a/Digitigrade/Model/BlockRelation.php +++ b/Digitigrade/Model/BlockRelation.php @@ -62,7 +62,7 @@ class BlockRelation extends Model implements Notifyable { return sprintf(__("notifications.block"), $this->subject->displayName); } public function getNotificationTitleLink(): ?string { - return '/@/' . $this->subject->getFullHandle(); + return $this->subject->getLocalUiHref(); } public function getNotificationImageUrl(): ?string { return $this->subject->avatar ?? '/static/default-avatar.png'; diff --git a/Digitigrade/Model/FollowRelation.php b/Digitigrade/Model/FollowRelation.php index ecb625a..066fc47 100644 --- a/Digitigrade/Model/FollowRelation.php +++ b/Digitigrade/Model/FollowRelation.php @@ -66,7 +66,7 @@ class FollowRelation extends Model implements Notifyable { return sprintf(__("notifications.follow.$status"), $this->subject->displayName); } public function getNotificationTitleLink(): ?string { - return '/@/' . $this->subject->getFullHandle(); + return $this->subject->getLocalUiHref(); } public function getNotificationImageUrl(): ?string { return $this->subject->avatar ?? '/static/default-avatar.png'; diff --git a/Digitigrade/Model/Interaction.php b/Digitigrade/Model/Interaction.php index 43d02a2..dd977fd 100644 --- a/Digitigrade/Model/Interaction.php +++ b/Digitigrade/Model/Interaction.php @@ -97,7 +97,7 @@ class Interaction extends PushableModel implements Notifyable { return sprintf(__('notifications.interaction.' . $this->kind->value . '.title'), $this->author->displayName); } public function getNotificationTitleLink(): ?string { - return '/@/' . $this->target->author->getFullHandle() . '/note/' . $this->target->id; + return $this->target->getLocalUiHref(); } public function getNotificationBody(): ?string { return isset($this->target->summary) ? ('[' . $this->target->summary . ']') : $this->target->plainContent; @@ -106,7 +106,7 @@ class Interaction extends PushableModel implements Notifyable { return $this->author->avatar ?? '/static/default-avatar.png'; } public function getNotificationImageLink(): ?string { - return '/@/' . $this->author->getFullHandle(); + return $this->author->getLocalUiHref(); } public function toJsonReference(): mixed { diff --git a/Digitigrade/Model/Note.php b/Digitigrade/Model/Note.php index 880e3e8..b32e625 100644 --- a/Digitigrade/Model/Note.php +++ b/Digitigrade/Model/Note.php @@ -7,11 +7,13 @@ use Digitigrade\FormattingProvider\SanitisedHtml; use Digitigrade\LinkPreview; use Digitigrade\Model\HomeTimelineItem; use Digitigrade\Notification\Notifyable; +use Digitigrade\Page; use Digitigrade\Timeline\TimelineIncludeable; use Digitigrade\Timeline\TimelineItem; class Note extends PushableModel implements TimelineIncludeable, Notifyable { public const EXTENSION_LINK_PREVIEWS = 'https://pawpub.entities.org.uk/extension/link-previews'; + public const EXTENSION_PAGES = 'https://pawpub.entities.org.uk/extension/pages'; public ?int $id; public string $uri; @@ -195,6 +197,29 @@ class Note extends PushableModel implements TimelineIncludeable, Notifyable { return $notes; } + public static function findAllWithExtension(string $extensionUri, ?int $limit = null, int $offset = 0): array { + $pdo = Db::getInstance()->getPdo(); + $query = 'SELECT note_id FROM note_extension LEFT JOIN note ON note.id = note_id ' + . 'WHERE note_extension.uri = ? ORDER BY note.created DESC'; + if ($limit != null) { + $query .= " LIMIT $limit OFFSET $offset"; + } + $stmt = $pdo->prepare($query); + $stmt->execute([$extensionUri]); + $notes = []; + while ($id = $stmt->fetchColumn(0)) { + $notes[] = self::find($id); + } + return $notes; + } + + public static function countWithExtension(string $extensionUri): int { + $pdo = Db::getInstance()->getPdo(); + $stmt = $pdo->prepare('SELECT COUNT(*) FROM note_extension WHERE uri = ?'); + $stmt->execute([$extensionUri]); + return $stmt->fetchColumn(0); + } + public function getInteractions(): array { return Interaction::findAllWithTarget($this); } @@ -268,6 +293,10 @@ class Note extends PushableModel implements TimelineIncludeable, Notifyable { return htmlspecialchars($this->plainContent); } + public function getLocalUiHref(bool $asPage = false): string { + return '/@/' . $this->author->getFullHandle() . ($asPage ? '/page/' : '/note/') . $this->id; + } + /** * Gets a list of LinkPreviews applicable to this note * @return LinkPreview[] @@ -285,6 +314,25 @@ class Note extends PushableModel implements TimelineIncludeable, Notifyable { } /** + * @return bool whether this note has an attached page + */ + public function hasPage(): bool { + return isset($this->extensions[self::EXTENSION_PAGES]); + } + + public function getPage(): ?Page { + if (!$this->hasPage()) + return null; + $mapper = new \JsonMapper(); + $mapper->bStrictObjectTypeChecking = false; // so that CharacterRanges can be decoded + return $mapper->map($this->extensions[self::EXTENSION_PAGES], Page::class); + } + + public function setPage(Page $page) { + $this->extensions[self::EXTENSION_PAGES] = json_decode(json_encode($page)); + } + + /** * Generates new LinkPreviews for this note (but does not save them automatically) * @return LinkPreview[] the new link previews */ @@ -324,7 +372,7 @@ class Note extends PushableModel implements TimelineIncludeable, Notifyable { return sprintf(__("notifications.$action.title"), $this->author->displayName); } public function getNotificationTitleLink(): ?string { - return '/@/' . $this->author->getFullHandle() . '/note/' . $this->id; + return $this->author->getLocalUiHref(); } public function getNotificationBody(): ?string { return isset($this->summary) ? "[$this->summary]" : $this->plainContent; @@ -333,7 +381,7 @@ class Note extends PushableModel implements TimelineIncludeable, Notifyable { return $this->author->avatar ?? '/static/default-avatar.png'; } public function getNotificationImageLink(): ?string { - return '/@/' . $this->author->getFullHandle(); + return $this->author->getLocalUiHref(); } public function processNotifications() { |
