Advertisement:

Author Topic: Personal Messages List  (Read 640 times)

Offline qICEp

  • Semi-Newbie
  • *
  • Posts: 36
Personal Messages List
« on: June 18, 2017, 04:01:33 AM »
Hey folks, im trying to make a dropdown list in my theme header with unread PM's. But im just stuck. I have my design and everything except the most important thing, messages in $context :D

So any help on how i can select all unread messages? By the way i dont mind using query.

EDIT: Ok a little bit of digging in source and checking database structure i got these:
Code: [Select]
$result = $smcFunc['db_query']('', '
SELECT *
FROM {db_prefix}pm_recipients AS pmr
INNER JOIN {db_prefix}personal_messages AS pm ON (pm.id_pm = pmr.id_pm)
INNER JOIN {db_prefix}members as memb ON ( pm.id_member_from = memb.id_member)
WHERE pmr.id_member = {int:current_member}
AND deleted = {int:not_deleted}',
array(
'current_member' => $context['user']['id'],
'not_deleted' => 0,
)
);

$messages = array();
while ($row = $smcFunc['db_fetch_assoc']($result))
{
$messages[] = $row;
}
I know its dirty and it selects 90% of stuff i wont ever use but for now i have no idea what im gonna use so i will leave it like that for now. Next problem is that i also need user (poster) avatar, and that is a freaking nightmare as i can see. Any help on how to select user avatar (im not thrilled with idea of running one query for each PM just to get sender avatar)
« Last Edit: June 18, 2017, 04:43:58 AM by qICEp »

Online Pipke

  • Jr. Member
  • **
  • Posts: 349
    • NRNS-GAMES
Re: Personal Messages List
« Reply #1 on: June 20, 2017, 04:30:58 PM »
you dont need to query that, it is already loaded in the global vars if set

Code: [Select]
// If the user is logged in, display stuff like avatar, their name and new unread private messages.
if ($context['user']['is_logged'])
{
if (!empty($context['user']['avatar']))
echo '<p class="avatar">', $context['user']['avatar']['image'], '</p>';
// Only tell them about their messages if they can read their messages and have a new ones!
if (($context['allow_pm']) && ($context['user']['unread_messages'] > 0))
echo '<a href="', $scripturl, '?action=pm">You got <strong>', $context['user']['unread_messages'] , '</strong> new Private Messages</a>';
}