Java源码示例:org.jivesoftware.smackx.iqlast.packet.LastActivity
示例1
private void getLastSeen (Contact contact)
{
if (getState() == ImConnection.LOGGED_IN) {
try {
LastActivity activity = mLastActivityManager.getLastActivity(JidCreate.bareFrom(contact.getAddress().getBareAddress()));
if (activity != null) {
Presence presence = contact.getPresence();
if (presence == null)
presence = new Presence();
Date now = new Date();
presence.setLastSeen(new Date(now.getTime() - (activity.getIdleTime() * 1000)));
contact.setPresence(presence);
}
} catch (Exception e) {
debug("LastActivity", "error getting last activity for: " + contact.getAddress().getAddress());
}
}
}
示例2
@Override
public void processStanza(Stanza packet) throws SmackException.NotConnectedException {
LOGGER.config("last activity: " + packet);
LastActivity lastActivity = (LastActivity) packet;
long lastActivityTime = lastActivity.getIdleTime();
if (lastActivityTime < 0) {
// error message or parsing error, not important here (logged by Client class)
return;
}
mControl.onLastActivity(JID.fromSmack(lastActivity.getFrom()),
lastActivity.getIdleTime(),
StringUtils.defaultString(lastActivity.getStatusMessage()));
}
示例3
@Test
public void checkProvider() throws Exception {
XMLBuilder xml = XMLBuilder.create("iq");
xml.a("from", "[email protected]/orchard")
.a("id", "last2")
.a("to", "[email protected]/balcony")
.a("type", "get")
.e("query")
.namespace(LastActivity.NAMESPACE);
DummyConnection c = new DummyConnection();
c.connect();
IQ lastRequest = PacketParserUtils.parseStanza(xml.asString());
assertTrue(lastRequest instanceof LastActivity);
c.processStanza(lastRequest);
Stanza reply = c.getSentPacket();
assertTrue(reply instanceof LastActivity);
LastActivity l = (LastActivity) reply;
assertEquals("last2", l.getStanzaId());
assertEquals(IQ.Type.result, l.getType());
}
示例4
public String getLastSeenMessage(String jid) {
if (!isConnected() || !connection.isAuthenticated()) {
return LocaleController.getString("Offline", R.string.Offline);
}
try {
LastActivityManager lastActivityManager = LastActivityManager.getInstanceFor(connection);
LastActivity activity = lastActivityManager.getLastActivity(JidCreate.bareFrom(jid));
int lastSeenBySeconds = Utilities.parseInt(activity.lastActivity + "");
String lastSeenMessage = "";
lastSeenMessage = LocaleController.getString("Offline", R.string.Offline);
if (lastSeenBySeconds >= 1) {
PrettyTime p = new PrettyTime();
Date date = new Date();
Calendar cal = Calendar.getInstance();
cal.add(Calendar.SECOND, -1 * lastSeenBySeconds);
lastSeenMessage = LocaleController.formatDateOnline(cal.getTime()); //p.format(cal.getTime());
} else {
lastSeenMessage = LocaleController.getString("Offline", R.string.Offline);
}
//FileLog.e("LAST ACTIVITY","" + ""+ "" + lastSeenBySeconds +" "+jid);
return lastSeenMessage;
} catch (Exception e) {
e.printStackTrace();
return LocaleController.getString("Offline", R.string.Offline);
}
//return "Offline";
}
示例5
private void sendLastActivityRequestAsync(JID jid) {
if (mFeatureDiscovery == null) {
LOGGER.warning("no feature discovery");
return;
}
// blocking
if (!mFeatureDiscovery.getFeaturesFor(jid.toDomain())
.containsKey(FeatureDiscovery.Feature.LAST_ACTIVITY))
// not supported by server
return;
LastActivity request = new LastActivity(jid.toBareSmack());
this.sendPacket(request);
}
示例6
public synchronized void enable() {
ServiceDiscoveryManager.getInstanceFor(connection()).addFeature(LastActivity.NAMESPACE);
enabled = true;
}
示例7
public synchronized void disable() {
ServiceDiscoveryManager.getInstanceFor(connection()).removeFeature(LastActivity.NAMESPACE);
enabled = false;
}
示例8
/**
* Returns the last activity of a particular jid. If the jid is a full JID
* (i.e., a JID of the form of '[email protected]/resource') then the last activity
* is the idle time of that connected resource. On the other hand, when the
* jid is a bare JID (e.g. '[email protected]') then the last activity is the lapsed
* time since the last logout or 0 if the user is currently logged in.
* Moreover, when the jid is a server or component (e.g., a JID of the form
* 'host') the last activity is the uptime.
*
* @param jid TODO javadoc me please
* the JID of the user.
* @return the LastActivity stanza of the jid.
* @throws XMPPErrorException if there was an XMPP error returned.
* thrown if a server error has occurred.
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException if the XMPP connection is not connected.
* @throws InterruptedException if the calling thread was interrupted.
*/
public LastActivity getLastActivity(Jid jid) throws NoResponseException, XMPPErrorException,
NotConnectedException, InterruptedException {
LastActivity activity = new LastActivity(jid);
return (LastActivity) connection().createStanzaCollectorAndSend(activity).nextResultOrThrow();
}
示例9
/**
* Returns true if Last Activity (XEP-0012) is supported by a given JID.
*
* @param jid a JID to be tested for Last Activity support
* @return true if Last Activity is supported, otherwise false
* @throws NotConnectedException if the XMPP connection is not connected.
* @throws XMPPErrorException if there was an XMPP error returned.
* @throws NoResponseException if there was no response from the remote entity.
* @throws InterruptedException if the calling thread was interrupted.
*/
public boolean isLastActivitySupported(Jid jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
return ServiceDiscoveryManager.getInstanceFor(connection()).supportsFeature(jid, LastActivity.NAMESPACE);
}