From 148dd6db50754b13d89201e4383bea5e2409df43 Mon Sep 17 00:00:00 2001 From: Phablulo Date: Sun, 16 Jan 2022 14:56:53 -0300 Subject: [PATCH] [PLUGINS][PinnedNotes] Basic activityPub support --- plugins/PinnedNotes/PinnedNotes.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/plugins/PinnedNotes/PinnedNotes.php b/plugins/PinnedNotes/PinnedNotes.php index 912d674f50..75e538af62 100644 --- a/plugins/PinnedNotes/PinnedNotes.php +++ b/plugins/PinnedNotes/PinnedNotes.php @@ -129,4 +129,21 @@ class PinnedNotes extends Plugin $styles[] = 'plugins/PinnedNotes/assets/css/pinned-notes.css'; return Event::next; } + + // Activity Pub handling stuff + public function onActivityPubAddActivityStreamsTwoData(string $type_name, &$type): bool + { + if ($type_name === 'Note') { + $actor = \Plugin\ActivityPub\ActivityPub::getActorByUri($type->get('attributedTo')); + // Note uri is `https://domain:port/object/note/3`. + // is it always like that? I honestly don't know, but I see + // no other way of getting Note id: + $uri_parts = explode('/', $type->get('id')); + $note_id = end($uri_parts); + $is_pinned = !\is_null(DB::findOneBy(E\PinnedNotes::class, ['actor_id' => $actor->getId(), 'note_id' => $note_id], return_null: true)); + + $type->set('pinned', $is_pinned); + } + return Event::next; + } }