diff --git a/CHANGELOG.md b/CHANGELOG.md index 2cf4bbe21..d8dbec9fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,10 @@ ### Configuration - Enable network timeline by default ([b95aec12](https://github.com/pixelfed/pixelfed/commit/b95aec12)) +### Postgres Compatibility +- Fix Story recent endpoint on postgres instances ([ddf41dc3](https://github.com/pixelfed/pixelfed/commit/ddf41dc3)) +- Fix Direct Message conversations endpoint on postgres instances ([fcabc9be](https://github.com/pixelfed/pixelfed/commit/fcabc9be)) + ### Added - Manual email verification requests. ([bc659387](https://github.com/pixelfed/pixelfed/commit/bc659387)) - Added StatusMentionService, fixes #3026. ([e5387d67](https://github.com/pixelfed/pixelfed/commit/e5387d67)) @@ -80,6 +84,7 @@ - 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)) +- Updated PublicApiController, fix accountStatuses pagination operator. ([85fc9dd0](https://github.com/pixelfed/pixelfed/commit/85fc9dd0)) - ([](https://github.com/pixelfed/pixelfed/commit/)) ## [v0.11.1 (2021-09-07)](https://github.com/pixelfed/pixelfed/compare/v0.11.0...v0.11.1) diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index c4adc5d33..b4cc51e93 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -1701,16 +1701,29 @@ class ApiV1Controller extends Controller $scope = $request->input('scope', 'inbox'); $pid = $request->user()->profile_id; - $dms = DirectMessage::when($scope === 'inbox', function($q, $scope) use($pid) { - return $q->whereIsHidden(false)->whereToId($pid)->orWhere('from_id', $pid)->groupBy('to_id'); - }) - ->when($scope === 'sent', function($q, $scope) use($pid) { - return $q->whereFromId($pid)->groupBy('to_id'); - }) - ->when($scope === 'requests', function($q, $scope) use($pid) { - return $q->whereToId($pid)->whereIsHidden(true); - }) - ->latest() + if(config('database.default') == 'pgsql') { + $dms = DirectMessage::when($scope === 'inbox', function($q, $scope) use($pid) { + return $q->whereIsHidden(false)->whereToId($pid)->orWhere('from_id', $pid); + }) + ->when($scope === 'sent', function($q, $scope) use($pid) { + return $q->whereFromId($pid); + }) + ->when($scope === 'requests', function($q, $scope) use($pid) { + return $q->whereToId($pid)->whereIsHidden(true); + }); + } else { + $dms = DirectMessage::when($scope === 'inbox', function($q, $scope) use($pid) { + return $q->whereIsHidden(false)->whereToId($pid)->orWhere('from_id', $pid)->groupBy('to_id'); + }) + ->when($scope === 'sent', function($q, $scope) use($pid) { + return $q->whereFromId($pid)->groupBy('to_id'); + }) + ->when($scope === 'requests', function($q, $scope) use($pid) { + return $q->whereToId($pid)->whereIsHidden(true); + }); + } + + $dms = $dms->latest() ->simplePaginate($limit) ->map(function($dm) use($pid) { $from = $pid == $dm->to_id ? $dm->from_id : $dm->to_id; diff --git a/app/Http/Controllers/PublicApiController.php b/app/Http/Controllers/PublicApiController.php index c1e71b09f..b678694b4 100644 --- a/app/Http/Controllers/PublicApiController.php +++ b/app/Http/Controllers/PublicApiController.php @@ -738,6 +738,10 @@ class PublicApiController extends Controller $min_id = $request->min_id; $scope = ['photo', 'photo:album', 'video', 'video:album']; + if(!$min_id && !$max_id) { + $min_id = 1; + } + if($profile['locked']) { if(!$user) { return response()->json([]); diff --git a/app/Http/Controllers/StoryController.php b/app/Http/Controllers/StoryController.php index 1c8890d87..216fed8b4 100644 --- a/app/Http/Controllers/StoryController.php +++ b/app/Http/Controllers/StoryController.php @@ -46,6 +46,8 @@ class StoryController extends StoryComposeController $r = new \StdClass; $r->id = $s->id; $r->profile_id = $s->profile_id; + $r->type = $s->type; + $r->path = $s->path; return $r; }) ->unique('profile_id'); diff --git a/app/Services/AccountService.php b/app/Services/AccountService.php index 2c3f97a7b..0410f8f64 100644 --- a/app/Services/AccountService.php +++ b/app/Services/AccountService.php @@ -33,6 +33,35 @@ class AccountService }); } + public static function getMastodon($id, $softFail = false) + { + $account = self::get($id, $softFail); + if(!$account) { + return null; + } + + unset( + $account['header_bg'], + $account['is_admin'], + $account['last_fetched_at'], + $account['local'], + $account['location'], + $account['note_text'], + $account['pronouns'], + $account['website'] + ); + + $account['avatar_static'] = $account['avatar']; + $account['bot'] = false; + $account['emojis'] = []; + $account['fields'] = []; + $account['header'] = url('/storage/headers/missing.png'); + $account['header_static'] = url('/storage/headers/missing.png'); + $account['last_status_at'] = null; + + return $account; + } + public static function del($id) { return Cache::forget(self::CACHE_KEY . $id); diff --git a/app/Services/MediaService.php b/app/Services/MediaService.php index 42f188eba..6960af5f1 100644 --- a/app/Services/MediaService.php +++ b/app/Services/MediaService.php @@ -18,26 +18,48 @@ class MediaService public static function get($statusId) { - $status = Status::find($statusId); - if(!$status) { - return []; - } - $ttl = $status->created_at->lt(now()->subMinutes(30)) ? 129600 : 30; - return Cache::remember(self::CACHE_KEY.$statusId, $ttl, function() use($status) { - if(!$status) { + return Cache::remember(self::CACHE_KEY.$statusId, 86400, function() use($statusId) { + $media = Media::whereStatusId($statusId)->orderBy('order')->get(); + if(!$media) { return []; } - if(in_array($status->type, ['group:post', 'photo', 'video', 'video:album', 'photo:album', 'loop', 'photo:video:album'])) { - $media = Media::whereStatusId($status->id)->orderBy('order')->get(); - $fractal = new Fractal\Manager(); - $fractal->setSerializer(new ArraySerializer()); - $resource = new Fractal\Resource\Collection($media, new MediaTransformer()); - return $fractal->createData($resource)->toArray(); - } - return []; + $fractal = new Fractal\Manager(); + $fractal->setSerializer(new ArraySerializer()); + $resource = new Fractal\Resource\Collection($media, new MediaTransformer()); + return $fractal->createData($resource)->toArray(); }); } + public static function getMastodon($id) + { + $media = self::get($id); + if(!$media) { + return []; + } + $medias = collect($media) + ->map(function($media) { + $mime = $media['mime'] ? explode('/', $media['mime']) : false; + unset( + $media['optimized_url'], + $media['license'], + $media['is_nsfw'], + $media['orientation'], + $media['filter_name'], + $media['filter_class'], + $media['mime'] + ); + + $media['type'] = $mime ? strtolower($mime[0]) : 'unknown'; + return $media; + }) + ->filter(function($m) { + return $m && isset($m['url']); + }) + ->values(); + + return $medias->toArray(); + } + public static function del($statusId) { return Cache::forget(self::CACHE_KEY . $statusId); diff --git a/app/Services/StatusService.php b/app/Services/StatusService.php index d272e478a..3532c8733 100644 --- a/app/Services/StatusService.php +++ b/app/Services/StatusService.php @@ -71,6 +71,7 @@ class StatusService $status['account']['note_text'], $status['account']['pronouns'], $status['account']['website'], + $status['media_attachments'], ); $status['account']['avatar_static'] = $status['account']['avatar']; $status['account']['bot'] = false; @@ -80,6 +81,8 @@ class StatusService $status['account']['header_static'] = url('/storage/headers/missing.png'); $status['account']['last_status_at'] = null; + $status['media_attachments'] = array_values(MediaService::getMastodon($status['id'])); + return $status; } diff --git a/app/Transformer/Api/AccountTransformer.php b/app/Transformer/Api/AccountTransformer.php index 8beb5b668..6e6d9ea16 100644 --- a/app/Transformer/Api/AccountTransformer.php +++ b/app/Transformer/Api/AccountTransformer.php @@ -25,8 +25,8 @@ class AccountTransformer extends Fractal\TransformerAbstract 'acct' => $acct, 'display_name' => $profile->name, 'locked' => (bool) $profile->is_private, - 'followers_count' => $profile->followerCount(), - 'following_count' => $profile->followingCount(), + 'followers_count' => (int) $profile->followerCount(), + 'following_count' => (int) $profile->followingCount(), 'statuses_count' => (int) $profile->statusCount(), 'note' => $profile->bio ?? '', 'note_text' => strip_tags($profile->bio), diff --git a/app/Transformer/Api/Mastodon/v1/AccountTransformer.php b/app/Transformer/Api/Mastodon/v1/AccountTransformer.php index 25f482303..5f1e58214 100644 --- a/app/Transformer/Api/Mastodon/v1/AccountTransformer.php +++ b/app/Transformer/Api/Mastodon/v1/AccountTransformer.php @@ -24,8 +24,8 @@ class AccountTransformer extends Fractal\TransformerAbstract 'url' => $profile->url(), 'avatar' => $profile->avatarUrl(), 'avatar_static' => $profile->avatarUrl(), - 'header' => '', - 'header_static' => '', + 'header' => url('/storage/headers/missing.png'), + 'header_static' => url('/storage/headers/missing.png'), 'followers_count' => (int) $profile->followerCount(), 'following_count' => (int) $profile->followingCount(), 'statuses_count' => (int) $profile->statusCount(), diff --git a/storage/app/public/.gitignore b/storage/app/public/.gitignore index 0e4505c04..e368b9e0e 100755 --- a/storage/app/public/.gitignore +++ b/storage/app/public/.gitignore @@ -2,4 +2,5 @@ !.gitignore !no-preview.png !m/ -!textimg/ \ No newline at end of file +!textimg/ +!headers/ diff --git a/storage/app/public/headers/.gitignore b/storage/app/public/headers/.gitignore new file mode 100644 index 000000000..ba3444e98 --- /dev/null +++ b/storage/app/public/headers/.gitignore @@ -0,0 +1,3 @@ +* +!.gitignore +!missing.png diff --git a/storage/app/public/headers/missing.png b/storage/app/public/headers/missing.png new file mode 100644 index 000000000..26b59e75a Binary files /dev/null and b/storage/app/public/headers/missing.png differ