diff sat_pubsub/pgsql_storage.py @ 282:7d54ff2eeaf2

actually retrieve the MAM messages
author souliane <souliane@mailoo.org>
date Thu, 15 Jan 2015 22:00:49 +0100
parents 8a71486c3e95
children 002c59dbc23f
line wrap: on
line diff
--- a/sat_pubsub/pgsql_storage.py	Wed Jan 14 10:43:27 2015 +0100
+++ b/sat_pubsub/pgsql_storage.py	Thu Jan 15 22:00:49 2015 +0100
@@ -644,6 +644,20 @@
             if authorized_groups:
                 args.append(authorized_groups)
 
+        if 'filters' in ext_data:  # MAM filters
+            for filter_ in ext_data['filters']:
+                if filter_.var == 'start':
+                    source += " AND date>='{date}'".format(date=filter_.value)
+                if filter_.var == 'end':
+                    source += " AND date<='{date}'".format(date=filter_.value)
+                if filter_.var == 'with':
+                    jid_s = filter_.value
+                    if '/' in jid_s:
+                        source += " AND publisher='{pub}'".format(pub=filter_.value)
+                    else:  # assume the publisher field in DB is always a full JID
+                        # XXX: need to escape the % with itself to avoid formatting error
+                        source += " AND publisher LIKE '{pub}/%%'".format(pub=filter_.value)
+
         query.append(source)
         order = "DESC"