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

Commit

Permalink
Switch to stable prefixes for MSC2285
Browse files Browse the repository at this point in the history
Signed-off-by: Šimon Brandner <[email protected]>
  • Loading branch information
SimonBrandner committed Jul 14, 2022
1 parent 13e359a commit b808bf6
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 35 deletions.
2 changes: 1 addition & 1 deletion synapse/api/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ class GuestAccess:

class ReceiptTypes:
READ: Final = "m.read"
READ_PRIVATE: Final = "org.matrix.msc2285.read.private"
READ_PRIVATE: Final = "m.read.private"
FULLY_READ: Final = "m.fully_read"


Expand Down
3 changes: 0 additions & 3 deletions synapse/config/experimental.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:
# MSC2716 (importing historical messages)
self.msc2716_enabled: bool = experimental.get("msc2716_enabled", False)

# MSC2285 (private read receipts)
self.msc2285_enabled: bool = experimental.get("msc2285_enabled", False)

# MSC3244 (room version capabilities)
self.msc3244_enabled: bool = experimental.get("msc3244_enabled", True)

Expand Down
11 changes: 4 additions & 7 deletions synapse/handlers/initial_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ async def _snapshot_all_rooms(
joined_rooms,
to_key=int(now_token.receipt_key),
)
if self.hs.config.experimental.msc2285_enabled:
receipt = ReceiptEventSource.filter_out_private_receipts(receipt, user_id)

receipt = ReceiptEventSource.filter_out_private_receipts(receipt, user_id)

tags_by_room = await self.store.get_tags_for_user(user_id)

Expand Down Expand Up @@ -456,11 +456,8 @@ async def get_receipts() -> List[JsonDict]:
)
if not receipts:
return []
if self.hs.config.experimental.msc2285_enabled:
receipts = ReceiptEventSource.filter_out_private_receipts(
receipts, user_id
)
return receipts

return ReceiptEventSource.filter_out_private_receipts(receipts, user_id)

