core: added getLastResource method
This commit is contained in:
parent
dc936be42b
commit
5380b684cd
1 changed files with 40 additions and 0 deletions
|
|
@ -419,6 +419,7 @@ class Memory:
|
|||
self.host = host
|
||||
self.contacts={}
|
||||
self.presenceStatus={}
|
||||
self.lastResource={} #tmp, will be refactored with bdd integration
|
||||
self.subscriptions={}
|
||||
self.params=Param(host)
|
||||
self.history={} #used to store chat history (key: short jid)
|
||||
|
|
@ -677,6 +678,19 @@ class Memory:
|
|||
attr, groups = self.contacts[profile][contact]
|
||||
ret.append([contact, attr, groups ])
|
||||
return ret
|
||||
|
||||
def getLastResource(self, contact, profile_key):
|
||||
"""Return the last resource used by a contact
|
||||
@param contact: contact jid (unicode)
|
||||
@param profile_key: %(doc_profile_key)s"""
|
||||
profile = self.getProfileName(profile_key)
|
||||
if not profile:
|
||||
error(_('Asking contacts for a non-existant profile'))
|
||||
return ""
|
||||
try:
|
||||
return self.lastResource[profile][jid.JID(contact).userhost()]
|
||||
except:
|
||||
return ""
|
||||
|
||||
def addPresenceStatus(self, contact_jid, show, priority, statuses, profile_key):
|
||||
profile = self.getProfileName(profile_key)
|
||||
|
|
@ -685,9 +699,14 @@ class Memory:
|
|||
return
|
||||
if not self.presenceStatus.has_key(profile):
|
||||
self.presenceStatus[profile] = {}
|
||||
if not self.lastResource.has_key(profile):
|
||||
self.lastResource[profile] = {}
|
||||
if not self.presenceStatus[profile].has_key(contact_jid.userhost()):
|
||||
self.presenceStatus[profile][contact_jid.userhost()] = {}
|
||||
resource = jid.parse(contact_jid.full())[2] or ''
|
||||
if resource:
|
||||
self.lastResource[profile][contact_jid.userhost()] = resource
|
||||
|
||||
self.presenceStatus[profile][contact_jid.userhost()][resource] = (show, priority, statuses)
|
||||
|
||||
def addWaitingSub(self, type, contact_jid, profile_key):
|
||||
|
|
|
|||
Loading…
Reference in a new issue