Personal Messages List

Started by qICEp, June 18, 2017, 04:01:33 AM

Previous topic - Next topic

qICEp

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:
$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)

Pipke

you dont need to query that, it is already loaded in the global vars if set


// 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>';
}
"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

Advertisement: