/src/services/LastActivity.py

http://pyaimt.googlecode.com/ · Python · 34 lines · 26 code · 6 blank · 2 comment · 2 complexity · a5f7e053ce2e500b4d90d7513fb476a1 MD5 · raw file

  1. # Copyright 2004-2006 Daniel Henninger <jadestorm@nc.rr.com>
  2. # Licensed for distribution under the GPL version 2, check COPYING for details
  3. import utils
  4. from twisted.words.xish.domish import Element
  5. import config
  6. from debug import LogEvent, INFO, WARN, ERROR
  7. import globals
  8. class LastActivity:
  9. def __init__(self, pytrans):
  10. self.pytrans = pytrans
  11. self.pytrans.disco.addFeature(globals.IQLAST, self.incomingIq, config.jid)
  12. self.pytrans.disco.addFeature(globals.IQLAST, self.incomingIq, "USER")
  13. def incomingIq(self, el):
  14. eltype = el.getAttribute("type")
  15. if eltype != "get": return # Only answer "get" stanzas
  16. self.sendLastActivity(el)
  17. def sendLastActivity(self, el):
  18. LogEvent(INFO)
  19. iq = Element((None, "iq"))
  20. iq.attributes["type"] = "result"
  21. iq.attributes["from"] = el.getAttribute("to")
  22. iq.attributes["to"] = el.getAttribute("from")
  23. if el.getAttribute("id"):
  24. iq.attributes["id"] = el.getAttribute("id")
  25. query = iq.addElement("query")
  26. query.attributes["xmlns"] = globals.IQLAST
  27. query.attributes["seconds"] = "0"
  28. self.pytrans.send(iq)