Java Code Examples for org.jivesoftware.smack.packet.Presence#getExtension()

The following examples show how to use org.jivesoftware.smack.packet.Presence#getExtension() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StatusBar.java    From Spark with Apache License 2.0 6 votes vote down vote up
public void changeAvailability(final Presence presence) {
	// SPARK-1524: if we were reconnected because of the error
	// then we get presence with the mode == null. 
	if (presence.getMode() == null)
		return;

	if ((presence.getMode() == currentPresence.getMode()) && (presence.getType() == currentPresence.getType()) && (presence.getStatus().equals(currentPresence.getStatus()))) {
		ExtensionElement pe = presence.getExtension("x", "vcard-temp:x:update");
		if (pe != null) {
			// Update VCard
			loadVCard();
		}
		return;
	}
	currentPresence = presence;

	SwingUtilities.invokeLater(changePresenceRunnable);
}
 
Example 2
Source File: ContactItem.java    From Spark with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the current presence on this contact item.
 *
 * @param presence the presence.
 */
public void setPresence(Presence presence) {

    this.presence = presence;

    final VCardUpdateExtension extension = presence.getExtension("x", "vcard-temp:x:update");

    // Handle vCard update packet.
    if (extension != null) {
        String hash = extension.getPhotoHash();
        if (hash != null) {
            this.hash = hash;

            if (!hashExists(hash)) {
                updateAvatar();
                updateAvatarInSideIcon();
            }
        }
    }

    
    updatePresenceIcon(presence);
}
 
Example 3
Source File: WorkgroupManager.java    From Spark with Apache License 2.0 6 votes vote down vote up
public void handleContactItem(final ContactItem contactItem) {
    Presence presence = contactItem.getPresence();

    ExtensionElement workgroup = presence.getExtension("workgroup", "http://jivesoftware.com/protocol/workgroup");
    ExtensionElement notifyQueue = presence.getExtension("notify-queue", "http://jabber.org/protocol/workgroup");

    if (workgroup == null && notifyQueue == null) {
        return;
    }

    if (!presence.isAway()){
        contactItem.setIcon(FastpathRes.getImageIcon(FastpathRes.FASTPATH_IMAGE_16x16));
    }
    else {
        contactItem.setIcon(FastpathRes.getImageIcon(FastpathRes.FASTPATH_OFFLINE_IMAGE_16x16));
        contactItem.setStatus(null);
    }
}
 
Example 4
Source File: XMPPContactsService.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
private boolean isSarosClient(Presence presence) {
  PacketExtension caps = presence.getExtension(EntityCapsManager.NAMESPACE);
  if (caps != null) {
    String identity = ((CapsExtension) caps).getNode();
    return XMPPConnectionService.XMPP_CLIENT_IDENTIFIER.equals(identity);
  }

  return false;
}
 
Example 5
Source File: AgentConversations.java    From Spark with Apache License 2.0 5 votes vote down vote up
private void calculateNumberOfChats(AgentRoster agentRoster) {
    int counter = 0;
    // TODO: CHECK FASTPATH
    for (EntityBareJid agent : agentRoster.getAgents()) {
        Presence presence = agentRoster.getPresence(agent);
        if (presence.isAvailable()) {
            AgentStatus agentStatus = (AgentStatus)presence.getExtension("agent-status", "http://jabber.org/protocol/workgroup");
            if (agentStatus != null) {
                counter += agentStatus.getCurrentChats().size();
            }
        }
    }

    FastpathPlugin.getUI().setTitleForComponent(FpRes.getString("message.current.chats", counter), this);
}
 
Example 6
Source File: GroupChatParticipantList.java    From Spark with Apache License 2.0 4 votes vote down vote up
protected void addParticipant(final EntityFullJid participantJID, Presence presence) {
// Remove reference to invitees
for (CharSequence displayName : invitees.keySet()) {
    EntityFullJid jid = SparkManager.getUserManager().getJIDFromDisplayName(
	    displayName);

    Occupant occ = chat.getOccupant(jid);
    if (occ != null) {
	String actualJID = occ.getJid().toString();
	if (actualJID.equals(jid)) {
	    removeUser(displayName);
	}
    }
}

Resourcepart nickname = participantJID.getResourcepart();

MUCAffiliation affiliation = null;
MUCRole role = null;
final MUCUser extension = (MUCUser) presence.getExtension( MUCUser.NAMESPACE );
if ( extension != null && extension.getItem() != null )
{
	affiliation = extension.getItem().getAffiliation();
	role = extension.getItem().getRole();
}

if ( affiliation == null ) {
	affiliation = MUCAffiliation.none;
}
if ( role == null ) {
	role = MUCRole.none;
}

usersToRoles.put(participantJID, role);
usersToAffiliation.put(participantJID, affiliation);

Icon icon;
if (_localPreferences.isShowingRoleIcons()) {
    icon = getIconForRole(role, affiliation);
} else {
    icon = PresenceManager.getIconFromPresence(presence);
    if (icon == null) {
		icon = SparkRes.getImageIcon(SparkRes.GREEN_BALL);
	}
}

if (!exists(nickname)) {
    addUser(icon, nickname);
} else {
    int index = getIndex(nickname);
    if (index != -1) {
	final JLabel userLabel = new JLabel(nickname.toString(), icon,
		JLabel.HORIZONTAL);
	model.setElementAt(userLabel, index);
    }
}
   }
 
