Commit 5fdfcbb7 authored by Philipp Hörist's avatar Philipp Hörist
Browse files

Set empty attr for activity and mood

parent 96593877
......@@ -20,6 +20,7 @@ import logging
from nbxmpp.protocol import NS_ACTIVITY
from nbxmpp.protocol import NS_PUBSUB_EVENT
from nbxmpp.protocol import Node
from nbxmpp.protocol import NodeProcessed
from nbxmpp.structs import StanzaHandler
from nbxmpp.structs import ActivityData
from nbxmpp.const import ACTIVITIES
......@@ -47,24 +48,28 @@ class Activity:
item = properties.pubsub_event.item
activity_node = item.getTag('activity', namespace=NS_ACTIVITY)
if not activity_node.getChildren():
data = properties.pubsub_event._replace(empty=True)
else:
activity, subactivity, text = None, None, None
for child in activity_node.getChildren():
name = child.getName()
if name == 'text':
text = child.getData()
elif name in ACTIVITIES:
activity = name
subactivity = self._parse_sub_activity(child)
activity, subactivity, text = None, None, None
for child in activity_node.getChildren():
name = child.getName()
if name == 'text':
text = child.getData()
elif name in ACTIVITIES:
activity = name
subactivity = self._parse_sub_activity(child)
if activity is None and activity_node.getPayload():
log.warning('No valid activity value found')
log.warning(stanza)
raise NodeProcessed
if activity is None and activity_node.getPayload():
log.warning('No valid activity value found')
log.warning(stanza)
return
data = ActivityData(activity, subactivity, text)
data = properties.pubsub_event._replace(data=data)
data = ActivityData(activity, subactivity, text)
log.info('Received activity: %s - %s', properties.jid, data)
properties.pubsub_event = properties.pubsub_event._replace(data=data)
properties.pubsub_event = data
@staticmethod
def _parse_sub_activity(activity):
......
......@@ -20,6 +20,7 @@ import logging
from nbxmpp.protocol import NS_MOOD
from nbxmpp.protocol import NS_PUBSUB_EVENT
from nbxmpp.protocol import Node
from nbxmpp.protocol import NodeProcessed
from nbxmpp.structs import StanzaHandler
from nbxmpp.structs import MoodData
from nbxmpp.const import MOODS
......@@ -47,23 +48,27 @@ class Mood:
item = properties.pubsub_event.item
mood_node = item.getTag('mood', namespace=NS_MOOD)
if not mood_node.getChildren():
data = properties.pubsub_event._replace(empty=True)
else:
mood, text = None, None
for child in mood_node.getChildren():
name = child.getName().strip()
if name == 'text':
text = child.getData()
elif name in MOODS:
mood = name
mood, text = None, None
for child in mood_node.getChildren():
name = child.getName().strip()
if name == 'text':
text = child.getData()
elif name in MOODS:
mood = name
if mood is None and mood_node.getPayload():
log.warning('No valid mood value found')
log.warning(stanza)
raise NodeProcessed
if mood is None and mood_node.getPayload():
log.warning('No valid mood value found')
log.warning(stanza)
return
data = MoodData(mood, text)
data = properties.pubsub_event._replace(data=data)
data = MoodData(mood, text)
log.info('Received mood: %s - %s', properties.jid, data)
properties.pubsub_event = properties.pubsub_event._replace(data=data)
properties.pubsub_event = data
def set_mood(self, data):
item = Node('mood', {'xmlns': NS_MOOD})
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment