Java 类org.jivesoftware.smack.filter.FromMatchesFilter 实例源码

项目:Smack    文件:FromMatchesFilterTest.java   
@Test
public void autoCompareMatchingServiceJid()
{
    FromMatchesFilter filter = FromMatchesFilter.create(SERVICE_JID1);
    Stanza packet = new Stanza() {
        @Override
        public String toXML() { return null; }
    };

    packet.setFrom(SERVICE_JID1);
    assertTrue(filter.accept(packet));

    packet.setFrom(SERVICE_JID2);
    assertFalse(filter.accept(packet));

    packet.setFrom(BASE_JID1);
    assertFalse(filter.accept(packet));

    packet.setFrom(FULL_JID1_R1);
    assertFalse(filter.accept(packet));

    packet.setFrom(BASE_JID3);
    assertFalse(filter.accept(packet));
}
项目:Smack    文件:FromMatchesFilterTest.java   
@Test
public void bareCompareMatchingServiceJid()
{
    FromMatchesFilter filter = FromMatchesFilter.createBare(SERVICE_JID1);
    Stanza packet = new Stanza() {
        @Override
        public String toXML() { return null; }
    };

    packet.setFrom(SERVICE_JID1);
    assertTrue(filter.accept(packet));

    packet.setFrom(SERVICE_JID2);
    assertFalse(filter.accept(packet));

    packet.setFrom(BASE_JID1);
    assertFalse(filter.accept(packet));

    packet.setFrom(FULL_JID1_R1);
    assertFalse(filter.accept(packet));

    packet.setFrom(BASE_JID3);
    assertFalse(filter.accept(packet));
}
项目:Smack    文件:FromMatchesFilterTest.java   
@Test
public void fullCompareMatchingServiceJid()
{
    FromMatchesFilter filter = FromMatchesFilter.createFull(SERVICE_JID1);
    Stanza packet = new Stanza() {
        @Override
        public String toXML() { return null; }
    };

    packet.setFrom(SERVICE_JID1);
    assertTrue(filter.accept(packet));

    packet.setFrom(SERVICE_JID2);
    assertFalse(filter.accept(packet));

    packet.setFrom(BASE_JID1);
    assertFalse(filter.accept(packet));

    packet.setFrom(FULL_JID1_R1);
    assertFalse(filter.accept(packet));

    packet.setFrom(BASE_JID3);
    assertFalse(filter.accept(packet));
}
项目:Smack    文件:AgentSession.java   
/**
 * Sets the agent's current status with the workgroup. The presence mode affects how offers
 * are routed to the agent. The possible presence modes with their meanings are as follows:<ul>
 * <p/>
 * <li>Presence.Mode.AVAILABLE -- (Default) the agent is available for more chats
 * (equivalent to Presence.Mode.CHAT).
 * <li>Presence.Mode.DO_NOT_DISTURB -- the agent is busy and should not be disturbed.
 * However, special case, or extreme urgency chats may still be offered to the agent.
 * <li>Presence.Mode.AWAY -- the agent is not available and should not
 * have a chat routed to them (equivalent to Presence.Mode.EXTENDED_AWAY).</ul>
 *
 * @param presenceMode the presence mode of the agent.
 * @param status       sets the status message of the presence update.
 * @throws XMPPErrorException 
 * @throws NoResponseException 
 * @throws NotConnectedException 
 * @throws IllegalStateException if the agent is not online with the workgroup.
 */
public void setStatus(Presence.Mode presenceMode, String status) throws NoResponseException, XMPPErrorException, NotConnectedException {
    if (!online) {
        throw new IllegalStateException("Cannot set status when the agent is not online.");
    }

    if (presenceMode == null) {
        presenceMode = Presence.Mode.available;
    }
    this.presenceMode = presenceMode;

    Presence presence = new Presence(Presence.Type.available);
    presence.setMode(presenceMode);
    presence.setTo(this.getWorkgroupJID());

    if (status != null) {
        presence.setStatus(status);
    }
    presence.addExtension(new MetaData(this.metaData));

    PacketCollector collector = this.connection.createPacketCollectorAndSend(new AndFilter(new StanzaTypeFilter(Presence.class),
            FromMatchesFilter.create(workgroupJID)), presence);

    collector.nextResultOrThrow();
}
项目:Smack    文件:FromMatchesFilterTest.java   
@Test
public void autoCompareMatchingFullJid()
{
    FromMatchesFilter filter = FromMatchesFilter.create(FULL_JID1_R1);
    Stanza packet = new Stanza() {
        @Override
        public String toXML() { return null; }
    };

    packet.setFrom(FULL_JID1_R1);
    assertTrue(filter.accept(packet));

    packet.setFrom(BASE_JID1);
    assertFalse(filter.accept(packet));

    packet.setFrom(FULL_JID1_R2);
    assertFalse(filter.accept(packet));

    packet.setFrom(BASE_JID2);
    assertFalse(filter.accept(packet));

    packet.setFrom(FULL_JID2);
    assertFalse(filter.accept(packet));

    packet.setFrom(BASE_JID3);
    assertFalse(filter.accept(packet));
}
项目:Smack    文件:FromMatchesFilterTest.java   
@Test
    public void autoCompareMatchingBaseJid()
    {
        FromMatchesFilter filter = FromMatchesFilter.create(BASE_JID1);
        Stanza packet = new Stanza() {
            @Override
            public String toXML() { return null; }
        };

        packet.setFrom(BASE_JID1);
        assertTrue(filter.accept(packet));

        packet.setFrom(FULL_JID1_R1);
        assertTrue(filter.accept(packet));

        packet.setFrom(FULL_JID1_R2);
        assertTrue(filter.accept(packet));

        packet.setFrom(BASE_JID2);
        assertFalse(filter.accept(packet));

        packet.setFrom(FULL_JID2);
        assertFalse(filter.accept(packet));

        packet.setFrom(BASE_JID3);
        assertFalse(filter.accept(packet));
}
项目:Smack    文件:FromMatchesFilterTest.java   
@Test
public void bareCompareMatchingFullJid()
{
    FromMatchesFilter filter = FromMatchesFilter.createBare(FULL_JID1_R1);
    Stanza packet = new Stanza() {
        @Override
        public String toXML() { return null; }
    };

    packet.setFrom(BASE_JID1);
    assertTrue(filter.accept(packet));

    packet.setFrom(FULL_JID1_R1);
    assertTrue(filter.accept(packet));

    packet.setFrom(FULL_JID1_R2);
    assertTrue(filter.accept(packet));

    packet.setFrom(BASE_JID2);
    assertFalse(filter.accept(packet));

    packet.setFrom(FULL_JID2);
    assertFalse(filter.accept(packet));

    packet.setFrom(BASE_JID3);
    assertFalse(filter.accept(packet));
}
项目:Smack    文件:FromMatchesFilterTest.java   
@Test
    public void bareCompareMatchingBaseJid()
    {
        FromMatchesFilter filter = FromMatchesFilter.createBare(BASE_JID1);
        Stanza packet = new Stanza() {
            @Override
            public String toXML() { return null; }
        };

        packet.setFrom(BASE_JID1);
        assertTrue(filter.accept(packet));

        packet.setFrom(FULL_JID1_R1);
        assertTrue(filter.accept(packet));

        packet.setFrom(FULL_JID1_R2);
        assertTrue(filter.accept(packet));

        packet.setFrom(BASE_JID2);
        assertFalse(filter.accept(packet));

        packet.setFrom(FULL_JID2);
        assertFalse(filter.accept(packet));

        packet.setFrom(BASE_JID3);
        assertFalse(filter.accept(packet));
}
项目:Smack    文件:FromMatchesFilterTest.java   
@Test
public void fullCompareMatchingFullJid()
{
    FromMatchesFilter filter = FromMatchesFilter.createFull(FULL_JID1_R1);
    Stanza packet = new Stanza() {
        @Override
        public String toXML() { return null; }
    };

    packet.setFrom(FULL_JID1_R1);
    assertTrue(filter.accept(packet));

    packet.setFrom(BASE_JID1);
    assertFalse(filter.accept(packet));

    packet.setFrom(FULL_JID1_R2);
    assertFalse(filter.accept(packet));

    packet.setFrom(BASE_JID2);
    assertFalse(filter.accept(packet));

    packet.setFrom(FULL_JID2);
    assertFalse(filter.accept(packet));

    packet.setFrom(BASE_JID3);
    assertFalse(filter.accept(packet));
}
项目:Smack    文件:FromMatchesFilterTest.java   
@Test
public void fullCompareMatchingBaseJid()
{
    FromMatchesFilter filter = FromMatchesFilter.createFull(BASE_JID1);
    Stanza packet = new Stanza() {
        @Override
        public String toXML() { return null; }
    };

    packet.setFrom(BASE_JID1);
    assertTrue(filter.accept(packet));

    packet.setFrom(FULL_JID1_R1);
    assertFalse(filter.accept(packet));

    packet.setFrom(FULL_JID1_R2);
    assertFalse(filter.accept(packet));

    packet.setFrom(BASE_JID2);
    assertFalse(filter.accept(packet));

    packet.setFrom(FULL_JID2);
    assertFalse(filter.accept(packet));

    packet.setFrom(BASE_JID3);
    assertFalse(filter.accept(packet));
}
项目:Smack    文件:AgentSession.java   
/**
 * Sets the agent's current status with the workgroup. The presence mode affects how offers
 * are routed to the agent. The possible presence modes with their meanings are as follows:<ul>
 * <p/>
 * <li>Presence.Mode.AVAILABLE -- (Default) the agent is available for more chats
 * (equivalent to Presence.Mode.CHAT).
 * <li>Presence.Mode.DO_NOT_DISTURB -- the agent is busy and should not be disturbed.
 * However, special case, or extreme urgency chats may still be offered to the agent.
 * <li>Presence.Mode.AWAY -- the agent is not available and should not
 * have a chat routed to them (equivalent to Presence.Mode.EXTENDED_AWAY).</ul>
 * <p/>
 * The max chats value is the maximum number of chats the agent is willing to have routed to
 * them at once. Some servers may be configured to only accept max chat values in a certain
 * range; for example, between two and five. In that case, the maxChats value the agent sends
 * may be adjusted by the server to a value within that range.
 *
 * @param presenceMode the presence mode of the agent.
 * @param maxChats     the maximum number of chats the agent is willing to accept.
 * @param status       sets the status message of the presence update.
 * @throws XMPPErrorException 
 * @throws NoResponseException 
 * @throws NotConnectedException 
 * @throws IllegalStateException if the agent is not online with the workgroup.
 */
public void setStatus(Presence.Mode presenceMode, int maxChats, String status)
                throws NoResponseException, XMPPErrorException, NotConnectedException {
    if (!online) {
        throw new IllegalStateException("Cannot set status when the agent is not online.");
    }

    if (presenceMode == null) {
        presenceMode = Presence.Mode.available;
    }
    this.presenceMode = presenceMode;
    this.maxChats = maxChats;

    Presence presence = new Presence(Presence.Type.available);
    presence.setMode(presenceMode);
    presence.setTo(this.getWorkgroupJID());

    if (status != null) {
        presence.setStatus(status);
    }
    // Send information about max chats and current chats as a packet extension.
    DefaultExtensionElement agentStatus = new DefaultExtensionElement(AgentStatus.ELEMENT_NAME,
                    AgentStatus.NAMESPACE);
    agentStatus.setValue("max-chats", "" + maxChats);
    presence.addExtension(agentStatus);
    presence.addExtension(new MetaData(this.metaData));

    PacketCollector collector = this.connection.createPacketCollectorAndSend(new AndFilter(
                    new StanzaTypeFilter(Presence.class),
                    FromMatchesFilter.create(workgroupJID)), presence);

    collector.nextResultOrThrow();
}
项目:Smack    文件:Workgroup.java   
/**
 * Returns true if the workgroup is available for receiving new requests. The workgroup will be
 * available only when agents are available for this workgroup.
 *
 * @return true if the workgroup is available for receiving new requests.
 * @throws XMPPErrorException 
 * @throws NoResponseException 
 * @throws NotConnectedException 
 */
public boolean isAvailable() throws NoResponseException, XMPPErrorException, NotConnectedException {
    Presence directedPresence = new Presence(Presence.Type.available);
    directedPresence.setTo(workgroupJID);
    StanzaFilter typeFilter = new StanzaTypeFilter(Presence.class);
    StanzaFilter fromFilter = FromMatchesFilter.create(workgroupJID);
    PacketCollector collector = connection.createPacketCollectorAndSend(new AndFilter(fromFilter,
            typeFilter), directedPresence);

    Presence response = (Presence)collector.nextResultOrThrow();
    return Presence.Type.available == response.getType();
}
项目:EIM    文件:Socks5TransferNegotiator.java   
@Override
public PacketFilter getInitiationPacketFilter(final String from, String streamID) {
    /*
     * this method is always called prior to #negotiateIncomingStream() so the SOCKS5
     * InitiationListener must ignore the next SOCKS5 Bytestream request with the given session
     * ID
     */
    this.manager.ignoreBytestreamRequestOnce(streamID);

    return new AndFilter(new FromMatchesFilter(from), new BytestreamSIDFilter(streamID));
}
项目:androidPN-client.    文件:Socks5TransferNegotiator.java   
@Override
public PacketFilter getInitiationPacketFilter(final String from, String streamID) {
    /*
     * this method is always called prior to #negotiateIncomingStream() so the SOCKS5
     * InitiationListener must ignore the next SOCKS5 Bytestream request with the given session
     * ID
     */
    this.manager.ignoreBytestreamRequestOnce(streamID);

    return new AndFilter(new FromMatchesFilter(from), new BytestreamSIDFilter(streamID));
}
项目:xmppsupport_v2    文件:Socks5TransferNegotiator.java   
@Override
public PacketFilter getInitiationPacketFilter(final String from,
        String streamID) {
    /*
     * this method is always called prior to #negotiateIncomingStream() so
     * the SOCKS5 InitiationListener must ignore the next SOCKS5 Bytestream
     * request with the given session ID
     */
    this.manager.ignoreBytestreamRequestOnce(streamID);

    return new AndFilter(new FromMatchesFilter(from),
            new BytestreamSIDFilter(streamID));
}
项目:java-bells    文件:Socks5TransferNegotiator.java   
@Override
public PacketFilter getInitiationPacketFilter(final String from, String streamID) {
    /*
     * this method is always called prior to #negotiateIncomingStream() so the SOCKS5
     * InitiationListener must ignore the next SOCKS5 Bytestream request with the given session
     * ID
     */
    this.manager.ignoreBytestreamRequestOnce(streamID);

    return new AndFilter(new FromMatchesFilter(from), new BytestreamSIDFilter(streamID));
}
项目:telegraph    文件:Socks5TransferNegotiator.java   
@Override
public PacketFilter getInitiationPacketFilter(final String from, String streamID) {
    /*
     * this method is always called prior to #negotiateIncomingStream() so the SOCKS5
     * InitiationListener must ignore the next SOCKS5 Bytestream request with the given session
     * ID
     */
    this.manager.ignoreBytestreamRequestOnce(streamID);

    return new AndFilter(new FromMatchesFilter(from), new BytestreamSIDFilter(streamID));
}
项目:Smack    文件:ChatManager.java   
PacketCollector createPacketCollector(Chat chat) {
    return connection().createPacketCollector(new AndFilter(new ThreadFilter(chat.getThreadID()), 
                    FromMatchesFilter.create(chat.getParticipant())));
}
项目:Openfire    文件:ThrottleTestReader.java   
/**
 * Starts the throttle test reader client.
 *
 * @param args application arguments.
 */
public static void main(String [] args) {
    if (args.length != 3) {
        System.out.println("Usage: java ThrottleTestReader [server] [username] [password]");
        System.exit(0);
    }
    String server = args[0];
    String username = args[1];
    String password = args[2];
    try {
        // Connect to the server, without TLS encryption.
        ConnectionConfiguration config = new ConnectionConfiguration(server);
        config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
        final XMPPConnection con = new XMPPConnection(config);
        System.out.print("Connecting to " + server + "... ");
        con.connect();

        con.login(username, password, "reader");
        System.out.print("success.");
        System.out.println("");

        // Get the "real" server address.
        server = con.getServiceName();

        final String writerAddress = username + "@" + server + "/writer";
        String readerAddress = username + "@" + server + "/reader";

        System.out.println("Registered as " + readerAddress);

        // Look for the reader process.
        System.out.print("Waiting for " + writerAddress + "...");
        PacketCollector collector = con.createPacketCollector(new AndFilter(
                new FromMatchesFilter(writerAddress), new PacketTypeFilter(Time.class)));
        Time timeRequest = (Time)collector.nextResult();
        Time timeReply = new Time(Calendar.getInstance());
        timeReply.setPacketID(timeRequest.getPacketID());
        timeReply.setType(IQ.Type.RESULT);
        timeReply.setTo(timeRequest.getFrom());
        con.sendPacket(timeReply);
        System.out.println(" found writer. Now in reading mode.");

        // Track how many packets we've read.
        con.addPacketListener(new PacketListener() {

            public void processPacket(Packet packet) {
                packetCount.getAndIncrement();
            }
        }, new PacketTypeFilter(Message.class));

        while (!done) {
            Thread.sleep(5000);
            int count = packetCount.getAndSet(0);
            System.out.println("Packets per second: " + (count/5));
        }

        // Sleep while we're reading packets.
        Thread.sleep(Integer.MAX_VALUE);
    }
    catch (Exception e) {
        System.out.println("\nError: " + e.getMessage());
    }
}
项目:g3server    文件:ThrottleTestReader.java   
/**
 * Starts the throttle test reader client.
 *
 * @param args application arguments.
 */
public static void main(String [] args) {
    if (args.length != 3) {
        System.out.println("Usage: java ThrottleTestReader [server] [username] [password]");
        System.exit(0);
    }
    String server = args[0];
    String username = args[1];
    String password = args[2];
    try {
        // Connect to the server, without TLS encryption.
        ConnectionConfiguration config = new ConnectionConfiguration(server);
        config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
        final XMPPConnection con = new XMPPConnection(config);
        System.out.print("Connecting to " + server + "... ");
        con.connect();

        con.login(username, password, "reader");
        System.out.print("success.");
        System.out.println("");

        // Get the "real" server address.
        server = con.getServiceName();

        final String writerAddress = username + "@" + server + "/writer";
        String readerAddress = username + "@" + server + "/reader";

        System.out.println("Registered as " + readerAddress);

        // Look for the reader process.
        System.out.print("Waiting for " + writerAddress + "...");
        PacketCollector collector = con.createPacketCollector(new AndFilter(
                new FromMatchesFilter(writerAddress), new PacketTypeFilter(Time.class)));
        Time timeRequest = (Time)collector.nextResult();
        Time timeReply = new Time(Calendar.getInstance());
        timeReply.setPacketID(timeRequest.getPacketID());
        timeReply.setType(IQ.Type.RESULT);
        timeReply.setTo(timeRequest.getFrom());
        con.sendPacket(timeReply);
        System.out.println(" found writer. Now in reading mode.");

        // Track how many packets we've read.
        con.addPacketListener(new PacketListener() {

            public void processPacket(Packet packet) {
                packetCount.getAndIncrement();
            }
        }, new PacketTypeFilter(Message.class));

        while (!done) {
            Thread.sleep(5000);
            int count = packetCount.getAndSet(0);
            System.out.println("Packets per second: " + (count/5));
        }

        // Sleep while we're reading packets.
        Thread.sleep(Integer.MAX_VALUE);
    }
    catch (Exception e) {
        System.out.println("\nError: " + e.getMessage());
    }
}
项目:openfire    文件:ThrottleTestReader.java   
/**
 * Starts the throttle test reader client.
 *
 * @param args application arguments.
 */
