[PLUGINS][PinnedNotes] Basic activityPub support

This commit is contained in:
Phablulo Joel 2022-01-16 14:56:53 -03:00 committed by Hugo Sales
parent 21c7912702
commit 148dd6db50
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
1 changed files with 17 additions and 0 deletions

View File

@ -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;
}
}