Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Matrix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Operate
Environments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Matrix
Commits
059651ef
Commit
059651ef
authored
10 years ago
by
Paul "LeoNerd" Evans
Browse files
Options
Downloads
Patches
Plain Diff
Have the Filtering API return Deferreds, so we can do the Datastore implementation nicely
parent
b1503112
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
synapse/api/filtering.py
+14
-2
14 additions, 2 deletions
synapse/api/filtering.py
synapse/rest/client/v2_alpha/filter.py
+5
-3
5 additions, 3 deletions
synapse/rest/client/v2_alpha/filter.py
tests/api/test_filtering.py
+3
-2
3 additions, 2 deletions
tests/api/test_filtering.py
with
22 additions
and
7 deletions
synapse/api/filtering.py
+
14
−
2
View file @
059651ef
...
...
@@ -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
This diff is collapsed.
Click to expand it.
synapse/rest/client/v2_alpha/filter.py
+
5
−
3
View file @
059651ef
...
...
@@ -54,10 +54,12 @@ class GetFilterRestServlet(RestServlet):
raise
SynapseError
(
400
,
"
Invalid filter_id
"
)
try
:
defer
.
returnValue
((
200
,
self
.
filtering
.
get_user_filter
(
filter
=
yield
self
.
filtering
.
get_user_filter
(
user_localpart
=
target_user
.
localpart
,
filter_id
=
filter_id
,
)))
)
defer
.
returnValue
((
200
,
filter
))
except
KeyError
:
raise
SynapseError
(
400
,
"
No such filter
"
)
...
...
@@ -89,7 +91,7 @@ class CreateFilterRestServlet(RestServlet):
except
:
raise
SynapseError
(
400
,
"
Invalid filter definition
"
)
filter_id
=
self
.
filtering
.
add_user_filter
(
filter_id
=
yield
self
.
filtering
.
add_user_filter
(
user_localpart
=
target_user
.
localpart
,
definition
=
content
,
)
...
...
This diff is collapsed.
Click to expand it.
tests/api/test_filtering.py
+
3
−
2
View file @
059651ef
...
...
@@ -53,14 +53,15 @@ class FilteringTestCase(unittest.TestCase):
self
.
filtering
=
hs
.
get_filtering
()
@defer.inlineCallbacks
def
test_filter
(
self
):
filter_id
=
self
.
filtering
.
add_user_filter
(
filter_id
=
yield
self
.
filtering
.
add_user_filter
(
user_localpart
=
user_localpart
,
definition
=
{
"
type
"
:
[
"
m.*
"
]},
)
self
.
assertEquals
(
filter_id
,
0
)
filter
=
self
.
filtering
.
get_user_filter
(
filter
=
yield
self
.
filtering
.
get_user_filter
(
user_localpart
=
user_localpart
,
filter_id
=
filter_id
,
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment