Search in sources :

Example 1 with JoinRoom

use of org.xmpp.muc.JoinRoom in project Openfire by igniterealtime.

the class Workgroup method sendInvitation.

/**
     * An agent has accepted the offer and was choosen to answer the user's requests. The workgroup
     * will create a new room where the agent can answer the user's needs. Once the room has been
     * created, the Agent and the user that made the request will receive invitiations to join the
     * newly created room.<p>
     * <p/>
     * The workgroup will listen for all the packets sent to the room and generate a conversation
     * transcript.
     *
     * @param agent   the AgentSession that accepted and was choosen to respond the user's requests.
     * @param request the request made by a user.
     */
public void sendInvitation(AgentSession agent, UserRequest request) {
    // we need to destroy all MUC rooms created by workgroups
    try {
        RoomInterceptorManager interceptorManager = RoomInterceptorManager.getInstance();
        WorkgroupManager workgroupManager = WorkgroupManager.getInstance();
        String userJID = request.getUserJID().toString();
        final Workgroup sessionWorkgroup = request.getWorkgroup();
        final String sessionID = request.getSessionID();
        String workgroupName = getJID().getNode();
        final String serviceName = workgroupManager.getMUCServiceName();
        final String roomName = sessionID + "@" + serviceName;
        final String roomJID = roomName + "/" + workgroupName;
        // Create the room by joining it. The workgroup will be the owner of the room and will
        // invite the Agent and the user to join the room
        JoinRoom joinRoom = new JoinRoom(getFullJID().toString(), roomJID);
        interceptorManager.invokeInterceptors(getJID().toBareJID(), joinRoom, false, false);
        send(joinRoom);
        interceptorManager.invokeInterceptors(getJID().toBareJID(), joinRoom, false, true);
        // Configure the newly created room
        Map<String, Collection<String>> fields = new HashMap<String, Collection<String>>();
        // Make a non-public room
        List<String> values = new ArrayList<String>();
        values.add("0");
        fields.put("muc#roomconfig_publicroom", values);
        // Set the room description
        values = new ArrayList<String>();
        values.add(roomName);
        fields.put("muc#roomconfig_roomdesc", values);
        // Set that anyone can change the room subject
        values = new ArrayList<String>();
        values.add("1");
        fields.put("muc#roomconfig_changesubject", values);
        // Make the room temporary
        values = new ArrayList<String>();
        values.add("0");
        fields.put("muc#roomconfig_persistentroom", values);
        // Set that only moderators can see the occupants' JID
        values = new ArrayList<String>();
        values.add("moderators");
        fields.put("muc#roomconfig_whois", values);
        // Set that we want packets to include the real JID
        values = new ArrayList<String>();
        values.add("0");
        fields.put("anonymous", values);
        // Only broadcast presences of participants and visitors
        values = new ArrayList<String>();
        values.add("participant");
        values.add("visitor");
        fields.put("muc#roomconfig_presencebroadcast", values);
        RoomConfiguration conf = new RoomConfiguration(fields);
        conf.setTo(roomName);
        conf.setFrom(getFullJID());
        interceptorManager.invokeInterceptors(getJID().toBareJID(), conf, false, false);
        send(conf);
        interceptorManager.invokeInterceptors(getJID().toBareJID(), conf, false, true);
        // Create a new entry for the active session and the request made by the user
        requests.put(sessionID, request);
        // Invite the Agent to the new room
        Invitation invitation = new Invitation(agent.getJID().toString(), sessionID);
        invitation.setTo(roomName);
        invitation.setFrom(getFullJID());
        // Add workgroup extension that includes the JID of the user that made the request
        Element element = invitation.addChildElement("offer", "http://jabber.org/protocol/workgroup");
        element.addAttribute("jid", userJID);
        // Add custom extension that includes the sessionID
        element = invitation.addChildElement("session", "http://jivesoftware.com/protocol/workgroup");
        element.addAttribute("workgroup", sessionWorkgroup.getJID().toString());
        element.addAttribute("id", sessionID);
        // anonymous user
        if (request.isAnonymousUser()) {
            element = invitation.addChildElement("user", "http://jivesoftware.com/protocol/workgroup");
            element.addAttribute("id", request.getUserID());
        }
        interceptorManager.invokeInterceptors(getJID().toBareJID(), invitation, false, false);
        send(invitation);
        interceptorManager.invokeInterceptors(getJID().toBareJID(), invitation, false, true);
        // Invite the user to the new room
        sendUserInvitiation(request, roomName);
        // Notify the request that invitations for support have been sent
        request.invitationsSent(sessionID);
    } catch (Exception e) {
        Log.error(e.getMessage(), e);
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) Invitation(org.xmpp.muc.Invitation) JoinRoom(org.xmpp.muc.JoinRoom) DbWorkgroup(org.jivesoftware.xmpp.workgroup.utils.DbWorkgroup) RoomInterceptorManager(org.jivesoftware.xmpp.workgroup.interceptor.RoomInterceptorManager) PacketRejectedException(org.jivesoftware.xmpp.workgroup.interceptor.PacketRejectedException) SQLException(java.sql.SQLException) NotFoundException(org.jivesoftware.util.NotFoundException) RoomConfiguration(org.xmpp.muc.RoomConfiguration) Collection(java.util.Collection)

Example 2 with JoinRoom

use of org.xmpp.muc.JoinRoom in project Openfire by igniterealtime.

the class Workgroup method createGroupChatRoom.

void createGroupChatRoom() {
    String roomJID = getGroupChatRoomName() + "/workgroup";
    // Create the room by joining it. The workgroup will be the owner of the room and will
    // invite the Agent and the user to join the room
    JoinRoom joinRoom = new JoinRoom(getFullJID().toString(), roomJID);
    send(joinRoom);
    // Configure the newly created room
    Map<String, Collection<String>> fields = new HashMap<String, Collection<String>>();
    // Make a non-public room
    List<String> values = new ArrayList<String>();
    values.add("0");
    fields.put("muc#roomconfig_publicroom", values);
    // Set the room name
    values = new ArrayList<String>();
    values.add("Workgroup " + getJID().getNode() + " Chat Room");
    fields.put("muc#roomconfig_roomname", values);
    // Set the room description
    values = new ArrayList<String>();
    values.add("Workgroup Chat Room");
    fields.put("muc#roomconfig_roomdesc", values);
    // Set the max number of occupants to unlimited
    values = new ArrayList<String>();
    values.add("0");
    fields.put("muc#roomconfig_maxusers", values);
    // Set that anyone can change the room subject
    values = new ArrayList<String>();
    values.add("1");
    fields.put("muc#roomconfig_changesubject", values);
    // Make the room persistent
    values = new ArrayList<String>();
    values.add("1");
    fields.put("muc#roomconfig_persistentroom", values);
    // Make the room not moderated
    values = new ArrayList<String>();
    values.add("0");
    fields.put("muc#roomconfig_moderatedroom", values);
    // Make the room not members-only
    values = new ArrayList<String>();
    values.add("0");
    fields.put("muc#roomconfig_membersonly", values);
    // Set that anyone can send invitations
    values = new ArrayList<String>();
    values.add("1");
    fields.put("muc#roomconfig_allowinvites", values);
    // Make the room not password protected
    values = new ArrayList<String>();
    values.add("0");
    fields.put("muc#roomconfig_passwordprotectedroom", values);
    // Enable the log for the room
    values = new ArrayList<String>();
    values.add("1");
    fields.put("muc#roomconfig_enablelogging", values);
    // Set that only moderators can see the occupants' JID
    values = new ArrayList<String>();
    values.add("moderators");
    fields.put("muc#roomconfig_whois", values);
    // Only broadcast presences of participants and visitors
    values = new ArrayList<String>();
    values.add("moderator");
    values.add("participant");
    values.add("visitor");
    fields.put("muc#roomconfig_presencebroadcast", values);
    RoomConfiguration conf = new RoomConfiguration(fields);
    conf.setTo(getGroupChatRoomName());
    conf.setFrom(getFullJID());
    send(conf);
    // Change the subject of the room by sending a new message
    Message message = new Message();
    message.setType(Message.Type.groupchat);
    message.setSubject("This is a private discussion room for members of this workgroup.");
    message.setFrom(getFullJID());
    message.setTo(getGroupChatRoomName());
    send(message);
    // Leave Chat Room
    LeaveRoom leaveRoom = new LeaveRoom(getFullJID().toString(), roomJID);
    send(leaveRoom);
}
Also used : Message(org.xmpp.packet.Message) LeaveRoom(org.xmpp.muc.LeaveRoom) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) RoomConfiguration(org.xmpp.muc.RoomConfiguration) ArrayList(java.util.ArrayList) JoinRoom(org.xmpp.muc.JoinRoom) Collection(java.util.Collection)

