federator/php/federator/jobs/newContentJob.php
Yannis Vogel 96bb1efe16
support external services to comment&like on CN
- integrate support to send new posts to CN
- save original article-id in DB (needs db-migration)
- votes and comments on CN-articles and comments are sent to CN, with proper signing and format
- fixed minor issue where delete-activity was not properly working with objects
- fixed minor issue where tombstone wasn't supported (which prevented being able to delete mastodon-posts from the db)
2025-05-28 16:52:20 +02:00

74 lines
No EOL
1.6 KiB
PHP

<?php
namespace Federator\Jobs;
class NewContentJob extends \Federator\Api
{
/** @var array<string, mixed> $args Arguments for the job */
public $args = [];
/**
* cache instance
*
* @var \Federator\Cache\Cache $cache
*/
protected $cache;
/**
* remote connector
*
* @var \Federator\Connector\Connector $connector
*/
protected $connector = null;
/**
* database instance
*
* @var \Mysqli $dbh
*/
protected $dbh;
/**
* constructor
*/
public function __construct()
{
parent::__construct();
}
/**
* Set up environment for this job
*/
public function setUp(): void
{
$this->openDatabase();
$this->loadPlugins();
}
/**
* Perform the inbox job.
*
* @return bool true on success, false on failure
*/
public function perform(): bool
{
error_log("NewContentJob: Starting job");
$user = $this->args['user'];
$recipientId = $this->args['recipientId'];
$activity = $this->args['activity'];
$articleId = $this->args['articleId'] ?? null;
$activity = \Federator\Data\ActivityPub\Factory::newActivityFromJson($activity);
if ($activity === false) {
error_log("NewContentJob: Failed to create activity from JSON");
return false;
}
$domain = $this->config['generic']['externaldomain'];
$ourUrl = 'https://' . $domain;
\Federator\Api\V1\NewContent::postForUser($this->dbh, $this->connector, $this->cache, $ourUrl, $user, $recipientId, $activity, $articleId);
return true;
}
}