forked from mirror/pixelfed
Merge pull request #2443 from pixelfed/staging
Update DirectMessageController, fix pgsql bug
This commit is contained in:
commit
7774862aa8
|
@ -95,6 +95,7 @@
|
|||
- Updated Profile + Timeline components, simplify UI. ([38d28ab4](https://github.com/pixelfed/pixelfed/commit/38d28ab4))
|
||||
- Updated Profile component, make modals scrollable. ([d1c664fa](https://github.com/pixelfed/pixelfed/commit/d1c664fa))
|
||||
- Updated PostComponent, fixes #2351. ([7a62a42a](https://github.com/pixelfed/pixelfed/commit/7a62a42a))
|
||||
- Updated DirectMessageController, fix pgsql bug. ([f1c28e7d](https://github.com/pixelfed/pixelfed/commit/f1c28e7d))
|
||||
|
||||
## [v0.10.9 (2020-04-17)](https://github.com/pixelfed/pixelfed/compare/v0.10.8...v0.10.9)
|
||||
### Added
|
||||
|
|
|
@ -39,6 +39,129 @@ class DirectMessageController extends Controller
|
|||
$action = $request->input('a', 'inbox');
|
||||
$page = $request->input('page');
|
||||
|
||||
if(config('database.default') == 'pgsql') {
|
||||
if($action == 'inbox') {
|
||||
$dms = DirectMessage::select('id', 'type', 'to_id', 'from_id', 'id', 'status_id', 'is_hidden', 'meta', 'created_at', 'read_at')
|
||||
->whereToId($profile)
|
||||
->with(['author','status'])
|
||||
->whereIsHidden(false)
|
||||
->when($page, function($q, $page) {
|
||||
if($page > 1) {
|
||||
return $q->offset($page * 8 - 8);
|
||||
}
|
||||
})
|
||||
->latest()
|
||||
->get()
|
||||
->unique('from_id')
|
||||
->take(8)
|
||||
->map(function($r) use($profile) {
|
||||
return $r->from_id !== $profile ? [
|
||||
'id' => (string) $r->from_id,
|
||||
'name' => $r->author->name,
|
||||
'username' => $r->author->username,
|
||||
'avatar' => $r->author->avatarUrl(),
|
||||
'url' => $r->author->url(),
|
||||
'isLocal' => (bool) !$r->author->domain,
|
||||
'domain' => $r->author->domain,
|
||||
'timeAgo' => $r->created_at->diffForHumans(null, true, true),
|
||||
'lastMessage' => $r->status->caption,
|
||||
'messages' => []
|
||||
] : [
|
||||
'id' => (string) $r->to_id,
|
||||
'name' => $r->recipient->name,
|
||||
'username' => $r->recipient->username,
|
||||
'avatar' => $r->recipient->avatarUrl(),
|
||||
'url' => $r->recipient->url(),
|
||||
'isLocal' => (bool) !$r->recipient->domain,
|
||||
'domain' => $r->recipient->domain,
|
||||
'timeAgo' => $r->created_at->diffForHumans(null, true, true),
|
||||
'lastMessage' => $r->status->caption,
|
||||
'messages' => []
|
||||
];
|
||||
})->values();
|
||||
}
|
||||
|
||||
if($action == 'sent') {
|
||||
$dms = DirectMessage::select('id', 'type', 'to_id', 'from_id', 'id', 'status_id', 'is_hidden', 'meta', 'created_at', 'read_at')
|
||||
->whereFromId($profile)
|
||||
->with(['author','status'])
|
||||
->orderBy('id', 'desc')
|
||||
->when($page, function($q, $page) {
|
||||
if($page > 1) {
|
||||
return $q->offset($page * 8 - 8);
|
||||
}
|
||||
})
|
||||
->get()
|
||||
->unique('to_id')
|
||||
->take(8)
|
||||
->map(function($r) use($profile) {
|
||||
return $r->from_id !== $profile ? [
|
||||
'id' => (string) $r->from_id,
|
||||
'name' => $r->author->name,
|
||||
'username' => $r->author->username,
|
||||
'avatar' => $r->author->avatarUrl(),
|
||||
'url' => $r->author->url(),
|
||||
'isLocal' => (bool) !$r->author->domain,
|
||||
'domain' => $r->author->domain,
|
||||
'timeAgo' => $r->created_at->diffForHumans(null, true, true),
|
||||
'lastMessage' => $r->status->caption,
|
||||
'messages' => []
|
||||
] : [
|
||||
'id' => (string) $r->to_id,
|
||||
'name' => $r->recipient->name,
|
||||
'username' => $r->recipient->username,
|
||||
'avatar' => $r->recipient->avatarUrl(),
|
||||
'url' => $r->recipient->url(),
|
||||
'isLocal' => (bool) !$r->recipient->domain,
|
||||
'domain' => $r->recipient->domain,
|
||||
'timeAgo' => $r->created_at->diffForHumans(null, true, true),
|
||||
'lastMessage' => $r->status->caption,
|
||||
'messages' => []
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
if($action == 'filtered') {
|
||||
$dms = DirectMessage::select('id', 'type', 'to_id', 'from_id', 'id', 'status_id', 'is_hidden', 'meta', 'created_at', 'read_at')
|
||||
->whereToId($profile)
|
||||
->with(['author','status'])
|
||||
->whereIsHidden(true)
|
||||
->orderBy('id', 'desc')
|
||||
->when($page, function($q, $page) {
|
||||
if($page > 1) {
|
||||
return $q->offset($page * 8 - 8);
|
||||
}
|
||||
})
|
||||
->get()
|
||||
->unique('from_id')
|
||||
->take(8)
|
||||
->map(function($r) use($profile) {
|
||||
return $r->from_id !== $profile ? [
|
||||
'id' => (string) $r->from_id,
|
||||
'name' => $r->author->name,
|
||||
'username' => $r->author->username,
|
||||
'avatar' => $r->author->avatarUrl(),
|
||||
'url' => $r->author->url(),
|
||||
'isLocal' => (bool) !$r->author->domain,
|
||||
'domain' => $r->author->domain,
|
||||
'timeAgo' => $r->created_at->diffForHumans(null, true, true),
|
||||
'lastMessage' => $r->status->caption,
|
||||
'messages' => []
|
||||
] : [
|
||||
'id' => (string) $r->to_id,
|
||||
'name' => $r->recipient->name,
|
||||
'username' => $r->recipient->username,
|
||||
'avatar' => $r->recipient->avatarUrl(),
|
||||
'url' => $r->recipient->url(),
|
||||
'isLocal' => (bool) !$r->recipient->domain,
|
||||
'domain' => $r->recipient->domain,
|
||||
'timeAgo' => $r->created_at->diffForHumans(null, true, true),
|
||||
'lastMessage' => $r->status->caption,
|
||||
'messages' => []
|
||||
];
|
||||
});
|
||||
}
|
||||
} elseif(config('database.default') == 'mysql') {
|
||||
if($action == 'inbox') {
|
||||
$dms = DirectMessage::selectRaw('*, max(created_at) as createdAt')
|
||||
->whereToId($profile)
|
||||
|
@ -160,8 +283,9 @@ class DirectMessageController extends Controller
|
|||
];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json($dms);
|
||||
return response()->json($dms->all());
|
||||
}
|
||||
|
||||
public function create(Request $request)
|
||||
|
|
Loading…
Reference in New Issue