'Remove all needactions of the current partner. If channel_ids is
given, restrict to messages written in one of those channels.'

@api.model
def mark_all_as_read(self, channel_ids=None, domain=None):

    partner_id = self.env.user.partner_id.id
    delete_mode = (not self.env.user.share)
    if ((domain is None) and delete_mode):
        query = 'DELETE    FROM    mail_message_res_partner_needaction_rel    WHERE    res_partner_id    IN    %s'
        args = [(partner_id,)]
        if channel_ids:
            query += '\n                                                                                AND    mail_message_id    in\n                                                                                                (SELECT    mail_message_id\n                                                                                                FROM    mail_message_mail_channel_rel\n                                                                                                WHERE    mail_channel_id    in    %s)'
            args += [tuple(channel_ids)]
        query += '    RETURNING    mail_message_id    as    id'
        self._cr.execute(query, args)
        self.invalidate_cache()
        ids = [m['id'] for m in self._cr.dictfetchall()]
    else:
        msg_domain = [('needaction_partner_ids', 'in', partner_id)]
        if channel_ids:
            msg_domain += [('channel_ids', 'in', channel_ids)]
        unread_messages = self.search(expression.AND([msg_domain, domain]))
        notifications = self.env['mail.notification'].sudo().search([('mail_message_id', 'in', unread_messages.ids), ('res_partner_id', '=', self.env.user.partner_id.id), ('is_read', '=', False)])
        if delete_mode:
            notifications.unlink()
        else:
            notifications.write({'is_read': True})
        ids = unread_messages.mapped('id')
    notification = {'type': 'mark_as_read', 'message_ids': ids, 'channel_ids': channel_ids}
    self.env['bus.bus'].sendone((self._cr.dbname, 'res.partner', self.env.user.partner_id.id), notification)
    return ids
