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

Commit

Permalink
Remove references to unstable identifiers from MSC3440. (#12382)
Browse files Browse the repository at this point in the history
Removes references to unstable thread relation, unstable
identifiers for filtering parameters, and the experimental
config flag.
  • Loading branch information
clokep committed Apr 12, 2022
1 parent 1783156 commit 86cf6a3
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 98 deletions.
1 change: 1 addition & 0 deletions changelog.d/12382.removal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove unstable identifiers from [MSC3440](https://github.com/matrix-org/matrix-doc/pull/3440).
2 changes: 0 additions & 2 deletions synapse/api/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,6 @@ class RelationTypes:
REPLACE: Final = "m.replace"
REFERENCE: Final = "m.reference"
THREAD: Final = "m.thread"
# TODO Remove this in Synapse >= v1.57.0.
UNSTABLE_THREAD: Final = "io.element.thread"


class LimitBlockingTypes:
Expand Down
12 changes: 0 additions & 12 deletions synapse/api/filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@
"org.matrix.not_labels": {"type": "array", "items": {"type": "string"}},
# MSC3440, filtering by event relations.
"related_by_senders": {"type": "array", "items": {"type": "string"}},
"io.element.relation_senders": {"type": "array", "items": {"type": "string"}},
"related_by_rel_types": {"type": "array", "items": {"type": "string"}},
"io.element.relation_types": {"type": "array", "items": {"type": "string"}},
},
}

Expand Down Expand Up @@ -323,16 +321,6 @@ def __init__(self, hs: "HomeServer", filter_json: JsonDict):
self.related_by_senders = self.filter_json.get("related_by_senders", None)
self.related_by_rel_types = self.filter_json.get("related_by_rel_types", None)

# Fallback to the unstable prefix if the stable version is not given.
if hs.config.experimental.msc3440_enabled:
self.related_by_senders = self.related_by_senders or self.filter_json.get(
"io.element.relation_senders", None
)
self.related_by_rel_types = (
self.related_by_rel_types
or self.filter_json.get("io.element.relation_types", None)
)

def filters_all_types(self) -> bool:
return "*" in self.not_types

Expand Down
3 changes: 0 additions & 3 deletions synapse/config/experimental.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ class ExperimentalConfig(Config):
def read_config(self, config: JsonDict, **kwargs: Any) -> None:
experimental = config.get("experimental_features") or {}

# MSC3440 (thread relation)
self.msc3440_enabled: bool = experimental.get("msc3440_enabled", False)

# MSC3026 (busy presence state)
self.msc3026_enabled: bool = experimental.get("msc3026_enabled", False)

Expand Down
6 changes: 0 additions & 6 deletions synapse/events/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@

if TYPE_CHECKING:
from synapse.handlers.relations import BundledAggregations
from synapse.server import HomeServer


# Split strings on "." but not "\." This uses a negative lookbehind assertion for '\'
Expand Down Expand Up @@ -396,9 +395,6 @@ class EventClientSerializer:
clients.
"""

def __init__(self, hs: "HomeServer"):
self._msc3440_enabled = hs.config.experimental.msc3440_enabled

def serialize_event(
self,
event: Union[JsonDict, EventBase],
Expand Down Expand Up @@ -525,8 +521,6 @@ def _inject_bundled_aggregations(
"current_user_participated": thread.current_user_participated,
}
serialized_aggregations[RelationTypes.THREAD] = thread_summary
if self._msc3440_enabled:
serialized_aggregations[RelationTypes.UNSTABLE_THREAD] = thread_summary

# Include the bundled aggregations in the event.
if serialized_aggregations:
Expand Down
5 changes: 1 addition & 4 deletions synapse/handlers/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -1102,10 +1102,7 @@ async def _validate_event_relation(self, event: EventBase) -> None:
raise SynapseError(400, "Can't send same reaction twice")

# Don't attempt to start a thread if the parent event is a relation.
elif (
relation_type == RelationTypes.THREAD
or relation_type == RelationTypes.UNSTABLE_THREAD
):
elif relation_type == RelationTypes.THREAD:
if await self.store.event_includes_relation(relates_to):
raise SynapseError(
400, "Cannot start threads from an event with a relation"
Expand Down
1 change: 0 additions & 1 deletion synapse/rest/client/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ def on_GET(self, request: Request) -> Tuple[int, JsonDict]:
# Adds support for jump to date endpoints (/timestamp_to_event) as per MSC3030
"org.matrix.msc3030": self.config.experimental.msc3030_enabled,
# Adds support for thread relations, per MSC3440.
"org.matrix.msc3440": self.config.experimental.msc3440_enabled,
"org.matrix.msc3440.stable": True, # TODO: remove when "v1.3" is added above
},
},
Expand Down
2 changes: 1 addition & 1 deletion synapse/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ def get_oidc_handler(self) -> "OidcHandler":

@cache_in_self
def get_event_client_serializer(self) -> EventClientSerializer:
return EventClientSerializer(self)
return EventClientSerializer()

@cache_in_self
def get_password_policy_handler(self) -> PasswordPolicyHandler:
Expand Down
5 changes: 1 addition & 4 deletions synapse/storage/databases/main/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -1819,10 +1819,7 @@ def _handle_event_relations(
if rel_type == RelationTypes.REPLACE:
txn.call_after(self.store.get_applicable_edit.invalidate, (parent_id,))

if (
rel_type == RelationTypes.THREAD
or rel_type == RelationTypes.UNSTABLE_THREAD
):
if rel_type == RelationTypes.THREAD:
txn.call_after(self.store.get_thread_summary.invalidate, (parent_id,))
# It should be safe to only invalidate the cache if the user has not
# previously participated in the thread, but that's difficult (and
Expand Down
78 changes: 16 additions & 62 deletions synapse/storage/databases/main/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import logging
from typing import (
TYPE_CHECKING,
Collection,
Dict,
FrozenSet,
Expand All @@ -32,20 +31,12 @@
from synapse.api.constants import RelationTypes
from synapse.events import EventBase
from synapse.storage._base import SQLBaseStore
from synapse.storage.database import (
DatabasePool,
LoggingDatabaseConnection,
LoggingTransaction,
make_in_list_sql_clause,
)
from synapse.storage.database import LoggingTransaction, make_in_list_sql_clause
from synapse.storage.databases.main.stream import generate_pagination_where_clause
from synapse.storage.engines import PostgresEngine
from synapse.types import JsonDict, RoomStreamToken, StreamToken
from synapse.util.caches.descriptors import cached, cachedList

if TYPE_CHECKING:
from synapse.server import HomeServer

logger = logging.getLogger(__name__)


Expand All @@ -63,16 +54,6 @@ class _RelatedEvent:


class RelationsWorkerStore(SQLBaseStore):
def __init__(
self,
database: DatabasePool,
db_conn: LoggingDatabaseConnection,
hs: "HomeServer",
):
super().__init__(database, db_conn, hs)

self._msc3440_enabled = hs.config.experimental.msc3440_enabled

@cached(uncached_args=("event",), tree=True)
async def get_relations_for_event(
self,
Expand Down Expand Up @@ -497,7 +478,7 @@ def _get_thread_summaries_txn(
AND parent.room_id = child.room_id
WHERE
%s
AND %s
AND relation_type = ?
ORDER BY parent.event_id, child.topological_ordering DESC, child.stream_ordering DESC
"""
else:
Expand All @@ -512,22 +493,16 @@ def _get_thread_summaries_txn(
AND parent.room_id = child.room_id
WHERE
%s
AND %s
AND relation_type = ?
ORDER BY child.topological_ordering DESC, child.stream_ordering DESC
"""

clause, args = make_in_list_sql_clause(
txn.database_engine, "relates_to_id", event_ids
)
args.append(RelationTypes.THREAD)

if self._msc3440_enabled:
relations_clause = "(relation_type = ? OR relation_type = ?)"
args.extend((RelationTypes.THREAD, RelationTypes.UNSTABLE_THREAD))
else:
relations_clause = "relation_type = ?"
args.append(RelationTypes.THREAD)

txn.execute(sql % (clause, relations_clause), args)
txn.execute(sql % (clause,), args)
latest_event_ids = {}
for parent_event_id, child_event_id in txn:
# Only consider the latest threaded reply (by topological ordering).
Expand All @@ -547,7 +522,7 @@ def _get_thread_summaries_txn(
AND parent.room_id = child.room_id
WHERE
%s
AND %s
AND relation_type = ?
GROUP BY parent.event_id
"""

Expand All @@ -556,15 +531,9 @@ def _get_thread_summaries_txn(
clause, args = make_in_list_sql_clause(
txn.database_engine, "relates_to_id", latest_event_ids.keys()
)
args.append(RelationTypes.THREAD)

if self._msc3440_enabled:
relations_clause = "(relation_type = ? OR relation_type = ?)"
args.extend((RelationTypes.THREAD, RelationTypes.UNSTABLE_THREAD))
else:
relations_clause = "relation_type = ?"
args.append(RelationTypes.THREAD)

txn.execute(sql % (clause, relations_clause), args)
txn.execute(sql % (clause,), args)
counts = dict(cast(List[Tuple[str, int]], txn.fetchall()))

return counts, latest_event_ids
Expand Down Expand Up @@ -622,7 +591,7 @@ async def get_threaded_messages_per_user(
parent.event_id = relates_to_id
AND parent.room_id = child.room_id
WHERE
%s
relation_type = ?
AND %s
AND %s
GROUP BY parent.event_id, child.sender
Expand All @@ -638,16 +607,9 @@ def _get_threaded_messages_per_user_txn(
txn.database_engine, "relates_to_id", event_ids
)

if self._msc3440_enabled:
relations_clause = "(relation_type = ? OR relation_type = ?)"
relations_args = [RelationTypes.THREAD, RelationTypes.UNSTABLE_THREAD]
else:
relations_clause = "relation_type = ?"
relations_args = [RelationTypes.THREAD]

txn.execute(
sql % (users_sql, events_clause, relations_clause),
users_args + events_args + relations_args,
sql % (users_sql, events_clause),
[RelationTypes.THREAD] + users_args + events_args,
)
return {(row[0], row[1]): row[2] for row in txn}

Expand Down Expand Up @@ -677,7 +639,7 @@ async def get_threads_participated(
user participated in that event's thread, otherwise false.
"""

def _get_thread_summary_txn(txn: LoggingTransaction) -> Set[str]:
def _get_threads_participated_txn(txn: LoggingTransaction) -> Set[str]:
# Fetch whether the requester has participated or not.
sql = """
SELECT DISTINCT relates_to_id
Expand All @@ -688,28 +650,20 @@ def _get_thread_summary_txn(txn: LoggingTransaction) -> Set[str]:
AND parent.room_id = child.room_id
WHERE
%s
AND %s
AND relation_type = ?
AND child.sender = ?
"""

clause, args = make_in_list_sql_clause(
txn.database_engine, "relates_to_id", event_ids
)
args.extend([RelationTypes.THREAD, user_id])

if self._msc3440_enabled:
relations_clause = "(relation_type = ? OR relation_type = ?)"
args.extend((RelationTypes.THREAD, RelationTypes.UNSTABLE_THREAD))
else:
relations_clause = "relation_type = ?"
args.append(RelationTypes.THREAD)

args.append(user_id)

txn.execute(sql % (clause, relations_clause), args)
txn.execute(sql % (clause,), args)
return {row[0] for row in txn.fetchall()}

participated_threads = await self.db_pool.runInteraction(
"get_thread_summary", _get_thread_summary_txn
"get_threads_participated", _get_threads_participated_txn
)

return {event_id: event_id in participated_threads for event_id in event_ids}
Expand Down
4 changes: 1 addition & 3 deletions tests/api/test_filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,9 +481,7 @@ def test_filter_relations(self):
# events). This is a bit cheeky, but tests the logic of _check_event_relations.

# Filter for a particular sender.
definition = {
"io.element.relation_senders": ["@foo:bar"],
}
definition = {"related_by_senders": ["@foo:bar"]}

async def events_have_relations(*args, **kwargs):
return ["$with_relation"]
Expand Down

0 comments on commit 86cf6a3

Please sign in to comment.