From 29b1af100cbc38b693ac7b0f4f81c06ecc71d44c Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Fri, 10 Feb 2023 02:01:15 -0700 Subject: [PATCH 01/11] Update ApiV1Controller, add BookmarkService logic to bookmark endpoints --- app/Http/Controllers/Api/ApiV1Controller.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index 8e9e7375..5dafa320 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -2376,6 +2376,7 @@ class ApiV1Controller extends Controller $res['favourited'] = LikeService::liked($user->profile_id, $res['id']); $res['reblogged'] = ReblogService::get($user->profile_id, $res['id']); + $res['bookmarked'] = BookmarkService::get($user->profile_id, $res['id']); return $this->json($res); } @@ -3064,7 +3065,10 @@ class ApiV1Controller extends Controller 'status_id' => $status->id, 'profile_id' => $request->user()->profile_id ]); + + BookmarkService::add($request->user()->profile_id, $status->id); $res = StatusService::getMastodon($status->id); + $res['bookmarked'] = true; return $this->json($res); } @@ -3086,9 +3090,14 @@ class ApiV1Controller extends Controller $bookmark = Bookmark::whereStatusId($status->id) ->whereProfileId($request->user()->profile_id) - ->firstOrFail(); - $bookmark->delete(); + ->first(); + + if($bookmark) { + BookmarkService::del($request->user()->profile_id, $status->id); + $bookmark->delete(); + } $res = StatusService::getMastodon($status->id); + $res['bookmarked'] = false; return $this->json($res); } From e8a6a8c71e4c57f139836f9ad63471f14f6409cc Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Fri, 10 Feb 2023 02:02:07 -0700 Subject: [PATCH 02/11] Update ApiV1Controller, filter conversations without last_status --- app/Http/Controllers/Api/ApiV1Controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index 5dafa320..edc5e48f 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -2335,7 +2335,7 @@ class ApiV1Controller extends Controller return $res; }) ->filter(function($dm) { - return isset($dm['accounts']) && count($dm['accounts']); + return isset($dm['accounts']) && count($dm['accounts']) && !empty($dm['last_status']); }) ->unique(function($item, $key) { return $item['accounts'][0]['id']; From 025e685f39979ededfe8349f77a3f138afde8317 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Fri, 10 Feb 2023 02:12:18 -0700 Subject: [PATCH 03/11] Update PostReactions partial, hide bookmark button unless post has public visibility --- .../partials/post/PostReactions.vue | 251 ++++++++++++++++++ 1 file changed, 251 insertions(+) create mode 100644 resources/assets/components/partials/post/PostReactions.vue diff --git a/resources/assets/components/partials/post/PostReactions.vue b/resources/assets/components/partials/post/PostReactions.vue new file mode 100644 index 00000000..7fec7813 --- /dev/null +++ b/resources/assets/components/partials/post/PostReactions.vue @@ -0,0 +1,251 @@ + + + From fe9c60480459ce69033411411ed52c69b853c2a1 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Fri, 10 Feb 2023 02:51:59 -0700 Subject: [PATCH 04/11] Update editorconfig --- .editorconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/.editorconfig b/.editorconfig index 6b67635e..1cd7d107 100644 --- a/.editorconfig +++ b/.editorconfig @@ -2,6 +2,7 @@ root = true [*] indent_size = 4 +indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true From e343061a13d2400beecda42efed29ffbeb805bf4 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Fri, 10 Feb 2023 04:06:18 -0700 Subject: [PATCH 05/11] Update ApiV1Controller and BookmarkController, fix api differences and allow unbookmarking regardless of relationship --- app/Http/Controllers/Api/ApiV1Controller.php | 50 ++++++++---- app/Http/Controllers/BookmarkController.php | 80 +++++++++++--------- 2 files changed, 81 insertions(+), 49 deletions(-) diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index edc5e48f..2c8ebfbd 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -3018,8 +3018,15 @@ class ApiV1Controller extends Controller ->orderByDesc('id') ->cursorPaginate($limit); - $bookmarks = $bookmarkQuery->map(function($bookmark) { - return \App\Services\StatusService::getMastodon($bookmark->status_id); + $bookmarks = $bookmarkQuery->map(function($bookmark) use($pid) { + $status = StatusService::getMastodon($bookmark->status_id, false); + + if($status) { + $status['bookmarked'] = true; + $status['favourited'] = LikeService::liked($pid, $status['id']); + $status['reblogged'] = ReblogService::get($pid, $status['id']); + } + return $status; }) ->filter() ->values() @@ -3057,17 +3064,29 @@ class ApiV1Controller extends Controller { abort_if(!$request->user(), 403); - $status = Status::whereNull('uri') - ->whereScope('public') - ->findOrFail($id); + $status = Status::findOrFail($id); + $pid = $request->user()->profile_id; + + abort_if($status->in_reply_to_id || $status->reblog_of_id, 404); + abort_if(!in_array($status->scope, ['public', 'unlisted', 'private']), 404); + abort_if(!in_array($status->type, ['photo','photo:album', 'video', 'video:album', 'photo:video:album']), 404); + + if($status->scope == 'private') { + abort_if( + $pid !== $status->profile_id && !FollowerService::follows($pid, $status->profile_id), + 404, + 'Error: You cannot bookmark private posts from accounts you do not follow.' + ); + } Bookmark::firstOrCreate([ 'status_id' => $status->id, - 'profile_id' => $request->user()->profile_id + 'profile_id' => $pid ]); - BookmarkService::add($request->user()->profile_id, $status->id); - $res = StatusService::getMastodon($status->id); + BookmarkService::add($pid, $status->id); + + $res = StatusService::getMastodon($status->id, false); $res['bookmarked'] = true; return $this->json($res); @@ -3084,19 +3103,22 @@ class ApiV1Controller extends Controller { abort_if(!$request->user(), 403); - $status = Status::whereNull('uri') - ->whereScope('public') - ->findOrFail($id); + $status = Status::findOrFail($id); + $pid = $request->user()->profile_id; + + abort_if($status->in_reply_to_id || $status->reblog_of_id, 404); + abort_if(!in_array($status->scope, ['public', 'unlisted', 'private']), 404); + abort_if(!in_array($status->type, ['photo','photo:album', 'video', 'video:album', 'photo:video:album']), 404); $bookmark = Bookmark::whereStatusId($status->id) - ->whereProfileId($request->user()->profile_id) + ->whereProfileId($pid) ->first(); if($bookmark) { - BookmarkService::del($request->user()->profile_id, $status->id); + BookmarkService::del($pid, $status->id); $bookmark->delete(); } - $res = StatusService::getMastodon($status->id); + $res = StatusService::getMastodon($status->id, false); $res['bookmarked'] = false; return $this->json($res); diff --git a/app/Http/Controllers/BookmarkController.php b/app/Http/Controllers/BookmarkController.php index f5f59457..a24520d6 100644 --- a/app/Http/Controllers/BookmarkController.php +++ b/app/Http/Controllers/BookmarkController.php @@ -11,47 +11,57 @@ use App\Services\FollowerService; class BookmarkController extends Controller { - public function __construct() - { - $this->middleware('auth'); - } + public function __construct() + { + $this->middleware('auth'); + } - public function store(Request $request) - { - $this->validate($request, [ - 'item' => 'required|integer|min:1', - ]); + public function store(Request $request) + { + $this->validate($request, [ + 'item' => 'required|integer|min:1', + ]); - $profile = Auth::user()->profile; - $status = Status::findOrFail($request->input('item')); + $profile = Auth::user()->profile; + $status = Status::findOrFail($request->input('item')); - abort_if(!in_array($status->scope, ['public', 'unlisted', 'private']), 404); + abort_if($status->in_reply_to_id || $status->reblog_of_id, 404); + abort_if(!in_array($status->scope, ['public', 'unlisted', 'private']), 404); + abort_if(!in_array($status->type, ['photo','photo:album', 'video', 'video:album', 'photo:video:album']), 404); - if($status->scope == 'private') { - abort_if( - $profile->id !== $status->profile_id && !FollowerService::follows($profile->id, $status->profile_id), - 404, - 'Error: You cannot bookmark private posts from accounts you do not follow.' - ); - } + if($status->scope == 'private') { + if($profile->id !== $status->profile_id && !FollowerService::follows($profile->id, $status->profile_id)) { + if($exists = Bookmark::whereStatusId($status->id)->whereProfileId($profile->id)->first()) { + BookmarkService::del($profile->id, $status->id); + $exists->delete(); - $bookmark = Bookmark::firstOrCreate( - ['status_id' => $status->id], ['profile_id' => $profile->id] - ); + if ($request->ajax()) { + return ['code' => 200, 'msg' => 'Bookmark removed!']; + } else { + return redirect()->back(); + } + } + abort(404, 'Error: You cannot bookmark private posts from accounts you do not follow.'); + } + } - if (!$bookmark->wasRecentlyCreated) { - BookmarkService::del($profile->id, $status->id); - $bookmark->delete(); - } else { - BookmarkService::add($profile->id, $status->id); - } + $bookmark = Bookmark::firstOrCreate( + ['status_id' => $status->id], ['profile_id' => $profile->id] + ); - if ($request->ajax()) { - $response = ['code' => 200, 'msg' => 'Bookmark saved!']; - } else { - $response = redirect()->back(); - } + if (!$bookmark->wasRecentlyCreated) { + BookmarkService::del($profile->id, $status->id); + $bookmark->delete(); + } else { + BookmarkService::add($profile->id, $status->id); + } - return $response; - } + if ($request->ajax()) { + $response = ['code' => 200, 'msg' => 'Bookmark saved!']; + } else { + $response = redirect()->back(); + } + + return $response; + } } From 64b6d2d5a7233db4e195124ea9d99f5cbe6cd194 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Fri, 10 Feb 2023 04:08:27 -0700 Subject: [PATCH 06/11] Update PostReactions, fix bookmark button visibility --- resources/assets/components/partials/post/PostReactions.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/assets/components/partials/post/PostReactions.vue b/resources/assets/components/partials/post/PostReactions.vue index 7fec7813..96d65935 100644 --- a/resources/assets/components/partials/post/PostReactions.vue +++ b/resources/assets/components/partials/post/PostReactions.vue @@ -71,7 +71,7 @@