charoom is deleted when sending a messge to chatroom

Issue #125 new
Former user created an issue

I have a situation where when I programmatically enter a chat room and do not exit the chatroom when program ends the chatroom is deleted. I commented the line "chatRoom.exit();" out sand then the chatroom is deleted. client.connect(); client.login("xxxxxxxx", "xxxxxxx"); MultiUserChatManager multiUserChatManager = client.getManager(MultiUserChatManager.class); Jid chatRoomJid = Jid.of(chatRoomName);

    ChatRoom chatRoom = multiUserChatManager.createChatRoom(chatRoomJid);
    chatRoom.enter(nick);
    chatRoom.sendMessage(message);
    //chatRoom.exit();
    client.close();

Comments (4)

  1. Christian Schudt repo owner

    I guess your XMPP server deletes the chat room if the room is empty (which it is, if you end the program or exit). Try to configure it as permanent room:

    chatRoom.enter(nick);
    RoomConfiguration roomConfiguration = RoomConfiguration.builder()
                            .persistent(true)
                            .build();
    chatRoom.configure(roomConfiguration);
    chatRoom.sendMessage(message);
    
  2. Jacques van der Merwe

    thanks, I created the chatroom outside of the Java code (using Jabber client). I actually only want to join the room and send messages. the library does not allow just join, you have to create a chatroom and according to your documentation this is valid for both new chatrooms and to join an existing room. If I add the chatRoom.exit(); line before closing the client then the chatroom is left undeleted. If I remove the chatRoom.exit(); line then the chatroom is deleted.

  3. Christian Schudt repo owner

    exit() simply sends an unavailable presence to the chat room in accordance with the specification.

    Please also note, that enter() and sendMessage() are asynchronous methods (they return Future<Void>). If you close() too early, the unavailable presence might not have been sent.

    In any case, I have no idea, why the room is deleted (on the server, right?), if you don't exit gracefully with unavailable presence (exit()). Maybe the server has a timeout and deletes them later?

    If you want to block (wait until sent, or until exited), try this:

    chatRoom.sendMessage("Hi").get();
    chatRoom.exit().get();
    

    To be clear: multiUserChatManager.createChatRoom(chatRoomJid); only creates a ChatRoom instance locally, so you can work with it.

  4. Log in to comment