core: improved roster management + misc:

- updated methods to no use anymore methods deprecated in Wokkel
    - use of full jid when it make sense instead of bare jid
    - getContacts, updateContact and delContact are now asynchronous
This commit is contained in:
Goffi 2014-12-10 18:32:33 +01:00
commit 6e144c6458

View file

@ -331,12 +331,15 @@ class SAT(service.Service):
def getContacts(self, profile_key):
client = self.getClient(profile_key)
ret = []
for item in client.roster.getItems(): # we get all items for client's roster
# and convert them to expected format
attr = client.roster.getAttributes(item)
ret.append([item.jid.userhost(), attr, item.groups])
return ret
def got_roster(dummy):
ret = []
for item in client.roster.getItems(): # we get all items for client's roster
# and convert them to expected format
attr = client.roster.getAttributes(item)
ret.append([item.jid.userhost(), attr, item.groups])
return ret
return client.roster.got_roster.addCallback(got_roster)
def getContactsFromGroup(self, group, profile_key):
client = self.getClient(profile_key)
@ -456,7 +459,7 @@ class SAT(service.Service):
def sendMessage(self, to_jid, msg, subject=None, mess_type='auto', extra={}, no_trigger=False, profile_key=C.PROF_KEY_NONE):
#FIXME: check validity of recipient
profile = self.memory.getProfileName(profile_key)
assert(profile)
assert profile
client = self.profiles[profile]
if extra is None:
extra = {}
@ -572,7 +575,7 @@ class SAT(service.Service):
if statuses is None:
statuses = {}
profile = self.memory.getProfileName(profile_key)
assert(profile)
assert profile
priority = int(self.memory.getParamA("Priority", "Connection", profile_key=profile))
self.profiles[profile].presence.available(to_jid, show, statuses, priority)
#XXX: FIXME: temporary fix to work around openfire 3.7.0 bug (presence is not broadcasted to generating resource)
@ -588,7 +591,7 @@ class SAT(service.Service):
@param raw_jid: unicode entity's jid
@param profile_key: profile"""
profile = self.memory.getProfileName(profile_key)
assert(profile)
assert profile
to_jid = jid.JID(raw_jid)
log.debug(_('subsciption request [%(subs_type)s] for %(jid)s') % {'subs_type': subs_type, 'jid': to_jid.full()})
if subs_type == "subscribe":
@ -606,8 +609,8 @@ class SAT(service.Service):
def addContact(self, to_jid, profile_key):
"""Add a contact in roster list"""
profile = self.memory.getProfileName(profile_key)
assert(profile)
#self.profiles[profile].roster.addItem(to_jid) #XXX: disabled (cf http://wokkel.ik.nu/ticket/56))
assert profile
# presence is sufficient, as a roster push will be sent according to RFC 6121 §3.1.2
self.profiles[profile].presence.subscribe(to_jid)
def _updateContact(self, to_jid_s, name, groups, profile_key):
@ -616,12 +619,12 @@ class SAT(service.Service):
def updateContact(self, to_jid, name, groups, profile_key):
"""update a contact in roster list"""
profile = self.memory.getProfileName(profile_key)
assert(profile)
assert profile
groups = set(groups)
roster_item = RosterItem(to_jid)
roster_item.name = name or None
roster_item.groups = set(groups)
self.profiles[profile].roster.updateItem(roster_item)
return self.profiles[profile].roster.setItem(roster_item)
def _delContact(self, to_jid_s, profile_key):
return self.delContact(jid.JID(to_jid_s), profile_key)
@ -629,10 +632,16 @@ class SAT(service.Service):
def delContact(self, to_jid, profile_key):
"""Remove contact from roster list"""
profile = self.memory.getProfileName(profile_key)
assert(profile)
self.profiles[profile].roster.removeItem(to_jid)
self.profiles[profile].presence.unsubscribe(to_jid)
assert profile
d1 = self.profiles[profile].roster.removeItem(to_jid)
d2 = self.profiles[profile].presence.unsubscribe(to_jid)
d_list = defer.DefferedList([d1, d2])
def check_result(list_result):
for success, value in list_result:
if not success:
raise value
d_list.addCallback(check_result)
return d_list
## Discovery ##
# discovery methods are shortcuts to self.memory.disco
@ -770,6 +779,9 @@ class SAT(service.Service):
@profile_key: %(doc_profile_key)s
@return: a deferred which fire a dict where key can be:
- xmlui: a XMLUI need to be displayed
- validated: if present, can be used to launch a callback, it can have the values
- C.BOOL_TRUE
- C.BOOL_FALSE
"""
profile = self.memory.getProfileName(profile_key)
if not profile: