Merge branch 'develop' of github.com:matrix-org/synapse into matrix-org-hotfixes

pull/8675/head
Erik Johnston 2020-06-17 16:32:39 +01:00
commit d06f4ab693
10 changed files with 38 additions and 34 deletions

1
changelog.d/7679.misc Normal file
View File

@ -0,0 +1 @@
Convert typing handler to async/await.

1
changelog.d/7680.misc Normal file
View File

@ -0,0 +1 @@
Require `parameterized` package version to be at least 0.7.0.

1
changelog.d/7711.bugfix Normal file
View File

@ -0,0 +1 @@
The `synapse_port_db` script no longer fails when the `ui_auth_sessions` table is non-empty. This bug has existed since v1.13.0rc1.

1
changelog.d/7716.feature Normal file
View File

@ -0,0 +1 @@
Add a per-room counter for unread messages in responses to `/sync` requests. Implements [MSC2625](https://github.com/matrix-org/matrix-doc/pull/2625).

View File

@ -127,6 +127,16 @@ APPEND_ONLY_TABLES = [
] ]
IGNORED_TABLES = {
"user_directory",
"user_directory_search",
"users_who_share_rooms",
"users_in_pubic_room",
"ui_auth_sessions",
"ui_auth_sessions_credentials",
}
# Error returned by the run function. Used at the top-level part of the script to # Error returned by the run function. Used at the top-level part of the script to
# handle errors and return codes. # handle errors and return codes.
end_error = None end_error = None
@ -289,13 +299,8 @@ class Porter(object):
) )
return return
if table in ( if table in IGNORED_TABLES:
"user_directory", # We don't port these tables, as they're a faff and we can regenerate
"user_directory_search",
"users_who_share_rooms",
"users_in_pubic_room",
):
# We don't port these tables, as they're a faff and we can regenreate
# them anyway. # them anyway.
self.progress.update(table, table_size) # Mark table as done self.progress.update(table, table_size) # Mark table as done
return return

View File

@ -17,8 +17,6 @@ import logging
from collections import namedtuple from collections import namedtuple
from typing import List, Tuple from typing import List, Tuple
from twisted.internet import defer
from synapse.api.errors import AuthError, SynapseError from synapse.api.errors import AuthError, SynapseError
from synapse.logging.context import run_in_background from synapse.logging.context import run_in_background
from synapse.types import UserID, get_domain_from_id from synapse.types import UserID, get_domain_from_id
@ -115,8 +113,7 @@ class TypingHandler(object):
def is_typing(self, member): def is_typing(self, member):
return member.user_id in self._room_typing.get(member.room_id, []) return member.user_id in self._room_typing.get(member.room_id, [])
@defer.inlineCallbacks async def started_typing(self, target_user, auth_user, room_id, timeout):
def started_typing(self, target_user, auth_user, room_id, timeout):
target_user_id = target_user.to_string() target_user_id = target_user.to_string()
auth_user_id = auth_user.to_string() auth_user_id = auth_user.to_string()
@ -126,7 +123,7 @@ class TypingHandler(object):
if target_user_id != auth_user_id: if target_user_id != auth_user_id:
raise AuthError(400, "Cannot set another user's typing state") raise AuthError(400, "Cannot set another user's typing state")
yield self.auth.check_user_in_room(room_id, target_user_id) await self.auth.check_user_in_room(room_id, target_user_id)
logger.debug("%s has started typing in %s", target_user_id, room_id) logger.debug("%s has started typing in %s", target_user_id, room_id)
@ -145,8 +142,7 @@ class TypingHandler(object):
self._push_update(member=member, typing=True) self._push_update(member=member, typing=True)
@defer.inlineCallbacks async def stopped_typing(self, target_user, auth_user, room_id):
def stopped_typing(self, target_user, auth_user, room_id):
target_user_id = target_user.to_string() target_user_id = target_user.to_string()
auth_user_id = auth_user.to_string() auth_user_id = auth_user.to_string()
@ -156,7 +152,7 @@ class TypingHandler(object):
if target_user_id != auth_user_id: if target_user_id != auth_user_id:
raise AuthError(400, "Cannot set another user's typing state") raise AuthError(400, "Cannot set another user's typing state")
yield self.auth.check_user_in_room(room_id, target_user_id) await self.auth.check_user_in_room(room_id, target_user_id)
logger.debug("%s has stopped typing in %s", target_user_id, room_id) logger.debug("%s has stopped typing in %s", target_user_id, room_id)
@ -164,12 +160,11 @@ class TypingHandler(object):
self._stopped_typing(member) self._stopped_typing(member)
@defer.inlineCallbacks
def user_left_room(self, user, room_id): def user_left_room(self, user, room_id):
user_id = user.to_string() user_id = user.to_string()
if self.is_mine_id(user_id): if self.is_mine_id(user_id):
member = RoomMember(room_id=room_id, user_id=user_id) member = RoomMember(room_id=room_id, user_id=user_id)
yield self._stopped_typing(member) self._stopped_typing(member)
def _stopped_typing(self, member): def _stopped_typing(self, member):
if member.user_id not in self._room_typing.get(member.room_id, set()): if member.user_id not in self._room_typing.get(member.room_id, set()):
@ -188,10 +183,9 @@ class TypingHandler(object):
self._push_update_local(member=member, typing=typing) self._push_update_local(member=member, typing=typing)
@defer.inlineCallbacks async def _push_remote(self, member, typing):
def _push_remote(self, member, typing):
try: try:
users = yield self.state.get_current_users_in_room(member.room_id) users = await self.state.get_current_users_in_room(member.room_id)
self._member_last_federation_poke[member] = self.clock.time_msec() self._member_last_federation_poke[member] = self.clock.time_msec()
now = self.clock.time_msec() now = self.clock.time_msec()
@ -215,8 +209,7 @@ class TypingHandler(object):
except Exception: except Exception:
logger.exception("Error pushing typing notif to remotes") logger.exception("Error pushing typing notif to remotes")
@defer.inlineCallbacks async def _recv_edu(self, origin, content):
def _recv_edu(self, origin, content):
room_id = content["room_id"] room_id = content["room_id"]
user_id = content["user_id"] user_id = content["user_id"]
@ -231,7 +224,7 @@ class TypingHandler(object):
) )
return return
users = yield self.state.get_current_users_in_room(room_id) users = await self.state.get_current_users_in_room(room_id)
domains = {get_domain_from_id(u) for u in users} domains = {get_domain_from_id(u) for u in users}
if self.server_name in domains: if self.server_name in domains:
@ -330,7 +323,7 @@ class TypingNotificationEventSource(object):
"content": {"user_ids": list(typing)}, "content": {"user_ids": list(typing)},
} }
def get_new_events(self, from_key, room_ids, **kwargs): async def get_new_events(self, from_key, room_ids, **kwargs):
with Measure(self.clock, "typing.get_new_events"): with Measure(self.clock, "typing.get_new_events"):
from_key = int(from_key) from_key = int(from_key)
handler = self.get_typing_handler() handler = self.get_typing_handler()
@ -344,7 +337,7 @@ class TypingNotificationEventSource(object):
events.append(self._make_event_for(room_id)) events.append(self._make_event_for(room_id))
return defer.succeed((events, handler._latest_room_serial)) return (events, handler._latest_room_serial)
def get_current_key(self): def get_current_key(self):
return self.get_typing_handler()._latest_room_serial return self.get_typing_handler()._latest_room_serial

View File

@ -42,7 +42,7 @@ def get_badge_count(store, user_id):
# We're populating this badge using the unread_count (instead of the # We're populating this badge using the unread_count (instead of the
# notify_count) as this badge is the number of missed messages, not the # notify_count) as this badge is the number of missed messages, not the
# number of missed notifications. # number of missed notifications.
badge += 1 if notifs["unread_count"] else 0 badge += 1 if notifs.get("unread_count") else 0
return badge return badge

View File

