# HG changeset patch
# User Goffi <goffi@goffi.org>
# Date 1575583086 -3600
# Node ID f8cc88c773c82e13acfd9008d3a3caa7f9eb23e1
# Parent  95c94d94872d7af64e02f71c301f8e78322c9f67
core (memory/sqlite): added `before_uid` filter to retrieve history before a message UID

diff -r 95c94d94872d -r f8cc88c773c8 sat/bridge/bridge_constructor/bridge_template.ini
--- a/sat/bridge/bridge_constructor/bridge_template.ini	Mon Nov 18 22:34:13 2019 +0100
+++ b/sat/bridge/bridge_constructor/bridge_template.ini	Thu Dec 05 22:58:06 2019 +0100
@@ -655,6 +655,7 @@
     - search: pattern must be in message body or source resource
     - types: type must be one of those, values are separated by spaces
     - not_types: type must not be one of those, values are separated by spaces
+    - before_uid: check only message received before message with given uid
 doc_param_5=%(doc_profile)s
 doc_return=Ordered list (by timestamp) of data as in [messageNew] (without final profile)
 
diff -r 95c94d94872d -r f8cc88c773c8 sat/memory/sqlite.py
--- a/sat/memory/sqlite.py	Mon Nov 18 22:34:13 2019 +0100
+++ b/sat/memory/sqlite.py	Thu Dec 05 22:58:06 2019 +0100
@@ -625,6 +625,9 @@
             if 'timestamp_start' in filters:
                 query_parts.append("AND timestamp>= ?")
                 values.append(float(filters['timestamp_start']))
+            if 'before_uid' in filters:
+                query_parts.append("AND history.rowid<(select rowid from history where uid=?)")
+                values.append(filters['before_uid'])
             if 'body' in filters:
                 # TODO: use REGEXP (function to be defined) instead of GLOB: https://www.sqlite.org/lang_expr.html
                 query_parts.append("AND message LIKE ?")