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

The following examples show how to use org.jivesoftware.smack.packet.Presence#getStatus() . 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: SparkSystemTray.java    From Spark with Apache License 2.0 6 votes vote down vote up
/**
 * Change the presence of the tray.
 *
 * @param presence the new presence.
 */
public void changePresence(Presence presence) {
    if (Spark.isMac()) {
        return;
    }

    if (presence.getMode() == Presence.Mode.available || presence.getMode() == Presence.Mode.chat) {
        setTrayIcon(availableIcon);
    }
    else if (presence.getMode() == Presence.Mode.away || presence.getMode() == Presence.Mode.xa) {
        setTrayIcon(awayIcon);
    }
    else {
        setTrayIcon(dndIcon);
    }

    // Get Status Text
    if (presence.isAvailable()) {
        String status = presence.getStatus();
        trayIcon.setToolTip(Default.getString(Default.APPLICATION_NAME) + "\n" + status);
    }
}
 
Example 2
Source File: Workpane.java    From Spark with Apache License 2.0 6 votes vote down vote up
public void presenceChanged(Presence presence) {
    String status = presence.getStatus();
    if (status == null) {
        status = "";
    }

    try {
        if (FastpathPlugin.getAgentSession().isOnline()) {
            Presence.Mode mode = presence.getMode();
            if (status == null) {
                status = "";
            }
            if (mode == null) {
                mode = Presence.Mode.available;
            }
            FastpathPlugin.getAgentSession().setStatus(presence.getMode(), status);
        }
    }
    catch (XMPPException | SmackException | InterruptedException e) {
        Log.error(e);
    }
}
 
Example 3
Source File: PresenceManager.java    From Spark with Apache License 2.0 5 votes vote down vote up
public static boolean isOnPhone(Presence presence) {
	Presence.Mode presenceMode = presence.getMode();
	 if (presenceMode == null) {
    	 presenceMode = Presence.Mode.available;
    }
	if (presence.getStatus() != null && 
		presence.getStatus().contains(Res.getString("status.on.phone")) && 
		presenceMode.equals(Presence.Mode.away)) {
		return true;
	}
	return false;
}
 
Example 4
Source File: PrivacyPresenceHandler.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * Send my presence for user
 * 
 * @param jid
 *            JID to send presence
 */
public void sendRealPresenceTo(Jid jid) throws SmackException.NotConnectedException
{
    Presence presence = SparkManager.getWorkspace().getStatusBar().getPresence(); 
    Presence pack = new Presence(presence.getType(), presence.getStatus(), 1, presence.getMode()); 
    pack.setTo(jid);
    try {
        SparkManager.getConnection().sendStanza(pack);
    } catch (InterruptedException e) {
        throw new IllegalStateException(e);
    }
}
 
Example 5
Source File: GroupChat_EBL.java    From olat with Apache License 2.0 4 votes vote down vote up
public void updateRosterListFrom(final Presence p) {

        synchronized (rosterList) {

            try {
                final String s = p.getStatus();
                final String t = p.getType().name();
                final String n = chatEbl.getFullUserName(extractUsername(p.getFrom()));

                if ("chatEcho".equals(s)) {
                    if (!rosterList.contains(n)) {
                        rosterList.add(n);
                    }
                } else if ("chatOpen".equals(s)) {
                    if (!rosterList.contains(n)) {
                        rosterList.add(n);
                    }
                    if (chatWindowOpen) {
                        muc.changeAvailabilityStatus("chatEcho", Presence.Mode.available);
                    }
                } else if ("chatClosed".equals(s)) {
                    if (chatWindowOpen) {
                        muc.changeAvailabilityStatus("chatEcho", Presence.Mode.available);
                    }
                    rosterList.remove(n);
                } else if (t.equals("available")) {
                    if (!rosterList.contains(n)) {
                        rosterList.add(n);
                    }
                } else if (t.equals("unavailable")) {
                    rosterList.remove(n);
                }

                if (!chatWindowOpen) {
                    rosterList.remove(getAnonymousNickName());
                }
                DBFactory.getInstance(false).commitAndCloseSession();

            } catch (final Exception e) {
                DBFactory.getInstance(false).rollbackAndCloseSession();
            }

        }
    }
 
Example 6
Source File: GroupChat_EBL.java    From olat with Apache License 2.0 4 votes vote down vote up
public void updateRosterListFrom(final Presence p) {

        synchronized (rosterList) {

            try {
                final String s = p.getStatus();
                final String t = p.getType().name();
                final String n = chatEbl.getFullUserName(extractUsername(p.getFrom()));

                if ("chatEcho".equals(s)) {
                    if (!rosterList.contains(n)) {
                        rosterList.add(n);
                    }
                } else if ("chatOpen".equals(s)) {
                    if (!rosterList.contains(n)) {
                        rosterList.add(n);
                    }
                    if (chatWindowOpen) {
                        muc.changeAvailabilityStatus("chatEcho", Presence.Mode.available);
                    }
                } else if ("chatClosed".equals(s)) {
                    if (chatWindowOpen) {
                        muc.changeAvailabilityStatus("chatEcho", Presence.Mode.available);
                    }
                    rosterList.remove(n);
                } else if (t.equals("available")) {
                    if (!rosterList.contains(n)) {
                        rosterList.add(n);
                    }
                } else if (t.equals("unavailable")) {
                    rosterList.remove(n);
                }

                if (!chatWindowOpen) {
                    rosterList.remove(getAnonymousNickName());
                }
                DBFactory.getInstance(false).commitAndCloseSession();

            } catch (final Exception e) {
                DBFactory.getInstance(false).rollbackAndCloseSession();
            }

        }
    }
 
Example 7
Source File: StatusBar.java    From Spark with Apache License 2.0 4 votes vote down vote up
public static Presence copyPresence(Presence presence) {
	return new Presence(presence.getType(), presence.getStatus(), presence.getPriority(), presence.getMode());
}
 
Example 8
Source File: StatusBar.java    From Spark with Apache License 2.0 4 votes vote down vote up
private String changePresence(Presence presence) {
	// SPARK-1521. Other clients can see "Invisible" status while we are disappearing.
	// So we send "Offline" instead of "Invisible" for them.
	boolean isNewPresenceInvisible = PresenceManager
			.isInvisible(presence);
	if (isNewPresenceInvisible && !PrivacyManager.getInstance().isPrivacyActive()) {
		JOptionPane.showMessageDialog(null, Res.getString("dialog.invisible.privacy.lists.not.supported"));
	}

	Presence copyPresence = copyPresence(presence);
	if (isNewPresenceInvisible) {
		copyPresence.setStatus(null);
	}
	if (PresenceManager.areEqual(getCurrentPresence(), copyPresence)) {
		return presence.getStatus();
	}

	// ask user to confirm that all group chat rooms will be closed if
	// he/she goes to invisible.
	if (isNewPresenceInvisible
			&& SparkManager.getChatManager().getChatContainer()
			.hasGroupChatRooms()) {
		int reply = JOptionPane
				.showConfirmDialog(
						null,
						Res.getString("dialog.confirm.close.all.conferences.if.invisible.msg"),
						Res.getString("dialog.confirm.to.reveal.visibility.title"),
						JOptionPane.YES_NO_OPTION);
		if (reply == JOptionPane.NO_OPTION) {
			return getCurrentPresence().getStatus();
		}
	}

	// If we go visible then we should send "Available" first.
	if (!isNewPresenceInvisible
			&& PresenceManager.isInvisible(getCurrentPresence()))
		PrivacyManager.getInstance().goToVisible();

	// Then set the current status.
	SparkManager.getSessionManager().changePresence(copyPresence);

	// If we go invisible we should activate the "globally invisible list"
	// and send "Available" after "Unavailable" presence.
	if (isNewPresenceInvisible) {
		SparkManager.getChatManager().getChatContainer()
		.closeAllGroupChatRooms();
		PrivacyManager.getInstance().goToInvisible();
	}

	return presence.getStatus();
}
 
Example 9
Source File: GatewayButton.java    From Spark with Apache License 2.0 4 votes vote down vote up
public GatewayButton(final Transport transport) {
     setLayout(new GridBagLayout());
     setOpaque(false);

     this.transport = transport;

     final StatusBar statusBar = SparkManager.getWorkspace().getStatusBar();
     final JPanel commandPanel = SparkManager.getWorkspace().getCommandPanel();

     if (PresenceManager.isOnline(transport.getXMPPServiceDomain())) {
         button.setIcon(transport.getIcon());
     }
     else {
         button.setIcon(transport.getInactiveIcon());
     }
     button.setToolTipText(transport.getName());

     commandPanel.add(button);

     button.addMouseListener(new MouseAdapter() {
         @Override
public void mousePressed(MouseEvent mouseEvent) {
             handlePopup(mouseEvent);
         }
     });
     commandPanel.updateUI();
     final Runnable registerThread = () -> {
         // Send directed presence if registered with this transport.
         final boolean isRegistered = TransportUtils.isRegistered(SparkManager.getConnection(), transport);
         if (isRegistered) {
             // Check if auto login is set.
             boolean autoJoin = TransportUtils.autoJoinService(transport.getXMPPServiceDomain());
             if (autoJoin) {
                 Presence oldPresence = statusBar.getPresence();
                 Presence presence = new Presence(oldPresence.getType(), oldPresence.getStatus(), oldPresence.getPriority(), oldPresence.getMode());
                 presence.setTo(transport.getXMPPServiceDomain());
                 try
                 {
                     SparkManager.getConnection().sendStanza(presence);
                 }
                 catch ( SmackException.NotConnectedException | InterruptedException e )
                 {
                     Log.error( "Unable to register.", e );
                 }
             }
         }
     };

     TaskEngine.getInstance().submit(registerThread);
 }
 
Example 10
Source File: AppleDock.java    From Spark with Apache License 2.0 4 votes vote down vote up
public AppleDock() {

	PopupMenu menu = new PopupMenu();

	PopupMenu statusmenu = new PopupMenu(Res.getString("menuitem.status"));

	for (Presence p : PresenceManager.getPresences()) {
	    MenuItem dd = new MenuItem(p.getStatus());
	    dd.addActionListener(this);
	    statusmenu.add(dd);
	}

	menu.add(statusmenu);

	JFrame frame = SparkManager.getMainWindow();
	frame.add(menu);

	// set dock menu
	Application app = new Application();
	app.setDockMenu(menu);

    }