Use `private` instead of `hidden` in MSC2285 related code. (#12635)

This commit is contained in:
Šimon Brandner 2022-05-05 14:31:25 +02:00 committed by GitHub
parent f90d381c7b
commit 9ae0253f4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 26 additions and 25 deletions

View File

@ -0,0 +1 @@
Implement [changes](https://github.com/matrix-org/matrix-spec-proposals/pull/2285/commits/4a77139249c2e830aec3c7d6bd5501a514d1cc27) to [MSC2285 (hidden read receipts)](https://github.com/matrix-org/matrix-spec-proposals/pull/2285). Contributed by @SimonBrandner.

View File

@ -32,7 +32,7 @@ class ExperimentalConfig(Config):
# MSC2716 (importing historical messages) # MSC2716 (importing historical messages)
self.msc2716_enabled: bool = experimental.get("msc2716_enabled", False) self.msc2716_enabled: bool = experimental.get("msc2716_enabled", False)
# MSC2285 (hidden read receipts) # MSC2285 (private read receipts)
self.msc2285_enabled: bool = experimental.get("msc2285_enabled", False) self.msc2285_enabled: bool = experimental.get("msc2285_enabled", False)
# MSC3244 (room version capabilities) # MSC3244 (room version capabilities)

View File

@ -143,7 +143,7 @@ class InitialSyncHandler:
to_key=int(now_token.receipt_key), to_key=int(now_token.receipt_key),
) )
if self.hs.config.experimental.msc2285_enabled: if self.hs.config.experimental.msc2285_enabled:
receipt = ReceiptEventSource.filter_out_hidden(receipt, user_id) receipt = ReceiptEventSource.filter_out_private(receipt, user_id)
tags_by_room = await self.store.get_tags_for_user(user_id) tags_by_room = await self.store.get_tags_for_user(user_id)
@ -449,7 +449,7 @@ class InitialSyncHandler:
if not receipts: if not receipts:
return [] return []
if self.hs.config.experimental.msc2285_enabled: if self.hs.config.experimental.msc2285_enabled:
receipts = ReceiptEventSource.filter_out_hidden(receipts, user_id) receipts = ReceiptEventSource.filter_out_private(receipts, user_id)
return receipts return receipts
presence, receipts, (messages, token) = await make_deferred_yieldable( presence, receipts, (messages, token) = await make_deferred_yieldable(

View File

@ -165,7 +165,7 @@ class ReceiptEventSource(EventSource[int, JsonDict]):
self.config = hs.config self.config = hs.config
@staticmethod @staticmethod
def filter_out_hidden(events: List[JsonDict], user_id: str) -> List[JsonDict]: def filter_out_private(events: List[JsonDict], user_id: str) -> List[JsonDict]:
""" """
This method takes in what is returned by This method takes in what is returned by
get_linearized_receipts_for_rooms() and goes through read receipts get_linearized_receipts_for_rooms() and goes through read receipts
@ -175,7 +175,7 @@ class ReceiptEventSource(EventSource[int, JsonDict]):
visible_events = [] visible_events = []
# filter out hidden receipts the user shouldn't see # filter out private receipts the user shouldn't see
for event in events: for event in events:
content = event.get("content", {}) content = event.get("content", {})
new_event = event.copy() new_event = event.copy()
@ -223,7 +223,7 @@ class ReceiptEventSource(EventSource[int, JsonDict]):
) )
if self.config.experimental.msc2285_enabled: if self.config.experimental.msc2285_enabled:
events = ReceiptEventSource.filter_out_hidden(events, user.to_string()) events = ReceiptEventSource.filter_out_private(events, user.to_string())
return events, to_key return events, to_key

View File

@ -93,7 +93,7 @@ class VersionsRestServlet(RestServlet):
"io.element.e2ee_forced.trusted_private": self.e2ee_forced_trusted_private, "io.element.e2ee_forced.trusted_private": self.e2ee_forced_trusted_private,
# Supports the busy presence state described in MSC3026. # Supports the busy presence state described in MSC3026.
"org.matrix.msc3026.busy_presence": self.config.experimental.msc3026_enabled, "org.matrix.msc3026.busy_presence": self.config.experimental.msc3026_enabled,
# Supports receiving hidden read receipts as per MSC2285 # Supports receiving private read receipts as per MSC2285
"org.matrix.msc2285": self.config.experimental.msc2285_enabled, "org.matrix.msc2285": self.config.experimental.msc2285_enabled,
# Adds support for importing historical messages as per MSC2716 # Adds support for importing historical messages as per MSC2716
"org.matrix.msc2716": self.config.experimental.msc2716_enabled, "org.matrix.msc2716": self.config.experimental.msc2716_enabled,

View File

