AbstractPresence presence = e.getPresence();
if (presence.getTo() == null) {
synchronized (LastActivityManager.this) {
// If an available presence with <show/> value 'away' or 'xa' is sent, append last activity information.
if (lastActivityStrategy != null && lastActivityStrategy.getLastActivity() != null && presence.isAvailable() && (presence.getShow() == AbstractPresence.Show.AWAY || presence.getShow() == AbstractPresence.Show.XA) && presence.getExtension(LastActivity.class) == null) {
presence.getExtensions().add(new LastActivity(getSecondsSince(lastActivityStrategy.getLastActivity()), presence.getStatus()));
}
}
}
}
}
});
xmppSession.addIQListener(new IQListener() {
@Override
public void handle(IQEvent e) {
IQ iq = e.getIQ();
if (e.isIncoming() && isEnabled() && !e.isConsumed() && iq.getType() == IQ.Type.GET && iq.getExtension(LastActivity.class) != null) {
// If someone asks me to get my last activity, reply.
synchronized (LastActivityManager.this) {
IQ result = iq.createResult();
long seconds = (lastActivityStrategy != null && lastActivityStrategy.getLastActivity() != null) ? getSecondsSince(lastActivityStrategy.getLastActivity()) : 0;
result.setExtension(new LastActivity(seconds, null));
xmppSession.send(result);
e.consume();
}
}
}