comparison 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
comparison
equal deleted inserted replaced
2714:57eac4fd0ec0 2715:b35c84ea73cf
554 554
555 # set to True if "ORDER BY" is already added 555 # set to True if "ORDER BY" is already added
556 order = False 556 order = False
557 557
558 if filters: 558 if filters:
559 if 'body' in filters: 559 if u'body' in filters:
560 # TODO: use REGEXP (function to be defined) instead of GLOB: https://www.sqlite.org/lang_expr.html 560 # TODO: use REGEXP (function to be defined) instead of GLOB: https://www.sqlite.org/lang_expr.html
561 query_parts.append(u"AND message LIKE ?") 561 query_parts.append(u"AND message LIKE ?")
562 values.append(u"%{}%".format(filters['body'])) 562 values.append(u"%{}%".format(filters['body']))
563 if 'search' in filters: 563 if u'search' in filters:
564 query_parts.append(u"AND (message LIKE ? OR source_res LIKE ?)") 564 query_parts.append(u"AND (message LIKE ? OR source_res LIKE ?)")
565 values.extend([u"%{}%".format(filters['search'])] * 2) 565 values.extend([u"%{}%".format(filters['search'])] * 2)
566 if 'types' in filters: 566 if u'types' in filters:
567 types = filters['types'].split() 567 types = filters['types'].split()
568 query_parts.append(u"AND type IN ({})".format(u','.join("?"*len(types)))) 568 query_parts.append(u"AND type IN ({})".format(u','.join("?"*len(types))))
569 values.extend(types) 569 values.extend(types)
570 if 'not_types' in filters: 570 if u'not_types' in filters:
571 types = filters['not_types'].split() 571 types = filters['not_types'].split()
572 query_parts.append(u"AND type NOT IN ({})".format(u','.join("?"*len(types)))) 572 query_parts.append(u"AND type NOT IN ({})".format(u','.join("?"*len(types))))
573 values.extend(types) 573 values.extend(types)
574 if 'last_stanza_id' in filters: 574 if u'last_stanza_id' in filters:
575 # this request get the last message with a "stanza_id" that we 575 # this request get the last message with a "stanza_id" that we
576 # have in history. This is mainly used to retrieve messages sent 576 # have in history. This is mainly used to retrieve messages sent
577 # while we were offline, using MAM (XEP-0313). 577 # while we were offline, using MAM (XEP-0313).
578 # It must be set after all other filters, because it contains an ORDER BY
578 if (filters[u'last_stanza_id'] is not True 579 if (filters[u'last_stanza_id'] is not True
579 or from_jid is not None or to_jid is not None
580 or limit != 1): 580 or limit != 1):
581 raise ValueError(u"Unexpected values for last_stanza_id filter") 581 raise ValueError(u"Unexpected values for last_stanza_id filter")
582 query_parts.append(u"AND stanza_id IS NOT NULL ORDER BY history.rowid DESC") 582 query_parts.append(u"AND stanza_id IS NOT NULL ORDER BY history.rowid DESC")
583 order = True 583 order = True
584
584 585
585 if not order: 586 if not order:
586 query_parts.append(u"ORDER BY timestamp DESC") # we reverse the order in sqliteHistoryToList 587 query_parts.append(u"ORDER BY timestamp DESC") # we reverse the order in sqliteHistoryToList
587 # we use DESC here so LIMIT keep the last messages 588 # we use DESC here so LIMIT keep the last messages
588 if limit is not None: 589 if limit is not None: