From 8de5608976dc8a73a400267601acb4c8e127de5a Mon Sep 17 00:00:00 2001 From: winter Date: Thu, 16 Jan 2025 18:33:18 +0000 Subject: note privacy and summary stuff --- routes/note_fragment.php | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'routes/note_fragment.php') 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(); } -- cgit v1.3