diff sat/memory/sqlite.py @ 2715:b35c84ea73cf

plugin XEP-0045: MAM implementation for MUC
author Goffi <goffi@goffi.org>
date Fri, 07 Dec 2018 19:13:28 +0100
parents 9adf44996e58
children 06160b529da6
line wrap: on
line diff
--- a/sat/memory/sqlite.py	Fri Dec 07 17:46:50 2018 +0100
+++ b/sat/memory/sqlite.py	Fri Dec 07 19:13:28 2018 +0100
@@ -556,32 +556,33 @@
         order = False
 
         if filters:
-            if 'body' in filters:
+            if u'body' in filters:
                 # TODO: use REGEXP (function to be defined) instead of GLOB: https://www.sqlite.org/lang_expr.html
                 query_parts.append(u"AND message LIKE ?")
                 values.append(u"%{}%".format(filters['body']))
-            if 'search' in filters:
+            if u'search' in filters:
                 query_parts.append(u"AND (message LIKE ? OR source_res LIKE ?)")
                 values.extend([u"%{}%".format(filters['search'])] * 2)
-            if 'types' in filters:
+            if u'types' in filters:
                 types = filters['types'].split()
                 query_parts.append(u"AND type IN ({})".format(u','.join("?"*len(types))))
                 values.extend(types)
-            if 'not_types' in filters:
+            if u'not_types' in filters:
                 types = filters['not_types'].split()
                 query_parts.append(u"AND type NOT IN ({})".format(u','.join("?"*len(types))))
                 values.extend(types)
-            if 'last_stanza_id' in filters:
+            if u'last_stanza_id' in filters:
                 # this request get the last message with a "stanza_id" that we
                 # have in history. This is mainly used to retrieve messages sent
                 # while we were offline, using MAM (XEP-0313).
+                # It must be set after all other filters, because it contains an ORDER BY
                 if (filters[u'last_stanza_id'] is not True
-                    or from_jid is not None or to_jid is not None
                     or limit != 1):
                     raise ValueError(u"Unexpected values for last_stanza_id filter")
                 query_parts.append(u"AND stanza_id IS NOT NULL ORDER BY history.rowid DESC")
                 order = True
 
+
         if not order:
             query_parts.append(u"ORDER BY timestamp DESC") # we reverse the order in sqliteHistoryToList
                                                            # we use DESC here so LIMIT keep the last messages