gajim-plural/src/common/pep.py

114 lines
3.7 KiB
Python
Raw Normal View History

2007-03-31 00:52:11 +02:00
from common import gajim, xmpp
2007-03-26 00:27:43 +02:00
def user_mood(items, name, jid):
2007-03-29 21:04:14 +02:00
(user, resource) = gajim.get_room_and_nick_from_fjid(jid)
contacts = gajim.contacts.get_contact(name, user, resource=resource)
2007-03-26 00:27:43 +02:00
for item in items.getTags('item'):
child = item.getTag('mood')
if child is not None:
for contact in contacts:
if contact.mood.has_key('mood'):
del contact.mood['mood']
if contact.mood.has_key('text'):
del contact.mood['text']
for ch in child.getChildren():
if ch.getName() != 'text':
2007-03-29 21:04:14 +02:00
contact.mood['mood'] = ch.getName()
else:
2007-03-29 21:04:14 +02:00
contact.mood['text'] = ch.getData()
2007-03-26 00:27:43 +02:00
def user_tune(items, name, jid):
2007-04-01 11:02:04 +02:00
(user, resource) = gajim.get_room_and_nick_from_fjid(jid)
contacts = gajim.contacts.get_contact(name, user, resource=resource)
for item in items.getTags('item'):
child = item.getTag('tune')
if child is not None:
for contact in contacts:
if contact.tune.has_key('artist'):
del contact.tune['artist']
if contact.tune.has_key('title'):
del contact.tune['title']
if contact.tune.has_key('source'):
del contact.tune['source']
if contact.tune.has_key('track'):
del contact.tune['track']
if contact.tune.has_key('length'):
del contact.tune['length']
for ch in child.getChildren():
if ch.getName() == 'artist':
contact.tune['artist'] = ch.getData()
elif ch.getName() == 'title':
contact.tune['title'] = ch.getData()
elif ch.getName() == 'source':
contact.tune['source'] = ch.getData()
elif ch.getName() == 'track':
contact.tune['track'] = ch.getData()
elif ch.getName() == 'length':
contact.tune['length'] = ch.getData()
2007-03-26 00:27:43 +02:00
def user_geoloc(items, name, jid):
pass
def user_activity(items, name, jid):
2007-03-29 21:04:14 +02:00
(user, resource) = gajim.get_room_and_nick_from_fjid(jid)
contacts = gajim.contacts.get_contact(name, user, resource=resource)
for item in items.getTags('item'):
child = item.getTag('activity')
if child is not None:
for contact in contacts:
if contact.activity.has_key('activity'):
del contact.activity['activity']
if contact.activity.has_key('subactivity'):
del contact.activity['subactivity']
if contact.activity.has_key('text'):
del contact.activity['text']
for ch in child.getChildren():
if ch.getName() != 'text':
2007-03-29 21:04:14 +02:00
contact.activity['activity'] = ch.getName()
for chi in ch.getChildren():
2007-03-29 21:04:14 +02:00
contact.activity['subactivity'] = chi.getName()
else:
2007-03-29 21:04:14 +02:00
contact.activity['text'] = ch.getData()
2007-03-31 00:52:11 +02:00
def user_send_mood(account, mood, message = ''):
item = xmpp.Node('mood', {'xmlns': xmpp.NS_MOOD})
item.addChild(mood)
if message != '':
i = item.addChild('text')
i.addData(message)
gajim.connections[account].send_pb_publish('', xmpp.NS_MOOD, item, '0')
def user_send_activity(account, activity, subactivity = '', message = ''):
item = xmpp.Node('activity', {'xmlns': xmpp.NS_ACTIVITY})
i = item.addChild(activity)
if subactivity != '':
i.addChild(subactivity)
if message != '':
i = item.addChild('text')
i.addData(message)
gajim.connections[account].send_pb_publish('', xmpp.NS_ACTIVITY, item, '0')
2007-04-01 11:02:04 +02:00
def user_send_tune(account, artist = '', title = '', source = '', track = 0,length = 0, items = None):
item = xmpp.Node('tune', {'xmlns': xmpp.NS_TUNE})
if artist != '':
i = item.addChild('artist')
i.addData(artist)
if title != '':
i = item.addChild('title')
i.addData(title)
if source != '':
i = item.addChild('source')
i.addData(source)
if track != 0:
i = item.addChild('track')
i.addData(track)
if length != 0:
i = item.addChild('length')
i.addData(length)
if items is not None:
item.addChild(payload=items)
gajim.connections[account].send_pb_publish('', xmpp.NS_TUNE, item, '0')