PageRenderTime 27ms CodeModel.GetById 14ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 4import utils
 5from twisted.words.xish.domish import Element
 6import config
 7from debug import LogEvent, INFO, WARN, ERROR
 8import globals
 9
10class LastActivity:
11	def __init__(self, pytrans):
12		self.pytrans = pytrans
13		self.pytrans.disco.addFeature(globals.IQLAST, self.incomingIq, config.jid)
14		self.pytrans.disco.addFeature(globals.IQLAST, self.incomingIq, "USER")
15
16	def incomingIq(self, el):
17		eltype = el.getAttribute("type")
18		if eltype != "get": return # Only answer "get" stanzas
19
20		self.sendLastActivity(el)
21
22	def sendLastActivity(self, el):
23		LogEvent(INFO)
24		iq = Element((None, "iq"))
25		iq.attributes["type"] = "result"
26		iq.attributes["from"] = el.getAttribute("to")
27		iq.attributes["to"] = el.getAttribute("from")
28		if el.getAttribute("id"):
29			iq.attributes["id"] = el.getAttribute("id")
30		query = iq.addElement("query")
31		query.attributes["xmlns"] = globals.IQLAST
32		query.attributes["seconds"] = "0"
33
34		self.pytrans.send(iq)