From 937cdfb7f96e26e3385872a82686716dff62e946 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 21 Dec 2021 21:40:10 -0700 Subject: [PATCH] Update StatusService --- app/Services/StatusService.php | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/app/Services/StatusService.php b/app/Services/StatusService.php index c13ddd58..9f00ab2b 100644 --- a/app/Services/StatusService.php +++ b/app/Services/StatusService.php @@ -41,6 +41,25 @@ class StatusService }); } + public static function getState($id, $pid) + { + $status = self::get($id, false); + + if(!$status) { + return [ + 'liked' => false, + 'shared' => false, + 'bookmarked' => false + ]; + } + + return [ + 'liked' => LikeService::liked($pid, $id), + 'shared' => self::isShared($id, $pid), + 'bookmarked' => self::isBookmarked($id, $pid) + ]; + } + public static function getFull($id, $pid, $publicOnly = true) { $res = self::get($id, $publicOnly); @@ -89,4 +108,24 @@ class StatusService self::get($id, false); self::get($id, true); } + + public static function isShared($id, $pid = null) + { + return $pid ? + DB::table('statuses') + ->where('reblog_of_id', $id) + ->where('profile_id', $pid) + ->exists() : + false; + } + + public static function isBookmarked($id, $pid = null) + { + return $pid ? + DB::table('bookmarks') + ->where('status_id', $id) + ->where('profile_id', $pid) + ->exists() : + false; + } }