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();
}
}
}
}
}
}
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));
}
}
}
}
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;
}
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);
}
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();
}
}
Aggregations