From bcc8b8842fce8dc67599baddade40032929f98f2 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 19 Nov 2024 01:55:32 -0700 Subject: [PATCH 1/3] Update DirectMessageController, fix ordering bug --- app/Http/Controllers/DirectMessageController.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/DirectMessageController.php b/app/Http/Controllers/DirectMessageController.php index 1a30032cd..bc4e60885 100644 --- a/app/Http/Controllers/DirectMessageController.php +++ b/app/Http/Controllers/DirectMessageController.php @@ -372,7 +372,7 @@ class DirectMessageController extends Controller ->exists(); if ($recipient->domain == null && $hidden == false && ! $nf) { - $notification = new Notification(); + $notification = new Notification; $notification->profile_id = $recipient->id; $notification->actor_id = $profile->id; $notification->action = 'dm'; @@ -405,6 +405,8 @@ class DirectMessageController extends Controller { $this->validate($request, [ 'pid' => 'required', + 'max_id' => 'sometimes|integer', + 'min_id' => 'sometimes|integer', ]); $user = $request->user(); abort_if($user->has_roles && ! UserRoleService::can('can-direct-message', $user->id), 403, 'Invalid permissions for this action'); @@ -423,9 +425,10 @@ class DirectMessageController extends Controller return $q->where([['from_id', $pid], ['to_id', $uid], ])->orWhere([['from_id', $uid], ['to_id', $pid]]); }) - ->latest() + ->orderBy('id', 'asc') ->take(8) - ->get(); + ->get() + ->reverse(); } elseif ($max_id) { $res = DirectMessage::select('*') ->where('id', '<', $max_id) @@ -433,7 +436,7 @@ class DirectMessageController extends Controller return $q->where([['from_id', $pid], ['to_id', $uid], ])->orWhere([['from_id', $uid], ['to_id', $pid]]); }) - ->latest() + ->orderBy('id', 'desc') ->take(8) ->get(); } else { @@ -441,7 +444,7 @@ class DirectMessageController extends Controller return $q->where([['from_id', $pid], ['to_id', $uid], ])->orWhere([['from_id', $uid], ['to_id', $pid]]); }) - ->latest() + ->orderBy('id', 'desc') ->take(8) ->get(); } @@ -636,7 +639,7 @@ class DirectMessageController extends Controller $status->in_reply_to_profile_id = $recipient->id; $status->save(); - $media = new Media(); + $media = new Media; $media->status_id = $status->id; $media->profile_id = $profile->id; $media->user_id = $user->id; From 044d410c49c3228a9dd50be2c6bca263993a56c6 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 19 Nov 2024 02:06:25 -0700 Subject: [PATCH 2/3] Update DirectMessageController, fix ordering bug --- .../Controllers/DirectMessageController.php | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/DirectMessageController.php b/app/Http/Controllers/DirectMessageController.php index bc4e60885..5b07f6adb 100644 --- a/app/Http/Controllers/DirectMessageController.php +++ b/app/Http/Controllers/DirectMessageController.php @@ -421,9 +421,10 @@ class DirectMessageController extends Controller if ($min_id) { $res = DirectMessage::select('*') ->where('id', '>', $min_id) - ->where(function ($q) use ($pid, $uid) { - return $q->where([['from_id', $pid], ['to_id', $uid], - ])->orWhere([['from_id', $uid], ['to_id', $pid]]); + ->where(function ($query) use ($pid, $uid) { + $query->where('from_id', $pid)->where('to_id', $uid); + })->orWhere(function ($query) use ($pid, $uid) { + $query->where('from_id', $uid)->where('to_id', $pid); }) ->orderBy('id', 'asc') ->take(8) @@ -432,17 +433,19 @@ class DirectMessageController extends Controller } elseif ($max_id) { $res = DirectMessage::select('*') ->where('id', '<', $max_id) - ->where(function ($q) use ($pid, $uid) { - return $q->where([['from_id', $pid], ['to_id', $uid], - ])->orWhere([['from_id', $uid], ['to_id', $pid]]); + ->where(function ($query) use ($pid, $uid) { + $query->where('from_id', $pid)->where('to_id', $uid); + })->orWhere(function ($query) use ($pid, $uid) { + $query->where('from_id', $uid)->where('to_id', $pid); }) ->orderBy('id', 'desc') ->take(8) ->get(); } else { - $res = DirectMessage::where(function ($q) use ($pid, $uid) { - return $q->where([['from_id', $pid], ['to_id', $uid], - ])->orWhere([['from_id', $uid], ['to_id', $pid]]); + $res = DirectMessage::where(function ($query) use ($pid, $uid) { + $query->where('from_id', $pid)->where('to_id', $uid); + })->orWhere(function ($query) use ($pid, $uid) { + $query->where('from_id', $uid)->where('to_id', $pid); }) ->orderBy('id', 'desc') ->take(8) From 3d8ae361d77fc7be8c3f51fe6a9fa3eba5d0c169 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 19 Nov 2024 02:09:01 -0700 Subject: [PATCH 3/3] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 783781abb..18e8c874f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## [Unreleased](https://github.com/pixelfed/pixelfed/compare/v0.12.3...dev) - Update AP helpers, reject statuses with invalid dates ([960f3849](https://github.com/pixelfed/pixelfed/commit/960f3849)) +- Update DirectMessage API, fix broken threading ([044d410c](https://github.com/pixelfed/pixelfed/commit/044d410c)) - ([](https://github.com/pixelfed/pixelfed/commit/)) ## [v0.12.4 (2024-11-08)](https://github.com/pixelfed/pixelfed/compare/v0.12.4...dev)