Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into mv/new-client-even…
Browse files Browse the repository at this point in the history
…t-partial-state-conflict
  • Loading branch information
Mathieu Velten committed Dec 13, 2022
2 parents 31ac5be + e2a1adb commit 0d283e4
Show file tree
Hide file tree
Showing 53 changed files with 1,032 additions and 899 deletions.
1 change: 0 additions & 1 deletion changelog.d/14595.misc

This file was deleted.

1 change: 1 addition & 0 deletions changelog.d/14642.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow selecting "prejoin" events by state keys in addition to event types.
1 change: 0 additions & 1 deletion changelog.d/14649.misc

This file was deleted.

1 change: 1 addition & 0 deletions changelog.d/14657.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Bump packaging from 21.3 to 22.0.
1 change: 1 addition & 0 deletions changelog.d/14662.removal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(remove from changelog: unreleased) Revert the deletion of stale devices due to performance issues.
1 change: 1 addition & 0 deletions changelog.d/14668.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Move `StateFilter` to `synapse.types`.
1 change: 1 addition & 0 deletions changelog.d/14670.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bugs introduced in 1.55.0 and 1.69.0 where application services would not be notified of events in the correct rooms, due to stale caches.
1 change: 1 addition & 0 deletions changelog.d/14671.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve type hints.
57 changes: 39 additions & 18 deletions docs/usage/configuration/config_documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -2501,32 +2501,53 @@ Config settings related to the client/server API
---
### `room_prejoin_state`

Controls for the state that is shared with users who receive an invite
to a room. By default, the following state event types are shared with users who
receive invites to the room:
- m.room.join_rules
- m.room.canonical_alias
- m.room.avatar
- m.room.encryption
- m.room.name
- m.room.create
- m.room.topic
This setting controls the state that is shared with users upon receiving an
invite to a room, or in reply to a knock on a room. By default, the following
state events are shared with users:

- `m.room.join_rules`
- `m.room.canonical_alias`
- `m.room.avatar`
- `m.room.encryption`
- `m.room.name`
- `m.room.create`
- `m.room.topic`

To change the default behavior, use the following sub-options:
* `disable_default_event_types`: set to true to disable the above defaults. If this
is enabled, only the event types listed in `additional_event_types` are shared.
Defaults to false.
* `additional_event_types`: Additional state event types to share with users when they are invited
to a room. By default, this list is empty (so only the default event types are shared).
* `disable_default_event_types`: boolean. Set to `true` to disable the above
defaults. If this is enabled, only the event types listed in
`additional_event_types` are shared. Defaults to `false`.
* `additional_event_types`: A list of additional state events to include in the
events to be shared. By default, this list is empty (so only the default event
types are shared).

Each entry in this list should be either a single string or a list of two
strings.
* A standalone string `t` represents all events with type `t` (i.e.
with no restrictions on state keys).
* A pair of strings `[t, s]` represents a single event with type `t` and
state key `s`. The same type can appear in two entries with different state
keys: in this situation, both state keys are included in prejoin state.

Example configuration:
```yaml
room_prejoin_state:
disable_default_event_types: true
disable_default_event_types: false
additional_event_types:
- org.example.custom.event.type
- m.room.join_rules
# Share all events of type `org.example.custom.event.typeA`
- org.example.custom.event.typeA
# Share only events of type `org.example.custom.event.typeB` whose
# state_key is "foo"
- ["org.example.custom.event.typeB", "foo"]
# Share only events of type `org.example.custom.event.typeC` whose
# state_key is "bar" or "baz"
- ["org.example.custom.event.typeC", "bar"]
- ["org.example.custom.event.typeC", "baz"]
```
*Changed in Synapse 1.74:* admins can filter the events in prejoin state based
on their state key.
---
### `track_puppeted_user_ips`

Expand Down
13 changes: 10 additions & 3 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ local_partial_types = True
no_implicit_optional = True
disallow_untyped_defs = True
strict_equality = True
warn_redundant_casts = True

