1
0
Fork 1
mirror of https://github.com/pixelfed/pixelfed.git synced 2024-12-21 23:32:39 +00:00

Add StatusView model to store views for discover algorithm

This commit is contained in:
Daniel Supernault 2020-12-26 20:16:35 -07:00
parent ea0c1e80c6
commit 7a68ee948a
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
3 changed files with 61 additions and 0 deletions

View file

@ -10,6 +10,7 @@ use App\AccountInterstitial;
use App\Media;
use App\Profile;
use App\Status;
use App\StatusView;
use App\Transformer\ActivityPub\StatusTransformer;
use App\Transformer\ActivityPub\Verb\Note;
use App\User;
@ -59,6 +60,14 @@ class StatusController extends Controller
}
}
if($request->user() && $request->user()->profile_id != $status->profile_id) {
StatusView::firstOrCreate([
'status_id' => $status->id,
'status_profile_id' => $status->profile_id,
'profile_id' => $request->user()->profile_id
]);
}
if ($request->wantsJson() && config('federation.activitypub.enabled')) {
return $this->showActivityPub($request, $status);
}

17
app/StatusView.php Normal file
View file

@ -0,0 +1,17 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class StatusView extends Model
{
use HasFactory;
protected $fillable = [
'status_id',
'status_profile_id',
'profile_id'
];
}

View file

@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateStatusViewsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('status_views', function (Blueprint $table) {
$table->bigIncrements('id');
$table->bigInteger('status_id')->unsigned()->nullable()->index();
$table->bigInteger('status_profile_id')->unsigned()->nullable()->index();
$table->bigInteger('profile_id')->unsigned()->nullable()->index();
$table->unique(['status_id', 'profile_id']);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('status_views');
}
}