Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add background update to remove unstable private read receipts #1

Merged
merged 10 commits into from
Jul 29, 2022
1 change: 0 additions & 1 deletion synapse/api/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ class GuestAccess:
class ReceiptTypes:
READ: Final = "m.read"
READ_PRIVATE: Final = "m.read.private"
READ_PRIVATE_UNSTABLE: Final = "org.matrix.msc2285.read.private"
FULLY_READ: Final = "m.fully_read"


Expand Down
17 changes: 5 additions & 12 deletions synapse/handlers/receipts.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,27 +203,20 @@ def filter_out_private_receipts(
for event_id, orig_event_content in room.get("content", {}).items():
event_content = orig_event_content
# If there are private read receipts, additional logic is necessary.
if (
ReceiptTypes.READ_PRIVATE in event_content
or ReceiptTypes.READ_PRIVATE_UNSTABLE in event_content
):
if ReceiptTypes.READ_PRIVATE in event_content:
# Make a copy without private read receipts to avoid leaking
# other user's private read receipts..
event_content = {
receipt_type: receipt_value
for receipt_type, receipt_value in event_content.items()
if receipt_type
not in (
ReceiptTypes.READ_PRIVATE,
ReceiptTypes.READ_PRIVATE_UNSTABLE,
)
if receipt_type != ReceiptTypes.READ_PRIVATE
}

# Copy the current user's private read receipt from the
# original content, if it exists.
user_private_read_receipt = orig_event_content.get(
ReceiptTypes.READ_PRIVATE, {}
).get(user_id, None)
user_private_read_receipt = orig_event_content[
ReceiptTypes.READ_PRIVATE
].get(user_id, None)
if user_private_read_receipt:
event_content[ReceiptTypes.READ_PRIVATE] = {
user_id: user_private_read_receipt
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* Copyright 2022 The Matrix.org Foundation C.I.C
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

DELETE FROM receipts_linearized WHERE receipt_type = 'org.matrix.msc2285.read.private';
DELETE FROM receipts_graph WHERE receipt_type = 'org.matrix.msc2285.read.private';
20 changes: 0 additions & 20 deletions tests/handlers/test_receipts.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,26 +296,6 @@ def test_leaves_our_private_and_their_public(self):
],
)

def test_filters_out_unstable_private_receipt(self):
self._test_filters_private(
[
{
"content": {
"$1435641916114394fHBLK:matrix.org": {
"org.matrix.msc2285.read.private": {
"@rikj:jki.re": {
"ts": 1436451550453,
}
}
}
},
"room_id": "!jEsUZKDJdhlrceRyVU:example.org",
"type": EduTypes.RECEIPT,
}
],
[],
)

def test_we_do_not_mutate(self):
"""Ensure the input values are not modified."""
events = [
Expand Down