aboutsummaryrefslogtreecommitdiffhomepage
path: root/routes/note_fragment.php
diff options
context:
space:
mode:
authorwinter2025-01-26 21:53:26 +0000
committerwinter2025-01-26 21:53:26 +0000
commit6b58bf53e312a67119289b894c5b482d057e5665 (patch)
treefef168089a75d73353af1a79456e711c72385ca3 /routes/note_fragment.php
parent7d3f35b1895dd3fe08af0f5fe403ff339acd2456 (diff)
make mentions work properly + ui for them
Diffstat (limited to 'routes/note_fragment.php')
-rw-r--r--routes/note_fragment.php28
1 files changed, 26 insertions, 2 deletions
diff --git a/routes/note_fragment.php b/routes/note_fragment.php
index 02399e6..74e987e 100644
--- a/routes/note_fragment.php
+++ b/routes/note_fragment.php
@@ -1,6 +1,7 @@
<?php
use Digitigrade\HttpResponseStatus\BadRequest;
+use Digitigrade\Model\Actor;
use Digitigrade\Model\Interaction;
use Digitigrade\Model\InteractionKind;
use Digitigrade\Model\Note;
@@ -56,8 +57,9 @@ Router::getInstance()->mount('/fragment/note/:id/reply', function (array $args)
);
$reply->inReplyTo = $note;
$reply->threadApex = $note->threadApex ?? $note;
- // TODO: do mentions properly and not just like this
- $reply->mentions = [$note->author];
+ foreach (($_POST['mentions'] ?? []) as $uid) {
+ $reply->mentions[] = Actor::find($uid);
+ }
$reply->save();
$reply->publish();
$reply->processTimelineAdditions();
@@ -80,9 +82,31 @@ Router::getInstance()->mount('/fragment/note', function (array $args) {
$summary,
NotePrivacyScope::from($_POST['scope'])
);
+ foreach (($_POST['mentions'] ?? []) as $uid) {
+ $note->mentions[] = Actor::find($uid);
+ }
+ $note->save();
$note->publish();
$note->processTimelineAdditions();
$note->processNotifications();
}
render_template('write_note_form', ['actor' => $author->actor]);
+});
+
+Router::getInstance()->mount('/fragment/note/mentionPill', function (array $args) {
+ // adding a mention to a new post
+ if (isset($_GET['handle'])) {
+ // look up and return a pill for the corresponding actor
+ $actor = Actor::findLocalByHandle($_GET['handle']) ?? Actor::findByWebfinger($_GET['handle']);
+ if ($actor == null) {
+ // too bad
+ render_template('user_mention_pill', ['type' => 'edit', 'invalid' => true, 'value' => $_GET['handle']]);
+ } else {
+ render_template('user_mention_pill', ['type' => 'user', 'actor' => $actor]);
+ render_template('user_mention_pill', ['type' => 'add']);
+ }
+ } else {
+ // start editing
+ render_template('user_mention_pill', ['type' => 'edit']);
+ }
}); \ No newline at end of file