bridge, memory: add "search" attribute to getHistory (filter the results with a unix globbing pattern)

This commit is contained in:
souliane 2014-10-04 10:25:32 +02:00
commit 767f3d50dc
6 changed files with 22 additions and 13 deletions

View file

@ -164,8 +164,8 @@ class DBusBridgeFrontend(BridgeFrontend):
def getEntityData(self, jid, keys, profile):
return self.db_core_iface.getEntityData(jid, keys, profile)
def getHistory(self, from_jid, to_jid, limit, between=True, profile="@NONE@", callback=None, errback=None):
return self.db_core_iface.getHistory(from_jid, to_jid, limit, between, profile, timeout=const_TIMEOUT, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err)))
def getHistory(self, from_jid, to_jid, limit, between=True, search='', profile="@NONE@", callback=None, errback=None):
return self.db_core_iface.getHistory(from_jid, to_jid, limit, between, search, profile, timeout=const_TIMEOUT, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err)))
def getLastResource(self, contact_jid, profile_key="@DEFAULT@"):
return unicode(self.db_core_iface.getLastResource(contact_jid, profile_key))

View file

@ -100,9 +100,10 @@ class QuickChat(object):
"""Refresh or scroll down the focus after the history is printed"""
pass
def historyPrint(self, size=C.HISTORY_LIMIT_DEFAULT, profile='@NONE@'):
def historyPrint(self, size=C.HISTORY_LIMIT_DEFAULT, search='', profile='@NONE@'):
"""Print the current history
@param size (int): number of messages
@param search (str): pattern to filter the history results
@param profile (str): %(doc_profile)s
"""
log.debug(_("now we print the history (%d messages)") % size)
@ -124,7 +125,7 @@ class QuickChat(object):
else:
target = self.target.bare
return self.host.bridge.getHistory(self.host.profiles[profile]['whoami'].bare, target, size, profile=profile, callback=onHistory, errback=onHistoryError)
return self.host.bridge.getHistory(self.host.profiles[profile]['whoami'].bare, target, size, search=search, profile=profile, callback=onHistory, errback=onHistoryError)
def _get_nick(self, jid):
"""Return nick of this jid when possible"""

View file

@ -277,10 +277,10 @@ class DbusObject(dbus.service.Object):
return self._callback("getEntityData", unicode(jid), keys, unicode(profile))
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
in_signature='ssibs', out_signature='a(dssssa{ss})',
in_signature='ssibss', out_signature='a(dssssa{ss})',
async_callbacks=('callback', 'errback'))
def getHistory(self, from_jid, to_jid, limit, between=True, profile="@NONE@", callback=None, errback=None):
return self._callback("getHistory", unicode(from_jid), unicode(to_jid), limit, between, unicode(profile), callback=callback, errback=errback)
def getHistory(self, from_jid, to_jid, limit, between=True, search='', profile="@NONE@", callback=None, errback=None):
return self._callback("getHistory", unicode(from_jid), unicode(to_jid), limit, between, unicode(search), unicode(profile), callback=callback, errback=errback)
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
in_signature='ss', out_signature='s',

View file

@ -483,16 +483,18 @@ doc_param_2=app: name of the frontend registering the parameters
async=
type=method
category=core
sig_in=ssibs
sig_in=ssibss
sig_out=a(dssssa{ss})
param_3_default=True
param_4_default="@NONE@"
param_4_default=''
param_5_default="@NONE@"
doc=Get history of a communication between two entities
doc_param_0=from_jid: source JID (bare jid for catch all, full jid else)
doc_param_1=to_jid: dest JID (bare jid for catch all, full jid else)
doc_param_2=limit: max number of history elements to get (0 for the whole history)
doc_param_3=between: True if we want history between the two jids (in both direction), False if we only want messages from from_jid to to_jid
doc_param_4=%(doc_profile)s
doc_param_4=search: pattern to filter the history results
doc_param_5=%(doc_profile)s
doc_return=Ordered list (by timestamp) of tuples (timestamp, full from_jid, full to_jid, message, type, extra)
[addContact]

View file

@ -350,7 +350,7 @@ class Memory(object):
extra = {}
return self.storage.addToHistory(from_jid, to_jid, message, type_, extra, timestamp, profile)
def getHistory(self, from_jid, to_jid, limit=C.HISTORY_LIMIT_NONE, between=True, profile=C.PROF_KEY_NONE):
def getHistory(self, from_jid, to_jid, limit=C.HISTORY_LIMIT_NONE, between=True, search=None, profile=C.PROF_KEY_NONE):
"""Retrieve messages in history
@param from_jid (JID): source JID (full, or bare for catchall)
@param to_jid (JID): dest JID (full, or bare for catchall)
@ -359,6 +359,7 @@ class Memory(object):
- C.HISTORY_LIMIT_NONE or None for unlimited
- C.HISTORY_LIMIT_DEFAULT to use the HISTORY_LIMIT parameter value
@param between (bool): confound source and dest (ignore the direction)
@param search (str): pattern to filter the history results
@param profile (str): %(doc_profile)s
@return: list of tuple as in http://wiki.goffi.org/wiki/Bridge_API#getHistory
"""
@ -369,7 +370,7 @@ class Memory(object):
limit = None
if limit == 0:
return defer.succeed([])
return self.storage.getHistory(jid.JID(from_jid), jid.JID(to_jid), limit, between, profile)
return self.storage.getHistory(jid.JID(from_jid), jid.JID(to_jid), limit, between, search, profile)
def _getLastResource(self, jid_s, profile_key):
jid_ = jid.JID(jid_s)

View file

@ -264,7 +264,7 @@ class SqliteStorage(object):
{"from_jid": from_jid.full(), "to_jid": to_jid.full(), "message": message})))
return d
def getHistory(self, from_jid, to_jid, limit=None, between=True, profile=None):
def getHistory(self, from_jid, to_jid, limit=None, between=True, search=None, profile=None):
"""Retrieve messages in history
@param from_jid (JID): source JID (full, or bare for catchall)
@param to_jid (JID): dest JID (full, or bare for catchall)
@ -272,6 +272,7 @@ class SqliteStorage(object):
- 0 for no message (returns the empty list)
- None for unlimited
@param between (bool): confound source and dest (ignore the direction)
@param search (str): pattern to filter the history results
@param profile (str): %(doc_profile)s
@return: list of tuple as in http://wiki.goffi.org/wiki/Bridge_API#getHistory
"""
@ -311,6 +312,10 @@ class SqliteStorage(object):
else:
query_parts.append("%s AND %s" % (test_jid('source', from_jid),
test_jid('dest', to_jid)))
if search:
# TODO: use REGEXP (function to be defined) instead of GLOB: https://www.sqlite.org/lang_expr.html
query_parts.append("AND message GLOB ?")
values.append("*%s*" % search)
query_parts.append("ORDER BY timestamp DESC")