mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-14 02:24:31 +00:00
commit
7ad48807f1
3 changed files with 135 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'
|
||||||
|
];
|
||||||
|
}
|
|
@ -8,6 +8,7 @@ use App\{
|
||||||
DirectMessage,
|
DirectMessage,
|
||||||
Follower,
|
Follower,
|
||||||
FollowRequest,
|
FollowRequest,
|
||||||
|
Instance,
|
||||||
Like,
|
Like,
|
||||||
Notification,
|
Notification,
|
||||||
Media,
|
Media,
|
||||||
|
@ -42,6 +43,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 +124,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 +1146,80 @@ class Inbox
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function handleFlagActivity()
|
||||||
|
{
|
||||||
|
if(!isset(
|
||||||
|
$this->payload['id'],
|
||||||
|
$this->payload['type'],
|
||||||
|
$this->payload['actor'],
|
||||||
|
$this->payload['object']
|
||||||
|
)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$id = $this->payload['id'];
|
||||||
|
$actor = $this->payload['actor'];
|
||||||
|
|
||||||
|
if(Helpers::validateLocalUrl($id) || parse_url($id, PHP_URL_HOST) !== parse_url($actor, PHP_URL_HOST)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$content = isset($this->payload['content']) ? Purify::clean($this->payload['content']) : null;
|
||||||
|
$object = $this->payload['object'];
|
||||||
|
|
||||||
|
if(empty($object) || (!is_array($object) && !is_string($object))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_array($object) && count($object) > 100) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$objects = collect([]);
|
||||||
|
$accountId = null;
|
||||||
|
|
||||||
|
foreach($object as $objectUrl) {
|
||||||
|
if(!Helpers::validateLocalUrl($objectUrl)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(str_contains($objectUrl, '/users/')) {
|
||||||
|
$username = last(explode('/', $objectUrl));
|
||||||
|
$profileId = Profile::whereUsername($username)->first();
|
||||||
|
if($profileId) {
|
||||||
|
$accountId = $profileId->id;
|
||||||
|
}
|
||||||
|
} else if(str_contains($objectUrl, '/p/')) {
|
||||||
|
$postId = last(explode('/', $objectUrl));
|
||||||
|
$objects->push($postId);
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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