Skip to content
Snippets Groups Projects
Commit 029db29a authored by Kristof De Jaeger's avatar Kristof De Jaeger
Browse files

Remove ActivityPub plugin

parent fec8184b
Branches
Tags 8.x-1.13
No related merge requests found
......@@ -468,9 +468,7 @@ content types or comments where needed. Posts, replies, likes, boosts and follow
- If you use a microsub server, you can subscribe to fediverse users through the microformats feed.
If you want to interact with the Fediverse using Drupal itself, you can also install the ActivityPub module
for Drupal: https://drupal.org/project/activitypub and then use the ActivityPub plugin in the Microsub module
at admin/config/services/indieweb/microsub to read incoming content from users you follow or interactions
on your content.
for Drupal: https://drupal.org/project/activitypub.
## Caching of image files
......
......@@ -10,5 +10,3 @@ aperture_enable_micropub: false
aperture_api_key: ''
push_notification_indigenous: false
push_notification_indigenous_key: ''
activitypub_channel: ''
activitypub_items_in_feed: 100
......@@ -42,9 +42,3 @@ indieweb_microsub.settings:
push_notification_indigenous_key:
type: string
label: 'Push notification Indigenous API key'
activitypub_channel:
type: string
label: 'The channel ID to save an incoming activity to'
activitypub_items_in_feed:
type: integer
label: 'The number of items to keep in this channel'
......@@ -54,28 +54,4 @@ class MicrosubCommands extends DrushCommands {
print_r($feeds);
}
/**
* Test Microsub ActivityPub plugin.
*
* @command indieweb:microsub-test-activity-plugin
*
* @param $activityId
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
public function testActivityParsing($activityId) {
/** @var \Drupal\activitypub\Entity\ActivityPubActivityInterface $activity */
$activity = \Drupal::entityTypeManager()->getStorage('activitypub_activity')->load($activityId);
if (!$activity) {
echo "No activity found";
return;
}
/** @var \Drupal\activitypub\Services\Type\TypePluginInterface $object */
$object = $activity->getTypePluginManager()->createInstance('activitypub_microsub');
$object->onActivityPostSave($activity, FALSE);
}
}
......@@ -181,34 +181,6 @@ class MicrosubSettingsForm extends ConfigFormBase {
'#default_value' => $config->get('push_notification_indigenous_key'),
];
$form['activitypub'] = [
'#type' => 'fieldset',
'#title' => $this->t('Activitypub'),
'#description' => $this->t('If you use the <a href="https://www.drupal.org/project/activitypub" target="_blank">ActivityPub</a> module, you can save incoming activities to a Microsub channel.<br />It will save posts, replies etc and push notifications will be sent too if configured.'),
'#states' => array(
'visible' => array(
':input[name="microsub_internal"]' => array('checked' => TRUE),
),
),
'#access' => \Drupal::moduleHandler()->moduleExists('activitypub'),
];
$form['activitypub']['activitypub_channel'] = [
'#title' => $this->t('Channel ID'),
'#description' => $this->t('The channel ID to save to. Leave empty to disable this feature.'),
'#type' => 'number',
'#min' => 0,
'#default_value' => $config->get('activitypub_channel'),
];
$form['activitypub']['activitypub_items_in_feed'] = [
'#title' => $this->t('Items to keep'),
'#description' => $this->t('Number of read items to keep in the feed. Set to 0 to keep all.'),
'#type' => 'number',
'#min' => 0,
'#default_value' => $config->get('activitypub_items_in_feed'),
];
return parent::buildForm($form, $form_state);
}
......@@ -231,8 +203,6 @@ class MicrosubSettingsForm extends ConfigFormBase {
->set('aperture_api_key', $form_state->getValue('aperture_api_key'))
->set('push_notification_indigenous', $form_state->getValue('push_notification_indigenous'))
->set('push_notification_indigenous_key', $form_state->getValue('push_notification_indigenous_key'))
->set('activitypub_channel', $form_state->getValue('activitypub_channel'))
->set('activitypub_items_in_feed', $form_state->getValue('activitypub_items_in_feed'))
->save();
Cache::invalidateTags(['rendered']);
......
<?php
namespace Drupal\indieweb_microsub\Plugin\activitypub\type;
use Drupal\activitypub\Entity\ActivityPubActivityInterface;
use Drupal\activitypub\Services\Type\TypePluginBase;
use p3k\XRay;
/**
* The ActivityPub static types.
*
* @ActivityPubType(
* id = "activitypub_microsub",
* label = @Translation("ActivityPub microsub integration")
* )
*/
class Microsub extends TypePluginBase {
/**
* {@inheritdoc}
*/
public function isExposed() {
return FALSE;
}
/**
* {@inheritdoc}
*/
public function onActivityPostSave(ActivityPubActivityInterface $activity, $update = TRUE) {
if (!$update && $activity->getCollection() == 'inbox' && ($channel_id = $this->configFactory->get('indieweb_microsub.settings')->get('activitypub_channel')) && is_numeric($channel_id)) {
$json = @json_decode($activity->getPayLoad(), TRUE);
$xray = new XRay();
$parsed = $xray->parse($json['id'], $json);
if ($parsed && !empty($parsed['data']['type']) && $parsed['data']['type'] != 'unknown') {
$target = \Drupal::request()->getSchemeAndHttpHost();
if (!empty($json['object']['inReplyTo'])) {
$target = $json['object']['inReplyTo'];
}
$values = [
'source' => $json['id'],
'target' => $target,
'author_name' => $parsed['data']['author']['name'],
];
/** @var \Drupal\indieweb_webmention\Entity\WebmentionInterface $webmention */
$webmention = \Drupal::entityTypeManager()->getStorage('indieweb_webmention')->create($values);
/** @var \Drupal\indieweb_microsub\MicrosubClient\MicrosubClientInterface $microsubClient */
$microsubClient = \Drupal::service('indieweb.microsub.client');
$microsubClient->sendNotification($webmention, $parsed, $channel_id);
// Send push notification if there's an in-reply-to and the host matches
// this one.
if (!empty($parsed['data']['in-reply-to'][0]) && strpos($parsed['data']['in-reply-to'][0], \Drupal::request()->getSchemeAndHttpHost()) !== FALSE) {
$microsubClient->sendPushNotification([$webmention]);
}
// Cleanup items.
$items_to_keep = $this->configFactory->get('indieweb_microsub.settings')->get('activitypub_items_in_feed');
if ($items_to_keep) {
$guids = [$parsed['url']];
$items_to_keep += 5;
$timestamp = \Drupal::entityTypeManager()->getStorage('indieweb_microsub_item')->getTimestampByRangeSourceAndChannel($items_to_keep, $channel_id, 0);
if ($timestamp) {
\Drupal::entityTypeManager()->getStorage('indieweb_microsub_item')->removeItemsBySourceAndChannelOlderThanTimestamp($timestamp, $channel_id, 0, $guids);
}
}
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment