summary refs log tree commit diff
path: root/synapse/api
diff options
context:
space:
mode:
authorPaul "LeoNerd" Evans <paul@matrix.org>2015-01-27 16:17:56 +0000
committerPaul "LeoNerd" Evans <paul@matrix.org>2015-01-27 16:17:56 +0000
commit059651efa19a88eb0823bce1d5beff2d95cb01c2 (patch)
tree51f89ec0377a8c4ec3016938b15ba82cfb76b9c4 /synapse/api
parentInitial trivial unittest of Filtering object (diff)
downloadsynapse-059651efa19a88eb0823bce1d5beff2d95cb01c2.tar.xz
Have the Filtering API return Deferreds, so we can do the Datastore implementation nicely
Diffstat (limited to 'synapse/api')
-rw-r--r--synapse/api/filtering.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/synapse/api/filtering.py b/synapse/api/filtering.py
index 922c40004c..014e2e1fc9 100644
--- a/synapse/api/filtering.py
+++ b/synapse/api/filtering.py
@@ -13,6 +13,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+from twisted.internet import defer
+
 
 # TODO(paul)
 _filters_for_user = {}
@@ -24,18 +26,28 @@ class Filtering(object):
         super(Filtering, self).__init__()
         self.hs = hs
 
+    @defer.inlineCallbacks
     def get_user_filter(self, user_localpart, filter_id):
         filters = _filters_for_user.get(user_localpart, None)
 
         if not filters or filter_id >= len(filters):
             raise KeyError()
 
-        return filters[filter_id]
+        # trivial yield to make it a generator so d.iC works
+        yield
+        defer.returnValue(filters[filter_id])
 
+    @defer.inlineCallbacks
     def add_user_filter(self, user_localpart, definition):
         filters = _filters_for_user.setdefault(user_localpart, [])
 
         filter_id = len(filters)
         filters.append(definition)
 
-        return filter_id
+        # trivial yield, see above
+        yield
+        defer.returnValue(filter_id)
+
+    # TODO(paul): surely we should probably add a delete_user_filter or
+    #   replace_user_filter at some point? There's no REST API specified for
+    #   them however