Search in sources :

Example 11 with Presence

use of org.jivesoftware.smack.packet.Presence in project Smack by igniterealtime.

the class PacketParserUtilsTest method validateSimplePresence.

@Test
public void validateSimplePresence() throws Exception {
    // CHECKSTYLE:OFF
    String stanza = "<presence from='juliet@example.com/balcony' to='romeo@example.net'/>";
    Presence presence = PacketParserUtils.parsePresence(PacketParserUtils.getParserFor(stanza));
    assertXMLEqual(stanza, presence.toXML().toString());
// CHECKSTYLE:ON
}
Also used : Presence(org.jivesoftware.smack.packet.Presence) Test(org.junit.Test)

Example 12 with Presence

use of org.jivesoftware.smack.packet.Presence in project Smack by igniterealtime.

the class PacketParserUtilsTest method validatePresenceProbe.

@Test
public void validatePresenceProbe() throws Exception {
    // CHECKSTYLE:OFF
    String stanza = "<presence from='mercutio@example.com' id='xv291f38' to='juliet@example.com' type='unsubscribed'/>";
    Presence presence = PacketParserUtils.parsePresence(PacketParserUtils.getParserFor(stanza));
    assertXMLEqual(stanza, presence.toXML().toString());
    assertEquals(Presence.Type.unsubscribed, presence.getType());
// CHECKSTYLE:ON
}
Also used : Presence(org.jivesoftware.smack.packet.Presence) Test(org.junit.Test)

Example 13 with Presence

use of org.jivesoftware.smack.packet.Presence in project Smack by igniterealtime.

the class PacketParserUtilsTest method validatePresenceOptionalElements.

@Test
public void validatePresenceOptionalElements() throws Exception {
    // CHECKSTYLE:OFF
    String stanza = "<presence xml:lang='en' type='unsubscribed'>" + "<show>dnd</show>" + "<status>Wooing Juliet</status>" + "<priority>1</priority>" + "</presence>";
    Presence presence = PacketParserUtils.parsePresence(PacketParserUtils.getParserFor(stanza));
    assertXMLEqual(stanza, presence.toXML().toString());
    assertEquals(Presence.Type.unsubscribed, presence.getType());
    assertEquals("dnd", presence.getMode().name());
    assertEquals("en", presence.getLanguage());
    assertEquals("Wooing Juliet", presence.getStatus());
    assertEquals(1, presence.getPriority());
// CHECKSTYLE:ON
}
Also used : Presence(org.jivesoftware.smack.packet.Presence) Test(org.junit.Test)

Example 14 with Presence

use of org.jivesoftware.smack.packet.Presence in project Smack by igniterealtime.

the class AgentSession method setOnline.

/**
     * Sets whether the agent is online with the workgroup. If the user tries to go online with
     * the workgroup but is not allowed to be an agent, an XMPPError with error code 401 will
     * be thrown.
     *
     * @param online true to set the agent as online with the workgroup.
     * @throws XMPPException if an error occurs setting the online status.
     * @throws SmackException             assertEquals(SmackException.Type.NO_RESPONSE_FROM_SERVER, e.getType());
            return;
     * @throws InterruptedException 
     */
public void setOnline(boolean online) throws XMPPException, SmackException, InterruptedException {
    // If the online status hasn't changed, do nothing.
    if (this.online == online) {
        return;
    }
    Presence presence;
    // If the user is going online...
    if (online) {
        presence = new Presence(Presence.Type.available);
        presence.setTo(workgroupJID);
        presence.addExtension(new StandardExtensionElement(AgentStatus.ELEMENT_NAME, AgentStatus.NAMESPACE));
        StanzaCollector collector = this.connection.createStanzaCollectorAndSend(new AndFilter(new StanzaTypeFilter(Presence.class), FromMatchesFilter.create(workgroupJID)), presence);
        presence = (Presence) collector.nextResultOrThrow();
        // We can safely update this iv since we didn't get any error
        this.online = online;
    } else // Otherwise the user is going offline...
    {
        // Update this iv now since we don't care at this point of any error
        this.online = online;
        presence = new Presence(Presence.Type.unavailable);
        presence.setTo(workgroupJID);
        presence.addExtension(new StandardExtensionElement(AgentStatus.ELEMENT_NAME, AgentStatus.NAMESPACE));
        connection.sendStanza(presence);
    }
}
Also used : AndFilter(org.jivesoftware.smack.filter.AndFilter) StanzaTypeFilter(org.jivesoftware.smack.filter.StanzaTypeFilter) StandardExtensionElement(org.jivesoftware.smack.packet.StandardExtensionElement) Presence(org.jivesoftware.smack.packet.Presence) StanzaCollector(org.jivesoftware.smack.StanzaCollector)

Example 15 with Presence

use of org.jivesoftware.smack.packet.Presence in project Smack by igniterealtime.

the class AgentSession method setStatus.

/**
     * 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 InterruptedException 
     * @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, InterruptedException {
    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.
    StandardExtensionElement.Builder builder = StandardExtensionElement.builder(AgentStatus.ELEMENT_NAME, AgentStatus.NAMESPACE);
    builder.addElement("max_chats", Integer.toString(maxChats));
    presence.addExtension(builder.build());
    presence.addExtension(new MetaData(this.metaData));
    StanzaCollector collector = this.connection.createStanzaCollectorAndSend(new AndFilter(new StanzaTypeFilter(Presence.class), FromMatchesFilter.create(workgroupJID)), presence);
    collector.nextResultOrThrow();
}
Also used : AndFilter(org.jivesoftware.smack.filter.AndFilter) StanzaTypeFilter(org.jivesoftware.smack.filter.StanzaTypeFilter) MetaData(org.jivesoftware.smackx.workgroup.MetaData) StandardExtensionElement(org.jivesoftware.smack.packet.StandardExtensionElement) Presence(org.jivesoftware.smack.packet.Presence) StanzaCollector(org.jivesoftware.smack.StanzaCollector)

Aggregations

Presence (org.jivesoftware.smack.packet.Presence)89 Message (org.jivesoftware.smack.packet.Message)17 MessageTypeFilter (org.jivesoftware.smack.filter.MessageTypeFilter)10 StanzaCollector (org.jivesoftware.smack.StanzaCollector)7 AndFilter (org.jivesoftware.smack.filter.AndFilter)7 Jid (org.jxmpp.jid.Jid)7 Resourcepart (org.jxmpp.jid.parts.Resourcepart)7 UserPresence (jetbrains.communicator.core.users.UserPresence)6 StanzaTypeFilter (org.jivesoftware.smack.filter.StanzaTypeFilter)5 MUCInitialPresence (org.jivesoftware.smackx.muc.packet.MUCInitialPresence)5 Test (org.junit.Test)5 BareJid (org.jxmpp.jid.BareJid)5 EntityFullJid (org.jxmpp.jid.EntityFullJid)5 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 WaitFor (jetbrains.communicator.util.WaitFor)4 AccountItem (com.xabber.android.data.account.AccountItem)3 ClientInfo (com.xabber.android.data.extension.capability.ClientInfo)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 XMPPException (org.jivesoftware.smack.XMPPException)3