OKay, I managed to fix the repetition problem, I pulled the code from the "recent topics" section of SSI.php (this is the latter section that I listed above)
So, for this code block, we should:
Find:
// Find all the posts. Newer ones will have higher IDs.
// This is stripped down from SSI.php
$request = db_query("
SELECT
m.subject, m.ID_TOPIC, m.ID_MSG,
LEFT(m.body, ". (!empty($modSettings['NiceTooltips_lenght']) ? $modSettings['NiceTooltips_lenght'] : 384) .") AS body
FROM ({$db_prefix}messages AS m, {$db_prefix}boards AS b)
WHERE m.ID_MSG >= " . ($modSettings['maxMsgID'] - 25 * min($num_recent, 5)) . "
AND b.ID_BOARD = m.ID_BOARD" . (empty($exclude) ? '' : "
AND b.ID_BOARD NOT IN (" . implode(', ', $exclude) . ")") . "
AND $user_info[query_see_board]
ORDER BY m.ID_MSG DESC
LIMIT $num_recent", __FILE__, __LINE__);
and, Replace with:
// Find all the posts in distinct topics. Newer ones will have higher IDs.
// This is stripped down from SSI.php
$request = db_query("
SELECT
m.subject, m.ID_TOPIC, m.ID_MSG,
LEFT(m.body, ". (!empty($modSettings['NiceTooltips_lenght']) ? $modSettings['NiceTooltips_lenght'] : 384) .") AS body
FROM ({$db_prefix}messages AS m, {$db_prefix}topics AS t, {$db_prefix}boards AS b, {$db_prefix}messages AS ms)
WHERE t.ID_LAST_MSG >= " . ($modSettings['maxMsgID'] - 25 * min($num_recent, 5)) . "
AND t.ID_LAST_MSG = m.ID_MSG
AND b.ID_BOARD = t.ID_BOARD" . (empty($exclude) ? '' : "
AND b.ID_BOARD NOT IN (" . implode(', ', $exclude) . ")") . "
AND $user_info[query_see_board]
AND ms.ID_MSG = t.ID_FIRST_MSG
ORDER BY t.ID_LAST_MSG DESC
LIMIT $num_recent", __FILE__, __LINE__);
The only problem to smooth out is to force the display (is this the array section of your code?) to display the topic name not the message name/subject as it currently does. Instead of:
Jimmy's new trucks it is showing Re: Jimmy's new trucks
This is because we are having it display the topics based on the most recent message so it is displaying the subject for that message. What would be cleaner is to have it display the topic name while still showing the most recent message in the popup (I believe this how your original code for this block worked).
UPDATE: I tried a number of things to remove the Re: and to display the topic name but I can't figure it out. I just don't understand enough about dbase queries and php. It looks like we are requesting all the info from the dbase, but I don't get what we need to do to output the relevant pieces.