bridge, memory: add "search" attribute to getHistory (filter the results with a unix globbing pattern)
This commit is contained in:
parent
7a344fcf5d
commit
767f3d50dc
6 changed files with 22 additions and 13 deletions
|
|
@ -164,8 +164,8 @@ class DBusBridgeFrontend(BridgeFrontend):
|
||||||
def getEntityData(self, jid, keys, profile):
|
def getEntityData(self, jid, keys, profile):
|
||||||
return self.db_core_iface.getEntityData(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):
|
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, profile, timeout=const_TIMEOUT, reply_handler=callback, error_handler=lambda err:errback(dbus_to_bridge_exception(err)))
|
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@"):
|
def getLastResource(self, contact_jid, profile_key="@DEFAULT@"):
|
||||||
return unicode(self.db_core_iface.getLastResource(contact_jid, profile_key))
|
return unicode(self.db_core_iface.getLastResource(contact_jid, profile_key))
|
||||||
|
|
|
||||||
|
|
@ -100,9 +100,10 @@ class QuickChat(object):
|
||||||
"""Refresh or scroll down the focus after the history is printed"""
|
"""Refresh or scroll down the focus after the history is printed"""
|
||||||
pass
|
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
|
"""Print the current history
|
||||||
@param size (int): number of messages
|
@param size (int): number of messages
|
||||||
|
@param search (str): pattern to filter the history results
|
||||||
@param profile (str): %(doc_profile)s
|
@param profile (str): %(doc_profile)s
|
||||||
"""
|
"""
|
||||||
log.debug(_("now we print the history (%d messages)") % size)
|
log.debug(_("now we print the history (%d messages)") % size)
|
||||||
|
|
@ -124,7 +125,7 @@ class QuickChat(object):
|
||||||
else:
|
else:
|
||||||
target = self.target.bare
|
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):
|
def _get_nick(self, jid):
|
||||||
"""Return nick of this jid when possible"""
|
"""Return nick of this jid when possible"""
|
||||||
|
|
|
||||||
|
|
@ -277,10 +277,10 @@ class DbusObject(dbus.service.Object):
|
||||||
return self._callback("getEntityData", unicode(jid), keys, unicode(profile))
|
return self._callback("getEntityData", unicode(jid), keys, unicode(profile))
|
||||||
|
|
||||||
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
@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'))
|
async_callbacks=('callback', 'errback'))
|
||||||
def getHistory(self, from_jid, to_jid, limit, between=True, profile="@NONE@", callback=None, errback=None):
|
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(profile), callback=callback, errback=errback)
|
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,
|
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
|
||||||
in_signature='ss', out_signature='s',
|
in_signature='ss', out_signature='s',
|
||||||
|
|
|
||||||
|
|
@ -483,16 +483,18 @@ doc_param_2=app: name of the frontend registering the parameters
|
||||||
async=
|
async=
|
||||||
type=method
|
type=method
|
||||||
category=core
|
category=core
|
||||||
sig_in=ssibs
|
sig_in=ssibss
|
||||||
sig_out=a(dssssa{ss})
|
sig_out=a(dssssa{ss})
|
||||||
param_3_default=True
|
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=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_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_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_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_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)
|
doc_return=Ordered list (by timestamp) of tuples (timestamp, full from_jid, full to_jid, message, type, extra)
|
||||||
|
|
||||||
[addContact]
|
[addContact]
|
||||||
|
|
|
||||||
|
|
@ -350,7 +350,7 @@ class Memory(object):
|
||||||
extra = {}
|
extra = {}
|
||||||
return self.storage.addToHistory(from_jid, to_jid, message, type_, extra, timestamp, profile)
|
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
|
"""Retrieve messages in history
|
||||||
@param from_jid (JID): source JID (full, or bare for catchall)
|
@param from_jid (JID): source JID (full, or bare for catchall)
|
||||||
@param to_jid (JID): dest 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_NONE or None for unlimited
|
||||||
- C.HISTORY_LIMIT_DEFAULT to use the HISTORY_LIMIT parameter value
|
- C.HISTORY_LIMIT_DEFAULT to use the HISTORY_LIMIT parameter value
|
||||||
@param between (bool): confound source and dest (ignore the direction)
|
@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
|
@param profile (str): %(doc_profile)s
|
||||||
@return: list of tuple as in http://wiki.goffi.org/wiki/Bridge_API#getHistory
|
@return: list of tuple as in http://wiki.goffi.org/wiki/Bridge_API#getHistory
|
||||||
"""
|
"""
|
||||||
|
|
@ -369,7 +370,7 @@ class Memory(object):
|
||||||
limit = None
|
limit = None
|
||||||
if limit == 0:
|
if limit == 0:
|
||||||
return defer.succeed([])
|
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):
|
def _getLastResource(self, jid_s, profile_key):
|
||||||
jid_ = jid.JID(jid_s)
|
jid_ = jid.JID(jid_s)
|
||||||
|
|
|
||||||
|
|
@ -264,7 +264,7 @@ class SqliteStorage(object):
|
||||||
{"from_jid": from_jid.full(), "to_jid": to_jid.full(), "message": message})))
|
{"from_jid": from_jid.full(), "to_jid": to_jid.full(), "message": message})))
|
||||||
return d
|
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
|
"""Retrieve messages in history
|
||||||
@param from_jid (JID): source JID (full, or bare for catchall)
|
@param from_jid (JID): source JID (full, or bare for catchall)
|
||||||
@param to_jid (JID): dest 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)
|
- 0 for no message (returns the empty list)
|
||||||
- None for unlimited
|
- None for unlimited
|
||||||
@param between (bool): confound source and dest (ignore the direction)
|
@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
|
@param profile (str): %(doc_profile)s
|
||||||
@return: list of tuple as in http://wiki.goffi.org/wiki/Bridge_API#getHistory
|
@return: list of tuple as in http://wiki.goffi.org/wiki/Bridge_API#getHistory
|
||||||
"""
|
"""
|
||||||
|
|
@ -311,6 +312,10 @@ class SqliteStorage(object):
|
||||||
else:
|
else:
|
||||||
query_parts.append("%s AND %s" % (test_jid('source', from_jid),
|
query_parts.append("%s AND %s" % (test_jid('source', from_jid),
|
||||||
test_jid('dest', to_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")
|
query_parts.append("ORDER BY timestamp DESC")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue