From 6a11e480c4148e791f50029d8938c6eb7cd5a5a9 Mon Sep 17 00:00:00 2001 From: manuroe Date: Wed, 27 Nov 2024 21:37:58 +0100 Subject: [PATCH 01/10] MSC4076: Add disable_badge_count to pusher configuration --- synapse/push/httppusher.py | 13 ++- tests/push/test_http.py | 177 +++++++++++++++++++++++++++++++++++++ 2 files changed, 186 insertions(+), 4 deletions(-) diff --git a/synapse/push/httppusher.py b/synapse/push/httppusher.py index dd9b64d6eff..69c1940f698 100644 --- a/synapse/push/httppusher.py +++ b/synapse/push/httppusher.py @@ -127,6 +127,9 @@ def __init__(self, hs: "HomeServer", pusher_config: PusherConfig): if self.data is None: raise PusherConfigException("'data' key can not be null for HTTP pusher") + # Check if badge counts should be disabled for this push gateway + self.disable_badge_count = bool(self.data.get("org.matrix.msc4076.disable_badge_count", False)) + self.name = "%s/%s/%s" % ( pusher_config.user_name, pusher_config.app_id, @@ -461,9 +464,10 @@ async def dispatch_push_event( content: JsonDict = { "event_id": event.event_id, "room_id": event.room_id, - "counts": {"unread": badge}, "prio": priority, } + if not self.disable_badge_count: + content["counts"] = {"unread": badge} # event_id_only doesn't include the tweaks, so override them. tweaks = {} else: @@ -478,11 +482,12 @@ async def dispatch_push_event( "type": event.type, "sender": event.user_id, "prio": priority, - "counts": { + } + if not self.disable_badge_count: + content["counts"] = { "unread": badge, # 'missed_calls': 2 - }, - } + } if event.type == "m.room.member" and event.is_state(): content["membership"] = event.content["membership"] content["user_is_target"] = event.state_key == self.user_id diff --git a/tests/push/test_http.py b/tests/push/test_http.py index bcca472617e..1224dee4c57 100644 --- a/tests/push/test_http.py +++ b/tests/push/test_http.py @@ -1085,3 +1085,180 @@ def test_jitter(self) -> None: self.pump() self.assertEqual(len(self.push_attempts), 11) + + def test_badge_count_disabled(self) -> None: + """ + Test that when disable_badge_count is set to True, the counts field is omitted + from the notification. + """ + # Register the user who gets notified + user_id = self.register_user("user", "pass") + access_token = self.login("user", "pass") + + # Register the user who sends the message + other_user_id = self.register_user("otheruser", "pass") + other_access_token = self.login("otheruser", "pass") + + # Register the pusher with disable_badge_count set to True + user_tuple = self.get_success( + self.hs.get_datastores().main.get_user_by_access_token(access_token) + ) + assert user_tuple is not None + device_id = user_tuple.device_id + + self.get_success( + self.hs.get_pusherpool().add_or_update_pusher( + user_id=user_id, + device_id=device_id, + kind="http", + app_id="m.http", + app_display_name="HTTP Push Notifications", + device_display_name="pushy push", + pushkey="a@example.com", + lang=None, + data={ + "url": "http://example.com/_matrix/push/v1/notify", + "org.matrix.msc4076.disable_badge_count": True, + }, + ) + ) + + # Create a room + room = self.helper.create_room_as(user_id, tok=access_token) + + # The other user joins + self.helper.join(room=room, user=other_user_id, tok=other_access_token) + + # The other user sends a message + self.helper.send(room, body="Hi!", tok=other_access_token) + + # Advance time a bit, so the pusher will register something has happened + self.pump() + + # One push was attempted to be sent + self.assertEqual(len(self.push_attempts), 1) + self.assertEqual( + self.push_attempts[0][1], "http://example.com/_matrix/push/v1/notify" + ) + + # Verify that the notification doesn't contain a counts field + self.assertNotIn("counts", self.push_attempts[0][2]["notification"]) + + def test_badge_count_disabled_event_id_only(self) -> None: + """ + Test that when disable_badge_count is set to True and format is event_id_only, + the counts field is omitted from the notification. + """ + # Register the user who gets notified + user_id = self.register_user("user", "pass") + access_token = self.login("user", "pass") + + # Register the user who sends the message + other_user_id = self.register_user("otheruser", "pass") + other_access_token = self.login("otheruser", "pass") + + # Register the pusher with disable_badge_count set to True and format set to event_id_only + user_tuple = self.get_success( + self.hs.get_datastores().main.get_user_by_access_token(access_token) + ) + assert user_tuple is not None + device_id = user_tuple.device_id + + self.get_success( + self.hs.get_pusherpool().add_or_update_pusher( + user_id=user_id, + device_id=device_id, + kind="http", + app_id="m.http", + app_display_name="HTTP Push Notifications", + device_display_name="pushy push", + pushkey="a@example.com", + lang=None, + data={ + "url": "http://example.com/_matrix/push/v1/notify", + "format": "event_id_only", + "org.matrix.msc4076.disable_badge_count": True, + }, + ) + ) + + # Create a room + room = self.helper.create_room_as(user_id, tok=access_token) + + # The other user joins + self.helper.join(room=room, user=other_user_id, tok=other_access_token) + + # The other user sends a message + self.helper.send(room, body="Hi!", tok=other_access_token) + + # Advance time a bit, so the pusher will register something has happened + self.pump() + + # One push was attempted to be sent + self.assertEqual(len(self.push_attempts), 1) + self.assertEqual( + self.push_attempts[0][1], "http://example.com/_matrix/push/v1/notify" + ) + + # Verify that the notification doesn't contain a counts field + self.assertNotIn("counts", self.push_attempts[0][2]["notification"]) + + def test_badge_count_enabled(self) -> None: + """ + Test that when disable_badge_count is set to False, the counts field is included + in the notification. + """ + # Register the user who gets notified + user_id = self.register_user("user", "pass") + access_token = self.login("user", "pass") + + # Register the user who sends the message + other_user_id = self.register_user("otheruser", "pass") + other_access_token = self.login("otheruser", "pass") + + # Register the pusher with disable_badge_count set to False + user_tuple = self.get_success( + self.hs.get_datastores().main.get_user_by_access_token(access_token) + ) + assert user_tuple is not None + device_id = user_tuple.device_id + + self.get_success( + self.hs.get_pusherpool().add_or_update_pusher( + user_id=user_id, + device_id=device_id, + kind="http", + app_id="m.http", + app_display_name="HTTP Push Notifications", + device_display_name="pushy push", + pushkey="a@example.com", + lang=None, + data={ + "url": "http://example.com/_matrix/push/v1/notify", + }, + ) + ) + + # Create a room + room = self.helper.create_room_as(user_id, tok=access_token) + + # The other user joins + self.helper.join(room=room, user=other_user_id, tok=other_access_token) + + # The other user sends a message + self.helper.send(room, body="Hi!", tok=other_access_token) + + # Advance time a bit, so the pusher will register something has happened + self.pump() + + # One push was attempted to be sent + self.assertEqual(len(self.push_attempts), 1) + self.assertEqual( + self.push_attempts[0][1], "http://example.com/_matrix/push/v1/notify" + ) + + # Verify that the notification contains a counts field + self.assertIn("counts", self.push_attempts[0][2]["notification"]) + self.assertEqual( + self.push_attempts[0][2]["notification"]["counts"]["unread"], 1 + ) From 384be795efdcabdd11c1deb2b0da9bc5474373e1 Mon Sep 17 00:00:00 2001 From: manuroe Date: Fri, 29 Nov 2024 16:22:21 +0100 Subject: [PATCH 02/10] Add the changlog entry --- changelog.d/17975.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/17975.feature diff --git a/changelog.d/17975.feature b/changelog.d/17975.feature new file mode 100644 index 00000000000..e76d2af1c33 --- /dev/null +++ b/changelog.d/17975.feature @@ -0,0 +1 @@ +[MSC4076](https://github.com/matrix-org/matrix-spec-proposals/pull/4076): Add `disable_badge_count` to pusher configuration From d921193b55b2486fc5f21908fce38003febcb599 Mon Sep 17 00:00:00 2001 From: manuroe Date: Fri, 29 Nov 2024 16:27:17 +0100 Subject: [PATCH 03/10] Missed one lint issue --- synapse/push/httppusher.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/synapse/push/httppusher.py b/synapse/push/httppusher.py index 69c1940f698..2177da84c76 100644 --- a/synapse/push/httppusher.py +++ b/synapse/push/httppusher.py @@ -128,7 +128,9 @@ def __init__(self, hs: "HomeServer", pusher_config: PusherConfig): raise PusherConfigException("'data' key can not be null for HTTP pusher") # Check if badge counts should be disabled for this push gateway - self.disable_badge_count = bool(self.data.get("org.matrix.msc4076.disable_badge_count", False)) + self.disable_badge_count = bool( + self.data.get("org.matrix.msc4076.disable_badge_count", False) + ) self.name = "%s/%s/%s" % ( pusher_config.user_name, From de456d0bd71485c87750f33385c59bf50e36f89d Mon Sep 17 00:00:00 2001 From: manuroe Date: Fri, 29 Nov 2024 16:34:11 +0100 Subject: [PATCH 04/10] One more linter pass --- tests/push/test_http.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/push/test_http.py b/tests/push/test_http.py index 1224dee4c57..9d46e5bcf56 100644 --- a/tests/push/test_http.py +++ b/tests/push/test_http.py @@ -1140,7 +1140,7 @@ def test_badge_count_disabled(self) -> None: self.assertEqual( self.push_attempts[0][1], "http://example.com/_matrix/push/v1/notify" ) - + # Verify that the notification doesn't contain a counts field self.assertNotIn("counts", self.push_attempts[0][2]["notification"]) @@ -1199,7 +1199,7 @@ def test_badge_count_disabled_event_id_only(self) -> None: self.assertEqual( self.push_attempts[0][1], "http://example.com/_matrix/push/v1/notify" ) - + # Verify that the notification doesn't contain a counts field self.assertNotIn("counts", self.push_attempts[0][2]["notification"]) @@ -1256,7 +1256,7 @@ def test_badge_count_enabled(self) -> None: self.assertEqual( self.push_attempts[0][1], "http://example.com/_matrix/push/v1/notify" ) - + # Verify that the notification contains a counts field self.assertIn("counts", self.push_attempts[0][2]["notification"]) self.assertEqual( From 2ccf6c7b428c92f9105cfed684918949fed5e5f7 Mon Sep 17 00:00:00 2001 From: manuroe Date: Fri, 29 Nov 2024 16:34:51 +0100 Subject: [PATCH 05/10] Missed a . on the changelog --- changelog.d/17975.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.d/17975.feature b/changelog.d/17975.feature index e76d2af1c33..48f41bddad0 100644 --- a/changelog.d/17975.feature +++ b/changelog.d/17975.feature @@ -1 +1 @@ -[MSC4076](https://github.com/matrix-org/matrix-spec-proposals/pull/4076): Add `disable_badge_count` to pusher configuration +[MSC4076](https://github.com/matrix-org/matrix-spec-proposals/pull/4076): Add `disable_badge_count` to pusher configuration. From 8b1902e216848b28e640fae31b6f480fd7ff298d Mon Sep 17 00:00:00 2001 From: manuroe Date: Tue, 3 Dec 2024 09:21:09 +0100 Subject: [PATCH 06/10] Kill `missed_calls` Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com> --- synapse/push/httppusher.py | 1 - 1 file changed, 1 deletion(-) diff --git a/synapse/push/httppusher.py b/synapse/push/httppusher.py index 2177da84c76..e89d7e57cd8 100644 --- a/synapse/push/httppusher.py +++ b/synapse/push/httppusher.py @@ -488,7 +488,6 @@ async def dispatch_push_event( if not self.disable_badge_count: content["counts"] = { "unread": badge, - # 'missed_calls': 2 } if event.type == "m.room.member" and event.is_state(): content["membership"] = event.content["membership"] From fd65e716894c370dae642863c964ec1cb68e9084 Mon Sep 17 00:00:00 2001 From: manuroe Date: Tue, 3 Dec 2024 15:21:51 +0100 Subject: [PATCH 07/10] Factorise tests into a single testing function using @parameterized --- tests/push/test_http.py | 232 ++++++++++++---------------------------- 1 file changed, 66 insertions(+), 166 deletions(-) diff --git a/tests/push/test_http.py b/tests/push/test_http.py index 9d46e5bcf56..423fd43eeec 100644 --- a/tests/push/test_http.py +++ b/tests/push/test_http.py @@ -20,6 +20,8 @@ from typing import Any, List, Tuple from unittest.mock import Mock +from parameterized import parameterized + from twisted.internet.defer import Deferred from twisted.test.proto_helpers import MemoryReactor @@ -1086,179 +1088,77 @@ def test_jitter(self) -> None: self.assertEqual(len(self.push_attempts), 11) - def test_badge_count_disabled(self) -> None: - """ - Test that when disable_badge_count is set to True, the counts field is omitted - from the notification. - """ - # Register the user who gets notified - user_id = self.register_user("user", "pass") - access_token = self.login("user", "pass") - - # Register the user who sends the message - other_user_id = self.register_user("otheruser", "pass") - other_access_token = self.login("otheruser", "pass") - - # Register the pusher with disable_badge_count set to True - user_tuple = self.get_success( - self.hs.get_datastores().main.get_user_by_access_token(access_token) - ) - assert user_tuple is not None - device_id = user_tuple.device_id - - self.get_success( - self.hs.get_pusherpool().add_or_update_pusher( - user_id=user_id, - device_id=device_id, - kind="http", - app_id="m.http", - app_display_name="HTTP Push Notifications", - device_display_name="pushy push", - pushkey="a@example.com", - lang=None, - data={ - "url": "http://example.com/_matrix/push/v1/notify", - "org.matrix.msc4076.disable_badge_count": True, - }, + @parameterized.expand([ + # Badge count disabled + (True, True), + (True, False), + # Badge count enabled + (False, True), + (False, False), + ]) + def test_msc4076_badge_count(self, disable_badge_count: bool, event_id_only: bool) -> None: + # Register the user who gets notified + user_id = self.register_user("user", "pass") + access_token = self.login("user", "pass") + + # Register the user who sends the message + other_user_id = self.register_user("otheruser", "pass") + other_access_token = self.login("otheruser", "pass") + + # Register the pusher with disable_badge_count set to True + user_tuple = self.get_success( + self.hs.get_datastores().main.get_user_by_access_token(access_token) ) - ) - - # Create a room - room = self.helper.create_room_as(user_id, tok=access_token) - - # The other user joins - self.helper.join(room=room, user=other_user_id, tok=other_access_token) - - # The other user sends a message - self.helper.send(room, body="Hi!", tok=other_access_token) + assert user_tuple is not None + device_id = user_tuple.device_id + + # Set the push data dict based on test input parameters + push_data = { + "url": "http://example.com/_matrix/push/v1/notify", + } + if disable_badge_count: + push_data["org.matrix.msc4076.disable_badge_count"] = True + if event_id_only: + push_data["format"] = "event_id_only" - # Advance time a bit, so the pusher will register something has happened - self.pump() - - # One push was attempted to be sent - self.assertEqual(len(self.push_attempts), 1) - self.assertEqual( - self.push_attempts[0][1], "http://example.com/_matrix/push/v1/notify" - ) - - # Verify that the notification doesn't contain a counts field - self.assertNotIn("counts", self.push_attempts[0][2]["notification"]) - - def test_badge_count_disabled_event_id_only(self) -> None: - """ - Test that when disable_badge_count is set to True and format is event_id_only, - the counts field is omitted from the notification. - """ - # Register the user who gets notified - user_id = self.register_user("user", "pass") - access_token = self.login("user", "pass") - - # Register the user who sends the message - other_user_id = self.register_user("otheruser", "pass") - other_access_token = self.login("otheruser", "pass") - - # Register the pusher with disable_badge_count set to True and format set to event_id_only - user_tuple = self.get_success( - self.hs.get_datastores().main.get_user_by_access_token(access_token) - ) - assert user_tuple is not None - device_id = user_tuple.device_id - - self.get_success( - self.hs.get_pusherpool().add_or_update_pusher( - user_id=user_id, - device_id=device_id, - kind="http", - app_id="m.http", - app_display_name="HTTP Push Notifications", - device_display_name="pushy push", - pushkey="a@example.com", - lang=None, - data={ - "url": "http://example.com/_matrix/push/v1/notify", - "format": "event_id_only", - "org.matrix.msc4076.disable_badge_count": True, - }, + self.get_success( + self.hs.get_pusherpool().add_or_update_pusher( + user_id=user_id, + device_id=device_id, + kind="http", + app_id="m.http", + app_display_name="HTTP Push Notifications", + device_display_name="pushy push", + pushkey="a@example.com", + lang=None, + data=push_data, + ) ) - ) - - # Create a room - room = self.helper.create_room_as(user_id, tok=access_token) - - # The other user joins - self.helper.join(room=room, user=other_user_id, tok=other_access_token) - - # The other user sends a message - self.helper.send(room, body="Hi!", tok=other_access_token) - - # Advance time a bit, so the pusher will register something has happened - self.pump() - - # One push was attempted to be sent - self.assertEqual(len(self.push_attempts), 1) - self.assertEqual( - self.push_attempts[0][1], "http://example.com/_matrix/push/v1/notify" - ) - # Verify that the notification doesn't contain a counts field - self.assertNotIn("counts", self.push_attempts[0][2]["notification"]) + # Create a room + room = self.helper.create_room_as(user_id, tok=access_token) - def test_badge_count_enabled(self) -> None: - """ - Test that when disable_badge_count is set to False, the counts field is included - in the notification. - """ - # Register the user who gets notified - user_id = self.register_user("user", "pass") - access_token = self.login("user", "pass") + # The other user joins + self.helper.join(room=room, user=other_user_id, tok=other_access_token) - # Register the user who sends the message - other_user_id = self.register_user("otheruser", "pass") - other_access_token = self.login("otheruser", "pass") + # The other user sends a message + self.helper.send(room, body="Hi!", tok=other_access_token) - # Register the pusher with disable_badge_count set to False - user_tuple = self.get_success( - self.hs.get_datastores().main.get_user_by_access_token(access_token) - ) - assert user_tuple is not None - device_id = user_tuple.device_id + # Advance time a bit, so the pusher will register something has happened + self.pump() - self.get_success( - self.hs.get_pusherpool().add_or_update_pusher( - user_id=user_id, - device_id=device_id, - kind="http", - app_id="m.http", - app_display_name="HTTP Push Notifications", - device_display_name="pushy push", - pushkey="a@example.com", - lang=None, - data={ - "url": "http://example.com/_matrix/push/v1/notify", - }, + # One push was attempted to be sent + self.assertEqual(len(self.push_attempts), 1) + self.assertEqual( + self.push_attempts[0][1], "http://example.com/_matrix/push/v1/notify" ) - ) - # Create a room - room = self.helper.create_room_as(user_id, tok=access_token) - - # The other user joins - self.helper.join(room=room, user=other_user_id, tok=other_access_token) - - # The other user sends a message - self.helper.send(room, body="Hi!", tok=other_access_token) - - # Advance time a bit, so the pusher will register something has happened - self.pump() - - # One push was attempted to be sent - self.assertEqual(len(self.push_attempts), 1) - self.assertEqual( - self.push_attempts[0][1], "http://example.com/_matrix/push/v1/notify" - ) - - # Verify that the notification contains a counts field - self.assertIn("counts", self.push_attempts[0][2]["notification"]) - self.assertEqual( - self.push_attempts[0][2]["notification"]["counts"]["unread"], 1 - ) + if disable_badge_count: + # Verify that the notification DOESN'T contain a counts field + self.assertNotIn("counts", self.push_attempts[0][2]["notification"]) + else: + # Ensure that the notification DOES contain a counts field + self.assertIn("counts", self.push_attempts[0][2]["notification"]) + self.assertEqual( + self.push_attempts[0][2]["notification"]["counts"]["unread"], 1 + ) From ae2a3aca6af1d822aff8d6432752119cb7d26d93 Mon Sep 17 00:00:00 2001 From: manuroe Date: Tue, 3 Dec 2024 15:31:54 +0100 Subject: [PATCH 08/10] Fix lint issue --- tests/push/test_http.py | 110 ++++++++++++++++++++-------------------- 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/tests/push/test_http.py b/tests/push/test_http.py index 423fd43eeec..384f5ada5e4 100644 --- a/tests/push/test_http.py +++ b/tests/push/test_http.py @@ -17,7 +17,7 @@ # [This file includes modifications made by New Vector Limited] # # -from typing import Any, List, Tuple +from typing import Any, Dict, List, Tuple from unittest.mock import Mock from parameterized import parameterized @@ -1097,68 +1097,68 @@ def test_jitter(self) -> None: (False, False), ]) def test_msc4076_badge_count(self, disable_badge_count: bool, event_id_only: bool) -> None: - # Register the user who gets notified - user_id = self.register_user("user", "pass") - access_token = self.login("user", "pass") + # Register the user who gets notified + user_id = self.register_user("user", "pass") + access_token = self.login("user", "pass") - # Register the user who sends the message - other_user_id = self.register_user("otheruser", "pass") - other_access_token = self.login("otheruser", "pass") + # Register the user who sends the message + other_user_id = self.register_user("otheruser", "pass") + other_access_token = self.login("otheruser", "pass") - # Register the pusher with disable_badge_count set to True - user_tuple = self.get_success( - self.hs.get_datastores().main.get_user_by_access_token(access_token) - ) - assert user_tuple is not None - device_id = user_tuple.device_id - - # Set the push data dict based on test input parameters - push_data = { - "url": "http://example.com/_matrix/push/v1/notify", - } - if disable_badge_count: - push_data["org.matrix.msc4076.disable_badge_count"] = True - if event_id_only: - push_data["format"] = "event_id_only" + # Register the pusher with disable_badge_count set to True + user_tuple = self.get_success( + self.hs.get_datastores().main.get_user_by_access_token(access_token) + ) + assert user_tuple is not None + device_id = user_tuple.device_id - self.get_success( - self.hs.get_pusherpool().add_or_update_pusher( - user_id=user_id, - device_id=device_id, - kind="http", - app_id="m.http", - app_display_name="HTTP Push Notifications", - device_display_name="pushy push", - pushkey="a@example.com", - lang=None, - data=push_data, - ) + # Set the push data dict based on test input parameters + push_data: Dict[str, Any] = { + "url": "http://example.com/_matrix/push/v1/notify", + } + if disable_badge_count: + push_data["org.matrix.msc4076.disable_badge_count"] = True + if event_id_only: + push_data["format"] = "event_id_only" + + self.get_success( + self.hs.get_pusherpool().add_or_update_pusher( + user_id=user_id, + device_id=device_id, + kind="http", + app_id="m.http", + app_display_name="HTTP Push Notifications", + device_display_name="pushy push", + pushkey="a@example.com", + lang=None, + data=push_data, ) + ) - # Create a room - room = self.helper.create_room_as(user_id, tok=access_token) + # Create a room + room = self.helper.create_room_as(user_id, tok=access_token) - # The other user joins - self.helper.join(room=room, user=other_user_id, tok=other_access_token) + # The other user joins + self.helper.join(room=room, user=other_user_id, tok=other_access_token) - # The other user sends a message - self.helper.send(room, body="Hi!", tok=other_access_token) + # The other user sends a message + self.helper.send(room, body="Hi!", tok=other_access_token) - # Advance time a bit, so the pusher will register something has happened - self.pump() + # Advance time a bit, so the pusher will register something has happened + self.pump() - # One push was attempted to be sent - self.assertEqual(len(self.push_attempts), 1) + # One push was attempted to be sent + self.assertEqual(len(self.push_attempts), 1) + self.assertEqual( + self.push_attempts[0][1], "http://example.com/_matrix/push/v1/notify" + ) + + if disable_badge_count: + # Verify that the notification DOESN'T contain a counts field + self.assertNotIn("counts", self.push_attempts[0][2]["notification"]) + else: + # Ensure that the notification DOES contain a counts field + self.assertIn("counts", self.push_attempts[0][2]["notification"]) self.assertEqual( - self.push_attempts[0][1], "http://example.com/_matrix/push/v1/notify" + self.push_attempts[0][2]["notification"]["counts"]["unread"], 1 ) - - if disable_badge_count: - # Verify that the notification DOESN'T contain a counts field - self.assertNotIn("counts", self.push_attempts[0][2]["notification"]) - else: - # Ensure that the notification DOES contain a counts field - self.assertIn("counts", self.push_attempts[0][2]["notification"]) - self.assertEqual( - self.push_attempts[0][2]["notification"]["counts"]["unread"], 1 - ) From cdd20197e88bb78bcc98d8057b252dc1f061d53f Mon Sep 17 00:00:00 2001 From: manuroe Date: Tue, 3 Dec 2024 15:51:22 +0100 Subject: [PATCH 09/10] more lint fun --- tests/push/test_http.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/tests/push/test_http.py b/tests/push/test_http.py index 384f5ada5e4..3472ecd92f4 100644 --- a/tests/push/test_http.py +++ b/tests/push/test_http.py @@ -1088,15 +1088,19 @@ def test_jitter(self) -> None: self.assertEqual(len(self.push_attempts), 11) - @parameterized.expand([ - # Badge count disabled - (True, True), - (True, False), - # Badge count enabled - (False, True), - (False, False), - ]) - def test_msc4076_badge_count(self, disable_badge_count: bool, event_id_only: bool) -> None: + @parameterized.expand( + [ + # Badge count disabled + (True, True), + (True, False), + # Badge count enabled + (False, True), + (False, False), + ] + ) + def test_msc4076_badge_count( + self, disable_badge_count: bool, event_id_only: bool + ) -> None: # Register the user who gets notified user_id = self.register_user("user", "pass") access_token = self.login("user", "pass") From 30694c2bbeb6e072df963ea394c7cc4114828900 Mon Sep 17 00:00:00 2001 From: manuroe Date: Tue, 3 Dec 2024 17:41:20 +0100 Subject: [PATCH 10/10] Use an experimental feature flag: `msc4076_enabled` --- synapse/config/experimental.py | 3 +++ synapse/push/httppusher.py | 2 +- tests/push/test_http.py | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/synapse/config/experimental.py b/synapse/config/experimental.py index 3411179a2a3..57ac27697f4 100644 --- a/synapse/config/experimental.py +++ b/synapse/config/experimental.py @@ -448,3 +448,6 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None: # MSC4222: Adding `state_after` to sync v2 self.msc4222_enabled: bool = experimental.get("msc4222_enabled", False) + + # MSC4076: Add `disable_badge_count`` to pusher configuration + self.msc4076_enabled: bool = experimental.get("msc4076_enabled", False) diff --git a/synapse/push/httppusher.py b/synapse/push/httppusher.py index e89d7e57cd8..69790ecab54 100644 --- a/synapse/push/httppusher.py +++ b/synapse/push/httppusher.py @@ -128,7 +128,7 @@ def __init__(self, hs: "HomeServer", pusher_config: PusherConfig): raise PusherConfigException("'data' key can not be null for HTTP pusher") # Check if badge counts should be disabled for this push gateway - self.disable_badge_count = bool( + self.disable_badge_count = self.hs.config.experimental.msc4076_enabled and bool( self.data.get("org.matrix.msc4076.disable_badge_count", False) ) diff --git a/tests/push/test_http.py b/tests/push/test_http.py index 3472ecd92f4..5c235bbe536 100644 --- a/tests/push/test_http.py +++ b/tests/push/test_http.py @@ -1098,6 +1098,7 @@ def test_jitter(self) -> None: (False, False), ] ) + @override_config({"experimental_features": {"msc4076_enabled": True}}) def test_msc4076_badge_count( self, disable_badge_count: bool, event_id_only: bool ) -> None: