Move common pep constructor logic to base class.
This commit is contained in:
parent
99e718583a
commit
3d5e8cc427
|
@ -215,6 +215,13 @@ class AbstractPEP(object):
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def __init__(self, jid, account, items):
|
||||||
|
self._pep_specific_data, self._retracted = self._extract_info(items)
|
||||||
|
self.do(jid, account)
|
||||||
|
|
||||||
|
def _extract_info(self, items):
|
||||||
|
'''To be implemented by subclasses'''
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
class UserMoodPEP(AbstractPEP):
|
class UserMoodPEP(AbstractPEP):
|
||||||
'''XEP-0107: User Mood'''
|
'''XEP-0107: User Mood'''
|
||||||
|
@ -222,11 +229,6 @@ class UserMoodPEP(AbstractPEP):
|
||||||
type = 'mood'
|
type = 'mood'
|
||||||
namespace = common.xmpp.NS_MOOD
|
namespace = common.xmpp.NS_MOOD
|
||||||
|
|
||||||
def __init__(self, jid, account, items):
|
|
||||||
self._mood_dict, self._retracted = self._extract_info(items)
|
|
||||||
|
|
||||||
self.user_mood(items, account, jid)
|
|
||||||
|
|
||||||
def _extract_info(self, items):
|
def _extract_info(self, items):
|
||||||
mood_dict = {}
|
mood_dict = {}
|
||||||
|
|
||||||
|
@ -242,9 +244,8 @@ class UserMoodPEP(AbstractPEP):
|
||||||
retracted = items.getTag('retract') or not mood_dict
|
retracted = items.getTag('retract') or not mood_dict
|
||||||
return (mood_dict, retracted)
|
return (mood_dict, retracted)
|
||||||
|
|
||||||
def user_mood(self, items, name, jid):
|
def do(self, jid, name):
|
||||||
|
mood_dict = {} if self._retracted else self._pep_specific_data
|
||||||
mood_dict = {} if self._retracted else self._mood_dict
|
|
||||||
|
|
||||||
if jid == common.gajim.get_jid_from_account(name):
|
if jid == common.gajim.get_jid_from_account(name):
|
||||||
acc = common.gajim.connections[name]
|
acc = common.gajim.connections[name]
|
||||||
|
@ -268,11 +269,6 @@ class UserTunePEP(AbstractPEP):
|
||||||
type = 'tune'
|
type = 'tune'
|
||||||
namespace = common.xmpp.NS_TUNE
|
namespace = common.xmpp.NS_TUNE
|
||||||
|
|
||||||
def __init__(self, jid, account, items):
|
|
||||||
self._tune_dict, self._retracted = self._extract_info(items)
|
|
||||||
|
|
||||||
self.user_tune(items, account, jid)
|
|
||||||
|
|
||||||
def _extract_info(self, items):
|
def _extract_info(self, items):
|
||||||
tune_dict = {}
|
tune_dict = {}
|
||||||
|
|
||||||
|
@ -287,8 +283,8 @@ class UserTunePEP(AbstractPEP):
|
||||||
return (tune_dict, retracted)
|
return (tune_dict, retracted)
|
||||||
|
|
||||||
|
|
||||||
def user_tune(self, items, name, jid):
|
def do(self, jid, name):
|
||||||
tune_dict = {} if self._retracted else self._tune_dict
|
tune_dict = {} if self._retracted else self._pep_specific_data
|
||||||
|
|
||||||
if jid == common.gajim.get_jid_from_account(name):
|
if jid == common.gajim.get_jid_from_account(name):
|
||||||
acc = common.gajim.connections[name]
|
acc = common.gajim.connections[name]
|
||||||
|
@ -312,18 +308,13 @@ class UserActivityPEP(AbstractPEP):
|
||||||
type = 'activity'
|
type = 'activity'
|
||||||
namespace = common.xmpp.NS_ACTIVITY
|
namespace = common.xmpp.NS_ACTIVITY
|
||||||
|
|
||||||
def __init__(self, jid, account, items):
|
|
||||||
self._activity_dict, self._retracted = self._extract_info(items)
|
|
||||||
|
|
||||||
self.user_activity(items, account, jid)
|
|
||||||
|
|
||||||
def _extract_info(self, items):
|
def _extract_info(self, items):
|
||||||
activity_dict = {}
|
activity_dict = {}
|
||||||
|
|
||||||
for item in items.getTags('item'):
|
for item in items.getTags('item'):
|
||||||
activity_tag = item.getTag('activity')
|
activity_tag = item.getTag('activity')
|
||||||
if activity_tag:
|
if activity_tag:
|
||||||
for child in child.getChildren():
|
for child in activity_tag.getChildren():
|
||||||
if child.getName() == 'text':
|
if child.getName() == 'text':
|
||||||
activity_dict['text'] = child.getData()
|
activity_dict['text'] = child.getData()
|
||||||
elif child.getName() in ACTIVITIES:
|
elif child.getName() in ACTIVITIES:
|
||||||
|
@ -335,8 +326,8 @@ class UserActivityPEP(AbstractPEP):
|
||||||
retracted = items.getTag('retract') or not activity_dict
|
retracted = items.getTag('retract') or not activity_dict
|
||||||
return (activity_dict, retracted)
|
return (activity_dict, retracted)
|
||||||
|
|
||||||
def user_activity(self, items, name, jid):
|
def do(self, jid, name):
|
||||||
activity_dict = {} if self._retracted else self._activity_dict
|
activity_dict = {} if self._retracted else self._pep_specific_data
|
||||||
|
|
||||||
if jid == common.gajim.get_jid_from_account(name):
|
if jid == common.gajim.get_jid_from_account(name):
|
||||||
acc = common.gajim.connections[name]
|
acc = common.gajim.connections[name]
|
||||||
|
@ -360,10 +351,6 @@ class UserNicknamePEP(AbstractPEP):
|
||||||
type = 'activity'
|
type = 'activity'
|
||||||
namespace = common.xmpp.NS_NICK
|
namespace = common.xmpp.NS_NICK
|
||||||
|
|
||||||
def __init__(self, jid, account, items):
|
|
||||||
self._nick, self._retracted = self._extract_info(items)
|
|
||||||
self.user_nickname(items, account, jid)
|
|
||||||
|
|
||||||
def _extract_info(self, items):
|
def _extract_info(self, items):
|
||||||
nick = ''
|
nick = ''
|
||||||
for item in items.getTags('item'):
|
for item in items.getTags('item'):
|
||||||
|
@ -375,15 +362,15 @@ class UserNicknamePEP(AbstractPEP):
|
||||||
retracted = items.getTag('retract') or not nick
|
retracted = items.getTag('retract') or not nick
|
||||||
return (nick, retracted)
|
return (nick, retracted)
|
||||||
|
|
||||||
def user_nickname(self, items, name, jid):
|
def do(self, jid, name):
|
||||||
if jid == common.gajim.get_jid_from_account(name):
|
if jid == common.gajim.get_jid_from_account(name):
|
||||||
if self._retracted:
|
if self._retracted:
|
||||||
common.gajim.nicks[name] = common.gajim.config.get_per('accounts',
|
common.gajim.nicks[name] = common.gajim.config.get_per('accounts',
|
||||||
name, 'name')
|
name, 'name')
|
||||||
else:
|
else:
|
||||||
common.gajim.nicks[name] = self._nick
|
common.gajim.nicks[name] = self._pep_specific_data
|
||||||
|
|
||||||
nick = '' if self._retracted else self._nick
|
nick = '' if self._retracted else self._pep_specific_data
|
||||||
|
|
||||||
user = common.gajim.get_room_and_nick_from_fjid(jid)[0]
|
user = common.gajim.get_room_and_nick_from_fjid(jid)[0]
|
||||||
for contact in common.gajim.contacts.get_contacts(name, user):
|
for contact in common.gajim.contacts.get_contacts(name, user):
|
||||||
|
|
Loading…
Reference in New Issue