comparison src/tools/memory.py @ 399:3ed53803b3b3

core: added getLastResource method
author Goffi <goffi@goffi.org>
date Thu, 06 Oct 2011 21:16:03 +0200
parents cb0285372818
children 62b17854254e
comparison
equal deleted inserted replaced
398:cb0285372818 399:3ed53803b3b3
417 def __init__(self, host): 417 def __init__(self, host):
418 info (_("Memory manager init")) 418 info (_("Memory manager init"))
419 self.host = host 419 self.host = host
420 self.contacts={} 420 self.contacts={}
421 self.presenceStatus={} 421 self.presenceStatus={}
422 self.lastResource={} #tmp, will be refactored with bdd integration
422 self.subscriptions={} 423 self.subscriptions={}
423 self.params=Param(host) 424 self.params=Param(host)
424 self.history={} #used to store chat history (key: short jid) 425 self.history={} #used to store chat history (key: short jid)
425 self.private={} #used to store private value 426 self.private={} #used to store private value
426 self.server_features={} #used to store discovery's informations 427 self.server_features={} #used to store discovery's informations
675 if self.contacts.has_key(profile): 676 if self.contacts.has_key(profile):
676 for contact in self.contacts[profile]: 677 for contact in self.contacts[profile]:
677 attr, groups = self.contacts[profile][contact] 678 attr, groups = self.contacts[profile][contact]
678 ret.append([contact, attr, groups ]) 679 ret.append([contact, attr, groups ])
679 return ret 680 return ret
681
682 def getLastResource(self, contact, profile_key):
683 """Return the last resource used by a contact
684 @param contact: contact jid (unicode)
685 @param profile_key: %(doc_profile_key)s"""
686 profile = self.getProfileName(profile_key)
687 if not profile:
688 error(_('Asking contacts for a non-existant profile'))
689 return ""
690 try:
691 return self.lastResource[profile][jid.JID(contact).userhost()]
692 except:
693 return ""
680 694
681 def addPresenceStatus(self, contact_jid, show, priority, statuses, profile_key): 695 def addPresenceStatus(self, contact_jid, show, priority, statuses, profile_key):
682 profile = self.getProfileName(profile_key) 696 profile = self.getProfileName(profile_key)
683 if not profile: 697 if not profile:
684 error(_('Trying to add presence status to a non-existant profile')) 698 error(_('Trying to add presence status to a non-existant profile'))
685 return 699 return
686 if not self.presenceStatus.has_key(profile): 700 if not self.presenceStatus.has_key(profile):
687 self.presenceStatus[profile] = {} 701 self.presenceStatus[profile] = {}
702 if not self.lastResource.has_key(profile):
703 self.lastResource[profile] = {}
688 if not self.presenceStatus[profile].has_key(contact_jid.userhost()): 704 if not self.presenceStatus[profile].has_key(contact_jid.userhost()):
689 self.presenceStatus[profile][contact_jid.userhost()] = {} 705 self.presenceStatus[profile][contact_jid.userhost()] = {}
690 resource = jid.parse(contact_jid.full())[2] or '' 706 resource = jid.parse(contact_jid.full())[2] or ''
707 if resource:
708 self.lastResource[profile][contact_jid.userhost()] = resource
709
691 self.presenceStatus[profile][contact_jid.userhost()][resource] = (show, priority, statuses) 710 self.presenceStatus[profile][contact_jid.userhost()][resource] = (show, priority, statuses)
692 711
693 def addWaitingSub(self, type, contact_jid, profile_key): 712 def addWaitingSub(self, type, contact_jid, profile_key):
694 """Called when a subcription request is received""" 713 """Called when a subcription request is received"""
695 profile = self.getProfileName(profile_key) 714 profile = self.getProfileName(profile_key)