@ -93,7 +93,8 @@ CONDITIONAL_REQUIREMENTS = {
"oidc": ["authlib>=0.14.0"], "oidc": ["authlib>=0.14.0"],
"systemd": ["systemd-python>=231"], "systemd": ["systemd-python>=231"],
"url_preview": ["lxml>=3.5.0"], "url_preview": ["lxml>=3.5.0"],
"test": ["mock>=2.0", "parameterized"], # parameterized_class decorator was introduced in parameterized 0.7.0
"test": ["mock>=2.0", "parameterized>=0.7.0"],
"sentry": ["sentry-sdk>=0.7.2"], "sentry": ["sentry-sdk>=0.7.2"],
"opentracing": ["jaeger-client>=4.0.0", "opentracing>=2.2.0"], "opentracing": ["jaeger-client>=4.0.0", "opentracing>=2.2.0"],
"jwt": ["pyjwt>=1.6.4"], "jwt": ["pyjwt>=1.6.4"],

View File

@ -123,7 +123,7 @@ class EventPushActionsWorkerStore(SQLBaseStore):
txn.execute(sql, (room_id, last_read_event_id)) txn.execute(sql, (room_id, last_read_event_id))
results = txn.fetchall() results = txn.fetchall()
if len(results) == 0: if len(results) == 0:
return {"notify_count": 0, "highlight_count": 0} return {"notify_count": 0, "highlight_count": 0, "unread_count": 0}
stream_ordering = results[0][0] stream_ordering = results[0][0]

View File

@ -129,6 +129,7 @@ class TypingNotificationsTestCase(unittest.HomeserverTestCase):
def check_user_in_room(room_id, user_id): def check_user_in_room(room_id, user_id):
if user_id not in [u.to_string() for u in self.room_members]: if user_id not in [u.to_string() for u in self.room_members]:
raise AuthError(401, "User is not in the room") raise AuthError(401, "User is not in the room")
return defer.succeed(None)
hs.get_auth().check_user_in_room = check_user_in_room hs.get_auth().check_user_in_room = check_user_in_room
@ -138,7 +139,7 @@ class TypingNotificationsTestCase(unittest.HomeserverTestCase):
self.datastore.get_joined_hosts_for_room = get_joined_hosts_for_room self.datastore.get_joined_hosts_for_room = get_joined_hosts_for_room
def get_current_users_in_room(room_id): def get_current_users_in_room(room_id):
return {str(u) for u in self.room_members} return defer.succeed({str(u) for u in self.room_members})
hs.get_state_handler().get_current_users_in_room = get_current_users_in_room hs.get_state_handler().get_current_users_in_room = get_current_users_in_room
@ -163,7 +164,7 @@ class TypingNotificationsTestCase(unittest.HomeserverTestCase):
self.assertEquals(self.event_source.get_current_key(), 0) self.assertEquals(self.event_source.get_current_key(), 0)
self.successResultOf( self.get_success(
self.handler.started_typing( self.handler.started_typing(
target_user=U_APPLE, auth_user=U_APPLE, room_id=ROOM_ID, timeout=20000 target_user=U_APPLE, auth_user=U_APPLE, room_id=ROOM_ID, timeout=20000
) )
@ -190,7 +191,7 @@ class TypingNotificationsTestCase(unittest.HomeserverTestCase):
def test_started_typing_remote_send(self): def test_started_typing_remote_send(self):
self.room_members = [U_APPLE, U_ONION] self.room_members = [U_APPLE, U_ONION]
self.successResultOf( self.get_success(
self.handler.started_typing( self.handler.started_typing(
target_user=U_APPLE, auth_user=U_APPLE, room_id=ROOM_ID, timeout=20000 target_user=U_APPLE, auth_user=U_APPLE, room_id=ROOM_ID, timeout=20000
) )
@ -265,7 +266,7 @@ class TypingNotificationsTestCase(unittest.HomeserverTestCase):
self.assertEquals(self.event_source.get_current_key(), 0) self.assertEquals(self.event_source.get_current_key(), 0)
self.successResultOf( self.get_success(
self.handler.stopped_typing( self.handler.stopped_typing(
target_user=U_APPLE, auth_user=U_APPLE, room_id=ROOM_ID target_user=U_APPLE, auth_user=U_APPLE, room_id=ROOM_ID
) )
@ -305,7 +306,7 @@ class TypingNotificationsTestCase(unittest.HomeserverTestCase):
self.assertEquals(self.event_source.get_current_key(), 0) self.assertEquals(self.event_source.get_current_key(), 0)
self.successResultOf( self.get_success(
self.handler.started_typing( self.handler.started_typing(
target_user=U_APPLE, auth_user=U_APPLE, room_id=ROOM_ID, timeout=10000 target_user=U_APPLE, auth_user=U_APPLE, room_id=ROOM_ID, timeout=10000
) )
@ -344,7 +345,7 @@ class TypingNotificationsTestCase(unittest.HomeserverTestCase):
# SYN-230 - see if we can still set after timeout # SYN-230 - see if we can still set after timeout
self.successResultOf( self.get_success(
self.handler.started_typing( self.handler.started_typing(
target_user=U_APPLE, auth_user=U_APPLE, room_id=ROOM_ID, timeout=10000 target_user=U_APPLE, auth_user=U_APPLE, room_id=ROOM_ID, timeout=10000
) )