From b2288254e47760a83a1e1a6e1ed742272d42c4a0 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 7 Dec 2022 11:36:58 -0700 Subject: [PATCH] Fix appservices taking over devices *with* encryption already created --- src/appservice/Intent.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/appservice/Intent.ts b/src/appservice/Intent.ts index 12f61a33..8890fa2b 100644 --- a/src/appservice/Intent.ts +++ b/src/appservice/Intent.ts @@ -128,8 +128,9 @@ export class Intent { // for devices without keys to impersonate, so it should be fine. In theory, // those devices won't even be present but we're cautious. const devicesWithKeys = Array.from(Object.entries(userDeviceKeys)) - .filter(d => d[0] === d[1].device_id && !!d[1].keys?.[`${DeviceKeyAlgorithm.Curve25519}:${d[1].device_id}`]); - deviceId = devicesWithKeys[0]?.[1]?.device_id; + .filter(d => d[0] === d[1].device_id && !!d[1].keys?.[`${DeviceKeyAlgorithm.Curve25519}:${d[1].device_id}`]) + .map(t => t[0]); // grab device ID from tuple + deviceId = ownDevices.find(d => !devicesWithKeys.includes(d.device_id))?.device_id; } } let prepared = false;