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

Commit 2799644

Browse files
committed
Don't overwrite the access token if we're updating an existing pusher
1 parent 7f19d5b commit 2799644

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

synapse/push/pusherpool.py

+25-6
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,16 @@ async def add_pusher(
152152
)
153153
)
154154

155+
# Before we actually create the pusher, we check if the user already has one for
156+
# this app ID and pushkey. If so, we want to keep the access token in place,
157+
# since this could be one device modifying (e.g. enabling/disabling) another
158+
# device's pusher.
159+
existing_config = await self._get_pusher_config_for_user_by_app_id_and_pushkey(
160+
user_id, app_id, pushkey
161+
)
162+
if existing_config:
163+
access_token = existing_config.access_token
164+
155165
await self.store.add_pusher(
156166
user_id=user_id,
157167
access_token=access_token,
@@ -279,6 +289,18 @@ async def on_new_receipts(
279289
except Exception:
280290
logger.exception("Exception in pusher on_new_receipts")
281291

292+
async def _get_pusher_config_for_user_by_app_id_and_pushkey(
293+
self, user_id: str, app_id: str, pushkey: str
294+
) -> Optional[PusherConfig]:
295+
resultlist = await self.store.get_pushers_by_app_id_and_pushkey(app_id, pushkey)
296+
297+
pusher_config = None
298+
for r in resultlist:
299+
if r.user_name == user_id:
300+
pusher_config = r
301+
302+
return pusher_config
303+
282304
async def process_pusher_change_by_id(
283305
self, app_id: str, pushkey: str, user_id: str
284306
) -> Optional[Pusher]:
@@ -296,12 +318,9 @@ async def process_pusher_change_by_id(
296318
if not self._pusher_shard_config.should_handle(self._instance_name, user_id):
297319
return None
298320

299-
resultlist = await self.store.get_pushers_by_app_id_and_pushkey(app_id, pushkey)
300-
301-
pusher_config = None
302-
for r in resultlist:
303-
if r.user_name == user_id:
304-
pusher_config = r
321+
pusher_config = await self._get_pusher_config_for_user_by_app_id_and_pushkey(
322+
user_id, app_id, pushkey
323+
)
305324

306325
if pusher_config and not pusher_config.enabled:
307326
self.maybe_stop_pusher(app_id, pushkey, user_id)

0 commit comments

Comments
 (0)