org.jivesoftware.smackx.iqlast.packet.LastActivity Java Examples
The following examples show how to use
org.jivesoftware.smackx.iqlast.packet.LastActivity.
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: XmppConnection.java From Zom-Android-XMPP with GNU General Public License v3.0 | 6 votes |
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()); } } }
Example #2
Source File: LastActivityListener.java From desktopclient-java with GNU General Public License v3.0 | 6 votes |
@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())); }
Example #3
Source File: LastActivityTest.java From Smack with Apache License 2.0 | 6 votes |
@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()); }
Example #4
Source File: XMPPManager.java From Yahala-Messenger with MIT License | 5 votes |
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"; }
Example #5
Source File: Client.java From desktopclient-java with GNU General Public License v3.0 | 5 votes |
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); }
Example #6
Source File: LastActivityManager.java From Smack with Apache License 2.0 | 4 votes |
public synchronized void enable() { ServiceDiscoveryManager.getInstanceFor(connection()).addFeature(LastActivity.NAMESPACE); enabled = true; }
Example #7
Source File: LastActivityManager.java From Smack with Apache License 2.0 | 4 votes |
public synchronized void disable() { ServiceDiscoveryManager.getInstanceFor(connection()).removeFeature(LastActivity.NAMESPACE); enabled = false; }
Example #8
Source File: LastActivityManager.java From Smack with Apache License 2.0 | 2 votes |
/** * Returns the last activity of a particular jid. If the jid is a full JID * (i.e., a JID of the form of 'user@host/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. 'user@host') 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(); }
Example #9
Source File: LastActivityManager.java From Smack with Apache License 2.0 | 2 votes |
/** * 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); }