2018-07-04 23:23:28 +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-0118: User Tune
|
|
|
|
|
2018-09-13 23:56:12 +02:00
|
|
|
from typing import Any
|
|
|
|
from typing import Tuple
|
|
|
|
|
2018-07-04 23:23:28 +02:00
|
|
|
import nbxmpp
|
|
|
|
|
2019-02-01 20:46:20 +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
|
2018-07-04 23:23:28 +02:00
|
|
|
from gajim.common.const import PEPEventType
|
|
|
|
|
|
|
|
|
2019-02-01 20:46:20 +01:00
|
|
|
class UserTune(BaseModule):
|
|
|
|
|
|
|
|
_nbxmpp_extends = 'Tune'
|
|
|
|
_nbxmpp_methods = [
|
|
|
|
'set_tune',
|
|
|
|
]
|
|
|
|
|
|
|
|
def __init__(self, con):
|
|
|
|
BaseModule.__init__(self, con)
|
|
|
|
self._register_pubsub_handler(self._tune_received)
|
|
|
|
|
|
|
|
@event_node(nbxmpp.NS_TUNE)
|
|
|
|
def _tune_received(self, _con, _stanza, properties):
|
|
|
|
data = properties.pubsub_event.data
|
|
|
|
empty = properties.pubsub_event.empty
|
|
|
|
|
|
|
|
for contact in app.contacts.get_contacts(self._account,
|
|
|
|
str(properties.jid)):
|
|
|
|
if not empty:
|
|
|
|
contact.pep[PEPEventType.TUNE] = data
|
|
|
|
else:
|
|
|
|
contact.pep.pop(PEPEventType.TUNE, None)
|
|
|
|
|
|
|
|
if properties.is_self_message:
|
|
|
|
if not empty:
|
|
|
|
self._con.pep[PEPEventType.TUNE] = data
|
|
|
|
else:
|
|
|
|
self._con.pep.pop(PEPEventType.TUNE, None)
|
|
|
|
|
|
|
|
app.nec.push_incoming_event(
|
|
|
|
NetworkEvent('tune-received',
|
|
|
|
account=self._account,
|
|
|
|
jid=properties.jid.getBare(),
|
|
|
|
tune=data,
|
|
|
|
is_self_message=properties.is_self_message))
|
|
|
|
|
|
|
|
@store_publish
|
|
|
|
def set_tune(self, tune):
|
2019-03-09 23:16:27 +01:00
|
|
|
self._log.info('Send %s', tune)
|
2019-02-01 20:46:20 +01:00
|
|
|
self._nbxmpp('Tune').set_tune(tune)
|
2018-07-07 13:52:44 +02:00
|
|
|
|
|
|
|
|
2018-09-13 23:56:12 +02:00
|
|
|
def get_instance(*args: Any, **kwargs: Any) -> Tuple[UserTune, str]:
|
2018-07-07 13:52:44 +02:00
|
|
|
return UserTune(*args, **kwargs), 'UserTune'
|