Przeglądaj źródła

Add BookmarkService

Daniel Supernault 3 lat temu
rodzic
commit
0157566c25

+ 16 - 0
app/Services/BookmarkService.php

@@ -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();
+		// });
+	}
+}

+ 4 - 1
app/Transformer/Api/StatusTransformer.php

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