'Fetch non-offline presence from the database so that we can register
the appropriate time outs.'

def _get_active_presence(self, db_conn):

    sql = 'SELECT    user_id,    state,    last_active_ts,    last_federation_update_ts,    last_user_sync_ts,    status_msg,    currently_active    FROM    presence_stream    WHERE    state    !=    ?'
    sql = self.database_engine.convert_param_style(sql)
    txn = db_conn.cursor()
    txn.execute(sql, (PresenceState.OFFLINE,))
    rows = self.cursor_to_dict(txn)
    txn.close()
    for row in rows:
        row['currently_active'] = bool(row['currently_active'])
    return [UserPresenceState(**row) for row in rows]
