@@ -152,6 +152,16 @@ async def add_pusher(
152
152
)
153
153
)
154
154
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
+
155
165
await self .store .add_pusher (
156
166
user_id = user_id ,
157
167
access_token = access_token ,
@@ -279,6 +289,18 @@ async def on_new_receipts(
279
289
except Exception :
280
290
logger .exception ("Exception in pusher on_new_receipts" )
281
291
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
+
282
304
async def process_pusher_change_by_id (
283
305
self , app_id : str , pushkey : str , user_id : str
284
306
) -> Optional [Pusher ]:
@@ -296,12 +318,9 @@ async def process_pusher_change_by_id(
296
318
if not self ._pusher_shard_config .should_handle (self ._instance_name , user_id ):
297
319
return None
298
320
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
+ )
305
324
306
325
if pusher_config and not pusher_config .enabled :
307
326
self .maybe_stop_pusher (app_id , pushkey , user_id )
0 commit comments