public void leaveRoom(String account, String room) { final MultiUserChat multiUserChat; RoomChat roomChat = getRoomChat(account, room); if (roomChat == null) return; multiUserChat = roomChat.getMultiUserChat(); roomChat.setState(RoomState.unavailable); roomChat.setRequested(false); roomChat.newAction(roomChat.getNickname(), null, ChatAction.leave); requestToWriteRoom(account, room, roomChat.getNickname(), roomChat.getPassword(), false); if (multiUserChat != null) { Thread thread = new Thread("Leave to room " + room + " from " + account) { @Override public void run() { try { multiUserChat.leave(); } catch (IllegalStateException e) { // Do nothing } } }; thread.setDaemon(true); thread.start(); } RosterManager.getInstance().onContactChanged(account, room); }
/** * Sends invitation. * * @param account * @param room * @param user * @throws NetworkException */ public void invite(String account, String room, String user) throws NetworkException { RoomChat roomChat = getRoomChat(account, room); if (roomChat == null || roomChat.getState() != RoomState.available) { Application.getInstance().onError(R.string.NOT_CONNECTED); return; } Message message = new Message(room); MUCUser mucUser = new MUCUser(); MUCUser.Invite invite = new MUCUser.Invite(); invite.setTo(user); invite.setReason(""); mucUser.setInvite(invite); message.addExtension(mucUser); ConnectionManager.getInstance().sendPacket(account, message); roomChat.putInvite(message.getPacketID(), user); roomChat.newAction(roomChat.getNickname(), user, ChatAction.invite_sent); }