Add BookmarkService

This commit is contained in:
Daniel Supernault 2022-01-27 05:17:55 -07:00
parent c0b1e0427e
commit 0157566c25
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
2 changed files with 20 additions and 1 deletions

View file

@ -0,0 +1,16 @@
<?php
namespace App\Services;
use App\Bookmark;
use Illuminate\Support\Facades\Cache;
class BookmarkService
{
public static function get($profileId, $statusId)
{
// return Cache::remember('pf:bookmarks:' . $profileId . ':' . $statusId, 84600, function() use($profileId, $statusId) {
return Bookmark::whereProfileId($profileId)->whereStatusId($statusId)->exists();
// });
}
}

View file

@ -17,13 +17,15 @@ use App\Services\ProfileService;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use App\Services\PollService; use App\Services\PollService;
use App\Models\CustomEmoji; use App\Models\CustomEmoji;
use App\Services\BookmarkService;
class StatusTransformer extends Fractal\TransformerAbstract class StatusTransformer extends Fractal\TransformerAbstract
{ {
public function transform(Status $status) public function transform(Status $status)
{ {
$pid = request()->user()->profile_id;
$taggedPeople = MediaTagService::get($status->id); $taggedPeople = MediaTagService::get($status->id);
$poll = $status->type === 'poll' ? PollService::get($status->id, request()->user()->profile_id) : null; $poll = $status->type === 'poll' ? PollService::get($status->id, $pid) : null;
return [ return [
'_v' => 1, '_v' => 1,
@ -69,6 +71,7 @@ class StatusTransformer extends Fractal\TransformerAbstract
'account' => ProfileService::get($status->profile_id), 'account' => ProfileService::get($status->profile_id),
'tags' => StatusHashtagService::statusTags($status->id), 'tags' => StatusHashtagService::statusTags($status->id),
'poll' => $poll, 'poll' => $poll,
'bookmarked' => BookmarkService::get($pid, $status->id),
]; ];
} }
} }