From 14ba350ba3f1bab6364a103b38441482b0929fe2 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 16 Feb 2020 23:15:24 -0700 Subject: [PATCH 1/4] Fix postgres bugs --- app/Http/Controllers/Auth/RegisterController.php | 8 ++++++++ app/Http/Controllers/ProfileController.php | 4 ++++ app/Util/ActivityPub/Helpers.php | 10 +++++----- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index fd0b2fa88..61634810f 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -53,6 +53,10 @@ class RegisterController extends Controller */ protected function validator(array $data) { + if(config('database.default') == 'pgsql') { + $data['username'] = strtolower($data['username']); + } + $this->validateUsername($data['username']); $this->validateEmail($data['email']); @@ -105,6 +109,10 @@ class RegisterController extends Controller */ protected function create(array $data) { + if(config('database.default') == 'pgsql') { + $data['username'] = strtolower($data['username']); + } + return User::create([ 'name' => $data['name'], 'username' => $data['username'], diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index 20e4d08ec..e5f90693a 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -22,6 +22,10 @@ class ProfileController extends Controller { public function show(Request $request, $username) { + if(config('database.default') == 'pgsql') { + $username = strtolower($username); + } + $user = Profile::whereNull('domain') ->whereNull('status') ->whereUsername($username) diff --git a/app/Util/ActivityPub/Helpers.php b/app/Util/ActivityPub/Helpers.php index da74a1cb2..af46fee5e 100644 --- a/app/Util/ActivityPub/Helpers.php +++ b/app/Util/ActivityPub/Helpers.php @@ -412,14 +412,14 @@ class Helpers { $profile = Profile::whereRemoteUrl($res['id'])->first(); if(!$profile) { $profile = new Profile(); - $profile->domain = $domain; - $profile->username = (string) Purify::clean($remoteUsername); + $profile->domain = strtolower($domain); + $profile->username = strtolower(Purify::clean($remoteUsername)); $profile->name = isset($res['name']) ? Purify::clean($res['name']) : 'user'; $profile->bio = isset($res['summary']) ? Purify::clean($res['summary']) : null; $profile->sharedInbox = isset($res['endpoints']) && isset($res['endpoints']['sharedInbox']) ? $res['endpoints']['sharedInbox'] : null; - $profile->inbox_url = $res['inbox']; - $profile->outbox_url = $res['outbox']; - $profile->remote_url = $res['id']; + $profile->inbox_url = strtolower($res['inbox']); + $profile->outbox_url = strtolower($res['outbox']); + $profile->remote_url = strtolower($res['id']); $profile->public_key = $res['publicKey']['publicKeyPem']; $profile->key_id = $res['publicKey']['id']; $profile->save(); From 5bcb43a673179c6eea35e16887fbc6622fac1bec Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 16 Feb 2020 23:26:49 -0700 Subject: [PATCH 2/4] Update RegisterController, fix CI bug --- app/Http/Controllers/Auth/RegisterController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index 61634810f..ec7e15b7c 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -55,6 +55,7 @@ class RegisterController extends Controller { if(config('database.default') == 'pgsql') { $data['username'] = strtolower($data['username']); + $data['email'] = strtolower($data['email']); } $this->validateUsername($data['username']); @@ -111,8 +112,9 @@ class RegisterController extends Controller { if(config('database.default') == 'pgsql') { $data['username'] = strtolower($data['username']); + $data['email'] = strtolower($data['email']); } - + return User::create([ 'name' => $data['name'], 'username' => $data['username'], From 5ffa71dacd0c5d7b18012f807998a8e7b81397f0 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 17 Feb 2020 00:00:33 -0700 Subject: [PATCH 3/4] Update StoryController, fixes #2018 --- app/Http/Controllers/StoryController.php | 27 ++++++++++++++++-------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/StoryController.php b/app/Http/Controllers/StoryController.php index a7cfb9717..68d93272b 100644 --- a/app/Http/Controllers/StoryController.php +++ b/app/Http/Controllers/StoryController.php @@ -108,16 +108,25 @@ class StoryController extends Controller $profile = $request->user()->profile; $following = $profile->following->pluck('id')->toArray(); - $groupBy = config('database.default') == 'pgsql' ? 'id' : 'profile_id'; - $stories = Story::with('profile') - ->groupBy($groupBy) - ->whereIn('profile_id', $following) - ->where('expires_at', '>', now()) - ->orderByDesc('expires_at') - ->take(9) - ->get() - ->map(function($s, $k) { + if(config('database.default') == 'pgsql') { + $db = Story::with('profile') + ->whereIn('profile_id', $following) + ->where('expires_at', '>', now()) + ->distinct('profile_id') + ->take(9) + ->get(); + } else { + $db = Story::with('profile') + ->whereIn('profile_id', $following) + ->where('expires_at', '>', now()) + ->orderByDesc('expires_at') + ->groupBy('profile_id') + ->take(9) + ->get(); + } + + $stories = $db->map(function($s, $k) { return [ 'id' => (string) $s->id, 'photo' => $s->profile->avatarUrl(), From 88534f2deb79021c275f5bdcd2d5182d43342cb3 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 17 Feb 2020 00:01:49 -0700 Subject: [PATCH 4/4] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca899ed46..99003abc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Added ### Fixed +- Stories on postgres instances ([5ffa71da](https://github.com/pixelfed/pixelfed/commit/5ffa71da)) ### Updated - Updated StatusController, restrict edits to 24 hours ([ae24433b](https://github.com/pixelfed/pixelfed/commit/ae24433b))