php-plug-web3/src/Lemmy/Delete.php
Snider 79d206009c feat: extract Web3 providers from app/Plug/Web3
Bluesky, Farcaster, Lemmy, Mastodon, Nostr, Threads
providers with Core\Plug\Web3 namespace alignment.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 17:28:07 +00:00

75 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
namespace Core\Plug\Web3\Lemmy;
use Core\Plug\Concern\BuildsResponse;
use Core\Plug\Concern\ManagesTokens;
use Core\Plug\Concern\UsesHttp;
use Core\Plug\Contract\Deletable;
use Core\Plug\Response;
/**
* Lemmy post deletion.
*/
class Delete implements Deletable
{
use BuildsResponse;
use ManagesTokens;
use UsesHttp;
private string $instanceUrl = '';
/**
* Set the instance URL.
*/
public function forInstance(string $instanceUrl): self
{
$this->instanceUrl = rtrim($instanceUrl, '/');
return $this;
}
/**
* Delete a post.
*/
public function delete(string $id): Response
{
if (! $this->instanceUrl) {
return $this->error('Instance URL is required');
}
$response = $this->http()
->withHeaders(['Authorization' => 'Bearer '.$this->accessToken()])
->post($this->instanceUrl.'/api/v3/post/delete', [
'post_id' => (int) $id,
'deleted' => true,
]);
return $this->fromHttp($response, fn () => [
'deleted' => true,
]);
}
/**
* Delete a comment.
*/
public function deleteComment(int $commentId): Response
{
if (! $this->instanceUrl) {
return $this->error('Instance URL is required');
}
$response = $this->http()
->withHeaders(['Authorization' => 'Bearer '.$this->accessToken()])
->post($this->instanceUrl.'/api/v3/comment/delete', [
'comment_id' => $commentId,
'deleted' => true,
]);
return $this->fromHttp($response, fn () => [
'deleted' => true,
]);
}
}