Okay, yes indeed.
The replacement should be:
'first_post' => 't.id_topic',
'last_post' => 't.id_last_msg'
to:
'first_post' => 'mf.poster_time',
'last_post' => 'ml.poster_time'
And this redefines the sorting order for last message (from message id to last post time) and first message (from topic id to first post time).
And, same file:
FROM {db_prefix}topics AS t' . ($sort_by === 'last_poster' ? '
to:
FROM {db_prefix}topics AS t' . (in_array($sort_by, array('last_poster', 'last_post') ? '
This should join the messages table (last => ml) for both last_poster and last_post (as modified above).
And:
in_array($sort_by, array('starter', 'subject'))
to:
in_array($sort_by, array('starter', 'subject', 'first_post'))
to join the message table (first => mf) for all the cases, including the above modified first_post.
Again, not tested (I'm working on other stuff and I don't have handy a good place to test)... sorry.