From 79976a3f8143fd2f681ce3893538973f95f648ba Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 19 Sep 2022 00:31:28 -0600 Subject: [PATCH 1/5] Update api routes --- routes/api.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/routes/api.php b/routes/api.php index 95c822562..cc147aff5 100644 --- a/routes/api.php +++ b/routes/api.php @@ -100,6 +100,7 @@ Route::group(['prefix' => 'api'], function() use($middleware) { Route::group(['prefix' => 'v1.1'], function() use($middleware) { Route::post('report', 'Api\ApiV1Dot1Controller@report')->middleware($middleware); Route::delete('accounts/avatar', 'Api\ApiV1Dot1Controller@deleteAvatar')->middleware($middleware); + Route::get('accounts/{id}/posts', 'Api\ApiV1Dot1Controller@accountPosts')->middleware($middleware); Route::group(['prefix' => 'direct'], function () use($middleware) { Route::get('thread', 'DirectMessageController@thread')->middleware($middleware); @@ -116,8 +117,9 @@ Route::group(['prefix' => 'api'], function() use($middleware) { Route::get('recent', 'StoryController@recent')->middleware($middleware); }); - Route::group(['prefix' => 'compose/v0'], function () use($middleware) { - Route::get('/search/location', 'ComposeController@searchLocation')->middleware($middleware); + Route::group(['prefix' => 'compose'], function () use($middleware) { + Route::get('search/location', 'ComposeController@searchLocation')->middleware($middleware); + Route::get('settings', 'ComposeController@composeSettings')->middleware($middleware); }); Route::group(['prefix' => 'discover'], function () use($middleware) { From ef0d1f84aed765aa0281c1745aa5a5379edaea6f Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 19 Sep 2022 00:48:08 -0600 Subject: [PATCH 2/5] Update ApiV1Controller, add optional place_id parameter to POST /api/v1/statuses endpoint --- app/Http/Controllers/Api/ApiV1Controller.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index 86db277db..e6f70bb95 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -2477,6 +2477,7 @@ class ApiV1Controller extends Controller 'sensitive' => 'nullable', 'visibility' => 'string|in:private,unlisted,public', 'spoiler_text' => 'sometimes|max:140', + 'place_id' => 'sometimes|integer|min:1|max:128769' ]); if(config('costar.enabled') == true) { @@ -2566,6 +2567,9 @@ class ApiV1Controller extends Controller $status->scope = 'draft'; $status->is_nsfw = $cw; $status->cw_summary = $spoilerText; + if($request->has('place_id')) { + $status->place_id = $request->input('place_id'); + } $status->save(); } From 4514ab1dbe82e20f0e7d925d67e19e72b9a4be34 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 19 Sep 2022 03:39:33 -0600 Subject: [PATCH 3/5] Update SettingsController, fix double json encoding and cache settings for 7 days --- app/Http/Controllers/SettingsController.php | 2 +- app/Services/AccountService.php | 40 ++++++++++--------- ...encoded_settings_in_usersettings_table.php | 38 ++++++++++++++++++ 3 files changed, 60 insertions(+), 20 deletions(-) create mode 100644 database/migrations/2022_09_19_093029_fix_double_json_encoded_settings_in_usersettings_table.php diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index 41b971bff..40691cce4 100644 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -303,7 +303,7 @@ class SettingsController extends Controller } if($changed) { - $setting->compose_settings = json_encode($compose); + $setting->compose_settings = $compose; $setting->save(); Cache::forget('profile:compose:settings:' . $request->user()->id); } diff --git a/app/Services/AccountService.php b/app/Services/AccountService.php index 3813f70fa..13cccffab 100644 --- a/app/Services/AccountService.php +++ b/app/Services/AccountService.php @@ -74,27 +74,29 @@ class AccountService public static function settings($id) { - $settings = UserSetting::whereUserId($id)->first(); - if(!$settings) { - return self::defaultSettings(); - } - return collect($settings) - ->filter(function($item, $key) { - return in_array($key, array_keys(self::defaultSettings())) == true; - }) - ->map(function($item, $key) { - if($key == 'compose_settings') { - $cs = self::defaultSettings()['compose_settings']; - $ms = is_array($item) ? $item : []; - return array_merge($cs, $ms); + return Cache::remember('profile:compose:settings:' . $id, 604800, function() use($id) { + $settings = UserSetting::whereUserId($id)->first(); + if(!$settings) { + return self::defaultSettings(); } + return collect($settings) + ->filter(function($item, $key) { + return in_array($key, array_keys(self::defaultSettings())) == true; + }) + ->map(function($item, $key) { + if($key == 'compose_settings') { + $cs = self::defaultSettings()['compose_settings']; + $ms = is_array($item) ? $item : []; + return array_merge($cs, $ms); + } - if($key == 'other') { - $other = self::defaultSettings()['other']; - $mo = is_array($item) ? $item : []; - return array_merge($other, $mo); - } - return $item; + if($key == 'other') { + $other = self::defaultSettings()['other']; + $mo = is_array($item) ? $item : []; + return array_merge($other, $mo); + } + return $item; + }); }); } diff --git a/database/migrations/2022_09_19_093029_fix_double_json_encoded_settings_in_usersettings_table.php b/database/migrations/2022_09_19_093029_fix_double_json_encoded_settings_in_usersettings_table.php new file mode 100644 index 000000000..d2f43213f --- /dev/null +++ b/database/migrations/2022_09_19_093029_fix_double_json_encoded_settings_in_usersettings_table.php @@ -0,0 +1,38 @@ +chunk(50, function($settings) { + foreach($settings as $userSetting) { + if(is_array($userSetting->compose_settings)) { + continue; + } + $userSetting->compose_settings = json_decode($userSetting->compose_settings); + $userSetting->save(); + } + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + + } +} From 3218719e4c89e0d6dcfc2059f608421aeaddc720 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 19 Sep 2022 03:46:02 -0600 Subject: [PATCH 4/5] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dfab75253..768af7f21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -81,6 +81,8 @@ - Update PronounService, fix json_decode null parameter ([d72cd819](https://github.com/pixelfed/pixelfed/commit/d72cd819)) - Update ApiV1Controller, normalize profile id comparison ([374bfdae](https://github.com/pixelfed/pixelfed/commit/374bfdae)) - Update ApiV1Controller, fix pagination header. Fixes #3354 ([4fe07e6f](https://github.com/pixelfed/pixelfed/commit/4fe07e6f)) +- Update ApiV1Controller, add optional place_id parameter to POST /api/v1/statuses endpoint ([ef0d1f84](https://github.com/pixelfed/pixelfed/commit/ef0d1f84)) +- Update SettingsController, fix double json encoding and cache settings for 7 days ([4514ab1d](https://github.com/pixelfed/pixelfed/commit/4514ab1d)) - ([](https://github.com/pixelfed/pixelfed/commit/)) ## [v0.11.3 (2022-05-09)](https://github.com/pixelfed/pixelfed/compare/v0.11.2...v0.11.3) From 842f40a1b54084d2c2b71314889217964c6d8a7e Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 19 Sep 2022 03:49:45 -0600 Subject: [PATCH 5/5] Update ApiV1Dot1Controller --- .../Controllers/Api/ApiV1Dot1Controller.php | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/app/Http/Controllers/Api/ApiV1Dot1Controller.php b/app/Http/Controllers/Api/ApiV1Dot1Controller.php index 34d483551..75bd2b3e9 100644 --- a/app/Http/Controllers/Api/ApiV1Dot1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Dot1Controller.php @@ -12,6 +12,8 @@ use App\Status; use App\Report; use App\Profile; use App\Services\AccountService; +use App\Services\StatusService; +use App\Services\ProfileStatusService; class ApiV1Dot1Controller extends Controller { @@ -166,4 +168,40 @@ class ApiV1Dot1Controller extends Controller return AccountService::get($user->profile_id); } + + /** + * GET /api/v1.1/accounts/{id}/posts + * + * @return \App\Transformer\Api\StatusTransformer + */ + public function accountPosts(Request $request, $id) + { + $user = $request->user(); + + abort_if(!$user, 403); + abort_if($user->status != null, 403); + + $account = AccountService::get($id); + + if(!$account || $account['username'] !== $request->input('username')) { + return $this->json([]); + } + + $posts = ProfileStatusService::get($id); + + if(!$posts) { + return $this->json([]); + } + + $res = collect($posts) + ->map(function($id) { + return StatusService::get($id); + }) + ->filter(function($post) { + return $post && isset($post['account']); + }) + ->toArray(); + + return $this->json($res); + } }