Search in sources :

Example 16 with MUCRoom

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

the class MultiUserChatServiceImpl method getIdentities.

@Override
public Iterator<Element> getIdentities(String name, String node, JID senderJID) {
    ArrayList<Element> identities = new ArrayList<>();
    if (name == null && node == null) {
        // Answer the identity of the MUC service
        Element identity = DocumentHelper.createElement("identity");
        identity.addAttribute("category", "conference");
        identity.addAttribute("name", getDescription());
        identity.addAttribute("type", "text");
        identities.add(identity);
        // TODO: Should internationalize Public Chatroom Search, and make it configurable.
        Element searchId = DocumentHelper.createElement("identity");
        searchId.addAttribute("category", "directory");
        searchId.addAttribute("name", "Public Chatroom Search");
        searchId.addAttribute("type", "chatroom");
        identities.add(searchId);
        if (!extraDiscoIdentities.isEmpty()) {
            identities.addAll(extraDiscoIdentities);
        }
    } else if (name != null && node == null) {
        // Answer the identity of a given room
        MUCRoom room = getChatRoom(name);
        if (room != null) {
            Element identity = DocumentHelper.createElement("identity");
            identity.addAttribute("category", "conference");
            identity.addAttribute("name", room.getNaturalLanguageName());
            identity.addAttribute("type", "text");
            identities.add(identity);
        }
    } else if (name != null && "x-roomuser-item".equals(node)) {
        // Answer reserved nickname for the sender of the disco request in the requested room
        MUCRoom room = getChatRoom(name);
        if (room != null) {
            String reservedNick = room.getReservedNickname(senderJID);
            if (reservedNick != null) {
                Element identity = DocumentHelper.createElement("identity");
                identity.addAttribute("category", "conference");
                identity.addAttribute("name", reservedNick);
                identity.addAttribute("type", "text");
                identities.add(identity);
            }
        }
    }
    return identities.iterator();
}
Also used : MUCRoom(org.jivesoftware.openfire.muc.MUCRoom) Element(org.dom4j.Element)

Example 17 with MUCRoom

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

the class ConversationEvent method run.

public void run(ConversationManager conversationManager) {
    if (Type.chatMessageReceived == type) {
        conversationManager.processMessage(sender, receiver, body, "", date);
    } else if (Type.roomDestroyed == type) {
        conversationManager.roomConversationEnded(roomJID, date);
    } else if (Type.occupantJoined == type) {
        conversationManager.joinedGroupConversation(roomJID, user, nickname, date);
    } else if (Type.occupantLeft == type) {
        conversationManager.leftGroupConversation(roomJID, user, date);
        // If there are no more occupants then consider the group conversarion over
        MUCRoom mucRoom = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(roomJID).getChatRoom(roomJID.getNode());
        if (mucRoom != null && mucRoom.getOccupantsCount() == 0) {
            conversationManager.roomConversationEnded(roomJID, date);
        }
    } else if (Type.nicknameChanged == type) {
        conversationManager.leftGroupConversation(roomJID, user, date);
        conversationManager.joinedGroupConversation(roomJID, user, nickname, new Date(date.getTime() + 1));
    } else if (Type.roomMessageReceived == type) {
        conversationManager.processRoomMessage(roomJID, user, nickname, body, stanza, date);
    }
}
Also used : MUCRoom(org.jivesoftware.openfire.muc.MUCRoom) Date(java.util.Date)

Example 18 with MUCRoom

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

the class IQQueryHandler method handleIQ.

public IQ handleIQ(IQ packet) throws UnauthorizedException {
    Session session = sessionManager.getSession(packet.getFrom());
    // If no session was found then answer with an error (if possible)
    if (session == null) {
        Log.error("Error during resource binding. Session not found in " + sessionManager.getPreAuthenticatedKeys() + " for key " + packet.getFrom());
        return buildErrorResponse(packet);
    }
    if (packet.getType().equals(IQ.Type.get)) {
        return buildSupportedFieldsResult(packet, session);
    }
    // Default to user's own archive
    JID archiveJid = packet.getTo();
    if (archiveJid == null) {
        archiveJid = packet.getFrom().asBareJID();
    }
    Log.debug("Archive requested is {}", archiveJid);
    // Now decide the type.
    boolean muc = false;
    if (!XMPPServer.getInstance().isLocal(archiveJid)) {
        Log.debug("Archive is not local (user)");
        if (XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(archiveJid) == null) {
            Log.debug("No chat service for this domain");
            return buildErrorResponse(packet);
        } else {
            muc = true;
            Log.debug("MUC");
        }
    }
    JID requestor = packet.getFrom().asBareJID();
    Log.debug("Requestor is {} for muc=={}", requestor, muc);
    // Auth checking.
    if (muc) {
        MultiUserChatService service = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(archiveJid);
        MUCRoom room = service.getChatRoom(archiveJid.getNode());
        if (room == null) {
            return buildErrorResponse(packet);
        }
        boolean pass = false;
        if (service.isSysadmin(requestor)) {
            pass = true;
        }
        MUCRole.Affiliation aff = room.getAffiliation(requestor);
        if (aff != MUCRole.Affiliation.outcast) {
            if (aff == MUCRole.Affiliation.owner || aff == MUCRole.Affiliation.admin) {
                pass = true;
            } else if (room.isMembersOnly()) {
                if (aff == MUCRole.Affiliation.member) {
                    pass = true;
                }
            } else {
                pass = true;
            }
        }
        if (!pass) {
            return buildForbiddenResponse(packet);
        }
    } else if (!archiveJid.equals(requestor)) {
        // ... disallow unless admin.
        if (!XMPPServer.getInstance().getAdmins().contains(requestor)) {
            return buildForbiddenResponse(packet);
        }
    }
    sendMidQuery(packet, session);
    final QueryRequest queryRequest = new QueryRequest(packet.getChildElement(), archiveJid);
    Collection<ArchivedMessage> archivedMessages = retrieveMessages(queryRequest);
    for (ArchivedMessage archivedMessage : archivedMessages) {
        sendMessageResult(session, queryRequest, archivedMessage);
    }
    sendEndQuery(packet, session, queryRequest);
    return null;
}
Also used : MUCRole(org.jivesoftware.openfire.muc.MUCRole) MUCRoom(org.jivesoftware.openfire.muc.MUCRoom) ArchivedMessage(com.reucon.openfire.plugin.archive.model.ArchivedMessage) MultiUserChatService(org.jivesoftware.openfire.muc.MultiUserChatService) Session(org.jivesoftware.openfire.session.Session)

Example 19 with MUCRoom

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

the class MUCRoomController method deleteAffiliation.

/**
	 * Delete affiliation.
	 *
	 * @param serviceName
	 *            the service name
	 * @param roomName
	 *            the room name
	 * @param jid
	 *            the jid
	 * @throws ServiceException
	 *             the service exception
	 */
public void deleteAffiliation(String serviceName, String roomName, String jid) throws ServiceException {
    MUCRoom room = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName).getChatRoom(roomName.toLowerCase());
    try {
        JID userJid = UserUtils.checkAndGetJID(jid);
        // Send a presence to other room members
        List<Presence> addNonePresence = room.addNone(userJid, room.getRole());
        for (Presence presence : addNonePresence) {
            room.send(presence);
        }
    } catch (ForbiddenException e) {
        throw new ServiceException("Could not delete affiliation", jid, ExceptionType.NOT_ALLOWED, Response.Status.FORBIDDEN, e);
    } catch (ConflictException e) {
        throw new ServiceException("Could not delete affiliation", jid, ExceptionType.NOT_ALLOWED, Response.Status.CONFLICT, e);
    }
}
Also used : ForbiddenException(org.jivesoftware.openfire.muc.ForbiddenException) LocalMUCRoom(org.jivesoftware.openfire.muc.spi.LocalMUCRoom) MUCRoom(org.jivesoftware.openfire.muc.MUCRoom) JID(org.xmpp.packet.JID) ServiceException(org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException) ConflictException(org.jivesoftware.openfire.muc.ConflictException) Presence(org.xmpp.packet.Presence)

Example 20 with MUCRoom

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

the class MUCRoomController method getChatRooms.

/**
	 * Gets the chat rooms.
	 * 
	 * @param serviceName
	 *            the service name
	 * @param channelType
	 *            the channel type
	 * @param roomSearch
	 *            the room search
	 * @return the chat rooms
	 */
public MUCRoomEntities getChatRooms(String serviceName, String channelType, String roomSearch, boolean expand) {
    List<MUCRoom> rooms = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName).getChatRooms();
    List<MUCRoomEntity> mucRoomEntities = new ArrayList<MUCRoomEntity>();
    for (MUCRoom chatRoom : rooms) {
        if (roomSearch != null) {
            if (!chatRoom.getName().contains(roomSearch)) {
                continue;
            }
        }
        if (channelType.equals(MUCChannelType.ALL)) {
            mucRoomEntities.add(convertToMUCRoomEntity(chatRoom, expand));
        } else if (channelType.equals(MUCChannelType.PUBLIC) && chatRoom.isPublicRoom()) {
            mucRoomEntities.add(convertToMUCRoomEntity(chatRoom, expand));
        }
    }
    return new MUCRoomEntities(mucRoomEntities);
}
Also used : LocalMUCRoom(org.jivesoftware.openfire.muc.spi.LocalMUCRoom) MUCRoom(org.jivesoftware.openfire.muc.MUCRoom) MUCRoomEntity(org.jivesoftware.openfire.plugin.rest.entity.MUCRoomEntity) ArrayList(java.util.ArrayList) MUCRoomEntities(org.jivesoftware.openfire.plugin.rest.entity.MUCRoomEntities)

Aggregations

MUCRoom (org.jivesoftware.openfire.muc.MUCRoom)20 ArrayList (java.util.ArrayList)6 Date (java.util.Date)5 Element (org.dom4j.Element)5 LocalMUCRoom (org.jivesoftware.openfire.muc.spi.LocalMUCRoom)5 JID (org.xmpp.packet.JID)5 MultiUserChatService (org.jivesoftware.openfire.muc.MultiUserChatService)4 NotAllowedException (org.jivesoftware.openfire.muc.NotAllowedException)3 DataForm (org.xmpp.forms.DataForm)3 ArchivedMessage (com.reucon.openfire.plugin.archive.model.ArchivedMessage)2 List (java.util.List)2 MUCRoomEntity (org.jivesoftware.openfire.entity.MUCRoomEntity)2 ConflictException (org.jivesoftware.openfire.muc.ConflictException)2 ForbiddenException (org.jivesoftware.openfire.muc.ForbiddenException)2 MUCRole (org.jivesoftware.openfire.muc.MUCRole)2 MUCRoomEntity (org.jivesoftware.openfire.plugin.rest.entity.MUCRoomEntity)2 ServiceException (org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException)2 FormField (org.xmpp.forms.FormField)2 IQ (org.xmpp.packet.IQ)2 Presence (org.xmpp.packet.Presence)2