diff options
author | Paul "LeoNerd" Evans <paul@matrix.org> | 2015-01-27 14:28:56 +0000 |
---|---|---|
committer | Paul "LeoNerd" Evans <paul@matrix.org> | 2015-01-27 14:28:56 +0000 |
commit | 05c7cba73a050f19cc52129b65b0183eaa832a42 (patch) | |
tree | e0ad0e2a239a409a11fcc987802408683ec5bd55 /synapse/api | |
parent | Use new V2AlphaRestTestCase (diff) | |
download | synapse-05c7cba73a050f19cc52129b65b0183eaa832a42.tar.xz |
Initial trivial implementation of an actual 'Filtering' object; move storage of user filters into there
Diffstat (limited to 'synapse/api')
-rw-r--r-- | synapse/api/filtering.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/synapse/api/filtering.py b/synapse/api/filtering.py new file mode 100644 index 0000000000..922c40004c --- /dev/null +++ b/synapse/api/filtering.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +# Copyright 2015 OpenMarket Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. + + +# TODO(paul) +_filters_for_user = {} + + +class Filtering(object): + + def __init__(self, hs): + super(Filtering, self).__init__() + self.hs = hs + + 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] + + 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 |