protected function get_users_messages_for_conversation(int $conversationid, int $userid) : moodle_recordset {
        global $DB;

        $usernamefields = \user_picture::fields('u');
        $sql = "SELECT $usernamefields, m.*
                  FROM {messages} m
                  JOIN {user} u
                    ON u.id = m.useridfrom
                  JOIN {message_email_messages} mem
                    ON mem.messageid = m.id
                 WHERE mem.useridto = ?
                   AND mem.conversationid = ?
                   AND mem.id <= ?";

        return $DB->get_recordset_sql($sql, [$userid, $conversationid, $this->maxid]);
    }