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

Commit 86cf6a3

Browse files
authored
Remove references to unstable identifiers from MSC3440. (#12382)
Removes references to unstable thread relation, unstable identifiers for filtering parameters, and the experimental config flag.
1 parent 1783156 commit 86cf6a3

File tree

11 files changed

+21
-98
lines changed

11 files changed

+21
-98
lines changed

changelog.d/12382.removal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove unstable identifiers from [MSC3440](https://github.com/matrix-org/matrix-doc/pull/3440).

synapse/api/constants.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,6 @@ class RelationTypes:
179179
REPLACE: Final = "m.replace"
180180
REFERENCE: Final = "m.reference"
181181
THREAD: Final = "m.thread"
182-
# TODO Remove this in Synapse >= v1.57.0.
183-
UNSTABLE_THREAD: Final = "io.element.thread"
184182

185183

186184
class LimitBlockingTypes:

synapse/api/filtering.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,7 @@
8989
"org.matrix.not_labels": {"type": "array", "items": {"type": "string"}},
9090
# MSC3440, filtering by event relations.
9191
"related_by_senders": {"type": "array", "items": {"type": "string"}},
92-
"io.element.relation_senders": {"type": "array", "items": {"type": "string"}},
9392
"related_by_rel_types": {"type": "array", "items": {"type": "string"}},
94-
"io.element.relation_types": {"type": "array", "items": {"type": "string"}},
9593
},
9694
}
9795

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

326-
# Fallback to the unstable prefix if the stable version is not given.
327-
if hs.config.experimental.msc3440_enabled:
328-
self.related_by_senders = self.related_by_senders or self.filter_json.get(
329-
"io.element.relation_senders", None
330-
)
331-
self.related_by_rel_types = (
332-
self.related_by_rel_types
333-
or self.filter_json.get("io.element.relation_types", None)
334-
)
335-
336324
def filters_all_types(self) -> bool:
337325
return "*" in self.not_types
338326

synapse/config/experimental.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ class ExperimentalConfig(Config):
2626
def read_config(self, config: JsonDict, **kwargs: Any) -> None:
2727
experimental = config.get("experimental_features") or {}
2828

29-
# MSC3440 (thread relation)
30-
self.msc3440_enabled: bool = experimental.get("msc3440_enabled", False)
31-
3229
# MSC3026 (busy presence state)
3330
self.msc3026_enabled: bool = experimental.get("msc3026_enabled", False)
3431

synapse/events/utils.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939

4040
if TYPE_CHECKING:
4141
from synapse.handlers.relations import BundledAggregations
42-
from synapse.server import HomeServer
4342

4443

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

399-
def __init__(self, hs: "HomeServer"):
400-
self._msc3440_enabled = hs.config.experimental.msc3440_enabled
401-
402398
def serialize_event(
403399
self,
404400
event: Union[JsonDict, EventBase],
@@ -525,8 +521,6 @@ def _inject_bundled_aggregations(
525521
"current_user_participated": thread.current_user_participated,
526522
}
527523
serialized_aggregations[RelationTypes.THREAD] = thread_summary
528-
if self._msc3440_enabled:
529-
serialized_aggregations[RelationTypes.UNSTABLE_THREAD] = thread_summary
530524

531525
# Include the bundled aggregations in the event.
532526
if serialized_aggregations:

synapse/handlers/message.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,10 +1102,7 @@ async def _validate_event_relation(self, event: EventBase) -> None:
11021102
raise SynapseError(400, "Can't send same reaction twice")
11031103

11041104
# Don't attempt to start a thread if the parent event is a relation.
1105-
elif (
1106-
relation_type == RelationTypes.THREAD
1107-
or relation_type == RelationTypes.UNSTABLE_THREAD
1108-
):
1105+
elif relation_type == RelationTypes.THREAD:
11091106
if await self.store.event_includes_relation(relates_to):
11101107
raise SynapseError(
11111108
400, "Cannot start threads from an event with a relation"

synapse/rest/client/versions.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ def on_GET(self, request: Request) -> Tuple[int, JsonDict]:
100100
# Adds support for jump to date endpoints (/timestamp_to_event) as per MSC3030
101101
"org.matrix.msc3030": self.config.experimental.msc3030_enabled,
102102
# Adds support for thread relations, per MSC3440.
103-
"org.matrix.msc3440": self.config.experimental.msc3440_enabled,
104103
"org.matrix.msc3440.stable": True, # TODO: remove when "v1.3" is added above
105104
},
106105
},

synapse/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ def get_oidc_handler(self) -> "OidcHandler":
758758

759759
@cache_in_self
760760
def get_event_client_serializer(self) -> EventClientSerializer:
761-
return EventClientSerializer(self)
761+
return EventClientSerializer()
762762

763763
@cache_in_self
764764
def get_password_policy_handler(self) -> PasswordPolicyHandler:

synapse/storage/databases/main/events.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,10 +1819,7 @@ def _handle_event_relations(
18191819
if rel_type == RelationTypes.REPLACE:
18201820
txn.call_after(self.store.get_applicable_edit.invalidate, (parent_id,))
18211821

1822-
if (
1823-
rel_type == RelationTypes.THREAD
1824-
or rel_type == RelationTypes.UNSTABLE_THREAD
1825-
):
1822+
if rel_type == RelationTypes.THREAD:
18261823
txn.call_after(self.store.get_thread_summary.invalidate, (parent_id,))
18271824
# It should be safe to only invalidate the cache if the user has not
18281825
# previously participated in the thread, but that's difficult (and

synapse/storage/databases/main/relations.py

Lines changed: 16 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import logging
1616
from typing import (
17-
TYPE_CHECKING,
1817
Collection,
1918
Dict,
2019
FrozenSet,
@@ -32,20 +31,12 @@
3231
from synapse.api.constants import RelationTypes
3332
from synapse.events import EventBase
3433
from synapse.storage._base import SQLBaseStore
35-
from synapse.storage.database import (
36-
DatabasePool,
37-
LoggingDatabaseConnection,
38-
LoggingTransaction,
39-
make_in_list_sql_clause,
40-
)
34+
from synapse.storage.database import LoggingTransaction, make_in_list_sql_clause
4135
from synapse.storage.databases.main.stream import generate_pagination_where_clause
4236
from synapse.storage.engines import PostgresEngine
4337
from synapse.types import JsonDict, RoomStreamToken, StreamToken
4438
from synapse.util.caches.descriptors import cached, cachedList
4539

46-
if TYPE_CHECKING:
47-
from synapse.server import HomeServer
48-
4940
logger = logging.getLogger(__name__)
5041

5142

@@ -63,16 +54,6 @@ class _RelatedEvent:
6354

6455

6556
class RelationsWorkerStore(SQLBaseStore):
66-
def __init__(
67-
self,
68-
database: DatabasePool,
69-
db_conn: LoggingDatabaseConnection,
70-
hs: "HomeServer",
71-
):
72-
super().__init__(database, db_conn, hs)
73-
74-
self._msc3440_enabled = hs.config.experimental.msc3440_enabled
75-
7657
@cached(uncached_args=("event",), tree=True)
7758
async def get_relations_for_event(
7859
self,
@@ -497,7 +478,7 @@ def _get_thread_summaries_txn(
497478
AND parent.room_id = child.room_id
498479
WHERE
499480
%s
500-
AND %s
481+
AND relation_type = ?
501482
ORDER BY parent.event_id, child.topological_ordering DESC, child.stream_ordering DESC
502483
"""
503484
else:
@@ -512,22 +493,16 @@ def _get_thread_summaries_txn(
512493
AND parent.room_id = child.room_id
513494
WHERE
514495
%s
515-
AND %s
496+
AND relation_type = ?
516497
ORDER BY child.topological_ordering DESC, child.stream_ordering DESC
517498
"""
518499

519500
clause, args = make_in_list_sql_clause(
520501
txn.database_engine, "relates_to_id", event_ids
521502
)
503+
args.append(RelationTypes.THREAD)
522504

523-
if self._msc3440_enabled:
524-
relations_clause = "(relation_type = ? OR relation_type = ?)"
525-
args.extend((RelationTypes.THREAD, RelationTypes.UNSTABLE_THREAD))
526-
else:
527-
relations_clause = "relation_type = ?"
528-
args.append(RelationTypes.THREAD)
529-
530-
txn.execute(sql % (clause, relations_clause), args)
505+
txn.execute(sql % (clause,), args)
531506
latest_event_ids = {}
532507
for parent_event_id, child_event_id in txn:
533508
# Only consider the latest threaded reply (by topological ordering).
@@ -547,7 +522,7 @@ def _get_thread_summaries_txn(
547522
AND parent.room_id = child.room_id
548523
WHERE
549524
%s
550-
AND %s
525+
AND relation_type = ?
551526
GROUP BY parent.event_id
552527
"""
553528

@@ -556,15 +531,9 @@ def _get_thread_summaries_txn(
556531
clause, args = make_in_list_sql_clause(
557532
txn.database_engine, "relates_to_id", latest_event_ids.keys()
558533
)
534+
args.append(RelationTypes.THREAD)
559535

560-
if self._msc3440_enabled:
561-
relations_clause = "(relation_type = ? OR relation_type = ?)"
562-
args.extend((RelationTypes.THREAD, RelationTypes.UNSTABLE_THREAD))
563-
else:
564-
relations_clause = "relation_type = ?"
565-
args.append(RelationTypes.THREAD)
566-
567-
txn.execute(sql % (clause, relations_clause), args)
536+
txn.execute(sql % (clause,), args)
568537
counts = dict(cast(List[Tuple[str, int]], txn.fetchall()))
569538

570539
return counts, latest_event_ids
@@ -622,7 +591,7 @@ async def get_threaded_messages_per_user(
622591
parent.event_id = relates_to_id
623592
AND parent.room_id = child.room_id
624593
WHERE
625-
%s
594+
relation_type = ?
626595
AND %s
627596
AND %s
628597
GROUP BY parent.event_id, child.sender
@@ -638,16 +607,9 @@ def _get_threaded_messages_per_user_txn(
638607
txn.database_engine, "relates_to_id", event_ids
639608
)
640609

641-
if self._msc3440_enabled:
642-
relations_clause = "(relation_type = ? OR relation_type = ?)"
643-
relations_args = [RelationTypes.THREAD, RelationTypes.UNSTABLE_THREAD]
644-
else:
645-
relations_clause = "relation_type = ?"
646-
relations_args = [RelationTypes.THREAD]
647-
648610
txn.execute(
649-
sql % (users_sql, events_clause, relations_clause),
650-
users_args + events_args + relations_args,
611+
sql % (users_sql, events_clause),
612+
[RelationTypes.THREAD] + users_args + events_args,
651613
)
652614
return {(row[0], row[1]): row[2] for row in txn}
653615

@@ -677,7 +639,7 @@ async def get_threads_participated(
677639
user participated in that event's thread, otherwise false.
678640
"""
679641

680-
def _get_thread_summary_txn(txn: LoggingTransaction) -> Set[str]:
642+
def _get_threads_participated_txn(txn: LoggingTransaction) -> Set[str]:
681643
# Fetch whether the requester has participated or not.
682644
sql = """
683645
SELECT DISTINCT relates_to_id
@@ -688,28 +650,20 @@ def _get_thread_summary_txn(txn: LoggingTransaction) -> Set[str]:
688650
AND parent.room_id = child.room_id
689651
WHERE
690652
%s
691-
AND %s
653+
AND relation_type = ?
692654
AND child.sender = ?
693655
"""
694656

695657
clause, args = make_in_list_sql_clause(
696658
txn.database_engine, "relates_to_id", event_ids
697659
)
660+
args.extend([RelationTypes.THREAD, user_id])
698661

699-
if self._msc3440_enabled:
700-
relations_clause = "(relation_type = ? OR relation_type = ?)"
701-
args.extend((RelationTypes.THREAD, RelationTypes.UNSTABLE_THREAD))
702-
else:
703-
relations_clause = "relation_type = ?"
704-
args.append(RelationTypes.THREAD)
705-
706-
args.append(user_id)
707-
708-
txn.execute(sql % (clause, relations_clause), args)
662+
txn.execute(sql % (clause,), args)
709663
return {row[0] for row in txn.fetchall()}
710664

711665
participated_threads = await self.db_pool.runInteraction(
712-
"get_thread_summary", _get_thread_summary_txn
666+
"get_threads_participated", _get_threads_participated_txn
713667
)
714668

715669
return {event_id: event_id in participated_threads for event_id in event_ids}

0 commit comments

Comments
 (0)