2018-06-25 23:00:40 +02:00
|
|
|
# This file is part of Gajim.
|
|
|
|
#
|
|
|
|
# Gajim is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published
|
|
|
|
# by the Free Software Foundation; version 3 only.
|
|
|
|
#
|
|
|
|
# Gajim is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
# XEP-0012: Last Activity
|
|
|
|
|
|
|
|
import nbxmpp
|
2019-02-19 19:34:14 +01:00
|
|
|
from nbxmpp.structs import StanzaHandler
|
2018-06-25 23:00:40 +02:00
|
|
|
|
|
|
|
from gajim.common import app
|
|
|
|
from gajim.common import idle
|
2019-02-19 19:34:14 +01:00
|
|
|
from gajim.common.modules.base import BaseModule
|
2018-06-25 23:00:40 +02:00
|
|
|
|
|
|
|
|
2019-02-19 19:34:14 +01:00
|
|
|
class LastActivity(BaseModule):
|
2018-06-25 23:00:40 +02:00
|
|
|
def __init__(self, con):
|
2019-02-19 19:34:14 +01:00
|
|
|
BaseModule.__init__(self, con)
|
2018-06-25 23:00:40 +02:00
|
|
|
|
2019-02-19 19:34:14 +01:00
|
|
|
self.handlers = [
|
|
|
|
StanzaHandler(name='iq',
|
|
|
|
typ='get',
|
|
|
|
callback=self._answer_request,
|
|
|
|
ns=nbxmpp.NS_LAST),
|
|
|
|
]
|
2018-06-25 23:00:40 +02:00
|
|
|
|
2019-02-19 19:34:14 +01:00
|
|
|
def _answer_request(self, _con, stanza, properties):
|
2019-03-09 23:16:27 +01:00
|
|
|
self._log.info('Request from %s', properties.jid)
|
2018-06-25 23:00:40 +02:00
|
|
|
|
|
|
|
allow_send = app.config.get_per(
|
|
|
|
'accounts', self._account, 'send_idle_time')
|
|
|
|
if app.is_installed('IDLE') and allow_send:
|
|
|
|
iq = stanza.buildReply('result')
|
|
|
|
query = iq.setQuery()
|
2019-02-19 19:34:14 +01:00
|
|
|
seconds = idle.Monitor.get_idle_sec()
|
|
|
|
query.attrs['seconds'] = seconds
|
2019-03-09 23:16:27 +01:00
|
|
|
self._log.info('Respond with seconds: %s', seconds)
|
2018-06-25 23:00:40 +02:00
|
|
|
else:
|
|
|
|
iq = stanza.buildReply('error')
|
|
|
|
err = nbxmpp.ErrorNode(nbxmpp.ERR_SERVICE_UNAVAILABLE)
|
|
|
|
iq.addChild(node=err)
|
|
|
|
|
|
|
|
self._con.connection.send(iq)
|
|
|
|
|
|
|
|
raise nbxmpp.NodeProcessed
|
2018-07-07 13:52:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
def get_instance(*args, **kwargs):
|
|
|
|
return LastActivity(*args, **kwargs), 'LastActivity'
|