Make user_tune a instance method, not a function.

This commit is contained in:
Stephan Erb 2009-11-14 20:54:42 +01:00
parent 85b7b89b49
commit 7c6dc424af
1 changed files with 60 additions and 59 deletions

View File

@ -221,7 +221,66 @@ class UserMoodPEP(AbstractPEP):
namespace = common.xmpp.NS_MOOD
def __init__(self, jid, account, items):
user_mood(items, account, jid)
self.user_mood(items, account, jid)
def user_mood(self, items, name, jid):
has_child = False
retract = False
mood = None
text = None
for item in items.getTags('item'):
child = item.getTag('mood')
if child is not None:
has_child = True
for ch in child.getChildren():
if ch.getName() != 'text':
mood = ch.getName()
else:
text = ch.getData()
if items.getTag('retract') is not None:
retract = True
if jid == common.gajim.get_jid_from_account(name):
acc = common.gajim.connections[name]
if has_child:
if 'mood' in acc.mood:
del acc.mood['mood']
if 'text' in acc.mood:
del acc.mood['text']
if mood is not None:
acc.mood['mood'] = mood
if text is not None:
acc.mood['text'] = text
elif retract:
if 'mood' in acc.mood:
del acc.mood['mood']
if 'text' in acc.mood:
del acc.mood['text']
(user, resource) = common.gajim.get_room_and_nick_from_fjid(jid)
for contact in common.gajim.contacts.get_contacts(name, user):
if has_child:
if 'mood' in contact.mood:
del contact.mood['mood']
if 'text' in contact.mood:
del contact.mood['text']
if mood is not None:
contact.mood['mood'] = mood
if text is not None:
contact.mood['text'] = text
elif retract:
if 'mood' in contact.mood:
del contact.mood['mood']
if 'text' in contact.mood:
del contact.mood['text']
if jid == common.gajim.get_jid_from_account(name):
common.gajim.interface.roster.draw_account(name)
common.gajim.interface.roster.draw_mood(user, name)
ctrl = common.gajim.interface.msg_win_mgr.get_control(user, name)
if ctrl:
ctrl.update_mood()
class UserTunePEP(AbstractPEP):
@ -300,64 +359,6 @@ class ConnectionPEP:
raise common.xmpp.NodeProcessed
def user_mood(items, name, jid):
has_child = False
retract = False
mood = None
text = None
for item in items.getTags('item'):
child = item.getTag('mood')
if child is not None:
has_child = True
for ch in child.getChildren():
if ch.getName() != 'text':
mood = ch.getName()
else:
text = ch.getData()
if items.getTag('retract') is not None:
retract = True
if jid == common.gajim.get_jid_from_account(name):
acc = common.gajim.connections[name]
if has_child:
if 'mood' in acc.mood:
del acc.mood['mood']
if 'text' in acc.mood:
del acc.mood['text']
if mood is not None:
acc.mood['mood'] = mood
if text is not None:
acc.mood['text'] = text
elif retract:
if 'mood' in acc.mood:
del acc.mood['mood']
if 'text' in acc.mood:
del acc.mood['text']
(user, resource) = common.gajim.get_room_and_nick_from_fjid(jid)
for contact in common.gajim.contacts.get_contacts(name, user):
if has_child:
if 'mood' in contact.mood:
del contact.mood['mood']
if 'text' in contact.mood:
del contact.mood['text']
if mood is not None:
contact.mood['mood'] = mood
if text is not None:
contact.mood['text'] = text
elif retract:
if 'mood' in contact.mood:
del contact.mood['mood']
if 'text' in contact.mood:
del contact.mood['text']
if jid == common.gajim.get_jid_from_account(name):
common.gajim.interface.roster.draw_account(name)
common.gajim.interface.roster.draw_mood(user, name)
ctrl = common.gajim.interface.msg_win_mgr.get_control(user, name)
if ctrl:
ctrl.update_mood()
def user_tune(items, name, jid):
has_child = False
retract = False