From 89206d6e1fbd558c8f2784995ae504d5723776b8 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 2 Jan 2022 23:26:18 -0700 Subject: [PATCH 1/7] Update mastoapi transformers --- .../Api/Mastodon/v1/AccountTransformer.php | 14 ++++++-------- .../Api/Mastodon/v1/MediaTransformer.php | 7 +++---- .../Api/Mastodon/v1/MentionTransformer.php | 4 +++- .../Api/Mastodon/v1/StatusTransformer.php | 6 +++--- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/app/Transformer/Api/Mastodon/v1/AccountTransformer.php b/app/Transformer/Api/Mastodon/v1/AccountTransformer.php index 00a895a17..25f482303 100644 --- a/app/Transformer/Api/Mastodon/v1/AccountTransformer.php +++ b/app/Transformer/Api/Mastodon/v1/AccountTransformer.php @@ -11,7 +11,6 @@ class AccountTransformer extends Fractal\TransformerAbstract public function transform(Profile $profile) { $local = $profile->domain == null; - $is_admin = !$local ? false : $profile->user->is_admin; $username = $local ? $profile->username : explode('@', substr($profile->username, 1))[0]; return [ 'id' => (string) $profile->id, @@ -19,22 +18,21 @@ class AccountTransformer extends Fractal\TransformerAbstract 'acct' => $username, 'display_name' => $profile->name, 'locked' => (bool) $profile->is_private, + 'bot' => false, 'created_at' => $profile->created_at->toJSON(), - 'followers_count' => $profile->followerCount(), - 'following_count' => $profile->followingCount(), - 'statuses_count' => (int) $profile->statusCount(), 'note' => $profile->bio ?? '', 'url' => $profile->url(), 'avatar' => $profile->avatarUrl(), 'avatar_static' => $profile->avatarUrl(), 'header' => '', 'header_static' => '', + 'followers_count' => (int) $profile->followerCount(), + 'following_count' => (int) $profile->followingCount(), + 'statuses_count' => (int) $profile->statusCount(), + 'last_status_at' => optional($profile->last_status_at)->toJSON(), 'emojis' => [], 'moved' => null, - 'fields' => null, - 'bot' => false, - 'software' => 'pixelfed', - 'is_admin' => (bool) $is_admin, + 'fields' => [], ]; } } diff --git a/app/Transformer/Api/Mastodon/v1/MediaTransformer.php b/app/Transformer/Api/Mastodon/v1/MediaTransformer.php index 26ee4a4f0..8f018d014 100644 --- a/app/Transformer/Api/Mastodon/v1/MediaTransformer.php +++ b/app/Transformer/Api/Mastodon/v1/MediaTransformer.php @@ -13,10 +13,9 @@ class MediaTransformer extends Fractal\TransformerAbstract 'id' => (string) $media->id, 'type' => lcfirst($media->activityVerb()), 'url' => $media->url(), - 'remote_url' => null, 'preview_url' => $media->thumbnailUrl(), - 'text_url' => null, - 'meta' => null, + 'remote_url' => $media->remote_url, + 'text_url' => $media->url(), 'description' => $media->caption, 'blurhash' => $media->blurhash ?? 'U4Rfzst8?bt7ogayj[j[~pfQ9Goe%Mj[WBay' ]; @@ -38,4 +37,4 @@ class MediaTransformer extends Fractal\TransformerAbstract return $res; } -} \ No newline at end of file +} diff --git a/app/Transformer/Api/Mastodon/v1/MentionTransformer.php b/app/Transformer/Api/Mastodon/v1/MentionTransformer.php index 774f4122e..26e801e7d 100644 --- a/app/Transformer/Api/Mastodon/v1/MentionTransformer.php +++ b/app/Transformer/Api/Mastodon/v1/MentionTransformer.php @@ -9,11 +9,13 @@ class MentionTransformer extends Fractal\TransformerAbstract { public function transform(Profile $profile) { + $local = $profile->domain == null; + $username = $local ? $profile->username : explode('@', substr($profile->username, 1))[0]; return [ 'id' => (string) $profile->id, 'url' => $profile->url(), 'username' => $profile->username, - 'acct' => $profile->username, + 'acct' => $username, ]; } } diff --git a/app/Transformer/Api/Mastodon/v1/StatusTransformer.php b/app/Transformer/Api/Mastodon/v1/StatusTransformer.php index 6b4177384..a30d998ee 100644 --- a/app/Transformer/Api/Mastodon/v1/StatusTransformer.php +++ b/app/Transformer/Api/Mastodon/v1/StatusTransformer.php @@ -17,14 +17,14 @@ class StatusTransformer extends Fractal\TransformerAbstract 'id' => (string) $status->id, 'created_at' => $status->created_at->toJSON(), 'in_reply_to_id' => $status->in_reply_to_id ? (string) $status->in_reply_to_id : null, - 'in_reply_to_account_id' => $status->in_reply_to_profile_id, + 'in_reply_to_account_id' => $status->in_reply_to_profile_id ? (string) $status->in_reply_to_profile_id : null, 'sensitive' => (bool) $status->is_nsfw, 'spoiler_text' => $status->cw_summary ?? '', 'visibility' => $status->visibility ?? $status->scope, 'language' => 'en', - 'uri' => $status->url(), + 'uri' => $status->permalink(''), 'url' => $status->url(), - 'replies_count' => 0, + 'replies_count' => $status->reply_count ?? 0, 'reblogs_count' => $status->reblogs_count ?? 0, 'favourites_count' => $status->likes_count ?? 0, 'reblogged' => $status->shared(), From bdc3ab17dc99d07b30e94458bed9d8052b98f5ab Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 2 Jan 2022 23:27:05 -0700 Subject: [PATCH 2/7] Add migration --- ...3_add_last_status_at_to_profiles_table.php | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 database/migrations/2022_01_03_052623_add_last_status_at_to_profiles_table.php diff --git a/database/migrations/2022_01_03_052623_add_last_status_at_to_profiles_table.php b/database/migrations/2022_01_03_052623_add_last_status_at_to_profiles_table.php new file mode 100644 index 000000000..9390b3ac6 --- /dev/null +++ b/database/migrations/2022_01_03_052623_add_last_status_at_to_profiles_table.php @@ -0,0 +1,32 @@ +timestamp('last_status_at')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('profiles', function (Blueprint $table) { + $table->dropColumn('last_status_at'); + }); + } +} From a64aef6726eae53d2e2835a3388c738395666de9 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 2 Jan 2022 23:27:47 -0700 Subject: [PATCH 3/7] Update Profile model, cast last_status_at as timestamp --- app/Profile.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Profile.php b/app/Profile.php index 2c216e6d7..17063ab8c 100644 --- a/app/Profile.php +++ b/app/Profile.php @@ -21,7 +21,8 @@ class Profile extends Model protected $dates = [ 'deleted_at', - 'last_fetched_at' + 'last_fetched_at', + 'last_status_at' ]; protected $hidden = ['private_key']; protected $visible = ['id', 'user_id', 'username', 'name']; From 772352903bf8f0b3086e6db0c0838c2adbc47797 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 2 Jan 2022 23:46:17 -0700 Subject: [PATCH 4/7] Update web routes --- app/Http/Controllers/PublicApiController.php | 20 ++++++++++++++++++++ routes/web.php | 1 + 2 files changed, 21 insertions(+) diff --git a/app/Http/Controllers/PublicApiController.php b/app/Http/Controllers/PublicApiController.php index ff48d0149..c1e71b09f 100644 --- a/app/Http/Controllers/PublicApiController.php +++ b/app/Http/Controllers/PublicApiController.php @@ -89,6 +89,26 @@ class PublicApiController extends Controller } } + public function getStatus(Request $request, $id) + { + abort_if(!$request->user(), 403); + $status = StatusService::get($id, false); + abort_if(!$status, 404); + if(in_array($status['visibility'], ['public', 'unlisted'])) { + return $status; + } + $pid = $request->user()->profile_id; + if($status['account']['id'] == $pid) { + return $status; + } + if($status['visibility'] == 'private') { + if(FollowerService::follows($pid, $status['account']['id'])) { + return $status; + } + } + abort(404); + } + public function status(Request $request, $username, int $postid) { $profile = Profile::whereUsername($username)->whereNull('status')->firstOrFail(); diff --git a/routes/web.php b/routes/web.php index c48b2017a..3e91ae99c 100644 --- a/routes/web.php +++ b/routes/web.php @@ -163,6 +163,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact Route::get('accounts/{id}/followers', 'PublicApiController@accountFollowers'); Route::post('accounts/{id}/block', 'Api\ApiV1Controller@accountBlockById'); Route::post('accounts/{id}/unblock', 'Api\ApiV1Controller@accountUnblockById'); + Route::get('statuses/{id}', 'PublicApiController@getStatus'); Route::get('accounts/{id}', 'PublicApiController@account'); Route::post('avatar/update', 'ApiController@avatarUpdate'); Route::get('custom_emojis', 'Api\ApiV1Controller@customEmojis'); From 36a129fe893831f64f0a15bdaf7c8b67ab261322 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 2 Jan 2022 23:47:08 -0700 Subject: [PATCH 5/7] Update StatusService, add getMastodon method for mastoapi compatibility --- app/Services/StatusService.php | 44 +++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/app/Services/StatusService.php b/app/Services/StatusService.php index 9f00ab2b6..d272e478a 100644 --- a/app/Services/StatusService.php +++ b/app/Services/StatusService.php @@ -6,7 +6,6 @@ use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Redis; use DB; use App\Status; -//use App\Transformer\Api\v3\StatusTransformer; use App\Transformer\Api\StatusStatelessTransformer; use App\Transformer\Api\StatusTransformer; use League\Fractal; @@ -41,6 +40,49 @@ class StatusService }); } + public static function getMastodon($id, $publicOnly = true) + { + $status = self::get($id, $publicOnly); + if(!$status) { + return null; + } + $status['replies_count'] = $status['reply_count']; + unset( + $status['_v'], + $status['comments_disabled'], + $status['content_text'], + $status['gid'], + $status['label'], + $status['liked_by'], + $status['local'], + $status['parent'], + $status['pf_type'], + $status['place'], + $status['replies'], + $status['reply_count'], + $status['shortcode'], + $status['taggedPeople'], + $status['thread'], + $status['account']['header_bg'], + $status['account']['is_admin'], + $status['account']['last_fetched_at'], + $status['account']['local'], + $status['account']['location'], + $status['account']['note_text'], + $status['account']['pronouns'], + $status['account']['website'], + ); + $status['account']['avatar_static'] = $status['account']['avatar']; + $status['account']['bot'] = false; + $status['account']['emojis'] = []; + $status['account']['fields'] = []; + $status['account']['header'] = url('/storage/headers/missing.png'); + $status['account']['header_static'] = url('/storage/headers/missing.png'); + $status['account']['last_status_at'] = null; + + return $status; + } + public static function getState($id, $pid) { $status = self::get($id, false); From 846ce395d513a2326b7afb625e5b63bf529c024c Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 2 Jan 2022 23:59:08 -0700 Subject: [PATCH 6/7] Update compiled assets --- public/js/spa.js | Bin 1701975 -> 1702153 bytes public/mix-manifest.json | Bin 1983 -> 1983 bytes 2 files changed, 0 insertions(+), 0 deletions(-) diff --git a/public/js/spa.js b/public/js/spa.js index fac852b9b2e1ee29f1e21c4382e9ad7efeb621e4..690610439106c76453f0c6f457b8b17f3922344a 100644 GIT binary patch delta 206 zcmccqA-(fcdP56i3sVbo3rh=Y3tJ0&3r7oQ3s(zw3r`Dg3ttQW7J+Oqc1#Sy~1U08SOo);y^61{qa1>l1Km*fLbE} delta 211 zcmeDDlz#m~dP56i3sVbo3rh=Y3tJ0&3r7oQ3s(zw3r`Dg3ttQW7J8HE-g}3)s z3v6MWu8=FhGu{80K>YTtwF0*VKzz&T%O(g2Zhzb-&!Urq^v}-6f=WVQ**;KOY>xN)8Yt0kdNXxBvhE delta 33 ocmdnbzn_1@Y&H>N%akNzv!o=8G&4&B^CU|HQ^Taq>)8Yt0k)b6;Q#;t From 6667f4f1d72bdc288c5c817f9ce971cdc26e925a Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 2 Jan 2022 23:59:20 -0700 Subject: [PATCH 7/7] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d26ea6643..2cf4bbe21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -79,6 +79,7 @@ - Updated RemoteAvatarFetch job, fixed bug preventing new avatars from being stored. ([92bc2845](https://github.com/pixelfed/pixelfed/commit/92bc2845)) - Updated AccountService, fix json casting. ([e5f8f344](https://github.com/pixelfed/pixelfed/commit/e5f8f344)) - Updated ApiV1Controller, fix illegal operator bug by setting default min_id. ([415826f2](https://github.com/pixelfed/pixelfed/commit/415826f2)) +- Updated StatusService, add getMastodon method for mastoapi compatibility. ([36a129fe](https://github.com/pixelfed/pixelfed/commit/36a129fe)) - ([](https://github.com/pixelfed/pixelfed/commit/)) ## [v0.11.1 (2021-09-07)](https://github.com/pixelfed/pixelfed/compare/v0.11.0...v0.11.1)