plugin XEP-0045: MAM implementation for MUC

This commit is contained in:
Goffi 2018-12-07 19:13:28 +01:00
commit 35e15c664c

View file

@ -556,32 +556,33 @@ class SqliteStorage(object):
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