'Compute the im_status of the users'

@api.multi
def _compute_im_status(self):

    self.env.cr.execute("\n                                                SELECT\n                                                                user_id    as    id,\n                                                                CASE    WHEN    age(now()    AT    TIME    ZONE    'UTC',    last_poll)    >    interval    %s    THEN    'offline'\n                                                                                    WHEN    age(now()    AT    TIME    ZONE    'UTC',    last_presence)    >    interval    %s    THEN    'away'\n                                                                                    ELSE    'online'\n                                                                END    as    status\n                                                FROM    bus_presence\n                                                WHERE    user_id    IN    %s\n                                ", (('%s    seconds' % DISCONNECTION_TIMER), ('%s    seconds' % AWAY_TIMER), tuple(self.ids)))
    res = dict(((status['id'], status['status']) for status in self.env.cr.dictfetchall()))
    for user in self:
        user.im_status = res.get(user.id, 'offline')
