summary refs log tree commit diff
path: root/synapse/api
diff options
context:
space:
mode:
authorKegan Dougal <kegan@matrix.org>2015-01-29 12:20:59 +0000
committerKegan Dougal <kegan@matrix.org>2015-01-29 12:20:59 +0000
commit83172487b05d7d99ccae0b353daee2f242445011 (patch)
tree45d234afe8aa2420b854a7ce878f27a56b66da2c /synapse/api
parentAdd more unit tests for the filter algorithm. (diff)
downloadsynapse-83172487b05d7d99ccae0b353daee2f242445011.tar.xz
Add basic filtering public API unit tests. Use defers in the right places.
Diffstat (limited to 'synapse/api')
-rw-r--r--synapse/api/filtering.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/synapse/api/filtering.py b/synapse/api/filtering.py
index 8bc95aa394..7e239138b7 100644
--- a/synapse/api/filtering.py
+++ b/synapse/api/filtering.py
@@ -12,6 +12,7 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
+from twisted.internet import defer
 
 from synapse.api.errors import SynapseError
 from synapse.types import UserID, RoomID
@@ -59,19 +60,21 @@ class Filtering(object):
     #   replace_user_filter at some point? There's no REST API specified for
     #   them however
 
+    @defer.inlineCallbacks
     def _filter_on_key(self, events, user, filter_id, keys):
-        filter_json = self.get_user_filter(user.localpart, filter_id)
+        filter_json = yield self.get_user_filter(user.localpart, filter_id)
         if not filter_json:
-            return events
+            defer.returnValue(events)
 
         try:
             # extract the right definition from the filter
             definition = filter_json
             for key in keys:
                 definition = definition[key]
-            return self._filter_with_definition(events, definition)
+            defer.returnValue(self._filter_with_definition(events, definition))
         except KeyError:
-            return events  # return all events if definition isn't specified.
+            # return all events if definition isn't specified.
+            defer.returnValue(events)  
 
     def _filter_with_definition(self, events, definition):
         return [e for e in events if self._passes_definition(definition, e)]