files =
docker/,
Expand Down Expand Up @@ -88,6 +89,12 @@ disallow_untyped_defs = False
[mypy-tests.*]
disallow_untyped_defs = False

[mypy-tests.config.test_api]
disallow_untyped_defs = True

[mypy-tests.federation.transport.test_client]
disallow_untyped_defs = True

[mypy-tests.handlers.test_sso]
disallow_untyped_defs = True

Expand All @@ -100,7 +107,7 @@ disallow_untyped_defs = True
[mypy-tests.push.test_bulk_push_rule_evaluator]
disallow_untyped_defs = True

[mypy-tests.test_server]
[mypy-tests.rest.*]
disallow_untyped_defs = True

[mypy-tests.state.test_profile]
Expand All @@ -109,10 +116,10 @@ disallow_untyped_defs = True
[mypy-tests.storage.*]
disallow_untyped_defs = True

[mypy-tests.rest.*]
[mypy-tests.test_server]
disallow_untyped_defs = True

[mypy-tests.federation.transport.test_client]
[mypy-tests.types.*]
disallow_untyped_defs = True

[mypy-tests.util.caches.*]
Expand Down
26 changes: 4 additions & 22 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions scripts-dev/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import urllib.request
from os import path
from tempfile import TemporaryDirectory
from typing import Any, List, Optional, cast
from typing import Any, List, Optional

import attr
import click
Expand Down Expand Up @@ -174,9 +174,7 @@ def _prepare() -> None:
click.get_current_context().abort()

# Switch to the release branch.
# Cast safety: parse() won't return a version.LegacyVersion from our
# version string format.
parsed_new_version = cast(version.Version, version.parse(new_version))
parsed_new_version = version.parse(new_version)

# We assume for debian changelogs that we only do RCs or full releases.
assert not parsed_new_version.is_devrelease
Expand Down
8 changes: 6 additions & 2 deletions synapse/appservice/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,9 @@ async def is_interested_in_room(
return True

# likewise with the room's aliases (if it has any)
alias_list = await store.get_aliases_for_room(room_id)
alias_list = await store.get_aliases_for_room(
room_id, on_invalidate=cache_context.invalidate
)
for alias in alias_list:
if self.is_room_alias_in_namespace(alias):
return True
Expand Down Expand Up @@ -311,7 +313,9 @@ async def is_interested_in_presence(
# Find all the rooms the sender is in
if self.is_interested_in_user(user_id.to_string()):
return True
room_ids = await store.get_rooms_for_user(user_id.to_string())
room_ids = await store.get_rooms_for_user(
user_id.to_string(), on_invalidate=cache_context.invalidate
)

# Then find out if the appservice is interested in any of those rooms
for room_id in room_ids:
Expand Down
3 changes: 3 additions & 0 deletions synapse/config/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ def validate_config(
config: the configuration value to be validated
config_path: the path within the config file. This will be used as a basis
for the error message.
Raises:
ConfigError, if validation fails.
"""
try:
jsonschema.validate(config, json_schema)
Expand Down
63 changes: 42 additions & 21 deletions synapse/config/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,34 @@
# limitations under the License.

import logging
from typing import Any, Iterable
from typing import Any, Iterable, Optional, Tuple

from synapse.api.constants import EventTypes
from synapse.config._base import Config, ConfigError
from synapse.config._util import validate_config
from synapse.types import JsonDict
from synapse.types.state import StateFilter

logger = logging.getLogger(__name__)


class ApiConfig(Config):
section = "api"

room_prejoin_state: StateFilter
track_puppetted_users_ips: bool

def read_config(self, config: JsonDict, **kwargs: Any) -> None:
validate_config(_MAIN_SCHEMA, config, ())
self.room_prejoin_state = list(self._get_prejoin_state_types(config))
self.room_prejoin_state = StateFilter.from_types(
self._get_prejoin_state_entries(config)
)
self.track_puppeted_user_ips = config.get("track_puppeted_user_ips", False)

def _get_prejoin_state_types(self, config: JsonDict) -> Iterable[str]:
"""Get the event types to include in the prejoin state
Parses the config and returns an iterable of the event types to be included.
"""
def _get_prejoin_state_entries(
self, config: JsonDict
) -> Iterable[Tuple[str, Optional[str]]]:
"""Get the event types and state keys to include in the prejoin state."""
room_prejoin_state_config = config.get("room_prejoin_state") or {}

# backwards-compatibility support for room_invite_state_types
Expand All @@ -50,33 +55,39 @@ def _get_prejoin_state_types(self, config: JsonDict) -> Iterable[str]:

logger.warning(_ROOM_INVITE_STATE_TYPES_WARNING)

yield from config["room_invite_state_types"]
for event_type in config["room_invite_state_types"]:
yield event_type, None
return

if not room_prejoin_state_config.get("disable_default_event_types"):
yield from _DEFAULT_PREJOIN_STATE_TYPES
yield from _DEFAULT_PREJOIN_STATE_TYPES_AND_STATE_KEYS

yield from room_prejoin_state_config.get("additional_event_types", [])
for entry in room_prejoin_state_config.get("additional_event_types", []):
if isinstance(entry, str):
yield entry, None
else:
yield entry


_ROOM_INVITE_STATE_TYPES_WARNING = """\
WARNING: The 'room_invite_state_types' configuration setting is now deprecated,
and replaced with 'room_prejoin_state'. New features may not work correctly
unless 'room_invite_state_types' is removed. See the sample configuration file for
details of 'room_prejoin_state'.
unless 'room_invite_state_types' is removed. See the config documentation at
https://matrix-org.github.io/synapse/latest/usage/configuration/config_documentation.html#room_prejoin_state
for details of 'room_prejoin_state'.
--------------------------------------------------------------------------------
"""

_DEFAULT_PREJOIN_STATE_TYPES = [
EventTypes.JoinRules,
EventTypes.CanonicalAlias,
EventTypes.RoomAvatar,
EventTypes.RoomEncryption,
EventTypes.Name,
_DEFAULT_PREJOIN_STATE_TYPES_AND_STATE_KEYS = [
(EventTypes.JoinRules, ""),
(EventTypes.CanonicalAlias, ""),
(EventTypes.RoomAvatar, ""),
(EventTypes.RoomEncryption, ""),
(EventTypes.Name, ""),
# Per MSC1772.
EventTypes.Create,
(EventTypes.Create, ""),
# Per MSC3173.
EventTypes.Topic,
(EventTypes.Topic, ""),
]


Expand All @@ -90,7 +101,17 @@ def _get_prejoin_state_types(self, config: JsonDict) -> Iterable[str]:
"disable_default_event_types": {"type": "boolean"},
"additional_event_types": {
"type": "array",
"items": {"type": "string"},
"items": {
"oneOf": [
{"type": "string"},
{
"type": "array",
"items": {"type": "string"},
"minItems": 2,
"maxItems": 2,
},
],
},
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion synapse/events/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
from synapse.events import EventBase, _EventInternalMetadata, make_event_from_dict
from synapse.state import StateHandler
from synapse.storage.databases.main import DataStore
from synapse.storage.state import StateFilter
from synapse.types import EventID, JsonDict
from synapse.types.state import StateFilter
from synapse.util import Clock
from synapse.util.stringutils import random_string

Expand Down
2 changes: 1 addition & 1 deletion synapse/events/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
if TYPE_CHECKING:
from synapse.storage.controllers import StorageControllers
from synapse.storage.databases.main import DataStore
from synapse.storage.state import StateFilter
from synapse.types.state import StateFilter


@attr.s(slots=True, auto_attribs=True)
Expand Down
Loading

0 comments on commit 0d283e4

Please sign in to comment.