diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index 35cc3231f..7ea3f5133 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -65,6 +65,7 @@ use App\Services\{ NotificationService, MediaPathService, PublicTimelineService, + ReblogService, RelationshipService, SearchApiV2Service, StatusService, @@ -1646,6 +1647,7 @@ class ApiV1Controller extends Controller if($pid) { $status['favourited'] = (bool) LikeService::liked($pid, $s['id']); + $status['reblogged'] = (bool) ReblogService::get($pid, $status['id']); } return $status; }) @@ -1676,6 +1678,7 @@ class ApiV1Controller extends Controller if($pid) { $status['favourited'] = (bool) LikeService::liked($pid, $s['id']); + $status['reblogged'] = (bool) ReblogService::get($pid, $status['id']); } return $status; }) @@ -1798,6 +1801,7 @@ class ApiV1Controller extends Controller if($user) { $status['favourited'] = (bool) LikeService::liked($user->profile_id, $k); + $status['reblogged'] = (bool) ReblogService::get($user->profile_id, $status['id']); } return $status; }) @@ -1839,7 +1843,7 @@ class ApiV1Controller extends Controller } $res['favourited'] = LikeService::liked($user->profile_id, $res['id']); - $res['reblogged'] = false; + $res['reblogged'] = ReblogService::get($user->profile_id, $res['id']); return response()->json($res); } @@ -2238,7 +2242,7 @@ class ApiV1Controller extends Controller } StatusService::del($status->id); - + ReblogService::add($user->profile_id, $status->id); $res = StatusService::getMastodon($status->id); $res['reblogged'] = true; @@ -2278,6 +2282,7 @@ class ApiV1Controller extends Controller } UndoSharePipeline::dispatch($reblog); + ReblogService::del($user->profile_id, $status->id); $res = StatusService::getMastodon($status->id); $res['reblogged'] = true; diff --git a/app/Http/Controllers/PublicApiController.php b/app/Http/Controllers/PublicApiController.php index 245c78004..dc2051a4f 100644 --- a/app/Http/Controllers/PublicApiController.php +++ b/app/Http/Controllers/PublicApiController.php @@ -32,6 +32,7 @@ use App\Services\{ LikeService, PublicTimelineService, ProfileService, + ReblogService, RelationshipService, StatusService, SnowflakeService, @@ -329,6 +330,7 @@ class PublicApiController extends Controller } $status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id); $status['bookmarked'] = (bool) BookmarkService::get($user->profile_id, $s->id); + $status['reblogged'] = (bool) ReblogService::get($user->profile_id, $s->id); return $status; }) ->filter(function($s) use($filtered) { @@ -372,6 +374,7 @@ class PublicApiController extends Controller } $status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id); $status['bookmarked'] = (bool) BookmarkService::get($user->profile_id, $s->id); + $status['reblogged'] = (bool) ReblogService::get($user->profile_id, $s->id); return $status; }) ->filter(function($s) use($filtered) { @@ -402,7 +405,7 @@ class PublicApiController extends Controller if($user) { $status['favourited'] = (bool) LikeService::liked($user->profile_id, $k); $status['bookmarked'] = (bool) BookmarkService::get($user->profile_id, $k); - + $status['reblogged'] = (bool) ReblogService::get($user->profile_id, $k); $status['relationship'] = RelationshipService::get($user->profile_id, $status['account']['id']); } return $status; @@ -524,6 +527,7 @@ class PublicApiController extends Controller } $status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id); $status['bookmarked'] = (bool) BookmarkService::get($user->profile_id, $s->id); + $status['reblogged'] = (bool) ReblogService::get($user->profile_id, $s->id); return $status; }) ->filter(function($s) use($filtered) { @@ -569,6 +573,7 @@ class PublicApiController extends Controller } $status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id); $status['bookmarked'] = (bool) BookmarkService::get($user->profile_id, $s->id); + $status['reblogged'] = (bool) ReblogService::get($user->profile_id, $s->id); return $status; }) ->filter(function($s) use($filtered) { @@ -623,6 +628,8 @@ class PublicApiController extends Controller ->map(function($s) use ($user) { $status = StatusService::get($s->id); $status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id); + $status['bookmarked'] = (bool) BookmarkService::get($user->profile_id, $s->id); + $status['reblogged'] = (bool) ReblogService::get($user->profile_id, $s->id); return $status; }); $res = $timeline->toArray(); @@ -646,6 +653,8 @@ class PublicApiController extends Controller ->map(function($s) use ($user) { $status = StatusService::get($s->id); $status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id); + $status['bookmarked'] = (bool) BookmarkService::get($user->profile_id, $s->id); + $status['reblogged'] = (bool) ReblogService::get($user->profile_id, $s->id); return $status; }); $res = $timeline->toArray(); diff --git a/app/Http/Controllers/StatusController.php b/app/Http/Controllers/StatusController.php index 71cd5b7d6..91c187a38 100644 --- a/app/Http/Controllers/StatusController.php +++ b/app/Http/Controllers/StatusController.php @@ -25,6 +25,7 @@ use Illuminate\Support\Str; use App\Services\HashidService; use App\Services\StatusService; use App\Util\Media\License; +use App\Services\ReblogService; class StatusController extends Controller { @@ -245,6 +246,7 @@ class StatusController extends Controller ->get(); foreach ($shares as $share) { UndoSharePipeline::dispatch($share); + ReblogService::del($profile->id, $status->id); $count--; } } else { @@ -255,6 +257,7 @@ class StatusController extends Controller $share->save(); $count++; SharePipeline::dispatch($share); + ReblogService::add($profile->id, $status->id); } Cache::forget('status:'.$status->id.':sharedby:userid:'.$user->id); diff --git a/app/Services/ReblogService.php b/app/Services/ReblogService.php new file mode 100644 index 000000000..f6655c8f6 --- /dev/null +++ b/app/Services/ReblogService.php @@ -0,0 +1,29 @@ +where('reblog_of_id', $id) - ->where('profile_id', $pid) - ->exists() : + ReblogService::get($pid, $id) : false; }