2016-01-06 21:26:29 -07:00
|
|
|
# Copyright 2014-2016 OpenMarket Ltd
|
2014-08-20 12:15:47 -06:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
|
|
|
|
|
|
|
import json
|
2020-12-02 08:26:25 -07:00
|
|
|
from typing import Dict
|
2021-04-09 11:44:38 -06:00
|
|
|
from unittest.mock import ANY, Mock, call
|
2018-07-09 00:09:20 -06:00
|
|
|
|
|
|
|
from twisted.internet import defer
|
2020-12-02 08:26:25 -07:00
|
|
|
from twisted.web.resource import Resource
|
2014-08-20 12:15:47 -06:00
|
|
|
|
2014-12-11 11:11:43 -07:00
|
|
|
from synapse.api.errors import AuthError
|
2020-12-02 08:26:25 -07:00
|
|
|
from synapse.federation.transport.server import TransportLayerServer
|
2020-08-26 10:05:36 -06:00
|
|
|
from synapse.types import UserID, create_requester
|
2014-12-09 16:53:07 -07:00
|
|
|
|
2018-07-09 00:09:20 -06:00
|
|
|
from tests import unittest
|
2020-08-12 07:29:06 -06:00
|
|
|
from tests.test_utils import make_awaitable
|
2019-11-27 14:54:07 -07:00
|
|
|
from tests.unittest import override_config
|
2018-07-09 00:09:20 -06:00
|
|
|
|
2019-03-04 03:05:39 -07:00
|
|
|
# Some local users to test with
|
|
|
|
U_APPLE = UserID.from_string("@apple:test")
|
|
|
|
U_BANANA = UserID.from_string("@banana:test")
|
|
|
|
|
|
|
|
# Remote user
|
|
|
|
U_ONION = UserID.from_string("@onion:farm")
|
|
|
|
|
|
|
|
# Test room id
|
|
|
|
ROOM_ID = "a-room"
|
2018-07-09 00:09:20 -06:00
|
|
|
|
2021-07-06 07:31:13 -06:00
|
|
|
# Room we're not in
|
|
|
|
OTHER_ROOM_ID = "another-room"
|
|
|
|
|
2014-08-20 12:15:47 -06:00
|
|
|
|
2018-09-03 18:23:18 -06:00
|
|
|
def _expect_edu_transaction(edu_type, content, origin="test"):
|
2014-08-20 12:15:47 -06:00
|
|
|
return {
|
|
|
|
"origin": origin,
|
2014-10-17 10:12:25 -06:00
|
|
|
"origin_server_ts": 1000000,
|
2014-08-20 12:15:47 -06:00
|
|
|
"pdus": [],
|
2018-08-10 07:54:09 -06:00
|
|
|
"edus": [{"edu_type": edu_type, "content": content}],
|
2014-08-20 12:15:47 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-03 18:23:18 -06:00
|
|
|
def _make_edu_transaction_json(edu_type, content):
|
2018-09-06 10:58:18 -06:00
|
|
|
return json.dumps(_expect_edu_transaction(edu_type, content)).encode("utf8")
|
2014-08-20 12:15:47 -06:00
|
|
|
|
|
|
|
|
2019-03-04 03:05:39 -07:00
|
|
|
class TypingNotificationsTestCase(unittest.HomeserverTestCase):
|
|
|
|
def make_homeserver(self, reactor, clock):
|
|
|
|
# we mock out the keyring so as to skip the authentication check on the
|
|
|
|
# federation API call.
|
|
|
|
mock_keyring = Mock(spec=["verify_json_for_server"])
|
|
|
|
mock_keyring.verify_json_for_server.return_value = defer.succeed(True)
|
2014-08-20 12:15:47 -06:00
|
|
|
|
2019-03-04 03:05:39 -07:00
|
|
|
# we mock out the federation client too
|
|
|
|
mock_federation_client = Mock(spec=["put_json"])
|
|
|
|
mock_federation_client.put_json.return_value = defer.succeed((200, "OK"))
|
2014-12-10 13:48:12 -07:00
|
|
|
|
2020-01-30 10:06:38 -07:00
|
|
|
# the tests assume that we are starting at unix time 1000
|
|
|
|
reactor.pump((1000,))
|
|
|
|
|
2019-03-04 03:05:39 -07:00
|
|
|
hs = self.setup_test_homeserver(
|
2020-05-22 07:21:54 -06:00
|
|
|
notifier=Mock(),
|
2020-12-02 09:09:24 -07:00
|
|
|
federation_http_client=mock_federation_client,
|
2020-05-22 07:21:54 -06:00
|
|
|
keyring=mock_keyring,
|
|
|
|
replication_streams={},
|
2015-02-11 04:37:30 -07:00
|
|
|
)
|
2014-08-20 12:15:47 -06:00
|
|
|
|
2019-03-04 03:05:39 -07:00
|
|
|
return hs
|
|
|
|
|
2020-12-02 08:26:25 -07:00
|
|
|
def create_resource_dict(self) -> Dict[str, Resource]:
|
|
|
|
d = super().create_resource_dict()
|
|
|
|
d["/_matrix/federation"] = TransportLayerServer(self.hs)
|
|
|
|
return d
|
|
|
|
|
2019-03-04 03:05:39 -07:00
|
|
|
def prepare(self, reactor, clock, hs):
|
|
|
|
mock_notifier = hs.get_notifier()
|
|
|
|
self.on_new_event = mock_notifier.on_new_event
|
|
|
|
|
2016-05-17 08:58:46 -06:00
|
|
|
self.handler = hs.get_typing_handler()
|
2014-08-20 12:15:47 -06:00
|
|
|
|
2021-09-21 11:34:26 -06:00
|
|
|
self.event_source = hs.get_event_sources().sources.typing
|
2014-08-20 12:15:47 -06:00
|
|
|
|
2022-02-23 04:04:02 -07:00
|
|
|
self.datastore = hs.get_datastores().main
|
2020-10-13 06:20:32 -06:00
|
|
|
self.datastore.get_destination_retry_timings = Mock(
|
2021-05-21 10:57:08 -06:00
|
|
|
return_value=defer.succeed(None)
|
2014-12-09 16:53:07 -07:00
|
|
|
)
|
2014-08-20 12:15:47 -06:00
|
|
|
|
2020-10-13 06:20:32 -06:00
|
|
|
self.datastore.get_device_updates_by_remote = Mock(
|
|
|
|
return_value=make_awaitable((0, []))
|
2020-02-07 06:56:38 -07:00
|
|
|
)
|
2017-01-25 07:27:27 -07:00
|
|
|
|
2020-10-13 06:20:32 -06:00
|
|
|
self.datastore.get_destination_last_successful_stream_ordering = Mock(
|
|
|
|
return_value=make_awaitable(None)
|
2020-09-15 02:07:19 -06:00
|
|
|
)
|
|
|
|
|
2014-08-20 12:15:47 -06:00
|
|
|
def get_received_txn_response(*args):
|
|
|
|
return defer.succeed(None)
|
2018-08-10 07:54:09 -06:00
|
|
|
|
2014-08-20 12:15:47 -06:00
|
|
|
self.datastore.get_received_txn_response = get_received_txn_response
|
|
|
|
|
|
|
|
self.room_members = []
|
|
|
|
|
2020-08-06 06:30:06 -06:00
|
|
|
async def check_user_in_room(room_id, user_id):
|
2014-12-11 11:11:43 -07:00
|
|
|
if user_id not in [u.to_string() for u in self.room_members]:
|
|
|
|
raise AuthError(401, "User is not in the room")
|
2020-08-06 06:30:06 -06:00
|
|
|
return None
|
2019-05-09 23:12:11 -06:00
|
|
|
|
2020-02-18 16:13:29 -07:00
|
|
|
hs.get_auth().check_user_in_room = check_user_in_room
|
2014-12-11 11:11:43 -07:00
|
|
|
|
2021-07-06 07:31:13 -06:00
|
|
|
async def check_host_in_room(room_id, server_name):
|
|
|
|
return room_id == ROOM_ID
|
|
|
|
|
|
|
|
hs.get_event_auth_handler().check_host_in_room = check_host_in_room
|
|
|
|
|
2016-05-16 12:48:07 -06:00
|
|
|
def get_joined_hosts_for_room(room_id):
|
2020-02-21 05:15:07 -07:00
|
|
|
return {member.domain for member in self.room_members}
|
2018-08-10 07:54:09 -06:00
|
|
|
|
2016-05-16 12:48:07 -06:00
|
|
|
self.datastore.get_joined_hosts_for_room = get_joined_hosts_for_room
|
|
|
|
|
2020-10-13 06:20:32 -06:00
|
|
|
async def get_users_in_room(room_id):
|
|
|
|
return {str(u) for u in self.room_members}
|
2019-05-09 23:12:11 -06:00
|
|
|
|
2020-07-15 08:47:27 -06:00
|
|
|
self.datastore.get_users_in_room = get_users_in_room
|
2016-08-26 08:06:14 -06:00
|
|
|
|
2020-10-13 06:20:32 -06:00
|
|
|
self.datastore.get_user_directory_stream_pos = Mock(
|
|
|
|
side_effect=(
|
|
|
|
# we deliberately return a non-None stream pos to avoid doing an initial_spam
|
|
|
|
lambda: make_awaitable(1)
|
|
|
|
)
|
2017-12-04 10:10:03 -07:00
|
|
|
)
|
|
|
|
|
2020-10-13 06:20:32 -06:00
|
|
|
self.datastore.get_current_state_deltas = Mock(return_value=(0, None))
|
2017-12-04 10:10:03 -07:00
|
|
|
|
2016-09-06 11:30:03 -06:00
|
|
|
self.datastore.get_to_device_stream_token = lambda: 0
|
2020-08-12 07:29:06 -06:00
|
|
|
self.datastore.get_new_device_msgs_for_remote = (
|
|
|
|
lambda *args, **kargs: make_awaitable(([], 0))
|
2020-02-07 06:56:38 -07:00
|
|
|
)
|
2020-08-27 15:24:46 -06:00
|
|
|
self.datastore.delete_device_msgs_for_remote = (
|
|
|
|
lambda *args, **kargs: make_awaitable(None)
|
|
|
|
)
|
2020-08-17 10:18:01 -06:00
|
|
|
self.datastore.set_received_txn_response = (
|
|
|
|
lambda *args, **kwargs: make_awaitable(None)
|
2019-10-29 08:05:32 -06:00
|
|
|
)
|
2016-09-06 11:30:03 -06:00
|
|
|
|
2014-08-20 12:15:47 -06:00
|
|
|
def test_started_typing_local(self):
|
2019-03-04 03:05:39 -07:00
|
|
|
self.room_members = [U_APPLE, U_BANANA]
|
2014-08-20 12:15:47 -06:00
|
|
|
|
2022-02-28 05:12:29 -07:00
|
|
|
self.assertEqual(self.event_source.get_current_key(), 0)
|
2014-12-10 14:01:49 -07:00
|
|
|
|
2020-06-17 08:37:59 -06:00
|
|
|
self.get_success(
|
2019-05-09 23:12:11 -06:00
|
|
|
self.handler.started_typing(
|
2020-08-26 10:05:36 -06:00
|
|
|
target_user=U_APPLE,
|
|
|
|
requester=create_requester(U_APPLE),
|
|
|
|
room_id=ROOM_ID,
|
|
|
|
timeout=20000,
|
2019-05-09 23:12:11 -06:00
|
|
|
)
|
2018-08-10 07:54:09 -06:00
|
|
|
)
|
2014-08-20 12:15:47 -06:00
|
|
|
|
2019-05-09 23:12:11 -06:00
|
|
|
self.on_new_event.assert_has_calls([call("typing_key", 1, rooms=[ROOM_ID])])
|
|
|
|
|
2022-02-28 05:12:29 -07:00
|
|
|
self.assertEqual(self.event_source.get_current_key(), 1)
|
2019-12-06 03:14:59 -07:00
|
|
|
events = self.get_success(
|
2021-09-21 11:34:26 -06:00
|
|
|
self.event_source.get_new_events(
|
|
|
|
user=U_APPLE, from_key=0, limit=None, room_ids=[ROOM_ID], is_guest=False
|
|
|
|
)
|
2019-12-06 03:14:59 -07:00
|
|
|
)
|
2022-02-28 05:12:29 -07:00
|
|
|
self.assertEqual(
|
2015-04-15 16:09:35 -06:00
|
|
|
events[0],
|
2014-12-10 14:01:49 -07:00
|
|
|
[
|
2018-08-10 07:54:09 -06:00
|
|
|
{
|
|
|
|
"type": "m.typing",
|
2019-03-04 03:05:39 -07:00
|
|
|
"room_id": ROOM_ID,
|
|
|
|
"content": {"user_ids": [U_APPLE.to_string()]},
|
2018-08-10 07:54:09 -06:00
|
|
|
}
|
|
|
|
],
|
2014-12-10 14:01:49 -07:00
|
|
|
)
|
|
|
|
|
2019-11-27 14:54:07 -07:00
|
|
|
@override_config({"send_federation": True})
|
2014-08-20 12:15:47 -06:00
|
|
|
def test_started_typing_remote_send(self):
|
2019-03-04 03:05:39 -07:00
|
|
|
self.room_members = [U_APPLE, U_ONION]
|
2014-08-20 12:15:47 -06:00
|
|
|
|
2020-06-17 08:37:59 -06:00
|
|
|
self.get_success(
|
2019-05-09 23:12:11 -06:00
|
|
|
self.handler.started_typing(
|
2020-08-26 10:05:36 -06:00
|
|
|
target_user=U_APPLE,
|
|
|
|
requester=create_requester(U_APPLE),
|
|
|
|
room_id=ROOM_ID,
|
|
|
|
timeout=20000,
|
2019-05-09 23:12:11 -06:00
|
|
|
)
|
|
|
|
)
|
2014-08-20 12:15:47 -06:00
|
|
|
|
2020-12-02 09:09:24 -07:00
|
|
|
put_json = self.hs.get_federation_http_client().put_json
|
2019-03-04 03:05:39 -07:00
|
|
|
put_json.assert_called_once_with(
|
|
|
|
"farm",
|
2019-03-26 05:35:29 -06:00
|
|
|
path="/_matrix/federation/v1/send/1000000",
|
2019-03-04 03:05:39 -07:00
|
|
|
data=_expect_edu_transaction(
|
|
|
|
"m.typing",
|
|
|
|
content={
|
|
|
|
"room_id": ROOM_ID,
|
|
|
|
"user_id": U_APPLE.to_string(),
|
|
|
|
"typing": True,
|
|
|
|
},
|
|
|
|
),
|
|
|
|
json_data_callback=ANY,
|
|
|
|
long_retries=True,
|
|
|
|
backoff_on_404=True,
|
2019-03-13 12:26:06 -06:00
|
|
|
try_trailing_slash_on_400=True,
|
2019-03-04 03:05:39 -07:00
|
|
|
)
|
2014-08-20 12:15:47 -06:00
|
|
|
|
|
|
|
def test_started_typing_remote_recv(self):
|
2019-03-04 03:05:39 -07:00
|
|
|
self.room_members = [U_APPLE, U_ONION]
|
2014-08-20 12:15:47 -06:00
|
|
|
|
2022-02-28 05:12:29 -07:00
|
|
|
self.assertEqual(self.event_source.get_current_key(), 0)
|
2014-12-10 14:01:49 -07:00
|
|
|
|
2020-12-15 07:44:04 -07:00
|
|
|
channel = self.make_request(
|
2016-02-19 08:34:38 -07:00
|
|
|
"PUT",
|
2019-03-26 05:35:29 -06:00
|
|
|
"/_matrix/federation/v1/send/1000000",
|
2018-09-03 18:23:18 -06:00
|
|
|
_make_edu_transaction_json(
|
2016-02-19 08:34:38 -07:00
|
|
|
"m.typing",
|
2014-08-20 12:15:47 -06:00
|
|
|
content={
|
2019-03-04 03:05:39 -07:00
|
|
|
"room_id": ROOM_ID,
|
|
|
|
"user_id": U_ONION.to_string(),
|
2014-08-20 12:15:47 -06:00
|
|
|
"typing": True,
|
2018-08-10 07:54:09 -06:00
|
|
|
},
|
2016-09-12 03:46:02 -06:00
|
|
|
),
|
2018-09-03 18:23:18 -06:00
|
|
|
federation_auth_origin=b"farm",
|
2014-08-20 12:15:47 -06:00
|
|
|
)
|
2019-03-04 03:05:39 -07:00
|
|
|
self.assertEqual(channel.code, 200)
|
2014-08-20 12:15:47 -06:00
|
|
|
|
2019-05-09 23:12:11 -06:00
|
|
|
self.on_new_event.assert_has_calls([call("typing_key", 1, rooms=[ROOM_ID])])
|
2014-08-20 12:15:47 -06:00
|
|
|
|
2022-02-28 05:12:29 -07:00
|
|
|
self.assertEqual(self.event_source.get_current_key(), 1)
|
2019-12-06 03:14:59 -07:00
|
|
|
events = self.get_success(
|
2021-09-21 11:34:26 -06:00
|
|
|
self.event_source.get_new_events(
|
|
|
|
user=U_APPLE, from_key=0, limit=None, room_ids=[ROOM_ID], is_guest=False
|
|
|
|
)
|
2019-12-06 03:14:59 -07:00
|
|
|
)
|
2022-02-28 05:12:29 -07:00
|
|
|
self.assertEqual(
|
2018-08-10 07:54:09 -06:00
|
|
|
events[0],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"type": "m.typing",
|
2019-03-04 03:05:39 -07:00
|
|
|
"room_id": ROOM_ID,
|
|
|
|
"content": {"user_ids": [U_ONION.to_string()]},
|
2018-08-10 07:54:09 -06:00
|
|
|
}
|
|
|
|
],
|
2015-11-05 07:32:26 -07:00
|
|
|
)
|
2014-12-10 14:01:49 -07:00
|
|
|
|
2021-07-06 07:31:13 -06:00
|
|
|
def test_started_typing_remote_recv_not_in_room(self):
|
|
|
|
self.room_members = [U_APPLE, U_ONION]
|
|
|
|
|
2022-02-28 05:12:29 -07:00
|
|
|
self.assertEqual(self.event_source.get_current_key(), 0)
|
2021-07-06 07:31:13 -06:00
|
|
|
|
|
|
|
channel = self.make_request(
|
|
|
|
"PUT",
|
|
|
|
"/_matrix/federation/v1/send/1000000",
|
|
|
|
_make_edu_transaction_json(
|
|
|
|
"m.typing",
|
|
|
|
content={
|
|
|
|
"room_id": OTHER_ROOM_ID,
|
|
|
|
"user_id": U_ONION.to_string(),
|
|
|
|
"typing": True,
|
|
|
|
},
|
|
|
|
),
|
|
|
|
federation_auth_origin=b"farm",
|
|
|
|
)
|
|
|
|
self.assertEqual(channel.code, 200)
|
|
|
|
|
|
|
|
self.on_new_event.assert_not_called()
|
|
|
|
|
2022-02-28 05:12:29 -07:00
|
|
|
self.assertEqual(self.event_source.get_current_key(), 0)
|
2021-07-06 07:31:13 -06:00
|
|
|
events = self.get_success(
|
2021-09-21 11:34:26 -06:00
|
|
|
self.event_source.get_new_events(
|
|
|
|
user=U_APPLE,
|
|
|
|
from_key=0,
|
|
|
|
limit=None,
|
|
|
|
room_ids=[OTHER_ROOM_ID],
|
|
|
|
is_guest=False,
|
|
|
|
)
|
2021-07-06 07:31:13 -06:00
|
|
|
)
|
2022-02-28 05:12:29 -07:00
|
|
|
self.assertEqual(events[0], [])
|
|
|
|
self.assertEqual(events[1], 0)
|
2021-07-06 07:31:13 -06:00
|
|
|
|
2019-11-27 14:54:07 -07:00
|
|
|
@override_config({"send_federation": True})
|
2014-08-20 12:15:47 -06:00
|
|
|
def test_stopped_typing(self):
|
2019-03-04 03:05:39 -07:00
|
|
|
self.room_members = [U_APPLE, U_BANANA, U_ONION]
|
2014-08-20 12:15:47 -06:00
|
|
|
|
|
|
|
# Gut-wrenching
|
|
|
|
from synapse.handlers.typing import RoomMember
|
2018-08-10 07:54:09 -06:00
|
|
|
|
2019-03-04 03:05:39 -07:00
|
|
|
member = RoomMember(ROOM_ID, U_APPLE.to_string())
|
2014-12-10 12:39:01 -07:00
|
|
|
self.handler._member_typing_until[member] = 1002000
|
2020-02-21 05:15:07 -07:00
|
|
|
self.handler._room_typing[ROOM_ID] = {U_APPLE.to_string()}
|
2014-08-20 12:15:47 -06:00
|
|
|
|
2022-02-28 05:12:29 -07:00
|
|
|
self.assertEqual(self.event_source.get_current_key(), 0)
|
2014-08-20 12:15:47 -06:00
|
|
|
|
2020-06-17 08:37:59 -06:00
|
|
|
self.get_success(
|
2019-05-09 23:12:11 -06:00
|
|
|
self.handler.stopped_typing(
|
2020-08-26 10:05:36 -06:00
|
|
|
target_user=U_APPLE,
|
|
|
|
requester=create_requester(U_APPLE),
|
|
|
|
room_id=ROOM_ID,
|
2019-05-09 23:12:11 -06:00
|
|
|
)
|
2018-08-10 07:54:09 -06:00
|
|
|
)
|
2014-08-20 12:15:47 -06:00
|
|
|
|
2019-05-09 23:12:11 -06:00
|
|
|
self.on_new_event.assert_has_calls([call("typing_key", 1, rooms=[ROOM_ID])])
|
|
|
|
|
2020-12-02 09:09:24 -07:00
|
|
|
put_json = self.hs.get_federation_http_client().put_json
|
2019-03-04 03:05:39 -07:00
|
|
|
put_json.assert_called_once_with(
|
|
|
|
"farm",
|
2019-03-26 05:35:29 -06:00
|
|
|
path="/_matrix/federation/v1/send/1000000",
|
2019-03-04 03:05:39 -07:00
|
|
|
data=_expect_edu_transaction(
|
|
|
|
"m.typing",
|
|
|
|
content={
|
|
|
|
"room_id": ROOM_ID,
|
|
|
|
"user_id": U_APPLE.to_string(),
|
|
|
|
"typing": False,
|
|
|
|
},
|
|
|
|
),
|
|
|
|
json_data_callback=ANY,
|
|
|
|
long_retries=True,
|
|
|
|
backoff_on_404=True,
|
2019-03-13 12:26:06 -06:00
|
|
|
try_trailing_slash_on_400=True,
|
2019-03-04 03:05:39 -07:00
|
|
|
)
|
2014-12-10 12:39:01 -07:00
|
|
|
|
2022-02-28 05:12:29 -07:00
|
|
|
self.assertEqual(self.event_source.get_current_key(), 1)
|
2019-12-06 03:14:59 -07:00
|
|
|
events = self.get_success(
|
2021-09-21 11:34:26 -06:00
|
|
|
self.event_source.get_new_events(
|
|
|
|
user=U_APPLE, from_key=0, limit=None, room_ids=[ROOM_ID], is_guest=False
|
|
|
|
)
|
2019-12-06 03:14:59 -07:00
|
|
|
)
|
2022-02-28 05:12:29 -07:00
|
|
|
self.assertEqual(
|
2018-08-10 07:54:09 -06:00
|
|
|
events[0],
|
2019-05-09 23:12:11 -06:00
|
|
|
[{"type": "m.typing", "room_id": ROOM_ID, "content": {"user_ids": []}}],
|
2015-11-05 07:32:26 -07:00
|
|
|
)
|
2014-12-10 14:01:49 -07:00
|
|
|
|
2014-12-10 12:39:01 -07:00
|
|
|
def test_typing_timeout(self):
|
2019-03-04 03:05:39 -07:00
|
|
|
self.room_members = [U_APPLE, U_BANANA]
|
2014-12-10 12:39:01 -07:00
|
|
|
|
2022-02-28 05:12:29 -07:00
|
|
|
self.assertEqual(self.event_source.get_current_key(), 0)
|
2014-12-10 14:01:49 -07:00
|
|
|
|
2020-06-17 08:37:59 -06:00
|
|
|
self.get_success(
|
2019-05-09 23:12:11 -06:00
|
|
|
self.handler.started_typing(
|
2020-08-26 10:05:36 -06:00
|
|
|
target_user=U_APPLE,
|
|
|
|
requester=create_requester(U_APPLE),
|
|
|
|
room_id=ROOM_ID,
|
|
|
|
timeout=10000,
|
2019-05-09 23:12:11 -06:00
|
|
|
)
|
2018-08-10 07:54:09 -06:00
|
|
|
)
|
2019-05-09 23:12:11 -06:00
|
|
|
|
|
|
|
self.on_new_event.assert_has_calls([call("typing_key", 1, rooms=[ROOM_ID])])
|
2015-07-02 04:40:56 -06:00
|
|
|
self.on_new_event.reset_mock()
|
2014-12-10 12:39:01 -07:00
|
|
|
|
2022-02-28 05:12:29 -07:00
|
|
|
self.assertEqual(self.event_source.get_current_key(), 1)
|
2019-12-06 03:14:59 -07:00
|
|
|
events = self.get_success(
|
2021-09-21 11:34:26 -06:00
|
|
|
self.event_source.get_new_events(
|
|
|
|
user=U_APPLE,
|
|
|
|
from_key=0,
|
|
|
|
limit=None,
|
|
|
|
room_ids=[ROOM_ID],
|
|
|
|
is_guest=False,
|
|
|
|
)
|
2019-12-06 03:14:59 -07:00
|
|
|
)
|
2022-02-28 05:12:29 -07:00
|
|
|
self.assertEqual(
|
2018-08-10 07:54:09 -06:00
|
|
|
events[0],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"type": "m.typing",
|
2019-03-04 03:05:39 -07:00
|
|
|
"room_id": ROOM_ID,
|
|
|
|
"content": {"user_ids": [U_APPLE.to_string()]},
|
2018-08-10 07:54:09 -06:00
|
|
|
}
|
|
|
|
],
|
2015-11-05 07:32:26 -07:00
|
|
|
)
|
2014-12-10 14:01:49 -07:00
|
|
|
|
2019-05-09 23:12:11 -06:00
|
|
|
self.reactor.pump([16])
|
2014-12-10 12:39:01 -07:00
|
|
|
|
2019-05-09 23:12:11 -06:00
|
|
|
self.on_new_event.assert_has_calls([call("typing_key", 2, rooms=[ROOM_ID])])
|
2014-12-10 14:01:49 -07:00
|
|
|
|
2022-02-28 05:12:29 -07:00
|
|
|
self.assertEqual(self.event_source.get_current_key(), 2)
|
2019-12-06 03:14:59 -07:00
|
|
|
events = self.get_success(
|
2021-09-21 11:34:26 -06:00
|
|
|
self.event_source.get_new_events(
|
|
|
|
user=U_APPLE,
|
|
|
|
from_key=1,
|
|
|
|
limit=None,
|
|
|
|
room_ids=[ROOM_ID],
|
|
|
|
is_guest=False,
|
|
|
|
)
|
2019-12-06 03:14:59 -07:00
|
|
|
)
|
2022-02-28 05:12:29 -07:00
|
|
|
self.assertEqual(
|
2018-08-10 07:54:09 -06:00
|
|
|
events[0],
|
2019-05-09 23:12:11 -06:00
|
|
|
[{"type": "m.typing", "room_id": ROOM_ID, "content": {"user_ids": []}}],
|
2015-11-05 07:32:26 -07:00
|
|
|
)
|
2015-01-12 11:01:33 -07:00
|
|
|
|
|
|
|
# SYN-230 - see if we can still set after timeout
|
|
|
|
|
2020-06-17 08:37:59 -06:00
|
|
|
self.get_success(
|
2019-05-09 23:12:11 -06:00
|
|
|
self.handler.started_typing(
|
2020-08-26 10:05:36 -06:00
|
|
|
target_user=U_APPLE,
|
|
|
|
requester=create_requester(U_APPLE),
|
|
|
|
room_id=ROOM_ID,
|
|
|
|
timeout=10000,
|
2019-05-09 23:12:11 -06:00
|
|
|
)
|
2018-08-10 07:54:09 -06:00
|
|
|
)
|
2019-05-09 23:12:11 -06:00
|
|
|
|
|
|
|
self.on_new_event.assert_has_calls([call("typing_key", 3, rooms=[ROOM_ID])])
|
2015-07-02 04:40:56 -06:00
|
|
|
self.on_new_event.reset_mock()
|
2015-01-12 11:01:33 -07:00
|
|
|
|
2022-02-28 05:12:29 -07:00
|
|
|
self.assertEqual(self.event_source.get_current_key(), 3)
|
2019-12-06 03:14:59 -07:00
|
|
|
events = self.get_success(
|
2021-09-21 11:34:26 -06:00
|
|
|
self.event_source.get_new_events(
|
|
|
|
user=U_APPLE,
|
|
|
|
from_key=0,
|
|
|
|
limit=None,
|
|
|
|
room_ids=[ROOM_ID],
|
|
|
|
is_guest=False,
|
|
|
|
)
|
2019-12-06 03:14:59 -07:00
|
|
|
)
|
2022-02-28 05:12:29 -07:00
|
|
|
self.assertEqual(
|
2018-08-10 07:54:09 -06:00
|
|
|
events[0],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"type": "m.typing",
|
2019-03-04 03:05:39 -07:00
|
|
|
"room_id": ROOM_ID,
|
|
|
|
"content": {"user_ids": [U_APPLE.to_string()]},
|
2018-08-10 07:54:09 -06:00
|
|
|
}
|
|
|
|
],
|
2015-11-05 07:32:26 -07:00
|
|
|
)
|