@ -25,8 +25,8 @@ class ReceiptsTestCase(unittest.HomeserverTestCase):
def prepare(self, reactor, clock, hs): def prepare(self, reactor, clock, hs):
self.event_source = hs.get_event_sources().sources.receipt self.event_source = hs.get_event_sources().sources.receipt
def test_filters_out_hidden_receipt(self): def test_filters_out_private_receipt(self):
self._test_filters_hidden( self._test_filters_private(
[ [
{ {
"content": { "content": {
@ -45,8 +45,8 @@ class ReceiptsTestCase(unittest.HomeserverTestCase):
[], [],
) )
def test_filters_out_hidden_receipt_and_ignores_rest(self): def test_filters_out_private_receipt_and_ignores_rest(self):
self._test_filters_hidden( self._test_filters_private(
[ [
{ {
"content": { "content": {
@ -84,8 +84,8 @@ class ReceiptsTestCase(unittest.HomeserverTestCase):
], ],
) )
def test_filters_out_event_with_only_hidden_receipts_and_ignores_the_rest(self): def test_filters_out_event_with_only_private_receipts_and_ignores_the_rest(self):
self._test_filters_hidden( self._test_filters_private(
[ [
{ {
"content": { "content": {
@ -126,7 +126,7 @@ class ReceiptsTestCase(unittest.HomeserverTestCase):
) )
def test_handles_missing_content_of_m_read(self): def test_handles_missing_content_of_m_read(self):
self._test_filters_hidden( self._test_filters_private(
[ [
{ {
"content": { "content": {
@ -162,7 +162,7 @@ class ReceiptsTestCase(unittest.HomeserverTestCase):
) )
def test_handles_empty_event(self): def test_handles_empty_event(self):
self._test_filters_hidden( self._test_filters_private(
[ [
{ {
"content": { "content": {
@ -196,8 +196,8 @@ class ReceiptsTestCase(unittest.HomeserverTestCase):
], ],
) )
def test_filters_out_receipt_event_with_only_hidden_receipt_and_ignores_rest(self): def test_filters_out_receipt_event_with_only_private_receipt_and_ignores_rest(self):
self._test_filters_hidden( self._test_filters_private(
[ [
{ {
"content": { "content": {
@ -249,7 +249,7 @@ class ReceiptsTestCase(unittest.HomeserverTestCase):
Context: https://github.com/matrix-org/synapse/issues/10603 Context: https://github.com/matrix-org/synapse/issues/10603
""" """
self._test_filters_hidden( self._test_filters_private(
[ [
{ {
"content": { "content": {
@ -278,8 +278,8 @@ class ReceiptsTestCase(unittest.HomeserverTestCase):
], ],
) )
def test_leaves_our_hidden_and_their_public(self): def test_leaves_our_private_and_their_public(self):
self._test_filters_hidden( self._test_filters_private(
[ [
{ {
"content": { "content": {
@ -332,9 +332,9 @@ class ReceiptsTestCase(unittest.HomeserverTestCase):
], ],
) )
def _test_filters_hidden( def _test_filters_private(
self, events: List[JsonDict], expected_output: List[JsonDict] self, events: List[JsonDict], expected_output: List[JsonDict]
): ):
"""Tests that the _filter_out_hidden returns the expected output""" """Tests that the _filter_out_private returns the expected output"""
filtered_events = self.event_source.filter_out_hidden(events, "@me:server.org") filtered_events = self.event_source.filter_out_private(events, "@me:server.org")
self.assertEqual(filtered_events, expected_output) self.assertEqual(filtered_events, expected_output)

View File

@ -407,7 +407,7 @@ class ReadReceiptsTestCase(unittest.HomeserverTestCase):
self.helper.join(room=self.room_id, user=self.user2, tok=self.tok2) self.helper.join(room=self.room_id, user=self.user2, tok=self.tok2)
@override_config({"experimental_features": {"msc2285_enabled": True}}) @override_config({"experimental_features": {"msc2285_enabled": True}})
def test_hidden_read_receipts(self) -> None: def test_private_read_receipts(self) -> None:
# Send a message as the first user # Send a message as the first user
res = self.helper.send(self.room_id, body="hello", tok=self.tok) res = self.helper.send(self.room_id, body="hello", tok=self.tok)
@ -639,7 +639,7 @@ class UnreadMessagesTestCase(unittest.HomeserverTestCase):
# Check that the unread counter is back to 0. # Check that the unread counter is back to 0.
self._check_unread_count(0) self._check_unread_count(0)
# Check that hidden read receipts don't break unread counts # Check that private read receipts don't break unread counts
res = self.helper.send(self.room_id, "hello", tok=self.tok2) res = self.helper.send(self.room_id, "hello", tok=self.tok2)
self._check_unread_count(1) self._check_unread_count(1)