'Add profiles to the user directory
Args:
room_id (str): A room_id that all users are joined to
users_with_profile (dict): Users to add to directory in the form of
mapping of user_id -> ProfileInfo'

def add_profiles_to_user_dir(self, room_id, users_with_profile):

    if isinstance(self.database_engine, PostgresEngine):
        sql = "\n                                                                INSERT    INTO    user_directory_search(user_id,    vector)\n                                                                VALUES    (?,\n                                                                                setweight(to_tsvector('english',    ?),    'A')\n                                                                                ||    setweight(to_tsvector('english',    ?),    'D')\n                                                                                ||    setweight(to_tsvector('english',    COALESCE(?,    '')),    'B')\n                                                                )\n                                                "
        args = ((user_id, get_localpart_from_id(user_id), get_domain_from_id(user_id), profile.display_name) for (user_id, profile) in users_with_profile.iteritems())
    elif isinstance(self.database_engine, Sqlite3Engine):
        sql = '\n                                                                INSERT    INTO    user_directory_search(user_id,    value)\n                                                                VALUES    (?,?)\n                                                '
        args = ((user_id, (('%s    %s' % (user_id, p.display_name)) if p.display_name else user_id)) for (user_id, p) in users_with_profile.iteritems())
    else:
        raise Exception('Unrecognized    database    engine')
    def _add_profiles_to_user_dir_txn(txn):
        txn.executemany(sql, args)
        self._simple_insert_many_txn(txn, table='user_directory', values=[{'user_id': user_id, 'room_id': room_id, 'display_name': profile.display_name, 'avatar_url': profile.avatar_url} for (user_id, profile) in users_with_profile.iteritems()])
        for user_id in users_with_profile:
            txn.call_after(self.get_user_in_directory.invalidate, (user_id,))
    return self.runInteraction('add_profiles_to_user_dir', _add_profiles_to_user_dir_txn)
