LastActivity: Use BaseModule and StanzaHandler
This commit is contained in:
parent
12389f4097
commit
12d909d636
|
@ -17,31 +17,37 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import nbxmpp
|
import nbxmpp
|
||||||
|
from nbxmpp.structs import StanzaHandler
|
||||||
|
|
||||||
from gajim.common import app
|
from gajim.common import app
|
||||||
from gajim.common import idle
|
from gajim.common import idle
|
||||||
|
from gajim.common.modules.base import BaseModule
|
||||||
|
|
||||||
log = logging.getLogger('gajim.c.m.last_activity')
|
log = logging.getLogger('gajim.c.m.last_activity')
|
||||||
|
|
||||||
|
|
||||||
class LastActivity:
|
class LastActivity(BaseModule):
|
||||||
def __init__(self, con):
|
def __init__(self, con):
|
||||||
self._con = con
|
BaseModule.__init__(self, con)
|
||||||
self._account = con.name
|
|
||||||
|
|
||||||
self.handlers = [('iq', self._answer_request, 'get', nbxmpp.NS_LAST)]
|
self.handlers = [
|
||||||
|
StanzaHandler(name='iq',
|
||||||
|
typ='get',
|
||||||
|
callback=self._answer_request,
|
||||||
|
ns=nbxmpp.NS_LAST),
|
||||||
|
]
|
||||||
|
|
||||||
def _answer_request(self, _con, stanza):
|
def _answer_request(self, _con, stanza, properties):
|
||||||
log.info('Request from %s', stanza.getFrom())
|
log.info('Request from %s', properties.jid)
|
||||||
if not app.account_is_connected(self._account):
|
|
||||||
return
|
|
||||||
|
|
||||||
allow_send = app.config.get_per(
|
allow_send = app.config.get_per(
|
||||||
'accounts', self._account, 'send_idle_time')
|
'accounts', self._account, 'send_idle_time')
|
||||||
if app.is_installed('IDLE') and allow_send:
|
if app.is_installed('IDLE') and allow_send:
|
||||||
iq = stanza.buildReply('result')
|
iq = stanza.buildReply('result')
|
||||||
query = iq.setQuery()
|
query = iq.setQuery()
|
||||||
query.attrs['seconds'] = idle.Monitor.get_idle_sec()
|
seconds = idle.Monitor.get_idle_sec()
|
||||||
|
query.attrs['seconds'] = seconds
|
||||||
|
log.info('Respond with seconds: %s', seconds)
|
||||||
else:
|
else:
|
||||||
iq = stanza.buildReply('error')
|
iq = stanza.buildReply('error')
|
||||||
err = nbxmpp.ErrorNode(nbxmpp.ERR_SERVICE_UNAVAILABLE)
|
err = nbxmpp.ErrorNode(nbxmpp.ERR_SERVICE_UNAVAILABLE)
|
||||||
|
|
Loading…
Reference in New Issue