'Return the last message of the given channels'

@api.multi
def channel_fetch_preview(self):

    self._cr.execute('\n                                                SELECT    mail_channel_id    AS    id,    MAX(mail_message_id)    AS    message_id\n                                                FROM    mail_message_mail_channel_rel\n                                                WHERE    mail_channel_id    IN    %s\n                                                GROUP    BY    mail_channel_id\n                                                ', (tuple(self.ids),))
    channels_preview = dict(((r['message_id'], r) for r in self._cr.dictfetchall()))
    last_messages = self.env['mail.message'].browse(channels_preview.keys()).message_format()
    for message in last_messages:
        channel = channels_preview[message['id']]
        del channel['message_id']
        channel['last_message'] = message
    return channels_preview.values()
