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

Commit b102118

Browse files
Fix invite notifications for users without pushers (#12840)
Signed-off-by: Nicolas Werner <[email protected]> Co-authored-by: Brendan Abolivier <[email protected]>
1 parent 2480461 commit b102118

File tree

4 files changed

+96
-12
lines changed

4 files changed

+96
-12
lines changed

changelog.d/12840.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix an issue introduced in Synapse 0.34 where the `/notifications` endpoint would only return notifications if a user registered at least one pusher. Contributed by Famedly.

synapse/push/bulk_push_rule_evaluator.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,10 @@ async def _get_rules_for_event(
153153
if event.type == "m.room.member" and event.content["membership"] == "invite":
154154
invited = event.state_key
155155
if invited and self.hs.is_mine_id(invited):
156-
has_pusher = await self.store.user_has_pusher(invited)
157-
if has_pusher:
158-
rules_by_user = dict(rules_by_user)
159-
rules_by_user[invited] = await self.store.get_push_rules_for_user(
160-
invited
161-
)
156+
rules_by_user = dict(rules_by_user)
157+
rules_by_user[invited] = await self.store.get_push_rules_for_user(
158+
invited
159+
)
162160

163161
return rules_by_user
164162

synapse/storage/databases/main/pusher.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,6 @@ def _decode_pushers_rows(self, rows: Iterable[dict]) -> Iterator[PusherConfig]:
9191

9292
yield PusherConfig(**r)
9393

94-
async def user_has_pusher(self, user_id: str) -> bool:
95-
ret = await self.db_pool.simple_select_one_onecol(
96-
"pushers", {"user_name": user_id}, "id", allow_none=True
97-
)
98-
return ret is not None
99-
10094
async def get_pushers_by_app_id_and_pushkey(
10195
self, app_id: str, pushkey: str
10296
) -> Iterator[PusherConfig]:
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Copyright 2022 The Matrix.org Foundation C.I.C.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
from unittest.mock import Mock
15+
16+
from twisted.test.proto_helpers import MemoryReactor
17+
18+
import synapse.rest.admin
19+
from synapse.rest.client import login, notifications, receipts, room
20+
from synapse.server import HomeServer
21+
from synapse.util import Clock
22+
23+
from tests.test_utils import simple_async_mock
24+
from tests.unittest import HomeserverTestCase
25+
26+
27+
class HTTPPusherTests(HomeserverTestCase):
28+
servlets = [
29+
synapse.rest.admin.register_servlets_for_client_rest_resource,
30+
room.register_servlets,
31+
login.register_servlets,
32+
receipts.register_servlets,
33+
notifications.register_servlets,
34+
]
35+
36+
def prepare(
37+
self, reactor: MemoryReactor, clock: Clock, homeserver: HomeServer
38+
) -> None:
39+
self.store = homeserver.get_datastores().main
40+
self.module_api = homeserver.get_module_api()
41+
self.event_creation_handler = homeserver.get_event_creation_handler()
42+
self.sync_handler = homeserver.get_sync_handler()
43+
self.auth_handler = homeserver.get_auth_handler()
44+
45+
def make_homeserver(self, reactor: MemoryReactor, clock: Clock) -> HomeServer:
46+
# Mock out the calls over federation.
47+
fed_transport_client = Mock(spec=["send_transaction"])
48+
fed_transport_client.send_transaction = simple_async_mock({})
49+
50+
return self.setup_test_homeserver(
51+
federation_transport_client=fed_transport_client,
52+
)
53+
54+
def test_notify_for_local_invites(self) -> None:
55+
"""
56+
Local users will get notified for invites
57+
"""
58+
59+
user_id = self.register_user("user", "pass")
60+
access_token = self.login("user", "pass")
61+
other_user_id = self.register_user("otheruser", "pass")
62+
other_access_token = self.login("otheruser", "pass")
63+
64+
# Create a room
65+
room = self.helper.create_room_as(user_id, tok=access_token)
66+
67+
# Check we start with no pushes
68+
channel = self.make_request(
69+
"GET",
70+
"/notifications",
71+
access_token=other_access_token,
72+
)
73+
self.assertEqual(channel.code, 200, channel.result)
74+
self.assertEqual(len(channel.json_body["notifications"]), 0, channel.json_body)
75+
76+
# Send an invite
77+
self.helper.invite(room=room, src=user_id, targ=other_user_id, tok=access_token)
78+
79+
# We should have a notification now
80+
channel = self.make_request(
81+
"GET",
82+
"/notifications",
83+
access_token=other_access_token,
84+
)
85+
self.assertEqual(channel.code, 200)
86+
self.assertEqual(len(channel.json_body["notifications"]), 1, channel.json_body)
87+
self.assertEqual(
88+
channel.json_body["notifications"][0]["event"]["content"]["membership"],
89+
"invite",
90+
channel.json_body,
91+
)

0 commit comments

Comments
 (0)