public void inviteOccupant( String subdomain, String roomName, String memberJid, String password, String reason) throws Exception { MultiUserChatService service = this.multiUserChatManager.getMultiUserChatService(subdomain); if (service == null) { throw new NotFoundException("MUC service not found for " + subdomain); } MUCRoom mucRoom = service.getChatRoom(roomName); if (mucRoom == null) { throw new NotFoundException("Room not found for " + subdomain + " roomName " + roomName); } String roomPassword = mucRoom.getPassword(); if (password == null && roomPassword != null) { throw new NotAllowedException("Password mismatch"); } if (mucRoom.getPassword() != null && !mucRoom.getPassword().equals(password)) { throw new NotAllowedException("Password mismatch"); } String ownerJid = mucRoom.getOwners().iterator().next(); if (!mucRoom.getOccupants().contains(new JID(ownerJid))) { throw new NotAllowedException("Owner is not in te room -- cannot invite"); } List<MUCRole> roles = mucRoom.getOccupantsByBareJID(ownerJid); JID memberJID = new JID(memberJid); for (MUCRole role : roles) { if (role.getAffiliation() == Affiliation.owner) { mucRoom.sendInvitation(memberJID, reason, role, null); break; } } }
public Map<String, Object> convertToRoomSpec(MUCRoom room) { Map<String, Object> roomSpec = new HashMap(); roomSpec.put("naturalLanguageName", room.getNaturalLanguageName()); roomSpec.put("name", room.getName()); roomSpec.put("description", room.getDescription()); roomSpec.put("canAnyoneDiscoverJID", room.canAnyoneDiscoverJID()); roomSpec.put("canChangeNickname", room.canChangeNickname()); roomSpec.put("canOccupantsChangeSubject", room.canOccupantsChangeSubject()); roomSpec.put("canOccupantsInvite", room.canOccupantsInvite()); roomSpec.put("publicRoom", room.isPublicRoom()); roomSpec.put("password", room.getPassword()); roomSpec.put("ID", room.getID()); roomSpec.put("persistent", room.isPersistent()); roomSpec.put("registrationEnabled", room.isRegistrationEnabled()); roomSpec.put("logEnabled", room.isLogEnabled()); roomSpec.put("loginRestrictedToNickname", room.isLoginRestrictedToNickname()); roomSpec.put("maxUsers", room.getMaxUsers()); roomSpec.put("membersOnly", room.isMembersOnly()); roomSpec.put("moderated", room.isModerated()); roomSpec.put("owners", convertJIDsToStringList(room.getOwners())); roomSpec.put("admins", convertJIDsToStringList(room.getAdmins())); roomSpec.put("members", convertJIDsToStringList(room.getMembers())); roomSpec.put("outcasts", convertJIDsToStringList(room.getOutcasts())); roomSpec.put("broadcastPresenceRoles", room.getRolesToBroadcastPresence()); roomSpec.put("creationDate", room.getCreationDate()); roomSpec.put("modificationDate", room.getModificationDate()); return roomSpec; }
public void kickOccupant( String subdomain, String roomName, String password, String memberJid, String reason) throws NotAllowedException { MUCRoom mucRoom = this.multiUserChatManager.getMultiUserChatService(subdomain).getChatRoom(roomName); String roomPassword = mucRoom.getPassword(); if (password == null && roomPassword != null) { throw new NotAllowedException("Password mismatch"); } if (mucRoom.getPassword() != null && !mucRoom.getPassword().equals(password)) { throw new NotAllowedException("Password mismatch"); } String actorJid = mucRoom.getOwners().iterator().next(); JID memberJID = new JID(memberJid); JID actorJID = new JID(actorJid); mucRoom.kickOccupant(memberJID, actorJID, reason); }