Example 7
Source File: Workspace.java    From Spark with Apache License 2.0 4 votes vote down vote up
/**
  * Starts the Loading of all Spark Plugins.
  */
 public void loadPlugins() {
 
     // Send Available status
     SparkManager.getSessionManager().changePresence(statusBox.getPresence());
     
     // Add presence and message listeners
     // we listen for these to force open a 1-1 peer chat window from other operators if
     // one isn't already open
     StanzaFilter workspaceMessageFilter = new StanzaTypeFilter(Message.class);

     // Add the packetListener to this instance
     SparkManager.getSessionManager().getConnection().addAsyncStanzaListener(this, workspaceMessageFilter);

     // Make presence available to anonymous requests, if from anonymous user in the system.
     StanzaListener workspacePresenceListener = stanza -> {
         Presence presence = (Presence)stanza;
         JivePropertiesExtension extension = (JivePropertiesExtension) presence.getExtension( JivePropertiesExtension.NAMESPACE );
         if (extension != null && extension.getProperty("anonymous") != null) {
             boolean isAvailable = statusBox.getPresence().getMode() == Presence.Mode.available;
             Presence reply = new Presence(Presence.Type.available);
             if (!isAvailable) {
                 reply.setType(Presence.Type.unavailable);
             }
             reply.setTo(presence.getFrom());
             try
             {
                 SparkManager.getSessionManager().getConnection().sendStanza(reply);
             }
             catch ( SmackException.NotConnectedException e )
             {
                 Log.warning( "Unable to send presence reply to " + reply.getTo(), e );
             }
         }
     };

     SparkManager.getSessionManager().getConnection().addAsyncStanzaListener(workspacePresenceListener, new StanzaTypeFilter(Presence.class));

     // Until we have better plugin management, will init after presence updates.
     gatewayPlugin = new GatewayPlugin();
     gatewayPlugin.initialize();

     // Load all non-presence related items.
     conferences.loadConferenceBookmarks();
     SearchManager.getInstance();
     transcriptPlugin = new ChatTranscriptPlugin();

     // Load Broadcast Plugin
     broadcastPlugin = new BroadcastPlugin();
     broadcastPlugin.initialize();

     // Load BookmarkPlugin
     bookmarkPlugin = new BookmarkPlugin();
     bookmarkPlugin.initialize();

     // Schedule loading of the plugins after two seconds.
     TaskEngine.getInstance().schedule(new TimerTask() {
         @Override
public void run() {
             final PluginManager pluginManager = PluginManager.getInstance();

             SparkManager.getMainWindow().addMainWindowListener(pluginManager);
             pluginManager.initializePlugins();

             // Subscriptions are always manual
             Roster roster = Roster.getInstanceFor( SparkManager.getConnection() );
             roster.setSubscriptionMode(Roster.SubscriptionMode.manual);
         }
     }, 2000);

     // Check URI Mappings
     SparkManager.getChatManager().handleURIMapping(Spark.ARGUMENTS);
 }
 
Example 8
Source File: OnlineAgents.java    From Spark with Apache License 2.0 4 votes vote down vote up
private String buildTooltip(Presence presence) {
    if (!presence.isAvailable()) {
        return FpRes.getString("message.user.not.logged.in");
    }

    AgentStatus agentStatus = presence.getExtension("agent-status", "http://jabber.org/protocol/workgroup");
    List<AgentStatus.ChatInfo> list = agentStatus.getCurrentChats();

    // Add new ones.
    Iterator<AgentStatus.ChatInfo> iter = list.iterator();
    StringBuilder buf = new StringBuilder();
    buf.append("<html>");
    buf.append("<body>");
    buf.append("<table>");

    while (iter.hasNext()) {
        AgentStatus.ChatInfo chatInfo = iter.next();
        Date startDate = chatInfo.getDate();

        String nickname = chatInfo.getUsername();
        if (!ModelUtil.hasLength(nickname)) {
            nickname = FpRes.getString("message.not.specified");
        }

        String question = chatInfo.getQuestion();
        if (!ModelUtil.hasLength(question)) {
            question = "No question asked";
        }

        String email = chatInfo.getEmail();
        if (!ModelUtil.hasLength(email)) {
            email = FpRes.getString("message.not.specified");
        }

        long startTime = startDate.getTime();
        long rightNow = System.currentTimeMillis();
        long totalTime = rightNow - startTime;
        String durationTime = ModelUtil.getTimeFromLong(totalTime);

        buf.append("<tr><td><b><u>Chatting with ").append(nickname).append("</u></b></td></tr>");
        buf.append("<tr><td>Email: ").append(email).append("</td></tr>");
        buf.append("<tr><td>Question: ").append(question).append("</td></tr>");
        buf.append("<tr><td>Chat Duration: ").append(durationTime).append("</td></tr>");
        buf.append("<tr><td><br></td></tr>");
    }

    if (list.size() == 0) {
        buf.append(FpRes.getString("message.agent.is.not.in.chat"));
    }

    buf.append("</table>");
    buf.append("</body>");
    buf.append("</html>");
    return buf.toString();
}
 
Example 9
Source File: IdleElement.java    From Smack with Apache License 2.0 2 votes vote down vote up
/**
 * Return the IdleElement from a presence.
 * Returns null, if no IdleElement found.
 *
 * @param presence presence
 * @return idleElement from presence or null
 */
public static IdleElement fromPresence(Presence presence) {
    return presence.getExtension(IdleElement.class);
}