Search in sources :

Example 1 with LocalMUCRoom

use of org.jivesoftware.openfire.muc.spi.LocalMUCRoom in project Openfire by igniterealtime.

the class MultiUserChatManager method joinedCluster.

// Cluster management tasks
@Override
public void joinedCluster() {
    if (!ClusterManager.isSeniorClusterMember()) {
        // Get transient rooms and persistent rooms with occupants from senior
        // cluster member and merge with local ones. If room configuration was
        // changed in both places then latest configuration will be kept
        @SuppressWarnings("unchecked") List<ServiceInfo> result = (List<ServiceInfo>) CacheFactory.doSynchronousClusterTask(new SeniorMemberServicesRequest(), ClusterManager.getSeniorClusterMember().toByteArray());
        if (result != null) {
            for (ServiceInfo serviceInfo : result) {
                MultiUserChatService service;
                service = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceInfo.getSubdomain());
                if (service == null) {
                    // This is a service we don't know about yet, create it locally and register it;
                    service = new MultiUserChatServiceImpl(serviceInfo.getSubdomain(), serviceInfo.getDescription(), serviceInfo.isHidden());
                    XMPPServer.getInstance().getMultiUserChatManager().registerMultiUserChatService(service);
                }
                MultiUserChatServiceImpl serviceImpl = (MultiUserChatServiceImpl) service;
                for (RoomInfo roomInfo : serviceInfo.getRooms()) {
                    LocalMUCRoom remoteRoom = roomInfo.getRoom();
                    LocalMUCRoom localRoom = serviceImpl.getLocalChatRoom(remoteRoom.getName());
                    if (localRoom == null) {
                        // Create local room with remote information
                        localRoom = remoteRoom;
                        serviceImpl.chatRoomAdded(localRoom);
                    } else {
                        // Update local room with remote information
                        localRoom.updateConfiguration(remoteRoom);
                    }
                    // TODO Handle conflict of nicknames
                    for (OccupantAddedEvent event : roomInfo.getOccupants()) {
                        event.setSendPresence(true);
                        event.run();
                    }
                }
            }
        }
    }
}
Also used : ServiceInfo(org.jivesoftware.openfire.muc.cluster.ServiceInfo) SeniorMemberServicesRequest(org.jivesoftware.openfire.muc.cluster.SeniorMemberServicesRequest) LocalMUCRoom(org.jivesoftware.openfire.muc.spi.LocalMUCRoom) MultiUserChatServiceImpl(org.jivesoftware.openfire.muc.spi.MultiUserChatServiceImpl) RoomInfo(org.jivesoftware.openfire.muc.cluster.RoomInfo) ArrayList(java.util.ArrayList) List(java.util.List) OccupantAddedEvent(org.jivesoftware.openfire.muc.cluster.OccupantAddedEvent)

Example 2 with LocalMUCRoom

use of org.jivesoftware.openfire.muc.spi.LocalMUCRoom in project Openfire by igniterealtime.

the class GetNewMemberRoomsRequest method run.

@Override
public void run() {
    rooms = new ArrayList<>();
    // Get all services that have local occupants and include them in the reply
    for (MultiUserChatService mucService : XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatServices()) {
        // Get rooms that have local occupants and include them in the reply
        for (MUCRoom room : mucService.getChatRooms()) {
            LocalMUCRoom localRoom = (LocalMUCRoom) room;
            Collection<MUCRole> localOccupants = new ArrayList<>();
            for (MUCRole occupant : room.getOccupants()) {
                if (occupant.isLocal()) {
                    localOccupants.add(occupant);
                }
            }
            if (!localOccupants.isEmpty()) {
                rooms.add(new RoomInfo(localRoom, localOccupants));
            }
        }
    }
}
Also used : MUCRole(org.jivesoftware.openfire.muc.MUCRole) MUCRoom(org.jivesoftware.openfire.muc.MUCRoom) LocalMUCRoom(org.jivesoftware.openfire.muc.spi.LocalMUCRoom) LocalMUCRoom(org.jivesoftware.openfire.muc.spi.LocalMUCRoom) ArrayList(java.util.ArrayList) MultiUserChatService(org.jivesoftware.openfire.muc.MultiUserChatService)

Example 3 with LocalMUCRoom

use of org.jivesoftware.openfire.muc.spi.LocalMUCRoom in project Openfire by igniterealtime.

the class MUCRoomTask method getRoom.

public LocalMUCRoom getRoom() {
    MultiUserChatService mucService = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(subdomain);
    if (mucService == null) {
        throw new IllegalArgumentException("MUC service not found for subdomain: " + subdomain);
    }
    LocalMUCRoom room = (LocalMUCRoom) mucService.getChatRoom(roomName);
    if (room == null) {
        throw new IllegalArgumentException("Room not found: " + roomName);
    }
    return room;
}
Also used : LocalMUCRoom(org.jivesoftware.openfire.muc.spi.LocalMUCRoom) MultiUserChatService(org.jivesoftware.openfire.muc.MultiUserChatService)

Example 4 with LocalMUCRoom

use of org.jivesoftware.openfire.muc.spi.LocalMUCRoom in project Openfire by igniterealtime.

the class RoomUpdatedEvent method readExternal.

@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    super.readExternal(in);
    room = new LocalMUCRoom();
    room.readExternal(in);
}
Also used : LocalMUCRoom(org.jivesoftware.openfire.muc.spi.LocalMUCRoom)

Example 5 with LocalMUCRoom

use of org.jivesoftware.openfire.muc.spi.LocalMUCRoom 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)

Aggregations

LocalMUCRoom (org.jivesoftware.openfire.muc.spi.LocalMUCRoom)8 ArrayList (java.util.ArrayList)4 List (java.util.List)2 MUCRoom (org.jivesoftware.openfire.muc.MUCRoom)2 MultiUserChatService (org.jivesoftware.openfire.muc.MultiUserChatService)2 OccupantAddedEvent (org.jivesoftware.openfire.muc.cluster.OccupantAddedEvent)2 RoomInfo (org.jivesoftware.openfire.muc.cluster.RoomInfo)2 MultiUserChatServiceImpl (org.jivesoftware.openfire.muc.spi.MultiUserChatServiceImpl)2 Date (java.util.Date)1 MUCRole (org.jivesoftware.openfire.muc.MUCRole)1 GetNewMemberRoomsRequest (org.jivesoftware.openfire.muc.cluster.GetNewMemberRoomsRequest)1 RoomUpdatedEvent (org.jivesoftware.openfire.muc.cluster.RoomUpdatedEvent)1 SeniorMemberServicesRequest (org.jivesoftware.openfire.muc.cluster.SeniorMemberServicesRequest)1 ServiceInfo (org.jivesoftware.openfire.muc.cluster.ServiceInfo)1 JID (org.xmpp.packet.JID)1