[DirectMessage] Simplify the inbox query
This commit is contained in:
parent
6cb3a0c390
commit
b2e009bcd3
|
@ -72,19 +72,17 @@ class MessageModel
|
||||||
*/
|
*/
|
||||||
public static function inboxMessages(User $to, ?int $page = null)
|
public static function inboxMessages(User $to, ?int $page = null)
|
||||||
{
|
{
|
||||||
// fetch all notice IDs related to the user $to
|
|
||||||
$attention = new Attention();
|
|
||||||
$attention->selectAdd('notice_id');
|
|
||||||
$attention->whereAdd('profile_id = ' . $to->getID());
|
|
||||||
|
|
||||||
$ids = $attention->find() ? $attention->fetchAll('notice_id') : [];
|
|
||||||
|
|
||||||
// get the messages
|
// get the messages
|
||||||
$message = new Notice();
|
$message = new Notice();
|
||||||
|
|
||||||
$message->whereAdd('scope = ' . NOTICE::MESSAGE_SCOPE);
|
$message->selectAdd();
|
||||||
$message->whereAddIn('id', $ids, 'int');
|
$message->selectAdd('notice.*');
|
||||||
$message->orderBy('created DESC, id DESC');
|
|
||||||
|
// fetch all notice IDs related to the user $to
|
||||||
|
$message->joinAdd(['id', 'attention:notice_id']);
|
||||||
|
$message->whereAdd('notice.scope = ' . Notice::MESSAGE_SCOPE);
|
||||||
|
$message->whereAdd('attention.profile_id = ' . $to->getID());
|
||||||
|
$message->orderBy('notice.created DESC, notice.id DESC');
|
||||||
|
|
||||||
if (!is_null($page) && $page >= 0) {
|
if (!is_null($page) && $page >= 0) {
|
||||||
$page = ($page == 0) ? 1 : $page;
|
$page = ($page == 0) ? 1 : $page;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user