mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-09 16:24:51 +00:00
Add Federated Reports
This commit is contained in:
parent
c294368b8f
commit
383c6fe8ee
3 changed files with 134 additions and 0 deletions
17
app/Models/RemoteReport.php
Normal file
17
app/Models/RemoteReport.php
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class RemoteReport extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
protected $casts = [
|
||||||
|
'status_ids' => 'array',
|
||||||
|
'action_taken_meta' => 'array',
|
||||||
|
'report_meta' => 'array'
|
||||||
|
];
|
||||||
|
}
|
|
@ -42,6 +42,7 @@ use App\Services\StatusService;
|
||||||
use App\Services\UserFilterService;
|
use App\Services\UserFilterService;
|
||||||
use App\Services\NetworkTimelineService;
|
use App\Services\NetworkTimelineService;
|
||||||
use App\Models\Conversation;
|
use App\Models\Conversation;
|
||||||
|
use App\Models\RemoteReport;
|
||||||
use App\Jobs\ProfilePipeline\IncrementPostCount;
|
use App\Jobs\ProfilePipeline\IncrementPostCount;
|
||||||
use App\Jobs\ProfilePipeline\DecrementPostCount;
|
use App\Jobs\ProfilePipeline\DecrementPostCount;
|
||||||
|
|
||||||
|
@ -122,6 +123,10 @@ class Inbox
|
||||||
$this->handleStoryReplyActivity();
|
$this->handleStoryReplyActivity();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'Flag':
|
||||||
|
$this->handleFlagActivity();
|
||||||
|
break
|
||||||
|
|
||||||
// case 'Update':
|
// case 'Update':
|
||||||
// (new UpdateActivity($this->payload, $this->profile))->handle();
|
// (new UpdateActivity($this->payload, $this->profile))->handle();
|
||||||
// break;
|
// break;
|
||||||
|
@ -1140,4 +1145,80 @@ class Inbox
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function handleFlagActivity()
|
||||||
|
{
|
||||||
|
if(!isset(
|
||||||
|
$this->payload['id'],
|
||||||
|
$this->payload['type'],
|
||||||
|
$this->payload['actor'],
|
||||||
|
$this->payload['content'],
|
||||||
|
$this->payload['object']
|
||||||
|
)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$id = $this->payload['id'];
|
||||||
|
$actor = $this->payload['actor'];
|
||||||
|
$content = Purify::clean($this->payload['content']);
|
||||||
|
$object = $this->payload['object'];
|
||||||
|
|
||||||
|
if(Helpers::validateLocalUrl($id) || parse_url($id, PHP_URL_HOST) !== parse_url($actor, PHP_URL_HOST)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!is_array($object) || empty($object)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(count($object) > 40) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$objects = collect([]);
|
||||||
|
$accountId = null;
|
||||||
|
|
||||||
|
foreach($object as $objectUrl) {
|
||||||
|
if(!Helpers::validateLocalUrl($objectUrl)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(str_contains($objectUrl, '/users/')) {
|
||||||
|
$username = last(explode('/', $objectUrl));
|
||||||
|
$profileId = Profile::whereUsername($username)->first();
|
||||||
|
if($profileId) {
|
||||||
|
$accountId = $profileId->id;
|
||||||
|
}
|
||||||
|
} else if(str_contains($object_url, '/p/')) {
|
||||||
|
$postId = last(explode('/', $objectUrl));
|
||||||
|
$objects->push($postId);
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!$accountId || !$objects->count()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$instanceHost = parse_url($id, PHP_URL_HOST);
|
||||||
|
|
||||||
|
$instance = Instance::updateOrCreate([
|
||||||
|
'domain' => $instanceHost
|
||||||
|
]);
|
||||||
|
|
||||||
|
$report = new RemoteReport;
|
||||||
|
$report->status_ids = $objects->toArray();
|
||||||
|
$report->comment = $content;
|
||||||
|
$report->account_id = $accountId;
|
||||||
|
$report->uri = $id;
|
||||||
|
$report->instance_id = $instance->id;
|
||||||
|
$report->report_meta = [
|
||||||
|
'actor' => $actor,
|
||||||
|
'object' => $object
|
||||||
|
];
|
||||||
|
$report->save();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('remote_reports', function (Blueprint $table) {
|
||||||
|
$table->bigIncrements('id');
|
||||||
|
$table->json('status_ids')->nullable();
|
||||||
|
$table->text('comment')->nullable();
|
||||||
|
$table->bigInteger('account_id')->unsigned()->nullable();
|
||||||
|
$table->string('uri')->nullable();
|
||||||
|
$table->unsignedInteger('instance_id')->nullable();
|
||||||
|
$table->timestamp('action_taken_at')->nullable()->index();
|
||||||
|
$table->json('report_meta')->nullable();
|
||||||
|
$table->json('action_taken_meta')->nullable();
|
||||||
|
$table->bigInteger('action_taken_by_account_id')->unsigned()->nullable();
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('remote_reports');
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in a new issue