2018-07-03 00:10:55 +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-0108: User Activity
|
|
|
|
|
2019-01-31 00:02:25 +01:00
|
|
|
from typing import Any
|
|
|
|
from typing import Tuple
|
|
|
|
|
2018-07-03 00:10:55 +02:00
|
|
|
import nbxmpp
|
|
|
|
|
2019-01-31 00:02:25 +01:00
|
|
|
from gajim.common import app
|
|
|
|
from gajim.common.nec import NetworkEvent
|
|
|
|
from gajim.common.modules.base import BaseModule
|
|
|
|
from gajim.common.modules.util import event_node
|
|
|
|
from gajim.common.modules.util import store_publish
|
|
|
|
from gajim.common.const import PEPEventType
|
2018-07-03 00:10:55 +02:00
|
|
|
|
|
|
|
|
2019-01-31 00:02:25 +01:00
|
|
|
class UserActivity(BaseModule):
|
2018-07-04 22:55:16 +02:00
|
|
|
|
2019-01-31 00:02:25 +01:00
|
|
|
_nbxmpp_extends = 'Activity'
|
|
|
|
_nbxmpp_methods = [
|
|
|
|
'set_activity',
|
|
|
|
]
|
2018-07-03 00:10:55 +02:00
|
|
|
|
2019-01-31 00:02:25 +01:00
|
|
|
def __init__(self, con):
|
|
|
|
BaseModule.__init__(self, con)
|
|
|
|
self._register_pubsub_handler(self._activity_received)
|
2018-07-03 00:10:55 +02:00
|
|
|
|
2019-01-31 00:02:25 +01:00
|
|
|
@event_node(nbxmpp.NS_ACTIVITY)
|
|
|
|
def _activity_received(self, _con, _stanza, properties):
|
|
|
|
data = properties.pubsub_event.data
|
2019-02-02 12:55:07 +01:00
|
|
|
empty = properties.pubsub_event.empty
|
|
|
|
|
2019-01-31 00:02:25 +01:00
|
|
|
for contact in app.contacts.get_contacts(self._account,
|
|
|
|
str(properties.jid)):
|
2019-02-02 12:55:07 +01:00
|
|
|
if not empty:
|
2019-01-31 00:02:25 +01:00
|
|
|
contact.pep[PEPEventType.ACTIVITY] = data
|
|
|
|
else:
|
|
|
|
contact.pep.pop(PEPEventType.ACTIVITY, None)
|
2018-07-03 00:10:55 +02:00
|
|
|
|
2019-01-31 00:02:25 +01:00
|
|
|
if properties.is_self_message:
|
2019-02-02 12:55:07 +01:00
|
|
|
if not empty:
|
2019-01-31 00:02:25 +01:00
|
|
|
self._con.pep[PEPEventType.ACTIVITY] = data
|
|
|
|
else:
|
|
|
|
self._con.pep.pop(PEPEventType.ACTIVITY, None)
|
2018-07-03 00:10:55 +02:00
|
|
|
|
2019-01-31 00:02:25 +01:00
|
|
|
app.nec.push_incoming_event(
|
|
|
|
NetworkEvent('activity-received',
|
|
|
|
account=self._account,
|
|
|
|
jid=properties.jid.getBare(),
|
|
|
|
activity=data,
|
|
|
|
is_self_message=properties.is_self_message))
|
2018-07-03 00:10:55 +02:00
|
|
|
|
2019-01-31 00:02:25 +01:00
|
|
|
@store_publish
|
|
|
|
def set_activity(self, activity):
|
2019-03-09 23:16:27 +01:00
|
|
|
self._log.info('Send %s', activity)
|
2019-01-31 00:02:25 +01:00
|
|
|
self._nbxmpp('Activity').set_activity(activity)
|
2018-07-03 00:10:55 +02:00
|
|
|
|
2019-01-19 20:56:47 +01:00
|
|
|
|
2019-01-31 00:02:25 +01:00
|
|
|
def get_instance(*args: Any, **kwargs: Any) -> Tuple[UserActivity, str]:
|
2018-07-07 13:52:44 +02:00
|
|
|
return UserActivity(*args, **kwargs), 'UserActivity'
|