core: added getLastResource method
This commit is contained in:
parent
dc936be42b
commit
5380b684cd
5 changed files with 40 additions and 0 deletions
|
|
@ -92,6 +92,9 @@ class DBusBridgeFrontend(BridgeFrontend):
|
|||
def getHistory(self, from_jid, to_jid, size):
|
||||
return self.db_core_iface.getHistory(from_jid, to_jid, size)
|
||||
|
||||
def getLastResource(self, contact_jid, profile_key="@DEFAULT@"):
|
||||
return unicode(self.db_core_iface.getLastResource(contact_jid, profile_key))
|
||||
|
||||
def getMenuHelp(self, category, name, menu_type):
|
||||
return unicode(self.db_core_iface.getMenuHelp(category, name, menu_type))
|
||||
|
||||
|
|
|
|||
|
|
@ -196,6 +196,12 @@ class DbusObject(dbus.service.Object):
|
|||
def getHistory(self, from_jid, to_jid, size):
|
||||
return self.cb["getHistory"](unicode(from_jid), unicode(to_jid), size)
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='ss', out_signature='s',
|
||||
async_callbacks=None)
|
||||
def getLastResource(self, contact_jid, profile_key="@DEFAULT@"):
|
||||
return self.cb["getLastResource"](unicode(contact_jid), unicode(profile_key))
|
||||
|
||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||
in_signature='sss', out_signature='s',
|
||||
async_callbacks=None)
|
||||
|
|
|
|||
|
|
@ -257,6 +257,17 @@ doc_return=array of tuples with the following values:
|
|||
- list of attributes as in [newContact]
|
||||
- groups where the contact is
|
||||
|
||||
[getLastResource]
|
||||
type=method
|
||||
category=core
|
||||
sig_in=ss
|
||||
sig_out=s
|
||||
param_1_default="@DEFAULT@"
|
||||
doc=Return the last resource connected for a contact
|
||||
doc_param_0=contact_jid: jid of the contact
|
||||
doc_param_1=%(doc_profile_key)s
|
||||
doc_return=the last resource connected of the contact, or ""
|
||||
|
||||
[getPresenceStatus]
|
||||
type=method
|
||||
category=core
|
||||
|
|
|
|||
|
|
@ -124,6 +124,7 @@ class SAT(service.Service):
|
|||
self.bridge.register("asyncConnect", self.asyncConnect)
|
||||
self.bridge.register("disconnect", self.disconnect)
|
||||
self.bridge.register("getContacts", self.memory.getContacts)
|
||||
self.bridge.register("getLastResource", self.memory.getLastResource)
|
||||
self.bridge.register("getPresenceStatus", self.memory.getPresenceStatus)
|
||||
self.bridge.register("getWaitingSub", self.memory.getWaitingSub)
|
||||
self.bridge.register("sendMessage", self.sendMessage)
|
||||
|
|
|
|||
|
|
@ -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