public static void main(String [] args) {
    if (args.length != 3) {
        System.out.println("Usage: java ThrottleTestReader [server] [username] [password]");
        System.exit(0);
    }
    String server = args[0];
    String username = args[1];
    String password = args[2];
    try {
        // Connect to the server, without TLS encryption.
        ConnectionConfiguration config = new ConnectionConfiguration(server);
        config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
        final XMPPConnection con = new XMPPConnection(config);
        System.out.print("Connecting to " + server + "... ");
        con.connect();

        con.login(username, password, "reader");
        System.out.print("success.");
        System.out.println("");

        // Get the "real" server address.
        server = con.getServiceName();

        final String writerAddress = username + "@" + server + "/writer";
        String readerAddress = username + "@" + server + "/reader";

        System.out.println("Registered as " + readerAddress);

        // Look for the reader process.
        System.out.print("Waiting for " + writerAddress + "...");
        PacketCollector collector = con.createPacketCollector(new AndFilter(
                new FromMatchesFilter(writerAddress), new PacketTypeFilter(Time.class)));
        Time timeRequest = (Time)collector.nextResult();
        Time timeReply = new Time(Calendar.getInstance());
        timeReply.setPacketID(timeRequest.getPacketID());
        timeReply.setType(IQ.Type.RESULT);
        timeReply.setTo(timeRequest.getFrom());
        con.sendPacket(timeReply);
        System.out.println(" found writer. Now in reading mode.");

        // Track how many packets we've read.
        con.addPacketListener(new PacketListener() {

            public void processPacket(Packet packet) {
                packetCount.getAndIncrement();
            }
        }, new PacketTypeFilter(Message.class));

        while (!done) {
            Thread.sleep(5000);
            int count = packetCount.getAndSet(0);
            System.out.println("Packets per second: " + (count/5));
        }

        // Sleep while we're reading packets.
        Thread.sleep(Integer.MAX_VALUE);
    }
    catch (Exception e) {
        System.out.println("\nError: " + e.getMessage());
    }
}
项目:NewCommunication-Android    文件:Socks5TransferNegotiator.java   
public PacketFilter getInitiationPacketFilter(String from, String sessionID) {
    return new AndFilter(new FromMatchesFilter(from),
            new BytestreamSIDFilter(sessionID));
}
项目:openfire-bespoke    文件:ThrottleTestReader.java   
/**
 * Starts the throttle test reader client.
 *
 * @param args application arguments.
 */