presence, receipts, (messages, token) = await make_deferred_yieldable(
gather_results(
Expand Down
7 changes: 3 additions & 4 deletions synapse/handlers/receipts.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,9 @@ async def get_new_events(
room_ids, from_key=from_key, to_key=to_key
)

if self.config.experimental.msc2285_enabled:
events = ReceiptEventSource.filter_out_private_receipts(
events, user.to_string()
)
events = ReceiptEventSource.filter_out_private_receipts(
events, user.to_string()
)

return events, to_key

Expand Down
2 changes: 1 addition & 1 deletion synapse/rest/client/read_marker.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async def on_POST(
)

read_private_event_id = body.get(ReceiptTypes.READ_PRIVATE, None)
if read_private_event_id and self.config.experimental.msc2285_enabled:
if read_private_event_id:
await self.receipts_handler.received_client_receipt(
room_id,
ReceiptTypes.READ_PRIVATE,
Expand Down
9 changes: 2 additions & 7 deletions synapse/rest/client/receipts.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,15 @@ async def on_POST(
) -> Tuple[int, JsonDict]:
requester = await self.auth.get_user_by_req(request)

if self.hs.config.experimental.msc2285_enabled and receipt_type not in [
if receipt_type not in [
ReceiptTypes.READ,
ReceiptTypes.READ_PRIVATE,
ReceiptTypes.FULLY_READ,
]:
raise SynapseError(
400,
"Receipt type must be 'm.read', 'org.matrix.msc2285.read.private' or 'm.fully_read'",
"Receipt type must be 'm.read', 'm.read.private' or 'm.fully_read'",
)
elif (
not self.hs.config.experimental.msc2285_enabled
and receipt_type != ReceiptTypes.READ
):
raise SynapseError(400, "Receipt type must be 'm.read'")

parse_json_object_from_request(request, allow_empty_body=False)

Expand Down
2 changes: 1 addition & 1 deletion synapse/rest/client/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def on_GET(self, request: Request) -> Tuple[int, JsonDict]:
# Supports the busy presence state described in MSC3026.
"org.matrix.msc3026.busy_presence": self.config.experimental.msc3026_enabled,
# Supports receiving private read receipts as per MSC2285
"org.matrix.msc2285": self.config.experimental.msc2285_enabled,
"org.matrix.msc2285.stable": True, # TODO: Remove when MSC2285 becomes a part of the spec
# Supports filtering of /publicRooms by room type MSC3827
"org.matrix.msc3827": self.config.experimental.msc3827_enabled,
# Adds support for importing historical messages as per MSC2716
Expand Down
17 changes: 6 additions & 11 deletions tests/rest/client/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
KnockingStrippedStateEventHelperMixin,
)
from tests.server import TimedOutException
from tests.unittest import override_config


class FilterTestCase(unittest.HomeserverTestCase):
Expand Down Expand Up @@ -408,15 +407,14 @@ def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None:
# Join the second user
self.helper.join(room=self.room_id, user=self.user2, tok=self.tok2)

@override_config({"experimental_features": {"msc2285_enabled": True}})
def test_private_read_receipts(self) -> None:
# Send a message as the first user
res = self.helper.send(self.room_id, body="hello", tok=self.tok)

# Send a private read receipt to tell the server the first user's message was read
channel = self.make_request(
"POST",
f"/rooms/{self.room_id}/receipt/org.matrix.msc2285.read.private/{res['event_id']}",
f"/rooms/{self.room_id}/receipt/m.read.private/{res['event_id']}",
{},
access_token=self.tok2,
)
Expand All @@ -425,7 +423,6 @@ def test_private_read_receipts(self) -> None:
# Test that the first user can't see the other user's private read receipt
self.assertIsNone(self._get_read_receipt())

@override_config({"experimental_features": {"msc2285_enabled": True}})
def test_public_receipt_can_override_private(self) -> None:
"""
Sending a public read receipt to the same event which has a private read
Expand Down Expand Up @@ -456,7 +453,6 @@ def test_public_receipt_can_override_private(self) -> None:
# Test that we did override the private read receipt
self.assertNotEqual(self._get_read_receipt(), None)

@override_config({"experimental_features": {"msc2285_enabled": True}})
def test_private_receipt_cannot_override_public(self) -> None:
"""
Sending a private read receipt to the same event which has a public read
Expand Down Expand Up @@ -543,7 +539,6 @@ def default_config(self) -> JsonDict:
config = super().default_config()
config["experimental_features"] = {
"msc2654_enabled": True,
"msc2285_enabled": True,
}
return config

Expand Down Expand Up @@ -625,7 +620,7 @@ def test_unread_counts(self) -> None:
# Send a read receipt to tell the server we've read the latest event.
channel = self.make_request(
"POST",
f"/rooms/{self.room_id}/receipt/org.matrix.msc2285.read.private/{res['event_id']}",
f"/rooms/{self.room_id}/receipt/m.read.private/{res['event_id']}",
{},
access_token=self.tok,
)
Expand Down Expand Up @@ -701,7 +696,7 @@ def test_unread_counts(self) -> None:
self._check_unread_count(5)
res2 = self.helper.send(self.room_id, "hello", tok=self.tok2)

# Make sure both m.read and org.matrix.msc2285.read.private advance
# Make sure both m.read and m.read.private advance
channel = self.make_request(
"POST",
f"/rooms/{self.room_id}/receipt/m.read/{res1['event_id']}",
Expand All @@ -713,7 +708,7 @@ def test_unread_counts(self) -> None:

channel = self.make_request(
"POST",
f"/rooms/{self.room_id}/receipt/org.matrix.msc2285.read.private/{res2['event_id']}",
f"/rooms/{self.room_id}/receipt/m.read.private/{res2['event_id']}",
{},
access_token=self.tok,
)
Expand All @@ -740,11 +735,11 @@ def test_read_receipts_only_go_down(self, receipt_type: ReceiptTypes) -> None:
self.assertEqual(channel.code, 200, channel.json_body)
self._check_unread_count(0)

# Make sure neither m.read nor org.matrix.msc2285.read.private make the
# Make sure neither m.read nor m.read.private make the
# read receipt go up to an older event
channel = self.make_request(
"POST",
f"/rooms/{self.room_id}/receipt/org.matrix.msc2285.read.private/{res1['event_id']}",
f"/rooms/{self.room_id}/receipt/m.read.private/{res1['event_id']}",
{},
access_token=self.tok,
)
Expand Down

0 comments on commit b808bf6

Please sign in to comment.