Project

General

Profile

Get the user online and offline

Lonely Lonely
Added almost 4 years ago

Hi,I by writing a plugin for users online, offline, and do some actions.

But I can get the user online state, but unable to get offline

public class App extends XMPPProcessor implements XMPPProcessorIfc {

    private static final String           ID                    = "offlinemessage";
    private static final Logger           log                   = Logger.getLogger(App.class.getCanonicalName());

    public String id() {
        return ID;
    }

    @Override
    public String[][] supElementNamePaths() {
        return ELEMENTS;
    }

    @Override
    public String[] supNamespaces() {
        return XMLNSS;
    }

    public void process(Packet packet, XMPPResourceConnection session,
            NonAuthUserRepository repo, Queue<Packet> results,
            Map<String, Object> settings) throws XMPPException {
        if (log.isLoggable(Level.FINEST)) {
            log.finest("Processing packet: " + packet.toString());
        }

        if (session != null) {

            if ((packet.getElemName() == Presence.ELEM_NAME) && (packet.getStanzaTo() == null)) {
                String currentUser = session.getJID().getLocalpart();

                if ((type == null) || (type == StanzaType.available)) {

                    System.out.println(currentUser + "online");
                } else if ((type == StanzaType.unavailable) || (type == StanzaType.error)) {

                    System.out.println(currentUser + "offline");
                }
            }
        }
    }
}

Replies (1)

Avatar?id=6023&size=32x32

Added by Artur Hefczyc TigaseTeam almost 4 years ago

if session == null then the user is offline.

    (1-1/1)