/** * Changes the nickname. * * @param newNickname The new nickname. * @return The async result with the presence returned by the chat room. * @see <a href="https://xmpp.org/extensions/xep-0045.html#changenick">7.6 Changing Nickname</a> */ public final AsyncResult<Presence> changeNickname(String newNickname) { if (!hasEntered()) { throw new IllegalStateException("You must have entered the room to change your nickname."); } final Presence changeNickNamePresence = new Presence(roomJid.withResource(newNickname)); return xmppSession.sendAndAwaitPresence(changeNickNamePresence, presence -> presence.getFrom().equals(changeNickNamePresence.getTo())); }
/** * Exits the room with a custom message. * * @param message The exit message. * @return The async result. * @see <a href="https://xmpp.org/extensions/xep-0045.html#exit">7.14 Exiting a Room</a> */ public final AsyncResult<Void> exit(String message) { if (!hasEntered()) { return new AsyncResult<>(CompletableFuture.completedFuture(null)); } // Store the current nick, to determine self-presence (because nick gets null before determining self-presence). final String usedNick = getNick(); return xmppSession.sendAndAwaitPresence(new Presence(roomJid.withResource(usedNick), Presence.Type.UNAVAILABLE, message), presence -> { Jid room = presence.getFrom().asBareJid(); return !presence.isAvailable() && room.equals(roomJid) && isSelfPresence(presence, usedNick); }).handle((result, throwable) -> { userHasExited(); return null; }); }
final OccupantEvent.Type type; if (previousOccupant == null && (isSelfPresence || hasEntered())) {