Update DirectMessageController, fix ordering bug

This commit is contained in:
Daniel Supernault 2024-11-19 02:06:25 -07:00
parent bcc8b8842f
commit 044d410c49
No known key found for this signature in database
GPG key ID: 23740873EE6F76A1

View file

@ -421,9 +421,10 @@ class DirectMessageController extends Controller
if ($min_id) { if ($min_id) {
$res = DirectMessage::select('*') $res = DirectMessage::select('*')
->where('id', '>', $min_id) ->where('id', '>', $min_id)
->where(function ($q) use ($pid, $uid) { ->where(function ($query) use ($pid, $uid) {
return $q->where([['from_id', $pid], ['to_id', $uid], $query->where('from_id', $pid)->where('to_id', $uid);
])->orWhere([['from_id', $uid], ['to_id', $pid]]); })->orWhere(function ($query) use ($pid, $uid) {
$query->where('from_id', $uid)->where('to_id', $pid);
}) })
->orderBy('id', 'asc') ->orderBy('id', 'asc')
->take(8) ->take(8)
@ -432,17 +433,19 @@ class DirectMessageController extends Controller
} elseif ($max_id) { } elseif ($max_id) {
$res = DirectMessage::select('*') $res = DirectMessage::select('*')
->where('id', '<', $max_id) ->where('id', '<', $max_id)
->where(function ($q) use ($pid, $uid) { ->where(function ($query) use ($pid, $uid) {
return $q->where([['from_id', $pid], ['to_id', $uid], $query->where('from_id', $pid)->where('to_id', $uid);
])->orWhere([['from_id', $uid], ['to_id', $pid]]); })->orWhere(function ($query) use ($pid, $uid) {
$query->where('from_id', $uid)->where('to_id', $pid);
}) })
->orderBy('id', 'desc') ->orderBy('id', 'desc')
->take(8) ->take(8)
->get(); ->get();
} else { } else {
$res = DirectMessage::where(function ($q) use ($pid, $uid) { $res = DirectMessage::where(function ($query) use ($pid, $uid) {
return $q->where([['from_id', $pid], ['to_id', $uid], $query->where('from_id', $pid)->where('to_id', $uid);
])->orWhere([['from_id', $uid], ['to_id', $pid]]); })->orWhere(function ($query) use ($pid, $uid) {
$query->where('from_id', $uid)->where('to_id', $pid);
}) })
->orderBy('id', 'desc') ->orderBy('id', 'desc')
->take(8) ->take(8)