Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Timo Ley
synapse
Commits
4006d583
Commit
4006d583
authored
10 years ago
by
Paul "LeoNerd" Evans
Browse files
Options
Downloads
Patches
Plain Diff
Store serial numbers per room for typing event stream purposes
parent
9eb819e8
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
synapse/handlers/typing.py
+28
-13
28 additions, 13 deletions
synapse/handlers/typing.py
tests/handlers/test_typing.py
+16
-30
16 additions, 30 deletions
tests/handlers/test_typing.py
with
44 additions
and
43 deletions
synapse/handlers/typing.py
+
28
−
13
View file @
4006d583
...
@@ -46,6 +46,12 @@ class TypingNotificationHandler(BaseHandler):
...
@@ -46,6 +46,12 @@ class TypingNotificationHandler(BaseHandler):
self
.
_member_typing_until
=
{}
# clock time we expect to stop
self
.
_member_typing_until
=
{}
# clock time we expect to stop
self
.
_member_typing_timer
=
{}
# deferreds to manage theabove
self
.
_member_typing_timer
=
{}
# deferreds to manage theabove
# map room IDs to serial numbers
self
.
_room_serials
=
{}
self
.
_latest_room_serial
=
0
# map room IDs to sets of users currently typing
self
.
_room_typing
=
{}
@defer.inlineCallbacks
@defer.inlineCallbacks
def
started_typing
(
self
,
target_user
,
auth_user
,
room_id
,
timeout
):
def
started_typing
(
self
,
target_user
,
auth_user
,
room_id
,
timeout
):
if
not
target_user
.
is_mine
:
if
not
target_user
.
is_mine
:
...
@@ -117,12 +123,11 @@ class TypingNotificationHandler(BaseHandler):
...
@@ -117,12 +123,11 @@ class TypingNotificationHandler(BaseHandler):
ignore_user
=
user
ignore_user
=
user
)
)
f
or
u
in
localusers
:
i
f
localusers
:
self
.
push_update_
to_clients
(
self
.
_
push_update_
local
(
room_id
=
room_id
,
room_id
=
room_id
,
observer_user
=
u
,
user
=
user
,
observed_user
=
user
,
typing
=
typing
typing
=
typing
,
)
)
deferreds
=
[]
deferreds
=
[]
...
@@ -151,18 +156,28 @@ class TypingNotificationHandler(BaseHandler):
...
@@ -151,18 +156,28 @@ class TypingNotificationHandler(BaseHandler):
room_id
,
localusers
=
localusers
room_id
,
localusers
=
localusers
)
)
f
or
u
in
localusers
:
i
f
localusers
:
self
.
push_update_
to_clients
(
self
.
_
push_update_
local
(
room_id
=
room_id
,
room_id
=
room_id
,
observer_user
=
u
,
user
=
user
,
observed_user
=
user
,
typing
=
content
[
"
typing
"
]
typing
=
content
[
"
typing
"
]
)
)
def
push_update_to_clients
(
self
,
room_id
,
observer_user
,
observed_user
,
def
_push_update_local
(
self
,
room_id
,
user
,
typing
):
typing
):
if
room_id
not
in
self
.
_room_serials
:
# TODO(paul) steal this from presence.py
self
.
_room_serials
[
room_id
]
=
0
pass
self
.
_room_typing
[
room_id
]
=
set
()
room_set
=
self
.
_room_typing
[
room_id
]
if
typing
:
room_set
.
add
(
user
)
elif
user
in
room_set
:
room_set
.
remove
(
user
)
self
.
_latest_room_serial
+=
1
self
.
_room_serials
[
room_id
]
=
self
.
_latest_room_serial
self
.
notifier
.
on_new_user_event
(
rooms
=
[
room_id
])
class
TypingNotificationEventSource
(
object
):
class
TypingNotificationEventSource
(
object
):
...
...
This diff is collapsed.
Click to expand it.
tests/handlers/test_typing.py
+
16
−
30
View file @
4006d583
...
@@ -65,6 +65,9 @@ class TypingNotificationsTestCase(unittest.TestCase):
...
@@ -65,6 +65,9 @@ class TypingNotificationsTestCase(unittest.TestCase):
self
.
mock_config
=
Mock
()
self
.
mock_config
=
Mock
()
self
.
mock_config
.
signing_key
=
[
MockKey
()]
self
.
mock_config
.
signing_key
=
[
MockKey
()]
mock_notifier
=
Mock
(
spec
=
[
"
on_new_user_event
"
])
self
.
on_new_user_event
=
mock_notifier
.
on_new_user_event
hs
=
HomeServer
(
"
test
"
,
hs
=
HomeServer
(
"
test
"
,
clock
=
self
.
clock
,
clock
=
self
.
clock
,
db_pool
=
None
,
db_pool
=
None
,
...
@@ -77,6 +80,7 @@ class TypingNotificationsTestCase(unittest.TestCase):
...
@@ -77,6 +80,7 @@ class TypingNotificationsTestCase(unittest.TestCase):
"
get_destination_retry_timings
"
,
"
get_destination_retry_timings
"
,
]),
]),
handlers
=
None
,
handlers
=
None
,
notifier
=
mock_notifier
,
resource_for_client
=
Mock
(),
resource_for_client
=
Mock
(),
resource_for_federation
=
self
.
mock_federation_resource
,
resource_for_federation
=
self
.
mock_federation_resource
,
http_client
=
self
.
mock_http_client
,
http_client
=
self
.
mock_http_client
,
...
@@ -85,11 +89,7 @@ class TypingNotificationsTestCase(unittest.TestCase):
...
@@ -85,11 +89,7 @@ class TypingNotificationsTestCase(unittest.TestCase):
)
)
hs
.
handlers
=
JustTypingNotificationHandlers
(
hs
)
hs
.
handlers
=
JustTypingNotificationHandlers
(
hs
)
self
.
mock_update_client
=
Mock
()
self
.
mock_update_client
.
return_value
=
defer
.
succeed
(
None
)
self
.
handler
=
hs
.
get_handlers
().
typing_notification_handler
self
.
handler
=
hs
.
get_handlers
().
typing_notification_handler
self
.
handler
.
push_update_to_clients
=
self
.
mock_update_client
self
.
datastore
=
hs
.
get_datastore
()
self
.
datastore
=
hs
.
get_datastore
()
self
.
datastore
.
get_destination_retry_timings
.
return_value
=
(
self
.
datastore
.
get_destination_retry_timings
.
return_value
=
(
...
@@ -158,11 +158,8 @@ class TypingNotificationsTestCase(unittest.TestCase):
...
@@ -158,11 +158,8 @@ class TypingNotificationsTestCase(unittest.TestCase):
timeout
=
20000
,
timeout
=
20000
,
)
)
self
.
mock_update_client
.
assert_has_calls
([
self
.
on_new_user_event
.
assert_has_calls
([
call
(
observer_user
=
self
.
u_banana
,
call
(
rooms
=
[
self
.
room_id
]),
observed_user
=
self
.
u_apple
,
room_id
=
self
.
room_id
,
typing
=
True
),
])
])
@defer.inlineCallbacks
@defer.inlineCallbacks
...
@@ -209,11 +206,8 @@ class TypingNotificationsTestCase(unittest.TestCase):
...
@@ -209,11 +206,8 @@ class TypingNotificationsTestCase(unittest.TestCase):
)
)
)
)
self
.
mock_update_client
.
assert_has_calls
([
self
.
on_new_user_event
.
assert_has_calls
([
call
(
observer_user
=
self
.
u_apple
,
call
(
rooms
=
[
self
.
room_id
]),
observed_user
=
self
.
u_onion
,
room_id
=
self
.
room_id
,
typing
=
True
),
])
])
@defer.inlineCallbacks
@defer.inlineCallbacks
...
@@ -243,6 +237,7 @@ class TypingNotificationsTestCase(unittest.TestCase):
...
@@ -243,6 +237,7 @@ class TypingNotificationsTestCase(unittest.TestCase):
self
.
handler
.
_member_typing_timer
[
member
]
=
(
self
.
handler
.
_member_typing_timer
[
member
]
=
(
self
.
clock
.
call_later
(
1002
,
lambda
:
0
)
self
.
clock
.
call_later
(
1002
,
lambda
:
0
)
)
)
self
.
handler
.
_room_typing
[
self
.
room_id
]
=
set
((
self
.
u_apple
,))
yield
self
.
handler
.
stopped_typing
(
yield
self
.
handler
.
stopped_typing
(
target_user
=
self
.
u_apple
,
target_user
=
self
.
u_apple
,
...
@@ -250,11 +245,8 @@ class TypingNotificationsTestCase(unittest.TestCase):
...
@@ -250,11 +245,8 @@ class TypingNotificationsTestCase(unittest.TestCase):
room_id
=
self
.
room_id
,
room_id
=
self
.
room_id
,
)
)
self
.
mock_update_client
.
assert_has_calls
([
self
.
on_new_user_event
.
assert_has_calls
([
call
(
observer_user
=
self
.
u_banana
,
call
(
rooms
=
[
self
.
room_id
]),
observed_user
=
self
.
u_apple
,
room_id
=
self
.
room_id
,
typing
=
False
),
])
])
yield
put_json
.
await_calls
()
yield
put_json
.
await_calls
()
...
@@ -270,19 +262,13 @@ class TypingNotificationsTestCase(unittest.TestCase):
...
@@ -270,19 +262,13 @@ class TypingNotificationsTestCase(unittest.TestCase):
timeout
=
10000
,
timeout
=
10000
,
)
)
self
.
mock_update_client
.
assert_has_calls
([
self
.
on_new_user_event
.
assert_has_calls
([
call
(
observer_user
=
self
.
u_banana
,
call
(
rooms
=
[
self
.
room_id
]),
observed_user
=
self
.
u_apple
,
room_id
=
self
.
room_id
,
typing
=
True
),
])
])
self
.
mock_update_cli
ent
.
reset_mock
()
self
.
on_new_user_ev
ent
.
reset_mock
()
self
.
clock
.
advance_time
(
11
)
self
.
clock
.
advance_time
(
11
)
self
.
mock_update_client
.
assert_has_calls
([
self
.
on_new_user_event
.
assert_has_calls
([
call
(
observer_user
=
self
.
u_banana
,
call
(
rooms
=
[
self
.
room_id
]),
observed_user
=
self
.
u_apple
,
room_id
=
self
.
room_id
,
typing
=
False
),
])
])
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