Search in sources :

Example 1 with RoomUpdatedEvent

use of org.jivesoftware.openfire.muc.cluster.RoomUpdatedEvent in project Openfire by igniterealtime.

the class MUCRoomController method createRoom.

/**
	 * Creates the room.
	 *
	 * @param mucRoomEntity
	 *            the MUC room entity
	 * @param serviceName
	 *            the service name
	 * @throws NotAllowedException
	 *             the not allowed exception
	 * @throws ForbiddenException
	 *             the forbidden exception
	 * @throws ConflictException
	 *             the conflict exception
	 * @throws AlreadyExistsException 
	 */
private void createRoom(MUCRoomEntity mucRoomEntity, String serviceName) throws NotAllowedException, ForbiddenException, ConflictException, AlreadyExistsException {
    // Set owner
    JID owner = XMPPServer.getInstance().createJID("admin", null);
    if (mucRoomEntity.getOwners() != null && mucRoomEntity.getOwners().size() > 0) {
        owner = new JID(mucRoomEntity.getOwners().get(0));
    } else {
        List<String> owners = new ArrayList<String>();
        owners.add(owner.toBareJID());
        mucRoomEntity.setOwners(owners);
    }
    //	Check if chat service is available, if not create a new one
    boolean serviceRegistered = XMPPServer.getInstance().getMultiUserChatManager().isServiceRegistered(serviceName);
    if (!serviceRegistered) {
        XMPPServer.getInstance().getMultiUserChatManager().createMultiUserChatService(serviceName, serviceName, false);
    }
    MUCRoom room = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName).getChatRoom(mucRoomEntity.getRoomName().toLowerCase(), owner);
    // Set values
    room.setNaturalLanguageName(mucRoomEntity.getNaturalName());
    room.setSubject(mucRoomEntity.getSubject());
    room.setDescription(mucRoomEntity.getDescription());
    room.setPassword(mucRoomEntity.getPassword());
    room.setPersistent(mucRoomEntity.isPersistent());
    room.setPublicRoom(mucRoomEntity.isPublicRoom());
    room.setRegistrationEnabled(mucRoomEntity.isRegistrationEnabled());
    room.setCanAnyoneDiscoverJID(mucRoomEntity.isCanAnyoneDiscoverJID());
    room.setCanOccupantsChangeSubject(mucRoomEntity.isCanOccupantsChangeSubject());
    room.setCanOccupantsInvite(mucRoomEntity.isCanOccupantsInvite());
    room.setChangeNickname(mucRoomEntity.isCanChangeNickname());
    room.setModificationDate(mucRoomEntity.getModificationDate());
    room.setLogEnabled(mucRoomEntity.isLogEnabled());
    room.setLoginRestrictedToNickname(mucRoomEntity.isLoginRestrictedToNickname());
    room.setMaxUsers(mucRoomEntity.getMaxUsers());
    room.setMembersOnly(mucRoomEntity.isMembersOnly());
    room.setModerated(mucRoomEntity.isModerated());
    // Fire RoomUpdateEvent if cluster is started
    if (ClusterManager.isClusteringStarted()) {
        CacheFactory.doClusterTask(new RoomUpdatedEvent((LocalMUCRoom) room));
    }
    // Set broadcast presence roles
    if (mucRoomEntity.getBroadcastPresenceRoles() != null) {
        room.setRolesToBroadcastPresence(mucRoomEntity.getBroadcastPresenceRoles());
    } else {
        room.setRolesToBroadcastPresence(new ArrayList<String>());
    }
    // Set all roles
    setRoles(room, mucRoomEntity);
    // Set creation date
    if (mucRoomEntity.getCreationDate() != null) {
        room.setCreationDate(mucRoomEntity.getCreationDate());
    } else {
        room.setCreationDate(new Date());
    }
    // Set modification date
    if (mucRoomEntity.getModificationDate() != null) {
        room.setModificationDate(mucRoomEntity.getModificationDate());
    } else {
        room.setModificationDate(new Date());
    }
    // Unlock the room, because the default configuration lock the room.  		
    room.unlock(room.getRole());
    // Save the room to the DB if the room should be persistant
    if (room.isPersistent()) {
        room.saveToDB();
    }
}
Also used : JID(org.xmpp.packet.JID) LocalMUCRoom(org.jivesoftware.openfire.muc.spi.LocalMUCRoom) MUCRoom(org.jivesoftware.openfire.muc.MUCRoom) RoomUpdatedEvent(org.jivesoftware.openfire.muc.cluster.RoomUpdatedEvent) LocalMUCRoom(org.jivesoftware.openfire.muc.spi.LocalMUCRoom) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 2 with RoomUpdatedEvent

use of org.jivesoftware.openfire.muc.cluster.RoomUpdatedEvent in project Openfire by igniterealtime.

the class LocalMUCRoom method changeSubject.

@Override
public void changeSubject(Message packet, MUCRole role) throws ForbiddenException {
    if ((canOccupantsChangeSubject() && role.getRole().compareTo(MUCRole.Role.visitor) < 0) || MUCRole.Role.moderator == role.getRole()) {
        // Set the new subject to the room
        subject = packet.getSubject();
        MUCPersistenceManager.updateRoomSubject(this);
        // Notify all the occupants that the subject has changed
        packet.setFrom(role.getRoleAddress());
        send(packet);
        // Fire event signifying that the room's subject has changed.
        MUCEventDispatcher.roomSubjectChanged(getJID(), role.getUserAddress(), subject);
        // Let other cluster nodes that the room has been updated
        CacheFactory.doClusterTask(new RoomUpdatedEvent(this));
    } else {
        throw new ForbiddenException();
    }
}
Also used : ForbiddenException(org.jivesoftware.openfire.muc.ForbiddenException) RoomUpdatedEvent(org.jivesoftware.openfire.muc.cluster.RoomUpdatedEvent)

Aggregations

RoomUpdatedEvent (org.jivesoftware.openfire.muc.cluster.RoomUpdatedEvent)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 ForbiddenException (org.jivesoftware.openfire.muc.ForbiddenException)1 MUCRoom (org.jivesoftware.openfire.muc.MUCRoom)1 LocalMUCRoom (org.jivesoftware.openfire.muc.spi.LocalMUCRoom)1 JID (org.xmpp.packet.JID)1