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 = collector . nextResultOrThrow ( ) ; // We can safely update this iv since we didn't get any error this . online = online ; } // Otherwise the user is going offline... else { // 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 ) ; } }
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 .