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

Return the main timeline for events which are not part of a thread. #14140

Merged
merged 2 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/14140.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Support for thread-specific notifications & receipts ([MSC3771](https://github.com/matrix-org/matrix-spec-proposals/pull/3771) and [MSC3773](https://github.com/matrix-org/matrix-spec-proposals/pull/3773)).
2 changes: 1 addition & 1 deletion synapse/push/bulk_push_rule_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ async def action_for_event_by_user(
else:
# Since the event has not yet been persisted we check whether
# the parent is part of a thread.
thread_id = await self.store.get_thread_id(relation.parent_id) or "main"
thread_id = await self.store.get_thread_id(relation.parent_id)

# It's possible that old room versions have non-integer power levels (floats or
# strings). Workaround this by explicitly converting to int.
Expand Down
12 changes: 7 additions & 5 deletions synapse/storage/databases/main/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

import attr

from synapse.api.constants import RelationTypes
from synapse.api.constants import MAIN_TIMELINE, RelationTypes
from synapse.events import EventBase
from synapse.storage._base import SQLBaseStore
from synapse.storage.database import LoggingTransaction, make_in_list_sql_clause
Expand Down Expand Up @@ -830,7 +830,7 @@ def _get_event_relations(
)

@cached()
async def get_thread_id(self, event_id: str) -> Optional[str]:
async def get_thread_id(self, event_id: str) -> str:
"""
Get the thread ID for an event. This considers multi-level relations,
e.g. an annotation to an event which is part of a thread.
Expand All @@ -840,7 +840,7 @@ async def get_thread_id(self, event_id: str) -> Optional[str]:

Returns:
The event ID of the root event in the thread, if this event is part
of a thread. None, otherwise.
of a thread. "main", otherwise.
"""
# Since event relations form a tree, we should only ever find 0 or 1
# results from the below query.
Expand All @@ -855,13 +855,15 @@ async def get_thread_id(self, event_id: str) -> Optional[str]:
) SELECT relates_to_id FROM related_events WHERE relation_type = 'm.thread';
"""

def _get_thread_id(txn: LoggingTransaction) -> Optional[str]:
def _get_thread_id(txn: LoggingTransaction) -> str:
txn.execute(sql, (event_id,))
# TODO Should we ensure there's only a single result here?
row = txn.fetchone()
if row:
return row[0]
return None

# If no thread was found, it is part of the main timeline.
return MAIN_TIMELINE

return await self.db_pool.runInteraction("get_thread_id", _get_thread_id)

Expand Down