Philipp Hörist pushed to branch master at gajim / python-nbxmpp
Commits:
b1cb29c0 by Philipp Hörist at 2019-02-01T17:07:48Z
Add UserTune (XEP-0118) module
- - - - -
3 changed files:
- nbxmpp/dispatcher_nb.py
- + nbxmpp/modules/tune.py
- nbxmpp/structs.py
Changes:
=====================================
nbxmpp/dispatcher_nb.py
=====================================
@@ -58,6 +58,7 @@ from nbxmpp.modules.entity_caps import EntityCaps
from nbxmpp.modules.blocking import Blocking
from nbxmpp.modules.pubsub import PubSub
from nbxmpp.modules.activity import Activity
+from nbxmpp.modules.tune import Tune
from nbxmpp.modules.mood import Mood
from nbxmpp.modules.misc import unwrap_carbon
from nbxmpp.modules.misc import unwrap_mam
@@ -185,6 +186,7 @@ class XMPPDispatcher(PlugIn):
self._modules['PubSub'] = PubSub(self._owner)
self._modules['Mood'] = Mood(self._owner)
self._modules['Activity'] = Activity(self._owner)
+ self._modules['Tune'] = Tune(self._owner)
for instance in self._modules.values():
for handler in instance.handlers:
=====================================
nbxmpp/modules/tune.py
=====================================
@@ -0,0 +1,87 @@
+# Copyright (C) 2018 Philipp Hörist <philipp AT hoerist.com>
+#
+# This file is part of nbxmpp.
+#
+# This program 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; either version 3
+# of the License, or (at your option) any later version.
+#
+# This program 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 this program; If not, see <http://www.gnu.org/licenses/>.
+
+import logging
+
+from nbxmpp.protocol import NS_TUNE
+from nbxmpp.protocol import NS_PUBSUB_EVENT
+from nbxmpp.protocol import Node
+from nbxmpp.structs import StanzaHandler
+from nbxmpp.structs import TuneData
+
+log = logging.getLogger('nbxmpp.m.tune')
+
+
+class Tune:
+ def __init__(self, client):
+ self._client = client
+ self.handlers = [
+ StanzaHandler(name='message',
+ callback=self._process_pubsub_tune,
+ ns=NS_PUBSUB_EVENT,
+ priority=16),
+ ]
+
+ def _process_pubsub_tune(self, _con, _stanza, properties):
+ if not properties.is_pubsub_event:
+ return
+
+ if properties.pubsub_event.node != NS_TUNE:
+ return
+
+ item = properties.pubsub_event.item
+
+ tune_node = item.getTag('tune', namespace=NS_TUNE)
+ if not tune_node.getChildren():
+ data = TuneData()
+ else:
+ artist = tune_node.getTagData('artist')
+ length = tune_node.getTagData('length')
+ rating = tune_node.getTagData('rating')
+ source = tune_node.getTagData('source')
+ title = tune_node.getTagData('title')
+ track = tune_node.getTagData('track')
+ uri = tune_node.getTagData('uri')
+
+ data = TuneData(artist, length, rating, source, title, track, uri)
+
+ log.info('Received tune: %s - %s', properties.jid, data)
+ properties.pubsub_event = properties.pubsub_event._replace(data=data)
+
+ def set_tune(self, data):
+ item = Node('tune', {'xmlns': NS_TUNE})
+ if data is None:
+ return item
+
+ if data.artist:
+ item.addChild('artist', payload=data.artist)
+ if data.length:
+ item.addChild('length', payload=data.length)
+ if data.rating:
+ item.addChild('length', payload=data.rating)
+ if data.source:
+ item.addChild('source', payload=data.source)
+ if data.title:
+ item.addChild('title', payload=data.title)
+ if data.track:
+ item.addChild('track', payload=data.track)
+ if data.uri:
+ item.addChild('track', payload=data.uri)
+
+ jid = self._client.get_bound_jid().getBare()
+ self._client.get_module('PubSub').publish(
+ jid, NS_TUNE, item, id_='current')
=====================================
nbxmpp/structs.py
=====================================
@@ -65,6 +65,22 @@ MoodData = namedtuple('MoodData', 'mood text')
ActivityData = namedtuple('ActivityData', 'activity subactivity text')
+class TuneData(namedtuple('TuneData', 'artist length rating source title track uri')):
+
+ __slots__ = []
+
+ def __new__(cls, artist=None, length=None, rating=None, source=None,
+ title=None, track=None, uri=None):
+ return super(TuneData, cls).__new__(cls, artist, length, rating,
+ source, title, track, uri)
+
+ @property
+ def was_removed(self):
+ return (self.artist is None and
+ self.title is None and
+ self.track is None)
+
+
class MAMData(namedtuple('MAMData', 'id query_id archive namespace timestamp')):
__slots__ = []
View it on GitLab: https://dev.gajim.org/gajim/python-nbxmpp/commit/b1cb29c0f415234f42971e722d…
--
View it on GitLab: https://dev.gajim.org/gajim/python-nbxmpp/commit/b1cb29c0f415234f42971e722d…
You're receiving this email because of your account on dev.gajim.org.
Philipp Hörist pushed to branch master at gajim / gajim
Commits:
18c422d8 by Philipp Hörist at 2019-02-01T16:24:33Z
Move print for debug message
- - - - -
2 changed files:
- gajim/common/app.py
- gajim/common/i18n.py
Changes:
=====================================
gajim/common/app.py
=====================================
@@ -44,6 +44,7 @@ import gajim
from gajim.common import config as c_config
from gajim.common import configpaths
from gajim.common import ged as ged_module
+from gajim.common.i18n import LANG
from gajim.common.contacts import LegacyContactsAPI
from gajim.common.events import Events
from gajim.common.types import NetworkEventsControllerT # pylint: disable=unused-import
@@ -337,6 +338,8 @@ def detect_dependencies():
for dep, val in _dependencies.items():
log('gajim').info('%-13s %s', dep, val)
+ log('gajim').info('Used language: %s', LANG)
+
def get_gpg_binary():
return _dependencies['GPG_BINARY']
=====================================
gajim/common/i18n.py
=====================================
@@ -171,7 +171,6 @@ try:
# Set the env var on Windows because gettext.find() uses it to
# find the translation
os.environ['LANG'] = LANG
- print('Found default language: %s' % LANG)
except Exception as error:
print('Failed to determine default language')
import traceback
View it on GitLab: https://dev.gajim.org/gajim/gajim/commit/18c422d843a60bccf6dcc43ba3a9e95610…
--
View it on GitLab: https://dev.gajim.org/gajim/gajim/commit/18c422d843a60bccf6dcc43ba3a9e95610…
You're receiving this email because of your account on dev.gajim.org.
Philipp Hörist pushed to branch master at gajim / gajim
Commits:
0b6fac44 by Philipp Hörist at 2019-02-01T16:03:46Z
Dont fail on malformed pubsub events
- - - - -
3 changed files:
- gajim/common/modules/user_activity.py
- gajim/common/modules/user_mood.py
- gajim/common/modules/util.py
Changes:
=====================================
gajim/common/modules/user_activity.py
=====================================
@@ -45,6 +45,8 @@ class UserActivity(BaseModule):
@event_node(nbxmpp.NS_ACTIVITY)
def _activity_received(self, _con, _stanza, properties):
data = properties.pubsub_event.data
+ if data is None:
+ return
for contact in app.contacts.get_contacts(self._account,
str(properties.jid)):
if data.activity is not None:
=====================================
gajim/common/modules/user_mood.py
=====================================
@@ -45,6 +45,8 @@ class UserMood(BaseModule):
@event_node(nbxmpp.NS_MOOD)
def _mood_received(self, _con, _stanza, properties):
data = properties.pubsub_event.data
+ if data is None:
+ return
for contact in app.contacts.get_contacts(self._account,
str(properties.jid)):
if data.mood is not None:
=====================================
gajim/common/modules/util.py
=====================================
@@ -55,6 +55,8 @@ def event_node(node):
def event_node_decorator(func):
@wraps(func)
def func_wrapper(self, _con, _stanza, properties):
+ if not properties.is_pubsub_event:
+ return
if properties.pubsub_event.node != node:
return
func(self, _con, _stanza, properties)
View it on GitLab: https://dev.gajim.org/gajim/gajim/commit/0b6fac44dc4775e667ac8d956df2295c8b…
--
View it on GitLab: https://dev.gajim.org/gajim/gajim/commit/0b6fac44dc4775e667ac8d956df2295c8b…
You're receiving this email because of your account on dev.gajim.org.