sco0ter / babbler

Java library for XMPP clients using JAXB
http://docs.xmpp.rocks
MIT License
6 stars 2 forks source link

charoom is deleted when sending a messge to chatroom #125

Open sco0ter opened 6 years ago

sco0ter commented 6 years ago

Original report by Anonymous.


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();
sco0ter commented 6 years ago

Original comment by Christian Schudt (Bitbucket: sco0ter, GitHub: sco0ter).


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);
sco0ter commented 6 years ago

Original comment by Jacques van der Merwe (Bitbucket: vanenkie, ).


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.

sco0ter commented 6 years ago

Original comment by Christian Schudt (Bitbucket: sco0ter, GitHub: sco0ter).


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.

sco0ter commented 6 years ago

Original comment by Christian Schudt (Bitbucket: sco0ter, GitHub: sco0ter).


Is this still an issue?