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-12-13 21:26:13 +01:00
|
|
|
has_child = False
|
|
|
|
mood = None
|
|
|
|
text = None
|
2007-03-26 00:27:43 +02:00
|
|
|
for item in items.getTags('item'):
|
|
|
|
child = item.getTag('mood')
|
|
|
|
if child is not None:
|
2007-12-13 21:26:13 +01:00
|
|
|
has_child = True
|
2007-08-09 17:54:16 +02:00
|
|
|
for ch in child.getChildren():
|
|
|
|
if ch.getName() != 'text':
|
2007-12-13 21:26:13 +01:00
|
|
|
mood = ch.getName()
|
2007-08-09 17:54:16 +02:00
|
|
|
else:
|
2007-12-13 21:26:13 +01:00
|
|
|
text = ch.getData()
|
|
|
|
if jid == gajim.get_jid_from_account(name):
|
|
|
|
acc = gajim.connections[name]
|
|
|
|
if has_child:
|
|
|
|
if acc.mood.has_key('mood'):
|
|
|
|
del acc.mood['mood']
|
|
|
|
if acc.mood.has_key('text'):
|
|
|
|
del acc.mood['text']
|
2008-04-18 02:26:07 +02:00
|
|
|
if mood is not None:
|
2007-12-13 21:26:13 +01:00
|
|
|
acc.mood['mood'] = mood
|
2008-04-18 02:26:07 +02:00
|
|
|
if text is not None:
|
2007-12-13 21:26:13 +01:00
|
|
|
acc.mood['text'] = text
|
2007-03-26 00:27:43 +02:00
|
|
|
|
2007-04-01 11:02:04 +02:00
|
|
|
(user, resource) = gajim.get_room_and_nick_from_fjid(jid)
|
2007-08-09 17:54:16 +02:00
|
|
|
contact = gajim.contacts.get_contact(name, user, resource=resource)
|
|
|
|
if not contact:
|
|
|
|
return
|
2007-12-13 21:26:13 +01:00
|
|
|
if has_child:
|
|
|
|
if contact.mood.has_key('mood'):
|
|
|
|
del contact.mood['mood']
|
|
|
|
if contact.mood.has_key('text'):
|
|
|
|
del contact.mood['text']
|
2008-04-18 02:26:07 +02:00
|
|
|
if mood is not None:
|
2007-12-13 21:26:13 +01:00
|
|
|
contact.mood['mood'] = mood
|
2008-04-18 02:26:07 +02:00
|
|
|
if text is not None:
|
2007-12-13 21:26:13 +01:00
|
|
|
contact.mood['text'] = text
|
|
|
|
|
|
|
|
def user_tune(items, name, jid):
|
|
|
|
has_child = False
|
|
|
|
artist = None
|
|
|
|
title = None
|
|
|
|
source = None
|
|
|
|
track = None
|
|
|
|
length = None
|
|
|
|
|
2007-04-01 11:02:04 +02:00
|
|
|
for item in items.getTags('item'):
|
|
|
|
child = item.getTag('tune')
|
|
|
|
if child is not None:
|
2007-12-13 21:26:13 +01:00
|
|
|
has_child = True
|
2007-08-09 17:54:16 +02:00
|
|
|
for ch in child.getChildren():
|
|
|
|
if ch.getName() == 'artist':
|
2007-12-13 21:26:13 +01:00
|
|
|
artist = ch.getData()
|
2007-08-09 17:54:16 +02:00
|
|
|
elif ch.getName() == 'title':
|
2007-12-13 21:26:13 +01:00
|
|
|
title = ch.getData()
|
2007-08-09 17:54:16 +02:00
|
|
|
elif ch.getName() == 'source':
|
2007-12-13 21:26:13 +01:00
|
|
|
source = ch.getData()
|
2007-08-09 17:54:16 +02:00
|
|
|
elif ch.getName() == 'track':
|
2007-12-13 21:26:13 +01:00
|
|
|
track = ch.getData()
|
2007-08-09 17:54:16 +02:00
|
|
|
elif ch.getName() == 'length':
|
2007-12-13 21:26:13 +01:00
|
|
|
length = ch.getData()
|
2007-03-26 00:27:43 +02:00
|
|
|
|
2007-12-13 21:26:13 +01:00
|
|
|
if jid == gajim.get_jid_from_account(name):
|
|
|
|
acc = gajim.connections[name]
|
|
|
|
if has_child:
|
|
|
|
if acc.tune.has_key('artist'):
|
|
|
|
del acc.tune['artist']
|
|
|
|
if acc.tune.has_key('title'):
|
|
|
|
del acc.tune['title']
|
|
|
|
if acc.tune.has_key('source'):
|
|
|
|
del acc.tune['source']
|
|
|
|
if acc.tune.has_key('track'):
|
|
|
|
del acc.tune['track']
|
|
|
|
if acc.tune.has_key('length'):
|
|
|
|
del acc.tune['length']
|
2008-04-18 02:26:07 +02:00
|
|
|
if artist is not None:
|
2007-12-13 21:26:13 +01:00
|
|
|
acc.tune['artist'] = artist
|
2008-04-18 02:26:07 +02:00
|
|
|
if title is not None:
|
2007-12-13 21:26:13 +01:00
|
|
|
acc.tune['title'] = title
|
2008-04-18 02:26:07 +02:00
|
|
|
if source is not None:
|
2007-12-13 21:26:13 +01:00
|
|
|
acc.tune['source'] = source
|
2008-04-18 02:26:07 +02:00
|
|
|
if track is not None:
|
2007-12-13 21:26:13 +01:00
|
|
|
acc.tune['track'] = track
|
2008-04-18 02:26:07 +02:00
|
|
|
if length is not None:
|
2007-12-13 21:26:13 +01:00
|
|
|
acc.tune['length'] = length
|
2007-03-28 23:18:16 +02:00
|
|
|
|
2007-03-29 21:04:14 +02:00
|
|
|
(user, resource) = gajim.get_room_and_nick_from_fjid(jid)
|
2007-08-09 17:54:16 +02:00
|
|
|
contact = gajim.contacts.get_contact(name, user, resource=resource)
|
|
|
|
if not contact:
|
|
|
|
return
|
2007-12-13 21:26:13 +01:00
|
|
|
if has_child:
|
|
|
|
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']
|
2008-04-18 02:26:07 +02:00
|
|
|
if artist is not None:
|
2007-12-13 21:26:13 +01:00
|
|
|
contact.tune['artist'] = artist
|
2008-04-18 02:26:07 +02:00
|
|
|
if title is not None:
|
2007-12-13 21:26:13 +01:00
|
|
|
contact.tune['title'] = title
|
2008-04-18 02:26:07 +02:00
|
|
|
if source is not None:
|
2007-12-13 21:26:13 +01:00
|
|
|
contact.tune['source'] = source
|
2008-04-18 02:26:07 +02:00
|
|
|
if track is not None:
|
2007-12-13 21:26:13 +01:00
|
|
|
contact.tune['track'] = track
|
2008-04-18 02:26:07 +02:00
|
|
|
if length is not None:
|
2007-12-13 21:26:13 +01:00
|
|
|
contact.tune['length'] = length
|
|
|
|
|
|
|
|
def user_geoloc(items, name, jid):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def user_activity(items, name, jid):
|
|
|
|
has_child = False
|
|
|
|
activity = None
|
|
|
|
subactivity = None
|
|
|
|
text = None
|
|
|
|
|
2007-03-28 23:18:16 +02:00
|
|
|
for item in items.getTags('item'):
|
|
|
|
child = item.getTag('activity')
|
|
|
|
if child is not None:
|
2007-12-13 21:26:13 +01:00
|
|
|
has_child = True
|
2007-08-09 17:54:16 +02:00
|
|
|
for ch in child.getChildren():
|
|
|
|
if ch.getName() != 'text':
|
2007-12-13 21:26:13 +01:00
|
|
|
activity = ch.getName()
|
2007-08-09 17:54:16 +02:00
|
|
|
for chi in ch.getChildren():
|
2007-12-13 21:26:13 +01:00
|
|
|
subactivity = chi.getName()
|
2007-08-09 17:54:16 +02:00
|
|
|
else:
|
2007-12-13 21:26:13 +01:00
|
|
|
text = ch.getData()
|
|
|
|
|
|
|
|
if jid == gajim.get_jid_from_account(name):
|
|
|
|
acc = gajim.connections[name]
|
|
|
|
if has_child:
|
|
|
|
if acc.activity.has_key('activity'):
|
|
|
|
del acc.activity['activity']
|
|
|
|
if acc.activity.has_key('subactivity'):
|
|
|
|
del acc.activity['subactivity']
|
|
|
|
if acc.activity.has_key('text'):
|
|
|
|
del acc.activity['text']
|
2008-04-18 02:26:07 +02:00
|
|
|
if activity is not None:
|
2007-12-13 21:26:13 +01:00
|
|
|
acc.activity['activity'] = activity
|
2008-04-18 02:26:07 +02:00
|
|
|
if subactivity is not None:
|
2007-12-13 21:26:13 +01:00
|
|
|
acc.activity['subactivity'] = subactivity
|
2008-04-18 02:26:07 +02:00
|
|
|
if text is not None:
|
2007-12-13 21:26:13 +01:00
|
|
|
acc.activity['text'] = text
|
|
|
|
|
|
|
|
(user, resource) = gajim.get_room_and_nick_from_fjid(jid)
|
|
|
|
contact = gajim.contacts.get_contact(name, user, resource=resource)
|
|
|
|
if not contact:
|
|
|
|
return
|
|
|
|
if has_child:
|
|
|
|
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']
|
2008-04-18 02:26:07 +02:00
|
|
|
if activity is not None:
|
2007-12-13 21:26:13 +01:00
|
|
|
contact.activity['activity'] = activity
|
2008-04-18 02:26:07 +02:00
|
|
|
if subactivity is not None:
|
2007-12-13 21:26:13 +01:00
|
|
|
contact.activity['subactivity'] = subactivity
|
2008-04-18 02:26:07 +02:00
|
|
|
if text is not None:
|
2007-12-13 21:26:13 +01:00
|
|
|
contact.activity['text'] = text
|
2007-03-31 00:52:11 +02:00
|
|
|
|
|
|
|
def user_send_mood(account, mood, message = ''):
|
2008-04-21 22:52:35 +02:00
|
|
|
if not gajim.config.get('publish_mood'):
|
2007-08-10 01:05:43 +02:00
|
|
|
return
|
2007-03-31 00:52:11 +02:00
|
|
|
item = xmpp.Node('mood', {'xmlns': xmpp.NS_MOOD})
|
2007-08-10 01:05:43 +02:00
|
|
|
if mood != '':
|
|
|
|
item.addChild(mood)
|
2007-03-31 00:52:11 +02:00
|
|
|
if message != '':
|
|
|
|
i = item.addChild('text')
|
|
|
|
i.addData(message)
|
|
|
|
|
|
|
|
gajim.connections[account].send_pb_publish('', xmpp.NS_MOOD, item, '0')
|
2007-03-31 11:09:16 +02:00
|
|
|
|
|
|
|
def user_send_activity(account, activity, subactivity = '', message = ''):
|
2008-04-21 22:52:35 +02:00
|
|
|
if not gajim.config.get('publish_activity'):
|
2007-08-10 01:05:43 +02:00
|
|
|
return
|
2007-03-31 11:09:16 +02:00
|
|
|
item = xmpp.Node('activity', {'xmlns': xmpp.NS_ACTIVITY})
|
2007-08-10 01:05:43 +02:00
|
|
|
if activity != '':
|
|
|
|
i = item.addChild(activity)
|
2007-03-31 11:09:16 +02:00
|
|
|
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):
|
2008-04-22 20:48:41 +02:00
|
|
|
if not (gajim.config.get('publish_tune') and \
|
|
|
|
gajim.connections[account].pep_supported):
|
2007-08-10 01:05:43 +02:00
|
|
|
return
|
2007-04-01 11:02:04 +02:00
|
|
|
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')
|