mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 06:21:27 +00:00
Fix Direct Message conversations endpoint on postgres instances
This commit is contained in:
parent
ddf41dc347
commit
fcabc9be02
1 changed files with 23 additions and 10 deletions
|
@ -1701,16 +1701,29 @@ class ApiV1Controller extends Controller
|
||||||
$scope = $request->input('scope', 'inbox');
|
$scope = $request->input('scope', 'inbox');
|
||||||
$pid = $request->user()->profile_id;
|
$pid = $request->user()->profile_id;
|
||||||
|
|
||||||
$dms = DirectMessage::when($scope === 'inbox', function($q, $scope) use($pid) {
|
if(config('database.default') == 'pgsql') {
|
||||||
return $q->whereIsHidden(false)->whereToId($pid)->orWhere('from_id', $pid)->groupBy('to_id');
|
$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)->groupBy('to_id');
|
->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);
|
->when($scope === 'requests', function($q, $scope) use($pid) {
|
||||||
})
|
return $q->whereToId($pid)->whereIsHidden(true);
|
||||||
->latest()
|
});
|
||||||
|
} 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)
|
->simplePaginate($limit)
|
||||||
->map(function($dm) use($pid) {
|
->map(function($dm) use($pid) {
|
||||||
$from = $pid == $dm->to_id ? $dm->from_id : $dm->to_id;
|
$from = $pid == $dm->to_id ? $dm->from_id : $dm->to_id;
|
||||||
|
|
Loading…
Reference in a new issue