aboutsummaryrefslogtreecommitdiffhomepage
path: root/routes
diff options
context:
space:
mode:
Diffstat (limited to 'routes')
-rw-r--r--routes/note.php19
-rw-r--r--routes/note_fragment.php27
2 files changed, 41 insertions, 5 deletions
diff --git a/routes/note.php b/routes/note.php
index 8a6c9da..f1d6650 100644
--- a/routes/note.php
+++ b/routes/note.php
@@ -1,8 +1,12 @@
<?php
+use Digitigrade\HttpResponseStatus\Forbidden;
use Digitigrade\HttpResponseStatus\NotFound;
use Digitigrade\HttpResponseStatus\TemporaryRedirect;
+use Digitigrade\Model\Instance;
use Digitigrade\Model\Note;
+use Digitigrade\Model\NotePrivacyScope;
+use Digitigrade\Model\UserAccount;
use Digitigrade\Router;
Router::getInstance()->mount('/note/:id', function (array $args) {
@@ -16,6 +20,14 @@ Router::getInstance()->mount('/note/:id', function (array $args) {
if (isset($_SERVER['HTTP_ACCEPT']) && str_contains($_SERVER['HTTP_ACCEPT'], 'text/html')) {
throw new TemporaryRedirect('/@/' . $note->author->handle . "/note/$note->id");
}
+ // if it's not public we need to check whether the requesting instance is allowed to see it
+ if ($note->privacy->scope != NotePrivacyScope::PUBLIC ) {
+ $instance = Instance::requireByRequestHeaders();
+ $allowed = $note->getRelevantServers();
+ if (!in_array($instance, $allowed)) {
+ throw new Forbidden();
+ }
+ }
json_response($note);
});
@@ -28,5 +40,12 @@ Router::getInstance()->mount('/@/:handle/note/:id', function (array $args) {
if ($args['handle'] != $note->author->getFullHandle()) {
throw new TemporaryRedirect('/@/' . $note->author->getFullHandle() . "/note/$note->id");
}
+ // check the current user is allowed to see it
+ if ($note->privacy->scope != NotePrivacyScope::PUBLIC ) {
+ $user = UserAccount::requireByCurrentSession();
+ if (!in_array($user->actor, $note->getRelevantActors())) {
+ throw new Forbidden();
+ }
+ }
render_template('thread_page', ['note' => $note]);
});
diff --git a/routes/note_fragment.php b/routes/note_fragment.php
index 4d8c1a6..84f68c6 100644
--- a/routes/note_fragment.php
+++ b/routes/note_fragment.php
@@ -4,6 +4,7 @@ use Digitigrade\HttpResponseStatus\BadRequest;
use Digitigrade\Model\Interaction;
use Digitigrade\Model\InteractionKind;
use Digitigrade\Model\Note;
+use Digitigrade\Model\NotePrivacyScope;
use Digitigrade\Model\UserAccount;
use Digitigrade\Router;
@@ -42,8 +43,16 @@ Router::getInstance()->mount('/fragment/note/:id/reply', function (array $args)
// replying to a note
$author = UserAccount::requireByCurrentSession();
$note = Note::find($args['id']);
- if (isset($_POST['content'])) {
- $reply = Note::create($author->actor, $_POST['content'], 'unk');
+ if (isset($_POST['content']) && strlen(trim($_POST['content'])) > 0) {
+ $summary = trim($_POST['summary'] ?? '');
+ $summary = $summary == '' ? null : $summary;
+ $reply = Note::create(
+ $author->actor,
+ trim($_POST['content']),
+ 'unk',
+ $summary,
+ $note->privacy->scope
+ );
$reply->inReplyTo = $note;
$reply->threadApex = $note->threadApex ?? $note;
$reply->save();
@@ -56,9 +65,17 @@ Router::getInstance()->mount('/fragment/note/:id/reply', function (array $args)
Router::getInstance()->mount('/fragment/note', function (array $args) {
// posting a new note
$author = UserAccount::requireByCurrentSession();
- if (isset($_POST['content'])) {
- // TODO: summary field, post language, privacy, etc
- $note = Note::create($author->actor, $_POST['content'], 'unk');
+ if (isset($_POST['content']) && strlen(trim($_POST['content'])) > 0) {
+ // TODO: post language, other privacy options, etc
+ $summary = trim($_POST['summary'] ?? '');
+ $summary = $summary == '' ? null : $summary;
+ $note = Note::create(
+ $author->actor,
+ trim($_POST['content']),
+ 'unk',
+ $summary,
+ NotePrivacyScope::from($_POST['scope'])
+ );
$note->publish();
$note->processTimelineAdditions();
}