소스 검색

Update StatusService

Daniel Supernault 3 년 전
부모
커밋
937cdfb7f9
1개의 변경된 파일39개의 추가작업 그리고 0개의 파일을 삭제
  1. 39 0
      app/Services/StatusService.php

+ 39 - 0
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;
+	}
 }