Example 3 with JoinRoom

use of org.xmpp.muc.JoinRoom in project Openfire by igniterealtime.

the class Workgroup method destroyGroupChatRoom.

private void destroyGroupChatRoom() {
    String roomJID = getGroupChatRoomName() + "/workgroup";
    // We need to be an occupant of the room to destroy it
    JoinRoom joinRoom = new JoinRoom(getFullJID().toString(), roomJID);
    send(joinRoom);
    // Destroy the group chat room of the workgroup
    DestroyRoom destroy = new DestroyRoom(null, null);
    destroy.setFrom(getFullJID());
    destroy.setTo(getGroupChatRoomName());
    send(destroy);
}
Also used : JoinRoom(org.xmpp.muc.JoinRoom) DestroyRoom(org.xmpp.muc.DestroyRoom)

Aggregations

JoinRoom (org.xmpp.muc.JoinRoom)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 RoomConfiguration (org.xmpp.muc.RoomConfiguration)2 SQLException (java.sql.SQLException)1 Element (org.dom4j.Element)1 NotFoundException (org.jivesoftware.util.NotFoundException)1 PacketRejectedException (org.jivesoftware.xmpp.workgroup.interceptor.PacketRejectedException)1 RoomInterceptorManager (org.jivesoftware.xmpp.workgroup.interceptor.RoomInterceptorManager)1 DbWorkgroup (org.jivesoftware.xmpp.workgroup.utils.DbWorkgroup)1 DestroyRoom (org.xmpp.muc.DestroyRoom)1 Invitation (org.xmpp.muc.Invitation)1 LeaveRoom (org.xmpp.muc.LeaveRoom)1 Message (org.xmpp.packet.Message)1