public static void main(String [] args) {
    if (args.length != 3) {
        System.out.println("Usage: java ThrottleTestReader [server] [username] [password]");
        System.exit(0);
    }
    String server = args[0];
    String username = args[1];
    String password = args[2];
    try {
        // Connect to the server, without TLS encryption.
        ConnectionConfiguration config = new ConnectionConfiguration(server);
        config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
        final XMPPConnection con = new XMPPConnection(config);
        System.out.print("Connecting to " + server + "... ");
        con.connect();

        con.login(username, password, "reader");
        System.out.print("success.");
        System.out.println("");

        // Get the "real" server address.
        server = con.getServiceName();

        final String writerAddress = username + "@" + server + "/writer";
        String readerAddress = username + "@" + server + "/reader";

        System.out.println("Registered as " + readerAddress);

        // Look for the reader process.
        System.out.print("Waiting for " + writerAddress + "...");
        PacketCollector collector = con.createPacketCollector(new AndFilter(
                new FromMatchesFilter(writerAddress), new PacketTypeFilter(Time.class)));
        Time timeRequest = (Time)collector.nextResult();
        Time timeReply = new Time(Calendar.getInstance());
        timeReply.setPacketID(timeRequest.getPacketID());
        timeReply.setType(IQ.Type.RESULT);
        timeReply.setTo(timeRequest.getFrom());
        con.sendPacket(timeReply);
        System.out.println(" found writer. Now in reading mode.");

        // Track how many packets we've read.
        con.addPacketListener(new PacketListener() {

            public void processPacket(Packet packet) {
                packetCount.getAndIncrement();
            }
        }, new PacketTypeFilter(Message.class));

        while (!done) {
            Thread.sleep(5000);
            int count = packetCount.getAndSet(0);
            System.out.println("Packets per second: " + (count/5));
        }

        // Sleep while we're reading packets.
        Thread.sleep(Integer.MAX_VALUE);
    }
    catch (Exception e) {
        System.out.println("\nError: " + e.getMessage());
    }
}
项目:spark-svn-mirror    文件:ChatRoomImpl.java   
/**
 * Constructs a 1-to-1 ChatRoom.
 *
 * @param participantJID      the participants jid to chat with.
 * @param participantNickname the nickname of the participant.
 * @param title               the title of the room.
 */
public ChatRoomImpl(final String participantJID, String participantNickname, String title, boolean initUi) {
    this.active = true;
    //activateNotificationTime = System.currentTimeMillis();
    this.participantJID = participantJID;
    this.participantNickname = participantNickname;

    // Loads the current history for this user.
    loadHistory();

    // Register PacketListeners
    PacketFilter fromFilter = new FromMatchesFilter(participantJID);
    PacketFilter orFilter = new OrFilter(new PacketTypeFilter(Presence.class), new PacketTypeFilter(Message.class));
    PacketFilter andFilter = new AndFilter(orFilter, fromFilter);

    SparkManager.getConnection().addPacketListener(this, andFilter);

    // The roomname will be the participantJID
    this.roomname = participantJID;

    // Use the agents username as the Tab Title
    this.tabTitle = title;

    // The name of the room will be the node of the user jid + conversation.
    this.roomTitle = participantNickname;

    // Add RoomInfo
    this.getSplitPane().setRightComponent(null);
    getSplitPane().setDividerSize(0);


    presence = PresenceManager.getPresence(participantJID);

    roster = SparkManager.getConnection().getRoster();

    RosterEntry entry = roster.getEntry(participantJID);

    tabIcon = PresenceManager.getIconFromPresence(presence);

    if (initUi) {
        // Create toolbar buttons.
        infoButton = new ChatRoomButton("", SparkRes.getImageIcon(SparkRes.PROFILE_IMAGE_24x24));
        infoButton.setToolTipText(Res.getString("message.view.information.about.this.user"));
        // Create basic toolbar.
        addChatRoomButton(infoButton);
        // Show VCard.
        infoButton.addActionListener(this);
    }

    // If the user is not in the roster, then allow user to add them.
    addToRosterButton = new ChatRoomButton("", SparkRes.getImageIcon(SparkRes.ADD_IMAGE_24x24));
    if (entry == null && !StringUtils.parseResource(participantJID).equals(participantNickname)) {
        addToRosterButton.setToolTipText(Res.getString("message.add.this.user.to.your.roster"));
        if(!Default.getBoolean(Default.ADD_CONTACT_DISABLED)) {
            addChatRoomButton(addToRosterButton);
        }
        addToRosterButton.addActionListener(this);
    }

    // If this is a private chat from a group chat room, do not show toolbar.
    if (StringUtils.parseResource(participantJID).equals(participantNickname)) {
        getToolBar().setVisible(false);
    }

    createChatStateTimerTask();

    lastActivity = System.currentTimeMillis();
    getChatInputEditor().addFocusListener(new ChatStateFocusListener());
}